diff --git a/index.js b/index.js index a19d324..0015e86 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,7 @@ 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'))); + req.send(JSON.stringify(await db.all('SELECT * FROM stats ORDER BY ko DESC LIMIT 100'))); }) app.ws('/', function (ws, req) { diff --git a/static/js/index.js b/static/js/index.js index 58ababf..89543e3 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -136,7 +136,7 @@ class Game extends GameBasic { let that = this; this.ws.close(); this.ws = new WebSocket(origin); - this.ws.addEventListener('message', function (e) { that.recv(e) }); + this.ws.addEventListener('open', () => this.opener(that)) } else if (player.isMenu) { player.r = Math.floor(Math.abs(player.rot / 1.2) % emojis.length); player.isMenu = false; @@ -157,7 +157,7 @@ class Game extends GameBasic { let p = player.legalProps.map(prop => player[prop]); - p.splice(0,0,'SYNC'); + p.splice(0, 0, 'SYNC'); this.ws.send(JSON.stringify(p)); } @@ -236,15 +236,17 @@ class Game extends GameBasic { this.ws = new WebSocket(origin); - this.ws.addEventListener('message', function (e) { that.recv(e) }); - - this.ws.addEventListener('open', function () { + this.opener = function (that) { that.sync(true); if (tok) { - that.ws.send(JSON.stringify(["AUTH",tok])); - } + that.ws.send(JSON.stringify(["AUTH", tok])); + } setInterval(function () { that.sync() }, 1000 / 5); - }) + + that.ws.addEventListener('message', function (e) { that.recv(e) }); + }; + + this.ws.addEventListener('open', () => this.opener(that)) setInterval(function () { that.render() }, 1000 / 60); @@ -259,7 +261,12 @@ class Game extends GameBasic { scores[e.ip] += e.ko ** 2; } - scores = Object.entries(scores).sort((a,b) => b[1] - a[1]); + for (let score in scores) { + let s = scores[score]; + scores[score] = Math.round(Math.sqrt(s)); + } + + scores = Object.entries(scores).sort((a, b) => b[1] - a[1]); document.querySelector('.lb').textContent = scores.map(x => `${x[0]}: ${x[1]}`).join('\n'); }