mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
- the client (1.3.0) sends one-way hashes of the device's ids at sign-in; the server keys them again with a secret of its own (data/device-key) and keeps them per account (lib/devices.js). a sign-in without them is refused with 426 (AJ_REQUIRE_DEVICE=0 lets it in), so 1.2 clients cannot sign in. - hardware bans: every device an account used in the last 90 days. any id but a network card blocks sign-in, sign-up and the game, on any account. a network card match, ids that look altered, or a device shared with a banned player raise hardware alerts instead. - both panels: hardware ban and lift, the account's hardware ids, search by hardware id, other accounts by device or address, a timeline (bans, staff actions, reports, alerts), and hardware bans and alerts in the bans tab. - jam-a-grams and wall posts go into the chat log, the filtered ones marked not sent. chat search filters by kind, by what the filter stopped, and from a time back; each player's page lists their jam-a-grams and wall posts, sent and received. - account search runs on the server and ranks exact names first, then names starting with the search; the admin panel no longer downloads every account. hidden tabs only refresh the waiting counts in the title. masterpieces can be searched by maker, approved ones too. reports can show the reported player's chat at the time. links follow the open tab and player. - admin actions on accounts go into the moderator log. - privacy policy covers hardware hashes and the new logs.
182 lines
5.8 KiB
JavaScript
182 lines
5.8 KiB
JavaScript
"use strict";
|
|
|
|
// what the end-to-end tests share: a game client that speaks the SWF's
|
|
// socket protocol, and a real server process on ports and a database of its
|
|
// own that is thrown away afterwards.
|
|
|
|
const assert = require("assert");
|
|
const {spawn} = require("child_process");
|
|
const crypto = require("crypto");
|
|
const fs = require("fs");
|
|
const net = require("net");
|
|
const os = require("os");
|
|
const path = require("path");
|
|
|
|
class GameClient {
|
|
constructor(gamePort) {
|
|
this.gamePort = gamePort;
|
|
this.queue = [];
|
|
this.varUpdates = [];
|
|
this.askedForGames = 0;
|
|
this.unaskedGames = [];
|
|
this.waiters = [];
|
|
this.buffer = Buffer.alloc(0);
|
|
}
|
|
|
|
connect() {
|
|
return new Promise((resolve, reject) => {
|
|
this.socket = net.connect(this.gamePort, "127.0.0.1", resolve);
|
|
this.socket.once("error", reject);
|
|
this.socket.on("data", chunk => {
|
|
this.buffer = Buffer.concat([this.buffer, chunk]);
|
|
let end;
|
|
while ((end = this.buffer.indexOf(0)) !== -1) {
|
|
this.queue.push(this.buffer.toString("utf8", 0, end));
|
|
if (process.env.AJ_TEST_TRACE) {
|
|
console.log(`<- ${this.queue[this.queue.length - 1].slice(0, 300)}`);
|
|
}
|
|
this.buffer = this.buffer.subarray(end + 1);
|
|
}
|
|
this.flush();
|
|
});
|
|
});
|
|
}
|
|
|
|
flush() {
|
|
while (this.queue.length && this.waiters.length) {
|
|
this.waiters.shift()(this.queue.shift());
|
|
}
|
|
}
|
|
|
|
send(message) {
|
|
if (process.env.AJ_TEST_TRACE) {
|
|
console.log(`-> ${message.slice(0, 300)}`);
|
|
}
|
|
this.socket.write(message + "\0");
|
|
}
|
|
|
|
xt(cmd, roomId, ...params) {
|
|
if (cmd === "mi") {
|
|
this.askedForGames++;
|
|
}
|
|
this.send(`%xt%o%${[cmd, roomId, ...params].join("%")}%`);
|
|
}
|
|
|
|
// the server describes the buddy games to a player who has just arrived
|
|
// without being asked ("mi"). is this message that, rather than the
|
|
// answer to a request of ours?
|
|
unasked(fields) {
|
|
if (fields[0] !== "mi") {
|
|
return false;
|
|
}
|
|
if (this.askedForGames === 0) {
|
|
this.unaskedGames.push(fields);
|
|
return true;
|
|
}
|
|
this.askedForGames--;
|
|
return false;
|
|
}
|
|
|
|
next() {
|
|
// made here, not in the timer, so that its stack says which line waited.
|
|
const timedOut = new Error("timed out waiting for a server message");
|
|
return new Promise((resolve, reject) => {
|
|
const timer = setTimeout(() => reject(timedOut), 5000);
|
|
this.waiters.push(message => {
|
|
clearTimeout(timer);
|
|
resolve(message);
|
|
});
|
|
this.flush();
|
|
});
|
|
}
|
|
|
|
// next raw extension message as [cmd, roomId, ...params]. user var
|
|
// updates ("zs") turn up between other messages whenever a counter the
|
|
// server keeps moves; they are set aside in `this.varUpdates` unless asked
|
|
// for, and the unasked list of buddy games in `this.unaskedGames`.
|
|
async nextXt(cmd) {
|
|
for (;;) {
|
|
const fields = (await this.next()).split("%").slice(2, -1);
|
|
if (fields[0] === "zs" && cmd !== "zs") {
|
|
this.varUpdates.push(fields);
|
|
continue;
|
|
}
|
|
if (this.unasked(fields)) {
|
|
continue;
|
|
}
|
|
assert.strictEqual(fields[0], cmd);
|
|
return fields;
|
|
}
|
|
}
|
|
|
|
// skips other messages until the next raw extension message for `cmd`.
|
|
async untilXt(cmd) {
|
|
for (;;) {
|
|
const fields = (await this.next()).split("%").slice(2, -1);
|
|
if (this.unasked(fields)) {
|
|
continue;
|
|
}
|
|
if (fields[0] === cmd) {
|
|
return fields;
|
|
}
|
|
}
|
|
}
|
|
|
|
async logIn(username, token) {
|
|
this.send("<msg t='sys'><body action='verChk' r='0'><ver v='165' /></body></msg>");
|
|
assert.match(await this.next(), /action='apiOK'/);
|
|
this.send("<msg t='sys'><body action='rndK' r='-1'></body></msg>");
|
|
assert.match(await this.next(), /<k>[0-9a-f]+<\/k>/);
|
|
const nick = `${username}%%0%1830%electron%1.5.7%win%df`;
|
|
this.send(`<msg t='sys' h='x'><body action='login' r='0'><login z='sbiLogin'><nick><![CDATA[${nick}]]></nick><pword><![CDATA[${token}]]></pword></login></body></msg>`);
|
|
return JSON.parse(await this.next()).b.o;
|
|
}
|
|
}
|
|
|
|
// what the client 1.3.0 sends about its computer (lib/devices.js), made up:
|
|
// one computer for each username, unless a test gives its own.
|
|
const deviceFor = name => {
|
|
const hash = kind => crypto.createHash("sha256").update(`test-device:${kind}:${String(name).toLowerCase()}`).digest("hex");
|
|
return {v: 1, ids: {os: hash("os"), install: hash("install"), disk: [hash("disk")], mac: [hash("mac")]}, notes: []};
|
|
};
|
|
|
|
const postJson = (url, body) => fetch(url, {
|
|
method: "POST",
|
|
headers: {"Content-Type": "application/json", "Origin": "null"},
|
|
body: JSON.stringify(/\/authenticate$/.test(url) && body && body.device === undefined ? {...body, device: deviceFor(body.username || "")} : body),
|
|
});
|
|
|
|
// starts a server on the given ports with an empty database, runs `run`
|
|
// against it, and prints `name` passed or the server's output on failure.
|
|
const withServer = async (name, httpPort, gamePort, run) => {
|
|
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), "aj-test-"));
|
|
const server = spawn(process.execPath, [path.join(__dirname, "..", "server.js")], {
|
|
env: {...process.env, AJ_HTTP_PORT: httpPort, AJ_GAME_PORT: gamePort, AJ_DATA_DIR: dataDir, AJ_QUIET: "1"},
|
|
stdio: ["ignore", "pipe", "inherit"],
|
|
});
|
|
let output = "";
|
|
try {
|
|
await new Promise((resolve, reject) => {
|
|
server.stdout.on("data", chunk => {
|
|
output += chunk;
|
|
if (output.includes("[server] ready")) {
|
|
resolve();
|
|
}
|
|
});
|
|
server.once("exit", code => reject(new Error(`server exited early (${code})\n${output}`)));
|
|
});
|
|
await run();
|
|
console.log(`${name} passed`);
|
|
}
|
|
catch (err) {
|
|
console.error(output);
|
|
throw err;
|
|
}
|
|
finally {
|
|
server.kill();
|
|
fs.rmSync(dataDir, {recursive: true, force: true});
|
|
}
|
|
};
|
|
|
|
module.exports = {deviceFor, GameClient, postJson, withServer};
|