diff --git a/index.js b/index.js index c64a3da..2a6c1c4 100644 --- a/index.js +++ b/index.js @@ -283,24 +283,44 @@ app.post('/api/nickname', (req, res) => { app.get('/game', async (req, res) => { - const locale = new Lang(req.acceptsLanguages()); - const game = await redis.json.get(`game:${req.query.id}`); if (req.session.nickname == null) { res.redirect('/setup'); } else if (req.query.id == null || game == null || game.state == 'expired' || req.session.activeGame == null) { - res.render("error", { - helpers: { - error: "Nie znaleziono wskazanej gry", - fallback: "/", - t: (key) => { return locale.t(key) } + auth.getLanguage(req.session.userId).then(language => { + var locale; + if (language) { + locale = new Lang([language]); + req.session.langs = [language]; + } else { + locale = new Lang(req.acceptsLanguages()); + req.session.langs = req.acceptsLanguages(); } + + res.render("error", { + helpers: { + error: "Nie znaleziono wskazanej gry", + fallback: "/", + t: (key) => { return locale.t(key) } + } + }); }); } else { - res.render('board', { - helpers: { - t: (key) => { return locale.t(key) } + auth.getLanguage(req.session.userId).then(language => { + var locale; + if (language) { + locale = new Lang([language]); + req.session.langs = [language]; + } else { + locale = new Lang(req.acceptsLanguages()); + req.session.langs = req.acceptsLanguages(); } + + res.render('board', { + helpers: { + t: (key) => { return locale.t(key) } + } + }); }); } }); diff --git a/public/assets/css/board-responsive.css b/public/assets/css/board-responsive.css index 4c71f53..81190f8 100644 --- a/public/assets/css/board-responsive.css +++ b/public/assets/css/board-responsive.css @@ -36,5 +36,9 @@ body { overflow-x: hidden; } + + .secondary { + transform: scale(0); + } } diff --git a/public/assets/js/socket-game.js b/public/assets/js/socket-game.js index 0c9f5cb..fd6d0a0 100644 --- a/public/assets/js/socket-game.js +++ b/public/assets/js/socket-game.js @@ -45,6 +45,8 @@ $('#board .field').on('click', function () { }); function manualPlace(posX, posY) { + hoveredShip = null; + refreshBoardView(); socket.emit("place ship", selectedShip, posX, posY, shipRotation); } @@ -57,6 +59,10 @@ $('#secondaryBoard .field').on('click', function () { } }); +function manualShoot(posX, posY) { + socket.emit("shoot", posX, posY); +} + $('.field').on('contextmenu', function () { if ($(this).hasClass('active') && new Date().getTime() / 1000 - lastTimeClick > 0.3) { let originPos = occupiedFields.find((elem) => elem.pos[0] == $(this).data('pos-x') && elem.pos[1] == $(this).data('pos-y')).origin; diff --git a/utils/auth.js b/utils/auth.js index ecd6d44..d84aaa5 100644 --- a/utils/auth.js +++ b/utils/auth.js @@ -136,12 +136,16 @@ export class MailAuth { authCode = authCode.slice(0, 4) + " " + authCode.slice(4); + const lookup = geoip.lookup(ip); + + const lookupData = `User-Agent: ${agent}\nAdres IP: ${ip}\nKraj: ${lookup.country}\nRegion: ${lookup.region}\nMiasto: ${lookup.city}`; + try { await this.mail.sendMail({ from: this.mailFrom, to: email, subject: `${authCode} to twój kod autoryzacji do Statków`, - html: html.replace("{{ CODE }}", authCode), + html: html.replace("{{ CODE }}", authCode).replace("{{ LOOKUP }}", lookupData), }); } catch (e) { reject(e); @@ -168,14 +172,19 @@ export class MailAuth { const lookup = geoip.lookup(ip); - const lookupData = `User-Agent: ${agent}\nAdres IP: ${ip}\nKraj: ${lookup.country}\nRegion: ${lookup.region}\nMiasto: ${lookup.city}` + const lookupData = `User-Agent: ${agent}\nAdres IP: ${ip}\nKraj: ${lookup.country}\nRegion: ${lookup.region}\nMiasto: ${lookup.city}`; - await this.mail.sendMail({ - from: this.mailFrom, - to: email, - subject: `${authCode} to twój kod logowania do Statków`, - html: html.replace("{{ NICKNAME }}", row.nickname).replace("{{ CODE }}", authCode).replace("{{ LOOKUP }}", lookupData), - }); + try { + await this.mail.sendMail({ + from: this.mailFrom, + to: email, + subject: `${authCode} to twój kod logowania do Statków`, + html: html.replace("{{ NICKNAME }}", row.nickname).replace("{{ CODE }}", authCode).replace("{{ LOOKUP }}", lookupData), + }); + } catch (e) { + reject(e); + } + resolve({ status: 1, uid: row.user_id }); });