add leaderboard
This commit is contained in:
parent
dc26c4281b
commit
dbab510358
9 changed files with 1575 additions and 8 deletions
25
game.js
25
game.js
|
@ -1,12 +1,18 @@
|
|||
import GameBasic from "./common/game_basic.js";
|
||||
import NPC from "./common/npc.js";
|
||||
|
||||
import initDb from './db.js';
|
||||
|
||||
import { createHash } from "crypto";
|
||||
|
||||
let db = await initDb();
|
||||
|
||||
class Game extends GameBasic {
|
||||
constructor() {
|
||||
super();
|
||||
this.ws = [];
|
||||
}
|
||||
sync(full = false) {
|
||||
async sync(full = false) {
|
||||
let onScreen = this.entities.filter(x => x && x.health > 0).length;
|
||||
|
||||
onScreen += 4;
|
||||
|
@ -31,11 +37,24 @@ class Game extends GameBasic {
|
|||
if (entList.length == 0) return;
|
||||
|
||||
for (let client of this.ws) {
|
||||
if (!client.active) continue;
|
||||
|
||||
let wsEnt = client.ent;
|
||||
|
||||
if (!wsEnt) continue;
|
||||
|
||||
if (full && wsEnt.health < 1 && !wsEnt.picked) {
|
||||
wsEnt.picked = true;
|
||||
|
||||
const hash = createHash('sha256');
|
||||
hash.update(client.ip || '');
|
||||
|
||||
await db.run('INSERT INTO stats (username, ip, ko) VALUES (?,?,?)', [
|
||||
wsEnt.you,
|
||||
hash.digest('hex'),
|
||||
wsEnt.headCount
|
||||
]);
|
||||
}
|
||||
|
||||
if (!client.active) continue;
|
||||
|
||||
wsEnt.isYou = true;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue