add auth
This commit is contained in:
parent
edd005cb4d
commit
5414c719f1
6 changed files with 141 additions and 10 deletions
27
index.js
27
index.js
|
@ -3,6 +3,7 @@ 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";
|
||||
|
||||
|
@ -19,7 +20,7 @@ app.use('/crypto.js', express.static('./common/crypto.js'));
|
|||
app.use('/js', express.static('./common'));
|
||||
app.use(express.static('./static'));
|
||||
|
||||
app.get('/leaderboard', async function(ws,req) {
|
||||
app.get('/leaderboard', async function (ws, req) {
|
||||
req.send(JSON.stringify(await db.all('SELECT * from stats')));
|
||||
})
|
||||
|
||||
|
@ -45,6 +46,30 @@ app.ws('/', function (ws, req) {
|
|||
data = [];
|
||||
}
|
||||
|
||||
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();
|
||||
ws.username = j.username;
|
||||
console.log(`Player ${player.you} uses username ${ws.username}`)
|
||||
})()
|
||||
return;
|
||||
}
|
||||
|
||||
data.splice(0, 1);
|
||||
|
||||
let newEnt = game.entities[playerI];
|
||||
|
||||
let { you } = newEnt;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue