refactors, fix username check

This commit is contained in:
biglyderv 2024-11-25 14:14:21 -05:00
parent 60e579c349
commit 0a9fd2faf9
4 changed files with 196 additions and 166 deletions

35
game.js
View file

@ -1,6 +1,7 @@
import GameBasic from "./common/game_basic.js";
import NPC from "./common/npc.js";
import Shooter from "./common/shooter.js";
import fetch from "node-fetch";
import initDb from './db.js';
@ -115,6 +116,40 @@ class Game extends GameBasic {
setInterval(function () { that.sync(false) }, 1000 / 10);
setInterval(function () { that.sync(true) }, 1000);
setInterval(function () { that.clean() }, 1000);
}
clean() {
for (let ent in this.entities) {
let x = this.entities[ent];
if ( x.health > 0 || x.type != 'Player') return;
this.entites[ent] = false;
}
}
async authUser(ws, data) {
ws.token = data;
let f = new FormData();
f.append('token', ws.token);
let j = await fetch("https://bg.xuyezo.net/api/form/auth_api/",
{
"method": "post",
"body": f
}
);
j = await j.json();
if (j.username == '!nobody' || !j.username) return;
if (this.ws.findIndex(x => x.username == j.username && x.ent.health > 0) != -1) {
console.log(`Player ${ws.ent.you} uses username ${j.username} illegally`)
return;
}
ws.ent.username = ws.username = j.username;
console.log(`Player ${ws.ent.you} uses username ${ws.username}`)
}
}