space-smasher-9001/server/JusticeGuard.js

47 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2021-10-17 23:00:29 +02:00
2021-10-18 01:53:50 +02:00
import db from './Database.js'
2021-10-17 23:00:29 +02:00
export default function (req, res, next) {
2021-10-18 02:33:29 +02:00
if (!process.env.enableJusticeGuard) {
return next()
}
2021-10-18 01:53:50 +02:00
const { points, shoots, time } = req.body
if (points > shoots)
return res.status(400).json({
2021-10-18 02:33:29 +02:00
error: "Stop that, Rule #1",
2021-10-18 01:53:50 +02:00
})
//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({
2021-10-18 02:33:29 +02:00
error: "Stop that, Rule #4"
2021-10-18 01:53:50 +02:00
})
//ship can shoot only 5 shoots per second
//and one bullet is worth max 1 point
2021-10-18 02:33:29 +02:00
const maxPossiblePointsByTime = time * 5
if (points > maxPossiblePointsByTime)
2021-10-18 01:53:50 +02:00
return res.status(400).json({
2021-10-18 02:33:29 +02:00
error: "Stop that, Rule #9" //yeah, greater numbers will scare hacker
2021-10-18 01:53:50 +02:00
})
2021-10-18 02:33:29 +02:00
//nobody will play for over an hour, I assure you
if (time > 60 * 60)
2021-10-18 01:53:50 +02:00
return res.status(400).json({
2021-10-18 02:33:29 +02:00
error: "Stop that, Rule #13"
2021-10-18 01:53:50 +02:00
})
2021-10-17 23:00:29 +02:00
2021-10-18 02:33:29 +02:00
//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"
})
2021-10-17 23:00:29 +02:00
2021-10-18 02:33:29 +02:00
return next()
2021-10-17 23:00:29 +02:00
}