add auth
This commit is contained in:
parent
edd005cb4d
commit
5414c719f1
6 changed files with 141 additions and 10 deletions
15
game.js
15
game.js
|
@ -45,12 +45,17 @@ class Game extends GameBasic {
|
|||
if (full && wsEnt.health < 1 && !wsEnt.picked) {
|
||||
wsEnt.picked = true;
|
||||
|
||||
const hash = createHash('sha256');
|
||||
let hash = client.username;
|
||||
|
||||
if (!hash) {
|
||||
hash = createHash('sha256');
|
||||
hash.update(client.ip || '');
|
||||
hash = hash.digest('hex');
|
||||
}
|
||||
|
||||
await db.run('INSERT INTO stats (username, ip, ko) VALUES (?,?,?)', [
|
||||
wsEnt.you,
|
||||
hash.digest('hex'),
|
||||
hash,
|
||||
wsEnt.headCount
|
||||
]);
|
||||
}
|
||||
|
@ -76,7 +81,7 @@ class Game extends GameBasic {
|
|||
|
||||
na.push(fi.str)
|
||||
if (fi.entity.isYou) {
|
||||
let narr = [... fi.basic];
|
||||
let narr = [...fi.basic];
|
||||
narr[fi.entity.serverProps.indexOf('isYou')] = 'true';
|
||||
na[na.length - 1] = JSON.stringify(narr);
|
||||
}
|
||||
|
@ -100,11 +105,11 @@ class Game extends GameBasic {
|
|||
that.entities = [];
|
||||
|
||||
for (let i = 0; i < 20; i++) {
|
||||
that.entities.push(new NPC(false,that))
|
||||
that.entities.push(new NPC(false, that))
|
||||
}
|
||||
|
||||
for (let i = 0; i < 30; i++) {
|
||||
that.entities.push(new Shooter(false,that))
|
||||
that.entities.push(new Shooter(false, that))
|
||||
}
|
||||
|
||||
setInterval(function () { that.sync(false) }, 1000 / 10);
|
||||
|
|
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;
|
||||
|
|
91
package-lock.json
generated
91
package-lock.json
generated
|
@ -8,6 +8,7 @@
|
|||
"crypto": "^1.0.1",
|
||||
"express": "^4.21.0",
|
||||
"express-ws": "^5.0.2",
|
||||
"node-fetch": "^3.3.2",
|
||||
"sqlite": "^5.1.1",
|
||||
"sqlite3": "^5.1.7"
|
||||
}
|
||||
|
@ -418,6 +419,15 @@
|
|||
"integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==",
|
||||
"deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in."
|
||||
},
|
||||
"node_modules/data-uri-to-buffer": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
|
||||
"integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 12"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
|
@ -664,6 +674,29 @@
|
|||
"express": "^4.0.0 || ^5.0.0-alpha.1"
|
||||
}
|
||||
},
|
||||
"node_modules/fetch-blob": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
|
||||
"integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/jimmywarting"
|
||||
},
|
||||
{
|
||||
"type": "paypal",
|
||||
"url": "https://paypal.me/jimmywarting"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"node-domexception": "^1.0.0",
|
||||
"web-streams-polyfill": "^3.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.20 || >= 14.13"
|
||||
}
|
||||
},
|
||||
"node_modules/file-uri-to-path": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
|
||||
|
@ -687,6 +720,18 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/formdata-polyfill": {
|
||||
"version": "4.0.10",
|
||||
"resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
|
||||
"integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fetch-blob": "^3.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.20.0"
|
||||
}
|
||||
},
|
||||
"node_modules/forwarded": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||
|
@ -1396,6 +1441,43 @@
|
|||
"integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/node-domexception": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
|
||||
"integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/jimmywarting"
|
||||
},
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://paypal.me/jimmywarting"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/node-fetch": {
|
||||
"version": "3.3.2",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz",
|
||||
"integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"data-uri-to-buffer": "^4.0.0",
|
||||
"fetch-blob": "^3.1.4",
|
||||
"formdata-polyfill": "^4.0.10"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/node-fetch"
|
||||
}
|
||||
},
|
||||
"node_modules/node-gyp": {
|
||||
"version": "8.4.1",
|
||||
"resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-8.4.1.tgz",
|
||||
|
@ -2180,6 +2262,15 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/web-streams-polyfill": {
|
||||
"version": "3.3.3",
|
||||
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz",
|
||||
"integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/which": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"crypto": "^1.0.1",
|
||||
"express": "^4.21.0",
|
||||
"express-ws": "^5.0.2",
|
||||
"node-fetch": "^3.3.2",
|
||||
"sqlite": "^5.1.1",
|
||||
"sqlite3": "^5.1.7"
|
||||
},
|
||||
|
|
|
@ -11,9 +11,10 @@
|
|||
<h1>UniButton</h1>
|
||||
<p>The <b>left mouse button</b> is the only input. No keyboard, moving the mouse, or anything else.</p>
|
||||
<p>Click to launch... figure out the rest of the combos yourself.</p>
|
||||
<a class='button' href='https://zenoverse.net/'>Created by Onez</a>
|
||||
<a class='button' href='https://git.xuyezo.net/explore/repos'>Created by Zux</a>
|
||||
<a class='button' href='https://discord.gg/wZ3mg58JMT'>Join our
|
||||
Discord</a>
|
||||
<a class='button' href='https://bg.xuyezo.net/client/login?redirect=https://ub.xuyezo.net/'>Log in</a>
|
||||
<canvas id='canvas'></canvas>
|
||||
</div>
|
||||
</section>
|
||||
|
|
|
@ -155,7 +155,11 @@ class Game extends GameBasic {
|
|||
player.ref = false;
|
||||
}
|
||||
|
||||
this.ws.send(JSON.stringify(player.legalProps.map(prop => player[prop])));
|
||||
let p = player.legalProps.map(prop => player[prop]);
|
||||
|
||||
p.splice(0,0,'SYNC');
|
||||
|
||||
this.ws.send(JSON.stringify(p));
|
||||
}
|
||||
recv({ data }) {
|
||||
let { player } = this;
|
||||
|
@ -225,6 +229,7 @@ class Game extends GameBasic {
|
|||
if (this.entities.length == 0) this.entities = [this.player];
|
||||
}
|
||||
async init() {
|
||||
let tok = new URL(window.location).searchParams.get('token');
|
||||
super.init();
|
||||
|
||||
let that = this;
|
||||
|
@ -235,6 +240,9 @@ class Game extends GameBasic {
|
|||
|
||||
this.ws.addEventListener('open', function () {
|
||||
that.sync(true);
|
||||
if (tok) {
|
||||
that.ws.send(JSON.stringify(["AUTH",tok]));
|
||||
}
|
||||
setInterval(function () { that.sync() }, 1000 / 5);
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue