diff --git a/.env b/.env new file mode 100644 index 0000000..5a1a22b --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +ACTUAL_ENV=dev +DB_USER=root +DB_PASSWORD=password +DB_NAME=battleship +DB_HOST=localhost +COOKIE_SECRET_KEY=secret_key diff --git a/.gitignore b/.gitignore index 6597792..dc2aa9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ node_modules/ .vscode/ -.env nginx.conf nginx/ secrets/ diff --git a/README.md b/README.md index 10a74f2..8a7031b 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ To use maettleship you'll need the following app on your computer * node js and npm * mysql +* docker # Installation @@ -45,12 +46,12 @@ touch .env The .env file should look like that ``` -ACTUAL_ENV=dev +echo "ACTUAL_ENV=dev DB_USER=root DB_PASSWORD=password DB_NAME=battleship DB_HOST=localhost -COOKIE_SECRET_KEY=secret_key +COOKIE_SECRET_KEY=secret_key" > .env ``` You can use the env file as it is in my example but if you want make it yours just don't forget to have the same variable in your env file that in you mysql config. diff --git a/database.js b/database.js index 9effe5a..f84b098 100644 --- a/database.js +++ b/database.js @@ -10,15 +10,15 @@ try { db_user = process.env.DB_USER db_user_password = process.env.DB_PASSWORD } else { - const db_user_password = fs.readFileSync(process.env.DB_USER_PASSWORD_FILE, 'utf8').replace(/\r?\n|\r/g, ""); - const db_user = fs.readFileSync(process.env.DB_USER_FILE, 'utf8').replace(/\r?\n|\r/g, ""); + db_user_password = fs.readFileSync(process.env.DB_USER_PASSWORD_FILE, 'utf8').replace(/\r?\n|\r/g, ""); + db_user = fs.readFileSync(process.env.DB_USER_FILE, 'utf8').replace(/\r?\n|\r/g, ""); } const connection = mysql.createPool({ - host: process.env.DB_HOST, - user: db_user, + host: process.env.DB_HOST, + user: db_user, password: db_user_password, - database: process.env.DB_NAME, + database: process.env.DB_NAME, }); module.exports = connection; diff --git a/index.js b/index.js index 6ea5d45..57242e8 100644 --- a/index.js +++ b/index.js @@ -25,6 +25,10 @@ app.get('/', (req, res) => { return res.sendFile(path.normalize(path.join(__dirname, '/public/pages/connectionView.html'))) }) +app.get('/scoreboard', (req, res) => { + return res.sendFile(path.normalize(path.join(__dirname, 'public/pages/scoreboardView.html'))) +}) + app.get('/register', (req, res) => { return res.sendFile(path.normalize(path.join(__dirname, '/public/pages/signupView.html'))) }) @@ -201,8 +205,9 @@ io.on("connection", (socket) => { socket.on("first connection", (socketId) => { const cookies = socket.request.headers.cookie; - const authToken = cookies.split('; ').find(cookie => cookie.startsWith('authToken=')).split('=')[1]; + if (!cookies) return + const authToken = cookies.split('; ').find(cookie => cookie.startsWith('authToken=')).split('=')[1]; if (authToken) { try { const decoded = jwt.verify(authToken, secretKey); diff --git a/public/assets/styles/background.css b/public/assets/styles/background.css new file mode 100644 index 0000000..b1f6d17 --- /dev/null +++ b/public/assets/styles/background.css @@ -0,0 +1,6 @@ +body{ + background-image: url("../images/background.jpeg"); + background-position: center; + background-repeat: no-repeat; + background-size: cover; +} \ No newline at end of file diff --git a/public/assets/styles/global.css b/public/assets/styles/global.css index 4c7d430..4895fea 100644 --- a/public/assets/styles/global.css +++ b/public/assets/styles/global.css @@ -10,10 +10,6 @@ html, body{ background-color: #ffffff; - background-image: url("../images/background.jpeg"); - background-position: center; - background-repeat: no-repeat; - background-size: cover; margin: 0; height: 100%; overflow: hidden; diff --git a/public/assets/styles/style.css b/public/assets/styles/style.css index 42065a0..049366b 100644 --- a/public/assets/styles/style.css +++ b/public/assets/styles/style.css @@ -52,6 +52,6 @@ .board-container { display: flex; align-items: center; - justify-content: column; - justify-content: space-evenly; + justify-content: center; + gap: 1rem; } \ No newline at end of file diff --git a/public/pages/connectionView.html b/public/pages/connectionView.html index 50f0e76..ed7cfb9 100644 --- a/public/pages/connectionView.html +++ b/public/pages/connectionView.html @@ -5,6 +5,7 @@ + Maettleship diff --git a/public/pages/gameView.html b/public/pages/gameView.html index e29241d..e3de987 100644 --- a/public/pages/gameView.html +++ b/public/pages/gameView.html @@ -85,6 +85,10 @@

+ + see scorebaord + +
diff --git a/public/pages/scoreboardView.html b/public/pages/scoreboardView.html new file mode 100644 index 0000000..152bdf0 --- /dev/null +++ b/public/pages/scoreboardView.html @@ -0,0 +1,13 @@ + + + + + + Scores ! + + + + keyboard_double_arrow_right + + + \ No newline at end of file diff --git a/public/pages/signupView.html b/public/pages/signupView.html index 4258217..75052ea 100644 --- a/public/pages/signupView.html +++ b/public/pages/signupView.html @@ -5,6 +5,7 @@ Maettleship + diff --git a/public/scripts/app.js b/public/scripts/app.js index 8aad78b..be8dd6f 100644 --- a/public/scripts/app.js +++ b/public/scripts/app.js @@ -266,4 +266,4 @@ document.getElementById('rematchButton').addEventListener('click', () => { handleError() } }) -}) \ No newline at end of file +}) diff --git a/tools/db_auto_save.sh b/tools/db_auto_save.sh new file mode 100755 index 0000000..88892db --- /dev/null +++ b/tools/db_auto_save.sh @@ -0,0 +1,17 @@ +#!/bin/bash +source .env + +TIMESTAMP=$(date +"%F") +BACKUP_DIR="../maettleship_save" +mkdir -p "$BACKUP_DIR/$TIMESTAMP" + +if [ $ACTUAL_ENV = 'dev' ]; then + docker exec -i mysql-maettleship mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME > "$BACKUP_DIR/$TIMESTAMP/$DB_NAME.sql" +else + db_user_file=$(cat ./secrets/db_user.txt) + db_password_file=$(cat ./secrets/db_password.txt) + db_name_file=$(cat ./secrets/db_name.txt) + docker exec -i mysql-maettleship mysqldump -u $db_user_file -p$db_password_file $db_name_file > "$BACKUP_DIR/$TIMESTAMP/$db_name_file.sql" +fi + +find "$BACKUP_DIR/" -type d -mtime +7 -exec rm -rf {} \; \ No newline at end of file