expand Justice

This commit is contained in:
KGrzeg 2021-10-18 02:33:29 +02:00
parent a16f5bb56e
commit e244da0942
8 changed files with 69 additions and 13 deletions

View file

@ -2,34 +2,45 @@
import db from './Database.js'
export default function (req, res, next) {
if (!process.env.enableJusticeGuard) {
return next()
}
const { points, shoots, time } = req.body
if (points > shoots)
return res.status(400).json({
error: "Stop that"
error: "Stop that, Rule #1",
})
//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"
error: "Stop that, Rule #4"
})
//ship can shoot only 5 shoots per second
//and one bullet is worth max 1 point
const maxPossiblePointsByTime = time * 0.2
if (points >= maxPossiblePointsByTime)
const maxPossiblePointsByTime = time * 5
if (points > maxPossiblePointsByTime)
return res.status(400).json({
error: "Stop that"
error: "Stop that, Rule #9" //yeah, greater numbers will scare hacker
})
//nobody will play for over hour, I assure you
if (time > 1000 * 60 * 60)
//nobody will play for over an hour, I assure you
if (time > 60 * 60)
return res.status(400).json({
error: "Stop that"
error: "Stop that, Rule #13"
})
//try to detect time manipulation
const startTimeOnServer = db.getLastPlayed(req.user.name)
const elapsedTimeOnServer = (Date.now() - startTimeOnServer) / 1000
if (elapsedTimeOnServer * 1.2 < time)
return res.status(400).json({
error: "Stop that, Rule #19"
})
next()
return next()
}