Justice Guard
This commit is contained in:
parent
12589a7452
commit
a16f5bb56e
3 changed files with 46 additions and 4 deletions
|
|
@ -21,9 +21,11 @@ export default class PlayScene extends Phaser.Scene {
|
||||||
|
|
||||||
if (window.myStuff.token) {
|
if (window.myStuff.token) {
|
||||||
const response = await API.record(pts, shts, time)
|
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)
|
this.add.image(250, 550, 'phaser-logo').setScale(0.5)
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,19 @@ class Database {
|
||||||
|
|
||||||
return 0
|
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
|
export default new Database
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,35 @@
|
||||||
|
|
||||||
|
import db from './Database.js'
|
||||||
|
|
||||||
export default function (req, res, next) {
|
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()
|
next()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue