refactors, fix username check
This commit is contained in:
parent
60e579c349
commit
0a9fd2faf9
4 changed files with 196 additions and 166 deletions
24
index.js
24
index.js
|
@ -3,7 +3,6 @@ import expressW from "express-ws";
|
|||
import Game from "./game.js";
|
||||
import NPC from "./common/npc.js";
|
||||
import Player from "./common/player.js";
|
||||
import fetch from "node-fetch";
|
||||
|
||||
import initDb from "./db.js";
|
||||
|
||||
|
@ -13,7 +12,6 @@ var app = express();
|
|||
expressW(app);
|
||||
|
||||
var game = new Game();
|
||||
|
||||
game.init();
|
||||
|
||||
app.use('/crypto.js', express.static('./common/crypto.js'));
|
||||
|
@ -49,27 +47,7 @@ app.ws('/', function (ws, req) {
|
|||
let type = data[0];
|
||||
|
||||
if (type == 'AUTH') {
|
||||
ws.token = data[1];
|
||||
|
||||
let f = new FormData();
|
||||
f.append('token', ws.token);
|
||||
|
||||
(async function () {
|
||||
let j = await fetch("https://bg.xuyezo.net/api/form/auth_api/",
|
||||
{
|
||||
"method": "post",
|
||||
"body": f
|
||||
}
|
||||
);
|
||||
j = await j.json();
|
||||
if (game.ws.findIndex(x => x.username == j.username && x.health >= 0) != -1) {
|
||||
console.log(`Player ${player.you} uses username ${x.username} illegally`)
|
||||
return;
|
||||
}
|
||||
ws.ent.username = ws.username = j.username;
|
||||
|
||||
console.log(`Player ${player.you} uses username ${ws.username}`)
|
||||
})()
|
||||
game.authUser(ws,data[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue