expand Justice
This commit is contained in:
parent
a16f5bb56e
commit
e244da0942
8 changed files with 69 additions and 13 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
const baseApiPath = "http://localhost:3000"
|
const baseApiPath = "http://localhost:3000"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
@ -70,5 +69,9 @@ export default {
|
||||||
|
|
||||||
async top() {
|
async top() {
|
||||||
return this.get("top")
|
return this.get("top")
|
||||||
|
},
|
||||||
|
|
||||||
|
async start() {
|
||||||
|
return this.get("start")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@ 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)
|
||||||
|
|
||||||
|
if (response.error) {
|
||||||
|
console.log("%c" + response.error, "color:red")
|
||||||
|
}
|
||||||
|
|
||||||
if (response.rank) {
|
if (response.rank) {
|
||||||
rank = response.rank
|
rank = response.rank
|
||||||
await window.updateTopList()
|
await window.updateTopList()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import Phaser from 'phaser'
|
import Phaser from 'phaser'
|
||||||
|
import API from "../api"
|
||||||
|
|
||||||
export default class StartScene extends Phaser.Scene {
|
export default class StartScene extends Phaser.Scene {
|
||||||
|
|
||||||
|
|
@ -42,8 +43,15 @@ export default class StartScene extends Phaser.Scene {
|
||||||
color: 'yellow'
|
color: 'yellow'
|
||||||
}).setOrigin(0.5, 0.5)
|
}).setOrigin(0.5, 0.5)
|
||||||
|
|
||||||
this.input.on('pointerup', () => {
|
this.input.on('pointerup', async () => {
|
||||||
window.freezeGui()
|
window.freezeGui()
|
||||||
|
if (window.myStuff.token) {
|
||||||
|
try {
|
||||||
|
await API.start()
|
||||||
|
} catch (error) {
|
||||||
|
console.log("oops", error)
|
||||||
|
}
|
||||||
|
}
|
||||||
this.scene.start('play-scene');
|
this.scene.start('play-scene');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
secret = oIMzR4YvM9x9NoPrQfk4
|
secret = oIMzR4YvM9x9NoPrQfk4
|
||||||
|
enableJusticeGuard = 1
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ export default {
|
||||||
name,
|
name,
|
||||||
password: password,
|
password: password,
|
||||||
record: 0,
|
record: 0,
|
||||||
|
lastPlayed: 0,
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -32,7 +33,7 @@ export default {
|
||||||
token
|
token
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
login(password) {
|
login(password) {
|
||||||
console.log("Logging user");
|
console.log("Logging user");
|
||||||
const user = db.getUserByPassword(password)
|
const user = db.getUserByPassword(password)
|
||||||
|
|
@ -47,8 +48,10 @@ export default {
|
||||||
record: user.record,
|
record: user.record,
|
||||||
}, process.env.secret)
|
}, process.env.secret)
|
||||||
|
|
||||||
|
const { lastPlayed, ...strippedUser } = user;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...user,
|
...strippedUser,
|
||||||
token
|
token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,10 @@ class Database {
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getUserByName(username) {
|
||||||
|
return this.db.data.users.find(user => user.name === username)
|
||||||
|
}
|
||||||
|
|
||||||
getUserByPassword(password) {
|
getUserByPassword(password) {
|
||||||
return this.db.data.users.find(user => user.password === password)
|
return this.db.data.users.find(user => user.password === password)
|
||||||
}
|
}
|
||||||
|
|
@ -74,6 +78,20 @@ class Database {
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLastPlayed(username) {
|
||||||
|
const user = this.getUserByName(username)
|
||||||
|
|
||||||
|
return user.lastPlayed
|
||||||
|
}
|
||||||
|
|
||||||
|
async setLastPlayedToNow(username) {
|
||||||
|
const user = this.getUserByName(username)
|
||||||
|
user.lastPlayed = Date.now()
|
||||||
|
|
||||||
|
await this.db.write()
|
||||||
|
return user.lastPlayed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new Database
|
export default new Database
|
||||||
|
|
|
||||||
|
|
@ -2,34 +2,45 @@
|
||||||
import db from './Database.js'
|
import db from './Database.js'
|
||||||
|
|
||||||
export default function (req, res, next) {
|
export default function (req, res, next) {
|
||||||
|
if (!process.env.enableJusticeGuard) {
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
|
||||||
const { points, shoots, time } = req.body
|
const { points, shoots, time } = req.body
|
||||||
|
|
||||||
if (points > shoots)
|
if (points > shoots)
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
error: "Stop that"
|
error: "Stop that, Rule #1",
|
||||||
})
|
})
|
||||||
|
|
||||||
//FIXES https://discord.com/channels/762566311930101761/892788974647656500/893963260045455410
|
//FIXES https://discord.com/channels/762566311930101761/892788974647656500/893963260045455410
|
||||||
const foreseeRank = db.foreseeRank(req.body.points)
|
const foreseeRank = db.foreseeRank(req.body.points)
|
||||||
if (foreseeRank == 1 && req.user.name == 'mw')
|
if (foreseeRank == 1 && req.user.name == 'mw')
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
error: "Stop that"
|
error: "Stop that, Rule #4"
|
||||||
})
|
})
|
||||||
|
|
||||||
//ship can shoot only 5 shoots per second
|
//ship can shoot only 5 shoots per second
|
||||||
//and one bullet is worth max 1 point
|
//and one bullet is worth max 1 point
|
||||||
const maxPossiblePointsByTime = time * 0.2
|
const maxPossiblePointsByTime = time * 5
|
||||||
if (points >= maxPossiblePointsByTime)
|
if (points > maxPossiblePointsByTime)
|
||||||
return res.status(400).json({
|
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
|
//nobody will play for over an hour, I assure you
|
||||||
if (time > 1000 * 60 * 60)
|
if (time > 60 * 60)
|
||||||
return res.status(400).json({
|
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()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,14 @@ app.get("/top", (req, res) => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.get("/start", protect, async (req, res) => {
|
||||||
|
await db.setLastPlayedToNow(req.user.name)
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
status: "ok"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
app.use(function (err, req, res, next) {
|
app.use(function (err, req, res, next) {
|
||||||
if (err.name === 'UnauthorizedError') {
|
if (err.name === 'UnauthorizedError') {
|
||||||
res.status(401).send('invalid token...');
|
res.status(401).send('invalid token...');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue