add leaderboard

This commit is contained in:
biglyderv 2024-11-25 14:14:21 -05:00
parent dc26c4281b
commit dbab510358
9 changed files with 1575 additions and 8 deletions

View file

@ -4,6 +4,10 @@ import Game from "./game.js";
import NPC from "./common/npc.js";
import Player from "./common/player.js";
import initDb from "./db.js";
let db = await initDb();
var app = express();
expressW(app);
@ -15,6 +19,10 @@ 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) {
req.send(JSON.stringify(await db.all('SELECT * from stats')));
})
app.ws('/', function (ws, req) {
game.ws.push(ws);
let player = new Player(false, true, game);
@ -23,9 +31,10 @@ app.ws('/', function (ws, req) {
ws.active = true;
ws.ent = player;
ws.ip = req.headers["x-real-ip"];
// This will only work under NGINX.
console.log(`Player ${player.you} joined under IP ${req.headers["x-real-ip"]}`)
console.log(`Player ${player.you} joined under IP ${ws.ip}`)
ws.on('message', function message(msg) {
let data = {};