diff --git a/game/src/scenes/GameOverScene.ts b/game/src/scenes/GameOverScene.ts index 8c40e1f..fb7b047 100644 --- a/game/src/scenes/GameOverScene.ts +++ b/game/src/scenes/GameOverScene.ts @@ -21,9 +21,11 @@ export default class PlayScene extends Phaser.Scene { if (window.myStuff.token) { const response = await API.record(pts, shts, time) - rank = response.rank - await window.updateTopList() + if (response.rank) { + rank = response.rank + await window.updateTopList() + } } this.add.image(250, 550, 'phaser-logo').setScale(0.5) diff --git a/server/Database.js b/server/Database.js index 64fae38..f010544 100644 --- a/server/Database.js +++ b/server/Database.js @@ -61,6 +61,19 @@ class Database { return 0 } + + foreseeRank(record) { + const users = this.db.data.users + .filter(user => user.record) + .sort((a, b) => a.record > b.record ? -1 : 1) + + for (let i = 0; i < users.length; ++i) { + if (users[i].record < record) + return i + 1 + } + + return 0 + } } export default new Database diff --git a/server/JusticeGuard.js b/server/JusticeGuard.js index 6c5e79e..5703786 100644 --- a/server/JusticeGuard.js +++ b/server/JusticeGuard.js @@ -1,8 +1,35 @@ +import db from './Database.js' + export default function (req, res, next) { - //available keys 'points', 'shoots', 'time' + const { points, shoots, time } = req.body + + if (points > shoots) + return res.status(400).json({ + error: "Stop that" + }) + + //FIXES https://discord.com/channels/762566311930101761/892788974647656500/893963260045455410 + const foreseeRank = db.foreseeRank(req.body.points) + if (foreseeRank == 1 && req.user.name == 'mw') + return res.status(400).json({ + error: "Stop that" + }) + + //ship can shoot only 5 shoots per second + //and one bullet is worth max 1 point + const maxPossiblePointsByTime = time * 0.2 + if (points >= maxPossiblePointsByTime) + return res.status(400).json({ + error: "Stop that" + }) + + //nobody will play for over hour, I assure you + if (time > 1000 * 60 * 60) + return res.status(400).json({ + error: "Stop that" + }) - //TODO: do some checks next() }