mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
Brought up to date with the private repository (a06d3c5)
This commit is contained in:
commit
eda992fcff
144 files changed
+31026
No files matched your search
+231
@@ -0,0 +1,231 @@
|
||||
"use strict";
|
||||
|
||||
// end-to-end check of the sign-up page's rules and the account page
|
||||
// (/account, lib/manage.js): signing in, password, username requests,
|
||||
// feedback, the lock, the switches for parts of the game, login history,
|
||||
// and the admin panel's side of it. simulated players, a real server.
|
||||
|
||||
const assert = require("assert");
|
||||
const art = require("../lib/ecard-art.json");
|
||||
const harness = require("./harness.js");
|
||||
|
||||
const HTTP_PORT = 18084;
|
||||
const GAME_PORT = 19343;
|
||||
const BASE = `http://127.0.0.1:${HTTP_PORT}`;
|
||||
const TOWNSHIP = "jamaa_township.room_main#1";
|
||||
const {postJson} = harness;
|
||||
|
||||
const authenticate = (username, password) => postJson(`${BASE}/authenticate`, {username, password});
|
||||
|
||||
const arrive = async (username, password) => {
|
||||
const auth = await (await authenticate(username, password)).json();
|
||||
const client = new harness.GameClient(GAME_PORT);
|
||||
await client.connect();
|
||||
const login = await client.logIn(username, auth.auth_token);
|
||||
assert.strictEqual(login.status, "1");
|
||||
client.xt("rj", 1, TOWNSHIP, 1, 0, 0);
|
||||
const roomId = (await client.untilXt("rj"))[4];
|
||||
await client.untilXt("rp");
|
||||
client.xt("au", roomId, 1, 400, 400, 14, 1);
|
||||
return {client, roomId, token: auth.auth_token};
|
||||
};
|
||||
|
||||
// A request to one of the two cookie-guarded pages' APIs.
|
||||
const page = prefix => async (pathname, body, cookie, headers = {}) => {
|
||||
const response = await fetch(`${BASE}/${prefix}/api/${pathname}`, {
|
||||
method: body === undefined ? "GET" : "POST",
|
||||
headers: {"Content-Type": "application/json", ...(cookie ? {Cookie: cookie} : {}), ...headers},
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
});
|
||||
return {status: response.status, data: await response.json(), cookie: (response.headers.get("set-cookie") || "").split(";")[0]};
|
||||
};
|
||||
const mine = page("account");
|
||||
const panel = page("admin");
|
||||
|
||||
const run = async () => {
|
||||
const register = (username, avatarType) => fetch(`${BASE}/api/register`, {method: "POST", headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({username, password: "Password01", avatarType, agreed: true})});
|
||||
assert.strictEqual((await register("Ann", 4)).status, 200);
|
||||
assert.strictEqual((await register("Ben", 24)).status, 200);
|
||||
// what a client shows beside its login form.
|
||||
const status = await (await fetch(`${BASE}/api/status`)).json();
|
||||
assert.ok(status.online === 0 && status.uptimeSeconds >= 0);
|
||||
|
||||
// --- the page and who may use it
|
||||
assert.match(await (await fetch(`${BASE}/account`)).text(), /Your account/);
|
||||
assert.strictEqual((await mine("me")).status, 401);
|
||||
assert.strictEqual((await mine("login", {username: "Ann", password: "wrong"})).status, 401);
|
||||
assert.strictEqual((await mine("login", {username: "Nobody", password: "Password01"})).status, 401);
|
||||
const signedIn = await mine("login", {username: "ann", password: "Password01"});
|
||||
assert.strictEqual(signedIn.status, 200);
|
||||
assert.match(signedIn.cookie, /^ajc_account=[0-9a-f]{48}$/);
|
||||
const ann = signedIn.cookie;
|
||||
assert.strictEqual((await mine("act", {action: "lock", locked: true}, ann, {Origin: "http://evil.example"})).status, 403);
|
||||
let me = (await mine("me", undefined, ann)).data;
|
||||
assert.deepStrictEqual([me.username, me.animalType, me.locked, me.features.chat], ["Ann", 4, false, true]); // the wolf she picked
|
||||
// the wrong password and the sign-in are both in her history, newest first.
|
||||
assert.deepStrictEqual(me.history.map(login => [login.via, login.ok]), [["web", true], ["web", false]]);
|
||||
|
||||
// --- parts of the game switched off
|
||||
const {client: a, roomId} = await arrive("Ann", "Password01");
|
||||
const {client: b} = await arrive("Ben", "Password01");
|
||||
await a.untilXt("ac");
|
||||
const set = async (feature, on) => assert.strictEqual((await mine("act", {action: "feature", feature, on}, ann)).status, 200);
|
||||
assert.strictEqual((await mine("act", {action: "feature", feature: "flying", on: false}, ann)).status, 400);
|
||||
|
||||
await set("buddies", false);
|
||||
b.xt("ba", roomId, "Ann");
|
||||
assert.deepStrictEqual((await b.untilXt("ba")).slice(2, 4), ["3", "Ann"]); // not accepting requests
|
||||
a.xt("ba", roomId, "Ben");
|
||||
assert.strictEqual((await a.untilXt("ba"))[2], "3");
|
||||
await set("buddies", true);
|
||||
b.xt("ba", roomId, "Ann");
|
||||
assert.strictEqual((await a.untilXt("ba"))[3], "Ben"); // it arrives now
|
||||
|
||||
await set("chat", false);
|
||||
a.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[hello%0]]></txt></body></msg>`);
|
||||
assert.deepStrictEqual((await a.untilXt("uc")).slice(3), ["-1", "5"]); // her line goes nowhere
|
||||
b.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[anyone%0]]></txt></body></msg>`);
|
||||
assert.strictEqual((await b.untilXt("uc"))[3], "anyone");
|
||||
await set("chat", true);
|
||||
b.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[again%0]]></txt></body></msg>`);
|
||||
assert.strictEqual((await a.untilXt("uc"))[3], "again"); // "anyone" never reached her
|
||||
|
||||
await set("trading", false);
|
||||
b.xt("ti", roomId, 0, "Ann", 0, 1, 0, 0, 0, 0);
|
||||
assert.deepStrictEqual((await b.untilXt("ti")).slice(2, 4), ["4", "Ann"]); // unavailable, before anything else is looked at
|
||||
await set("jamagrams", false);
|
||||
b.xt("es", roomId, "Ann", art.cards[0], art.stamps[0], 0, "hi", 0, 0, 0);
|
||||
assert.strictEqual((await b.untilXt("es"))[2], "-2"); // not accepting them
|
||||
await set("jamagrams", true);
|
||||
b.xt("es", roomId, "Ann", art.cards[0], art.stamps[0], 0, "hi", 0, 0, 0);
|
||||
assert.strictEqual((await b.untilXt("es"))[2], "1");
|
||||
await set("jamagrams", false);
|
||||
me = (await mine("me", undefined, ann)).data;
|
||||
assert.deepStrictEqual([me.features.trading, me.features.jamagrams, me.features.buddies, me.online], [false, false, true, true]);
|
||||
|
||||
// --- buddies with a note, the block list, achievements, den visitors
|
||||
b.xt("bc", roomId, "Ann", 1); // ben says yes to her request from before
|
||||
a.xt("ba", roomId, "Ben");
|
||||
await b.untilXt("ba");
|
||||
b.xt("bc", roomId, "Ann", 1);
|
||||
await a.untilXt("bs");
|
||||
assert.strictEqual((await mine("act", {action: "buddyNote", name: "Ben", note: " met at the fountain "}, ann)).status, 200);
|
||||
assert.strictEqual((await mine("act", {action: "buddyNote", name: "Nobody", note: "x"}, ann)).status, 400);
|
||||
assert.strictEqual((await mine("act", {action: "block", name: "Nobody"}, ann)).status, 400);
|
||||
assert.strictEqual((await mine("act", {action: "block", name: "Ben"}, ann)).status, 200);
|
||||
await a.untilXt("bl"); // her game hears of it: its buddy list, then its block list
|
||||
assert.deepStrictEqual((await a.untilXt("bl")).slice(2, 5), ["1", "1", "ben"]);
|
||||
assert.strictEqual((await mine("act", {action: "block", name: "Ben"}, ann)).status, 400);
|
||||
b.xt("dj", roomId, "denAnn", 1, -1);
|
||||
await b.untilXt("rj"); // locked out: she blocked him
|
||||
assert.strictEqual((await mine("act", {action: "unblock", name: "ben"}, ann)).status, 200);
|
||||
b.xt("dj", roomId, "denAnn", 1, -1);
|
||||
const inDen = await b.untilXt("rj");
|
||||
assert.strictEqual(inDen[3], "denAnn");
|
||||
b.xt("rj", inDen[4], TOWNSHIP, 1, 0, 0);
|
||||
await b.untilXt("rp");
|
||||
me = (await mine("me", undefined, ann)).data;
|
||||
assert.deepStrictEqual(me.buddyList, [{name: "Ben", online: true, note: "met at the fountain"}]);
|
||||
assert.deepStrictEqual([me.blocked, me.denVisits.map(visit => visit.name), me.trades, me.offers], [[], ["Ben"], [], {incoming: [], outgoing: []}]);
|
||||
assert.ok(me.achievements.of > 200 && me.achievements.counted.some(counted => counted.name === "Gems Earned" && counted.next > 0));
|
||||
|
||||
// --- a trade offer left for someone, answered from their page
|
||||
const giveTo = async (username, query) => {
|
||||
const found = (await (await fetch(`${BASE}/api/search?q=${query}&kind=clothing`)).json()).results[0];
|
||||
await fetch(`${BASE}/api/give`, {method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({username, kind: "clothing", id: found.id, colorIndex: 0})});
|
||||
return found.name;
|
||||
};
|
||||
const hatName = await giveTo("Ann", "top+hat");
|
||||
const scarfName = await giveTo("Ben", "scarf");
|
||||
let benHas = await b.untilXt("il");
|
||||
while (benHas[2] !== "2" || benHas[5] !== "Ben") { // past the lists he was sent of Ann's clothes
|
||||
benHas = await b.untilXt("il");
|
||||
}
|
||||
b.xt("ts", roomId, 0, 1, 0, benHas[9]); // ben puts his scarf up for trade, in the game
|
||||
await b.untilXt("tl");
|
||||
const benPageCookie = (await mine("login", {username: "Ben", password: "Password01"})).cookie;
|
||||
const tradable = (await mine("tradable?of=ben", undefined, ann)).data;
|
||||
assert.deepStrictEqual([tradable.found, tradable.theirs.map(item => item.name), tradable.mine.map(item => item.name)], [true, [scarfName], [hatName]]);
|
||||
assert.strictEqual((await mine("act", {action: "offer", to: "Ben", wanted: tradable.theirs[0], offered: []}, ann)).status, 400);
|
||||
assert.strictEqual((await mine("act", {action: "offer", to: "Ben", wanted: {type: 0, inv: 999999}, offered: tradable.mine}, ann)).status, 400);
|
||||
assert.strictEqual((await mine("act", {action: "offer", to: "Ben", wanted: tradable.theirs[0], offered: tradable.mine}, ann)).status, 400); // she has trading off
|
||||
await set("trading", true);
|
||||
assert.strictEqual((await mine("act", {action: "offer", to: "Ben", wanted: tradable.theirs[0], offered: tradable.mine}, ann)).status, 200);
|
||||
let benPage = (await mine("me", undefined, benPageCookie)).data;
|
||||
assert.deepStrictEqual(benPage.offers.incoming.map(offer => [offer.from, offer.wanted.name, offer.offered.map(item => item.name)]), [["Ann", scarfName, [hatName]]]);
|
||||
assert.strictEqual((await mine("me", undefined, ann)).data.offers.outgoing.length, 1);
|
||||
assert.strictEqual((await mine("act", {action: "answerOffer", id: benPage.offers.incoming[0].id, accept: true}, benPageCookie)).status, 200);
|
||||
await a.untilXt("di"); // both are in the game: their inventories are sent afresh
|
||||
await b.untilXt("di");
|
||||
benPage = (await mine("me", undefined, benPageCookie)).data;
|
||||
assert.deepStrictEqual([benPage.offers.incoming, benPage.trades.map(trade => [trade.with, trade.got, trade.gave])], [[], [["Ann", [hatName], [scarfName]]]]);
|
||||
assert.deepStrictEqual((await mine("tradable?of=ben", undefined, ann)).data.mine.map(item => item.name), [scarfName]);
|
||||
|
||||
// --- a username request, approved from the admin panel
|
||||
assert.strictEqual((await mine("act", {action: "requestName", newName: "Ben"}, ann)).status, 400); // taken
|
||||
assert.strictEqual((await mine("act", {action: "requestName", newName: "Ann"}, ann)).status, 400); // hers already
|
||||
assert.strictEqual((await mine("act", {action: "requestName", newName: "x"}, ann)).status, 400);
|
||||
const asked = await mine("act", {action: "requestName", newName: "Annabel", reason: "my real nickname"}, ann);
|
||||
assert.strictEqual(asked.status, 200);
|
||||
assert.deepStrictEqual(asked.data.account.nameRequests.map(request => [request.newName, request.status]), [["Annabel", "waiting"]]);
|
||||
assert.strictEqual((await mine("act", {action: "feedback", kind: "bug", text: " the slide is stuck "}, ann)).status, 200);
|
||||
assert.strictEqual((await mine("act", {action: "feedback", kind: "bug", text: " "}, ann)).status, 400);
|
||||
assert.strictEqual((await mine("act", {action: "feedback", kind: "rant", text: "x"}, ann)).status, 400);
|
||||
|
||||
const admin = (await panel("setup", {password: "admin-password-1"})).cookie;
|
||||
const waiting = (await panel("support?handled=0", undefined, admin)).data;
|
||||
assert.deepStrictEqual([waiting.open, waiting.names[0].newName, waiting.names[0].reason, waiting.feedback[0].text],
|
||||
[2, "Annabel", "my real nickname", "the slide is stuck"]);
|
||||
assert.strictEqual((await panel("overview", undefined, admin)).data.stats.support, 2);
|
||||
assert.strictEqual((await panel("support", {action: "read", id: waiting.feedback[0].id}, admin)).status, 200);
|
||||
assert.strictEqual((await panel("support", {action: "approve", id: waiting.names[0].id}, admin)).status, 200);
|
||||
assert.strictEqual((await panel("support", {action: "approve", id: waiting.names[0].id}, admin)).status, 400); // only once
|
||||
assert.strictEqual((await mine("me", undefined, ann)).status, 401); // renamed: sign in again, with the new name
|
||||
assert.strictEqual((await authenticate("Ann", "Password01")).status, 401);
|
||||
const annabel = (await mine("login", {username: "Annabel", password: "Password01"})).cookie;
|
||||
me = (await mine("me", undefined, annabel)).data;
|
||||
assert.deepStrictEqual([me.username, me.nameRequests[0].status, me.feedback[0].handledAt > 0], ["Annabel", "approved", true]);
|
||||
|
||||
// --- the lock: out of the game, and no way back in until it is undone
|
||||
const {token} = await arrive("Annabel", "Password01");
|
||||
assert.strictEqual((await mine("act", {action: "lock", locked: true}, annabel)).status, 200);
|
||||
assert.strictEqual((await authenticate("Annabel", "Password01")).status, 401);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {refresh_token: token})).status, 401); // the saved sign-in is gone
|
||||
assert.strictEqual((await panel("accounts", undefined, admin)).data.accounts.find(account => account.username === "Annabel").locked, true);
|
||||
assert.strictEqual((await mine("login", {username: "Annabel", password: "Password01"})).status, 200); // the page still lets her in
|
||||
assert.strictEqual((await mine("act", {action: "lock", locked: false}, annabel)).status, 200);
|
||||
assert.strictEqual((await authenticate("Annabel", "Password01")).status, 200);
|
||||
|
||||
// --- the password: the old one is asked for, and stops working
|
||||
assert.strictEqual((await mine("act", {action: "password", current: "wrong", password: "Password02"}, annabel)).status, 400);
|
||||
assert.strictEqual((await mine("act", {action: "password", current: "Password01", password: "short"}, annabel)).status, 400);
|
||||
assert.strictEqual((await mine("act", {action: "password", current: "Password01", password: "Password02"}, annabel)).status, 200);
|
||||
assert.strictEqual((await authenticate("Annabel", "Password01")).status, 401);
|
||||
assert.strictEqual((await authenticate("Annabel", "Password02")).status, 200);
|
||||
me = (await mine("me", undefined, annabel)).data;
|
||||
assert.ok(me.history.some(login => login.via === "launcher" && !login.ok) && me.history.some(login => login.via === "game" && login.ok));
|
||||
|
||||
assert.strictEqual((await mine("logout", {}, annabel)).status, 200);
|
||||
assert.strictEqual((await mine("me", undefined, annabel)).status, 401);
|
||||
|
||||
// --- deleting one's own account: the password and the name, then it is gone
|
||||
const {client: b2} = await arrive("Ben", "Password01");
|
||||
const ben = (await mine("login", {username: "Ben", password: "Password01"})).cookie;
|
||||
assert.strictEqual((await mine("act", {action: "delete", current: "wrong", confirm: "Ben"}, ben)).status, 400);
|
||||
assert.strictEqual((await mine("act", {action: "delete", current: "Password01", confirm: "Annabel"}, ben)).status, 400);
|
||||
const gone = await mine("act", {action: "delete", current: "Password01", confirm: "ben"}, ben);
|
||||
assert.deepStrictEqual([gone.status, gone.data.deleted, gone.data.account], [200, true, undefined]);
|
||||
assert.strictEqual((await mine("me", undefined, ben)).status, 401);
|
||||
assert.strictEqual((await authenticate("Ben", "Password01")).status, 401);
|
||||
assert.ok(!(await panel("accounts", undefined, admin)).data.accounts.some(account => account.username === "Ben"));
|
||||
assert.strictEqual((await register("Ben", 5)).status, 200); // the name is free again
|
||||
b2.socket.destroy();
|
||||
a.socket.destroy();
|
||||
b.socket.destroy();
|
||||
};
|
||||
|
||||
harness.withServer("account page test", HTTP_PORT, GAME_PORT, run).catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,311 @@
|
||||
"use strict";
|
||||
|
||||
// end-to-end check of the buddy games: the invitation, and each of the
|
||||
// eight games played through by two simulated players against a real server.
|
||||
|
||||
const assert = require("assert");
|
||||
const harness = require("./harness.js");
|
||||
|
||||
const HTTP_PORT = 18083;
|
||||
const GAME_PORT = 19342;
|
||||
const BASE = `http://127.0.0.1:${HTTP_PORT}`;
|
||||
const TOWNSHIP = "jamaa_township.room_main#1";
|
||||
const {postJson} = harness;
|
||||
const GAMES = {ticTacToe: 89, fourGems: 90, rockPaperScissors: 91, shellGame: 92, pairs: 93, scooped: 95, bowling: 98, marbles: 101};
|
||||
|
||||
const arrive = async username => {
|
||||
const auth = await (await postJson(`${BASE}/authenticate`, {username, password: "Password01"})).json();
|
||||
const client = new harness.GameClient(GAME_PORT);
|
||||
await client.connect();
|
||||
const login = await client.logIn(username, auth.auth_token);
|
||||
assert.strictEqual(login.status, "1");
|
||||
client.xt("rj", 1, TOWNSHIP, 1, 0, 0);
|
||||
const roomId = (await client.untilXt("rj"))[4];
|
||||
await client.untilXt("rp");
|
||||
client.xt("au", roomId, 1, 400, 400, 14, 1);
|
||||
return {client, roomId, id: String(login.params.userId), animal: String(login.params.perUserAvId)};
|
||||
};
|
||||
|
||||
const run = async () => {
|
||||
for (const username of ["Ann", "Ben", "Cat"]) {
|
||||
const response = await fetch(`${BASE}/api/register`, {method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({username, password: "Password01", avatarType: 1, agreed: true})});
|
||||
assert.strictEqual(response.status, 200);
|
||||
}
|
||||
const ann = await arrive("Ann");
|
||||
const ben = await arrive("Ben");
|
||||
const cat = await arrive("Cat");
|
||||
const [a, b, c] = [ann.client, ben.client, cat.client];
|
||||
// everything about arriving and seeing each other arrive is behind them
|
||||
// once each has had an answer to something asked afterwards.
|
||||
for (const [client, me] of [[a, ann], [b, ben], [c, cat]]) {
|
||||
client.xt("zg", me.roomId);
|
||||
await client.untilXt("zg");
|
||||
}
|
||||
|
||||
// --- a player who arrives is told of the eight games, each for two players and ready to be played against another
|
||||
const told = a.unaskedGames[0];
|
||||
assert.strictEqual(told[2], "8");
|
||||
const perGame = (told.length - 3) / 8;
|
||||
assert.strictEqual(perGame, 19);
|
||||
const first = told.slice(3, 3 + perGame);
|
||||
assert.deepStrictEqual([first[0], first[2], first[4], first[5], first[7], first[8], first[12], first[17]], ["89", "PVP_TicTacToe", "2", "2", "0", "5063", "1", "5063"]);
|
||||
|
||||
// --- invitations
|
||||
// Ann asks Ben; he says no, and she is told.
|
||||
a.xt("mp", ann.roomId, GAMES.ticTacToe, 0, "Ben");
|
||||
assert.deepStrictEqual((await b.nextXt("mp")).slice(2), ["89", "0", "Ann", "1"]);
|
||||
// while that is open neither can be asked, nor ask, anything else.
|
||||
c.xt("mp", cat.roomId, GAMES.pairs, 0, "Ann");
|
||||
assert.deepStrictEqual((await c.nextXt("mp")).slice(2), ["93", "1"]);
|
||||
b.xt("mp", ben.roomId, GAMES.ticTacToe, 1);
|
||||
assert.deepStrictEqual((await a.nextXt("mp")).slice(2), ["89", "1"]);
|
||||
// asked again, and taken back.
|
||||
a.xt("mp", ann.roomId, GAMES.ticTacToe, 0, "Ben");
|
||||
await b.nextXt("mp");
|
||||
a.xt("mp", ann.roomId, GAMES.ticTacToe, 1);
|
||||
assert.deepStrictEqual((await b.nextXt("mp")).slice(2), ["89", "1"]);
|
||||
// nobody of that name, a game that is not a buddy game, oneself: all "no".
|
||||
for (const [game, name] of [[GAMES.ticTacToe, "Nobody"], [4, "Ben"], [GAMES.ticTacToe, "Ann"]]) {
|
||||
a.xt("mp", ann.roomId, game, 0, name);
|
||||
assert.strictEqual((await a.nextXt("mp"))[3], "1");
|
||||
}
|
||||
// A buddy game cannot be started alone.
|
||||
a.xt("mj", ann.roomId, GAMES.ticTacToe, 0, 0, 0);
|
||||
assert.deepStrictEqual((await a.nextXt("mj")).slice(2), ["as", "0"]);
|
||||
await a.untilXt("ua");
|
||||
|
||||
// starts `game` between Ann (who asks) and Ben, up to both saying they
|
||||
// are ready. returns the game room's id and what the start message added.
|
||||
const begin = async game => {
|
||||
a.xt("mp", ann.roomId, game, 0, "Ben");
|
||||
await b.untilXt("mp");
|
||||
b.xt("mp", ben.roomId, game, 0);
|
||||
let room;
|
||||
let extra;
|
||||
for (const [client, me] of [[a, ann], [b, ben]]) {
|
||||
const joined = await client.untilXt("rj");
|
||||
assert.deepStrictEqual([joined[3].split("_")[0], joined[10], joined[13]], [`game${game}`, "1", "1"]); // a game's room, beside the one they are in
|
||||
room = joined[4];
|
||||
assert.deepStrictEqual((await client.untilXt("mj")).slice(1), [room, ann.id, ben.id]);
|
||||
const started = await client.nextXt("ms");
|
||||
// two players, their ids, then each one's animal and name
|
||||
assert.deepStrictEqual(started.slice(1, 9), [room, "2", ann.id, ben.id, ann.animal, "Ann", ben.animal, "Ben"]);
|
||||
extra = started.slice(9);
|
||||
void me;
|
||||
}
|
||||
a.xt("mm", room, game, "ready");
|
||||
b.xt("mm", room, game, "ready");
|
||||
return {room, extra};
|
||||
};
|
||||
// what both players are told next, checked to be the same.
|
||||
const both = async word => {
|
||||
const [toAnn, toBen] = [await a.nextXt("mm"), await b.nextXt("mm")];
|
||||
assert.deepStrictEqual(toAnn, toBen);
|
||||
assert.strictEqual(toAnn[2], word);
|
||||
return toAnn.slice(3);
|
||||
};
|
||||
const say = (who, room, game, ...words) => (who === 0 ? a : b).xt("mm", room, game, ...words);
|
||||
const finish = async room => {
|
||||
// each game ends itself: "quit", then out of its room. after a game
|
||||
// that was decided nobody is told the other "left".
|
||||
for (const client of [a, b]) {
|
||||
client.xt("rl", room, room);
|
||||
}
|
||||
a.xt("zg", ann.roomId);
|
||||
assert.strictEqual((await a.nextXt("zg"))[0], "zg");
|
||||
b.xt("zg", ben.roomId);
|
||||
assert.strictEqual((await b.nextXt("zg"))[0], "zg");
|
||||
};
|
||||
|
||||
// --- Tic Tac Toe: the top row for whoever starts
|
||||
{
|
||||
const {room} = await begin(GAMES.ticTacToe);
|
||||
const [turn, ...ids] = await both("round");
|
||||
assert.deepStrictEqual(ids, [ann.id, ben.id]);
|
||||
const x = Number(turn);
|
||||
const o = 1 - x;
|
||||
say(o, room, GAMES.ticTacToe, "mark", 1, 1); // not their turn
|
||||
assert.deepStrictEqual((await (o === 0 ? a : b).nextXt("mm")).slice(2), ["invalid", String(x)]);
|
||||
say(x, room, GAMES.ticTacToe, "mark", 0, 0);
|
||||
assert.deepStrictEqual(await both("mark"), [String(x), "0", "0", "0", "0", String(o)]);
|
||||
say(o, room, GAMES.ticTacToe, "mark", 0, 0); // taken
|
||||
assert.deepStrictEqual((await (o === 0 ? a : b).nextXt("mm")).slice(2), ["invalid", String(o)]);
|
||||
say(o, room, GAMES.ticTacToe, "time"); // and then they run out of time: the turn passes
|
||||
assert.deepStrictEqual(await both("invalid"), [String(x)]);
|
||||
say(x, room, GAMES.ticTacToe, "mark", 1, 0);
|
||||
await both("mark");
|
||||
say(o, room, GAMES.ticTacToe, "mark", 1, 1);
|
||||
await both("mark");
|
||||
say(x, room, GAMES.ticTacToe, "mark", 2, 0);
|
||||
assert.deepStrictEqual(await both("mark"), [String(x), "2", "0", "1", "0", String(x)]); // won
|
||||
await finish(room);
|
||||
}
|
||||
|
||||
// --- Four Gems: four in one column
|
||||
{
|
||||
const {room} = await begin(GAMES.fourGems);
|
||||
const x = Number((await both("round"))[0]);
|
||||
const o = 1 - x;
|
||||
for (let move = 0; move < 3; move++) {
|
||||
say(x, room, GAMES.fourGems, "mark", 3);
|
||||
assert.deepStrictEqual(await both("mark"), [String(x), "3", "0", "0", String(o)]);
|
||||
say(o, room, GAMES.fourGems, "mark", 4);
|
||||
await both("mark");
|
||||
}
|
||||
say(x, room, GAMES.fourGems, "mark", 9); // no such column
|
||||
assert.strictEqual((await (x === 0 ? a : b).nextXt("mm"))[2], "invalid");
|
||||
say(x, room, GAMES.fourGems, "mark", 3);
|
||||
assert.deepStrictEqual(await both("mark"), [String(x), "3", "1", "0", String(x)]);
|
||||
await finish(room);
|
||||
}
|
||||
|
||||
// --- Rock Paper Scissors: a draw, then Ben wins two rounds
|
||||
{
|
||||
const game = GAMES.rockPaperScissors;
|
||||
const {room} = await begin(game);
|
||||
const round = async (annHand, benHand) => {
|
||||
assert.deepStrictEqual(await both("round"), [ann.id, ben.id]);
|
||||
say(0, room, game, "time", annHand);
|
||||
say(1, room, game, "time", benHand);
|
||||
const result = await both("mark");
|
||||
return result;
|
||||
};
|
||||
assert.deepStrictEqual(await round("rock", "rock"), ["rock", "rock", "0", "0"]);
|
||||
say(0, room, game, "ready");
|
||||
say(1, room, game, "ready");
|
||||
assert.deepStrictEqual(await round("rock", "paper"), ["rock", "paper", "0", "1", "1"]);
|
||||
say(0, room, game, "ready");
|
||||
say(1, room, game, "ready");
|
||||
assert.deepStrictEqual(await round("nonsense", "scissors"), ["off", "scissors", "1", "1"]); // no hand loses to any
|
||||
await finish(room);
|
||||
}
|
||||
|
||||
// --- the Shell Game: the right shell against the wrong one, twice
|
||||
{
|
||||
const game = GAMES.shellGame;
|
||||
const {room} = await begin(game);
|
||||
for (const over of [false, true]) {
|
||||
const [first, second, shell] = await both("round");
|
||||
assert.deepStrictEqual([first, second], [ann.id, ben.id]);
|
||||
assert.ok(["1", "2", "3"].includes(shell));
|
||||
const wrong = String(Number(shell) % 3 + 1);
|
||||
say(0, room, game, "time", shell);
|
||||
say(1, room, game, "time", wrong);
|
||||
assert.deepStrictEqual(await both("mark"), over ? [shell, wrong, "1", "0"] : [shell, wrong, "0", "1", "0"]);
|
||||
if (!over) {
|
||||
say(0, room, game, "ready");
|
||||
say(1, room, game, "ready");
|
||||
}
|
||||
}
|
||||
await finish(room);
|
||||
}
|
||||
|
||||
// --- Pairs: whoever starts turns up all eight pairs
|
||||
{
|
||||
const game = GAMES.pairs;
|
||||
const {room} = await begin(game);
|
||||
const [starter, , count, ...cards] = await both("round");
|
||||
assert.deepStrictEqual([count, cards.length, [...cards].map(Number).sort((one, two) => one - two).join()], ["16", 16, "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16"]);
|
||||
const me = starter === ann.id ? 0 : 1;
|
||||
const them = 1 - me;
|
||||
const watcher = them === 0 ? a : b;
|
||||
const at = picture => cards.indexOf(String(picture));
|
||||
// A miss first, by the other player's clock running out... no: by two cards that do not match.
|
||||
say(me, room, game, "c1", at(1));
|
||||
assert.deepStrictEqual((await watcher.nextXt("mm")).slice(2), ["c1", String(at(1))]);
|
||||
say(me, room, game, "c2", at(2));
|
||||
assert.deepStrictEqual((await watcher.nextXt("mm")).slice(2), ["c2", String(at(2))]);
|
||||
assert.deepStrictEqual(await both("results"), ["0", "0"]);
|
||||
say(them, room, game, "c1", at(3)); // nothing moves until both have watched the result
|
||||
say(0, room, game, "rp");
|
||||
say(1, room, game, "rp");
|
||||
await both("nextround");
|
||||
say(them, room, game, "time"); // the other player's turn now; they let it run out
|
||||
await both("time");
|
||||
say(0, room, game, "rp");
|
||||
say(1, room, game, "rp");
|
||||
await both("nextround");
|
||||
say(me, room, game, "emote", 3);
|
||||
assert.deepStrictEqual((await watcher.nextXt("mm")).slice(2), ["emote", "3"]);
|
||||
for (let picture = 1; picture <= 8; picture++) {
|
||||
say(me, room, game, "c1", at(picture));
|
||||
say(me, room, game, "c2", at(picture + 8));
|
||||
await watcher.nextXt("mm");
|
||||
await watcher.nextXt("mm");
|
||||
if (picture < 8) {
|
||||
assert.deepStrictEqual(await both("results"), ["0", "1"]);
|
||||
say(0, room, game, "rp");
|
||||
say(1, room, game, "rp");
|
||||
await both("nextround");
|
||||
}
|
||||
}
|
||||
assert.deepStrictEqual(await both("results"), ["1", starter]);
|
||||
await finish(room);
|
||||
}
|
||||
|
||||
// --- Scooped: scoops are shown to the other player; the first to finish wins
|
||||
{
|
||||
const game = GAMES.scooped;
|
||||
const {room} = await begin(game);
|
||||
assert.deepStrictEqual(await both("start"), []);
|
||||
say(0, room, game, "sc_click", "flavor3");
|
||||
assert.deepStrictEqual((await b.nextXt("mm")).slice(2), ["sc_click", "flavor3"]);
|
||||
say(1, room, game, "sc_done");
|
||||
assert.deepStrictEqual(await both("sc_done"), ["1"]);
|
||||
await finish(room);
|
||||
}
|
||||
|
||||
// --- Bowling: balls and the wait between them are passed across
|
||||
{
|
||||
const game = GAMES.bowling;
|
||||
const {room} = await begin(game);
|
||||
const [bowler] = await both("round");
|
||||
const thrower = bowler === ann.id ? 0 : 1;
|
||||
say(thrower, room, game, "ball", "12.5", "-3.25", "410");
|
||||
assert.deepStrictEqual((await (thrower === 0 ? b : a).nextXt("mm")).slice(2), ["ball", "12.5", "-3.25", "410"]);
|
||||
say(0, room, game, "rp");
|
||||
say(1, room, game, "rp");
|
||||
assert.deepStrictEqual(await both("nextround"), []);
|
||||
say(thrower, room, game, "time");
|
||||
assert.deepStrictEqual(await both("time"), []);
|
||||
// Ann walks off mid-game: Ben's game is told she left.
|
||||
a.xt("rl", room, room);
|
||||
assert.deepStrictEqual((await b.nextXt("ml")).slice(1), [room, ann.id]);
|
||||
b.xt("rl", room, room);
|
||||
}
|
||||
|
||||
// --- Marbles: a layout with the start, then aim, shot and end of turn
|
||||
{
|
||||
const game = GAMES.marbles;
|
||||
const {room, extra} = await begin(game);
|
||||
assert.ok(extra.length === 1 && Number(extra[0]) >= 1 && Number(extra[0]) <= 14);
|
||||
assert.ok(["0", "1"].includes((await both("start"))[0]));
|
||||
say(0, room, game, "pos", 300, 200);
|
||||
assert.deepStrictEqual((await b.nextXt("mm")).slice(2), ["pos", "300", "200"]);
|
||||
say(0, room, game, "shoot", "301.5", "199", "-40.25", "12");
|
||||
assert.deepStrictEqual((await b.nextXt("mm")).slice(2), ["shoot", "301.5", "199", "-40.25", "12"]);
|
||||
say(0, room, game, "endTurn");
|
||||
say(1, room, game, "endTurn");
|
||||
assert.deepStrictEqual(await both("endTurn"), []);
|
||||
say(0, room, game, "shoot", "1%2", "x", "3", "4"); // not numbers: dropped
|
||||
// the server cannot tell when this game is over (the clients keep the
|
||||
// score), so the one who stays is told when the other goes.
|
||||
a.xt("rl", room, room);
|
||||
assert.deepStrictEqual((await b.nextXt("ml")).slice(1), [room, ann.id]);
|
||||
b.xt("rl", room, room);
|
||||
}
|
||||
|
||||
// --- a player who logs off takes their invitation with them
|
||||
a.xt("mp", ann.roomId, GAMES.marbles, 0, "Ben");
|
||||
await b.untilXt("mp");
|
||||
a.socket.destroy();
|
||||
assert.deepStrictEqual((await b.untilXt("mp")).slice(2), ["101", "1"]);
|
||||
|
||||
b.socket.destroy();
|
||||
c.socket.destroy();
|
||||
};
|
||||
|
||||
harness.withServer("buddy games test", HTTP_PORT, GAME_PORT, run).catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,666 @@
|
||||
"use strict";
|
||||
|
||||
// end-to-end check of what smoke.js does not cover: achievements, the
|
||||
// currency exchange, pets' characters, Adopt-A-Pet, gifts in the lands,
|
||||
// parties, Jam-A-Grams, Jammer Walls, reports, blocking, chat commands and
|
||||
// the admin panel's pages for them. three simulated players, a real server.
|
||||
|
||||
const assert = require("assert");
|
||||
const harness = require("./harness.js");
|
||||
|
||||
const HTTP_PORT = 18081;
|
||||
const GAME_PORT = 19340;
|
||||
const BASE = `http://127.0.0.1:${HTTP_PORT}`;
|
||||
const TOWNSHIP = "jamaa_township.room_main#1";
|
||||
const {postJson} = harness;
|
||||
|
||||
const say = (client, roomId, text) =>
|
||||
client.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[${text}%0]]></txt></body></msg>`);
|
||||
|
||||
// registers nothing: logs an existing account in and walks it into Jamaa
|
||||
// Township. returns {client, login, roomId}.
|
||||
const arrive = async (username, password) => {
|
||||
const auth = await (await postJson(`${BASE}/authenticate`, {username, password})).json();
|
||||
const client = new harness.GameClient(GAME_PORT);
|
||||
await client.connect();
|
||||
const login = await client.logIn(username, auth.auth_token);
|
||||
assert.strictEqual(login.status, "1");
|
||||
client.xt("rj", 1, TOWNSHIP, 1, 0, 0);
|
||||
const roomId = (await client.untilXt("rj"))[4];
|
||||
await client.untilXt("rp");
|
||||
client.xt("au", roomId, 1, 400, 400, 14, 1);
|
||||
return {client, login, roomId};
|
||||
};
|
||||
|
||||
// DenXtCommManager.denItemsResponse as [{inv, def, placed}], nine fields an item.
|
||||
const denItems = fields => {
|
||||
const items = [];
|
||||
for (let i = 5; i < fields.length; i += 9) {
|
||||
items.push({inv: fields[i], def: fields[i + 1], placed: fields[i + 2]});
|
||||
}
|
||||
return items;
|
||||
};
|
||||
|
||||
const wall = async body => (await postJson(`${BASE}/wall`, body)).json();
|
||||
|
||||
const run = async () => {
|
||||
const registerJson = body => fetch(`${BASE}/api/register`, {method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({avatarType: 1, agreed: true, ...body})});
|
||||
for (const username of ["Ann", "Ben", "Cat"]) {
|
||||
assert.strictEqual((await registerJson({username, password: "Password01"})).status, 200);
|
||||
}
|
||||
|
||||
// --- the admin panel's message of the day reaches a player once their first room has loaded
|
||||
const panel = async (pathname, body, cookie) => {
|
||||
const response = await fetch(`${BASE}/admin/api/${pathname}`, {
|
||||
method: body === undefined ? "GET" : "POST",
|
||||
headers: {"Content-Type": "application/json", ...(cookie ? {Cookie: cookie} : {})},
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
});
|
||||
return {status: response.status, data: await response.json(), cookie: (response.headers.get("set-cookie") || "").split(";")[0]};
|
||||
};
|
||||
const admin = (await panel("setup", {password: "admin-password-1"})).cookie;
|
||||
assert.strictEqual((await panel("motd", {text: "Welcome to the test server"}, admin)).status, 200);
|
||||
assert.strictEqual((await panel("messages", undefined, admin)).data.motd, "Welcome to the test server");
|
||||
|
||||
const {client: a, login: annLogin, roomId} = await arrive("Ann", "Password01");
|
||||
// "ua": the text sits where a room id usually does, then 1 = system message.
|
||||
assert.deepStrictEqual((await a.untilXt("ua")).slice(1), ["Welcome to the test server", "1"]);
|
||||
assert.strictEqual((await panel("motd", {text: ""}, admin)).status, 200);
|
||||
|
||||
// every account says it is two days old: a newer one gets a cut-down party list.
|
||||
assert.ok(Math.abs(Date.now() / 1000 - 2 * 86400 - annLogin.params.createdAt) < 60);
|
||||
// the phrase menus are not empty (the Jam-A-Gram window reads the first of list 66).
|
||||
a.xt("gl", roomId, 66);
|
||||
assert.deepStrictEqual((await a.nextXt("gl")).slice(8, 10), ["15", "1759"]);
|
||||
// walls are switched on, and each day's first login finds an Adopt-A-Pet.
|
||||
assert.strictEqual(annLogin.params.webWallStatus, 1);
|
||||
assert.strictEqual(annLogin.params.usableAdoptAPetDefs.length, 1);
|
||||
assert.strictEqual(annLogin.params.usableAdoptAPetDefs[0].hasSeen, false);
|
||||
a.xt("padc", roomId, "Ann");
|
||||
assert.deepStrictEqual((await a.nextXt("padc")).slice(2), ["1"]);
|
||||
a.xt("pad", roomId, "Ann");
|
||||
assert.deepStrictEqual((await a.nextXt("pad")).slice(2), ["1", "1", String(annLogin.params.usableAdoptAPetDefs[0].defId), String(annLogin.params.usableAdoptAPetDefs[0].invId)]);
|
||||
|
||||
const {client: b, login: benLogin} = await arrive("Ben", "Password01");
|
||||
await a.untilXt("ac");
|
||||
await a.nextXt("il");
|
||||
|
||||
// --- a shop's title is its room's name, as the id of the string that says so
|
||||
b.xt("rj", roomId, "jamaa_township.clothes_shop#1", 1, 0, 0);
|
||||
const shopRoom = await b.untilXt("rj");
|
||||
assert.strictEqual(shopRoom[14], "Jam Mart Clothing");
|
||||
await b.nextXt("rp");
|
||||
b.xt("gl", shopRoom[4], 11); // the tables in that room open list 11
|
||||
const titled = await b.nextXt("gl");
|
||||
assert.deepStrictEqual(titled.slice(3, 5), ["1000", "389"]); // string 389: "Jam Mart Clothing"
|
||||
b.xt("gl", shopRoom[4], 5); // a shop that is not in this room keeps its own title
|
||||
assert.strictEqual((await b.nextXt("gl"))[4], "");
|
||||
b.xt("rj", shopRoom[4], TOWNSHIP, 1, 0, 0);
|
||||
await b.untilXt("rj");
|
||||
await b.nextXt("rp");
|
||||
await b.nextXt("ac");
|
||||
await b.nextXt("il");
|
||||
b.xt("au", roomId, 1, 420, 400, 14, 1);
|
||||
await a.untilXt("ar");
|
||||
await a.untilXt("ac");
|
||||
await a.nextXt("il");
|
||||
|
||||
// --- minigames: which game is which, a game in a window over the room, gems, a full-screen game
|
||||
a.xt("mi", roomId, 15, 4, 999999);
|
||||
const gameInfo = await a.nextXt("mi");
|
||||
// 19 fields a game. 15 is the popcorn machine, in a window (type 0).
|
||||
assert.deepStrictEqual([gameInfo[2], gameInfo.length, gameInfo[3], gameInfo[6], gameInfo[10]], ["3", 3 + 3 * 19, "15", "MicroPopcorn", "0"]);
|
||||
assert.deepStrictEqual([gameInfo[22], gameInfo[25], gameInfo[29], gameInfo[31]], ["4", "Pachinko", "1", "16"]); // gem Ball: full screen, counts in var 16
|
||||
assert.strictEqual(gameInfo[39], "4295"); // its picture in the Games window
|
||||
// an id nobody knows still gets an entry (a room draws no game signs unless
|
||||
// it hears about all of them), with a name the client can look up.
|
||||
assert.strictEqual(gameInfo[41], "999999");
|
||||
assert.ok(Number(gameInfo[42]) > 0);
|
||||
// the HUD's Games window: game def ids, each with a picture, none of the unfinished ones.
|
||||
a.xt("gl", roomId, 341);
|
||||
const library = (await a.nextXt("gl")).slice(9);
|
||||
assert.ok(library.includes("4") && library.includes("94") && !library.includes("62") && library.length > 15);
|
||||
// phantom Invasion: 10 gems a go, and the prize a win would bring is named up front.
|
||||
a.xt("mj", roomId, 72, 0, 0, -1);
|
||||
const invasionRoom = (await a.nextXt("rj"))[4];
|
||||
await a.untilXt("ms");
|
||||
a.xt("mm", invasionRoom, 72, "cp");
|
||||
assert.strictEqual((await a.nextXt("cu"))[2], "0"); // gems
|
||||
const go = await a.nextXt("mm");
|
||||
assert.deepStrictEqual([go[2], go[3], go[5]], ["cp", "1", "1"]);
|
||||
const [serialNo, prizeDef] = [Number(go[4]), go[6]];
|
||||
assert.ok(serialNo > 0 && Number(prizeDef) > 0);
|
||||
const uidNow = annLogin.params.userId;
|
||||
a.xt("mm", invasionRoom, 72, "cd", 11 * 5 + (uidNow + 99) * 3 + (serialNo + 49) * 5, (serialNo + uidNow + 11) * 3 + 11 * 3);
|
||||
assert.ok(denItems(await a.untilXt("di")).some(item => item.def === prizeDef)); // kept: it is in the den inventory
|
||||
a.xt("rl", invasionRoom, invasionRoom);
|
||||
a.xt("mj", roomId, 15, 0, 0, -1);
|
||||
const subRoom = await a.nextXt("rj");
|
||||
assert.deepStrictEqual([subRoom[2], subRoom[10], subRoom[12], subRoom[13]], ["1", "1", "1", "1"]); // a game room, temporary, beside the room
|
||||
const gemSerial = Number((await a.nextXt("mg"))[2]);
|
||||
await a.nextXt("ma");
|
||||
assert.deepStrictEqual((await a.nextXt("mj")).slice(1), [subRoom[4], String(annLogin.params.userId)]);
|
||||
assert.deepStrictEqual((await a.nextXt("ms")).slice(1), [subRoom[4], "1", String(annLogin.params.userId), String(annLogin.params.dbUserId), "Ann"]);
|
||||
// 25 gems, signed the way MinigameManager.sendGemAward signs them.
|
||||
const uid = annLogin.params.userId;
|
||||
a.xt("mg", subRoom[4], (25 + 29) * 7 + (uid + 99) * 3 + (gemSerial + 49) * 5, (15 + 49) * 3 + (gemSerial + 83) * 5, (gemSerial + uid + 25) * 3 + 25 * 3);
|
||||
const nextSerial = Number((await a.nextXt("mg"))[2]);
|
||||
a.xt("mg", subRoom[4], 1, 2, 3); // not signed: no gems
|
||||
await a.nextXt("mg");
|
||||
assert.ok(nextSerial > 0);
|
||||
a.xt("rl", subRoom[4], subRoom[4]);
|
||||
a.xt("mj", roomId, 4, 0, 0, -1); // gem Ball takes the room's place
|
||||
const gameRoom = await a.nextXt("rj");
|
||||
assert.deepStrictEqual([gameRoom[10], gameRoom[13]], ["1", "0"]);
|
||||
await a.nextXt("mg");
|
||||
await a.nextXt("ma");
|
||||
await a.nextXt("mj");
|
||||
await a.nextXt("ms");
|
||||
assert.deepStrictEqual((await b.untilXt("ar")).slice(2), [String(annLogin.params.userId)]); // gone from the township meanwhile
|
||||
a.xt("zs", gameRoom[4], 16, 1, 1); // "one more game played", twice: a counter, not a value
|
||||
await a.nextXt("zs");
|
||||
a.xt("zs", gameRoom[4], 16, 1, 1);
|
||||
assert.deepStrictEqual((await a.nextXt("zs")).slice(2, 4), ["16", "2"]);
|
||||
a.xt("mj", gameRoom[4], 62, 0, 0, -1); // a game that needs more than is here yet
|
||||
assert.deepStrictEqual((await a.nextXt("mj")).slice(2), ["as", "0"]);
|
||||
assert.match((await a.nextXt("ua"))[1], /not ready/);
|
||||
a.xt("rj", gameRoom[4], TOWNSHIP, 1, 0, 0); // and back
|
||||
await a.untilXt("rj");
|
||||
await a.nextXt("rp");
|
||||
await a.nextXt("ac");
|
||||
await a.nextXt("il");
|
||||
a.xt("au", roomId, 1, 400, 400, 14, 1);
|
||||
await b.untilXt("ac");
|
||||
await b.nextXt("il");
|
||||
|
||||
// --- name tags: the colour and badge go with a colour change, reach the room, and stay
|
||||
a.xt("gl", roomId, 110);
|
||||
const badges = await a.nextXt("gl");
|
||||
assert.deepStrictEqual([badges[3], badges[8], badges[9], badges[70]], ["1049", "75", "1", "62"]); // every badge, in id order: the game's 62 and the thirteen the admin gives
|
||||
const tag = 6 | 11 << 8; // colour 6, the twelfth badge
|
||||
a.xt("ap", roomId, 1, 2, 3, tag);
|
||||
assert.deepStrictEqual((await a.nextXt("ap")).slice(2), ["1"]);
|
||||
assert.deepStrictEqual((await b.untilXt("an")).slice(2), [String(annLogin.params.userId), String(tag)]);
|
||||
a.xt("ap", roomId, 1, 2, 3, 6 | 200 << 8); // no such badge: the colours change, the tag stays
|
||||
await a.nextXt("ap");
|
||||
b.xt("ag", roomId, "Ann");
|
||||
assert.strictEqual((await b.untilXt("ag"))[10], String(tag));
|
||||
|
||||
// --- the currency exchange: 1 diamond for 1,000 gems (def 4, at counter 169)
|
||||
a.xt("gl", roomId, 169);
|
||||
const exchange = await a.nextXt("gl");
|
||||
assert.deepStrictEqual([exchange[3], ...exchange.slice(8)], ["1051", "4", "4", "5", "6", "7"]);
|
||||
a.xt("ce", roomId, 169, 4);
|
||||
assert.deepStrictEqual((await a.nextXt("cu")).slice(2), ["0", String(annLogin.params.gemsCount + 1015), "0"]); // 25 won, 10 spent on Phantom Invasion
|
||||
assert.deepStrictEqual((await a.nextXt("ce")).slice(2), ["1", String(annLogin.params.diamondsCount - 1)]);
|
||||
// 1,000 gems earned (25 in the game, 1,000 here) is an achievement (def 1); the counter came on its own.
|
||||
assert.ok(a.varUpdates.some(update => update[2] === "1" && update[3] === "1025" && update[4] === "1" && update[6] === "1"));
|
||||
a.xt("ce", roomId, 5, 4); // not an exchange counter
|
||||
assert.deepStrictEqual((await a.nextXt("ce")).slice(2), ["0", "0"]);
|
||||
|
||||
// --- pets have a personality and favourites; mastery has to be earned
|
||||
a.xt("pc", roomId, 312, 1, 0, 0, 15386, 15428, 0);
|
||||
const petInv = (await a.nextXt("pc"))[5];
|
||||
a.xt("pl", roomId, "Ann");
|
||||
const petList = await a.nextXt("pl");
|
||||
const [mastery, personality, toy, food] = petList.slice(11, 15).map(Number);
|
||||
assert.strictEqual(mastery, 0);
|
||||
assert.ok(personality >= 25865 && personality <= 25932 && toy > 0 && food > 0);
|
||||
await a.nextXt("pu");
|
||||
// the kitten's foods (list 439) are the first ten in the pack, starting with hamburgers.
|
||||
a.xt("gl", roomId, 439);
|
||||
const foods = await a.nextXt("gl");
|
||||
assert.deepStrictEqual([foods[3], foods[8], foods[9], foods[10]], ["1062", "10", "1", "25933"]);
|
||||
assert.ok(foods.slice(9).filter((_, i) => i % 2 === 0).includes(String(food)));
|
||||
a.xt("gl", roomId, 432);
|
||||
assert.deepStrictEqual((await a.nextXt("gl")).slice(8, 10), ["68", "25865"]);
|
||||
a.xt("pm", roomId, 1, petInv);
|
||||
assert.deepStrictEqual((await a.nextXt("pm")).slice(2), ["0"]);
|
||||
|
||||
// --- gifts lying about in the lands: one per spot, the next one after it is taken
|
||||
a.xt("gl", roomId, 583);
|
||||
const spots = await a.nextXt("gl");
|
||||
assert.deepStrictEqual([spots[3], spots[8]], ["1064", "3"]);
|
||||
a.xt("wig", roomId, spots[9], 0, 0);
|
||||
assert.strictEqual((await a.untilXt("wig"))[2], "1");
|
||||
a.xt("wig", roomId, spots[9], 0, 0); // only once
|
||||
assert.strictEqual((await a.untilXt("wig"))[2], "0");
|
||||
a.xt("gl", roomId, 583);
|
||||
const spotsAfter = await a.untilXt("gl");
|
||||
assert.ok(spotsAfter[8] === "3" && !spotsAfter.slice(9).includes(spots[9]));
|
||||
|
||||
// --- parties: the game's own, always open
|
||||
a.xt("sl", roomId);
|
||||
const partyList = await a.nextXt("sl");
|
||||
assert.ok(Number(partyList[3]) > 20 && partyList[5] === "0" && Number(partyList[3]) * 3 === partyList.length - 4);
|
||||
a.xt("sj", roomId, partyList[4]);
|
||||
const partyJoin = await a.nextXt("rj");
|
||||
assert.deepStrictEqual(partyJoin.slice(2, 4), ["1", `party${partyList[4]}`]);
|
||||
const partyRoom = await a.nextXt("rp");
|
||||
assert.deepStrictEqual([partyRoom[2].split(".")[0], partyRoom[4], partyRoom[5]], ["party", "5", partyList[4]]);
|
||||
a.xt("sj", partyJoin[4], 4); // bunnies only, and Ann is not one
|
||||
assert.deepStrictEqual((await a.nextXt("sj")).slice(2), ["0", "NA", "4"]);
|
||||
|
||||
// --- parties put back: the Trading Party in the trading barn, and two rooms no party used
|
||||
const offered = partyList.slice(4).filter((field, index) => index % 3 === 0);
|
||||
assert.ok(["6", "52", "53"].every(id => offered.includes(id)) && !offered.includes("3"));
|
||||
a.xt("sj", partyJoin[4], 6);
|
||||
assert.deepStrictEqual((await a.nextXt("rj")).slice(3, 4), ["party6"]);
|
||||
assert.strictEqual((await a.nextXt("rp"))[2], "party.venue_pl_barn_trading");
|
||||
|
||||
// --- the Summer Carnival: gone from the official room list, back in ours; its games pay in tickets
|
||||
assert.ok(partyList.slice(4).filter((field, index) => index % 3 === 0).includes("18"));
|
||||
a.xt("sj", partyJoin[4], 18);
|
||||
const carnival = await a.nextXt("rj");
|
||||
assert.deepStrictEqual(carnival.slice(2, 4), ["1", "party18"]);
|
||||
assert.strictEqual((await a.nextXt("rp"))[2], "party.venue_carnival");
|
||||
// its shops sell what is priced in tickets: 76 pieces of clothing at the first.
|
||||
a.xt("gl", carnival[4], 101);
|
||||
const ticketClothes = await a.nextXt("gl");
|
||||
assert.deepStrictEqual([ticketClothes[3], ticketClothes[8]], ["1000", "76"]);
|
||||
a.xt("mi", carnival[4], 68, 96);
|
||||
const booths = await a.nextXt("mi");
|
||||
assert.deepStrictEqual([booths[6], booths[25]], ["Skeeball", "DunkAPhantom"]);
|
||||
a.xt("mj", carnival[4], 68, 0, 0, -1);
|
||||
const booth = (await a.nextXt("rj"))[4];
|
||||
await a.untilXt("ms");
|
||||
// "pz" and "pg" each bring a serial number, hidden as (n + 5) * 3 - 7.
|
||||
const shown = async word => {
|
||||
const message = await a.nextXt("mm");
|
||||
assert.strictEqual(message[2], word);
|
||||
return message;
|
||||
};
|
||||
const serial1 = (Number((await shown("pz"))[3]) + 7) / 3 - 5;
|
||||
a.xt("mm", booth, 68, "pg");
|
||||
assert.strictEqual((await a.nextXt("cu"))[2], "0"); // 5 gems a go
|
||||
const paid = await shown("pg");
|
||||
assert.strictEqual(paid[3], "1");
|
||||
const serial2 = (Number(paid[4]) + 7) / 3 - 5;
|
||||
const points = 250; // at 10 points a ticket
|
||||
a.xt("mm", booth, 68, "gr", (points + 29) * 7 + (serial1 + 49) * 5, (points + 49) * 3 + (serial2 + 83) * 5, (serial1 + points) * 3 + points * 3);
|
||||
assert.deepStrictEqual((await a.nextXt("cu")).slice(2, 4), ["1", String(annLogin.params.ticketsCount + 25)]);
|
||||
assert.strictEqual((await shown("gr"))[3], "25");
|
||||
a.xt("mm", booth, 68, "gr", 1, 2, 3); // the same go again, and unsigned: nothing
|
||||
assert.strictEqual((await shown("gr"))[3], "0");
|
||||
a.xt("rj", booth, "party18", 1, 0, 0); // back out of the game
|
||||
assert.strictEqual((await a.untilXt("rj"))[3], "party18");
|
||||
await a.nextXt("rp");
|
||||
|
||||
// --- sale dates: a window comes round each year (lib/sales.js)
|
||||
const sales = require("../lib/sales.js");
|
||||
const day = (year, month, date) => Date.UTC(year, month - 1, date) / 86400000;
|
||||
const at = (year, month, date) => Date.UTC(year, month - 1, date, 12) / 1000;
|
||||
const october = [[day(2023, 10, 1), day(2023, 11, 11)], [day(2024, 10, 5), day(2024, 11, 11)]];
|
||||
assert.deepStrictEqual(sales.windowFor(october, at(2030, 10, 20)), [at(2030, 10, 1) - 43200, at(2030, 11, 11) - 43200]); // on sale now
|
||||
assert.deepStrictEqual(sales.windowFor(october, at(2030, 3, 1))[0], at(2030, 10, 1) - 43200); // waiting for the next one
|
||||
assert.deepStrictEqual(sales.windowFor([[day(2018, 1, 1), day(2019, 2, 1)]], at(2030, 3, 1)), [0, 0]); // sold all year round: always
|
||||
assert.strictEqual(sales.windowFor(undefined, at(2030, 3, 1)), null);
|
||||
|
||||
// --- a party of Ann's own: the lists its window needs, then hosting it
|
||||
a.xt("gl", partyJoin[4], 370);
|
||||
const hostable = await a.nextXt("gl");
|
||||
assert.ok(hostable[3] === "1047" && Number(hostable[8]) >= 5);
|
||||
a.xt("gl", partyJoin[4], 401);
|
||||
const music = await a.nextXt("gl");
|
||||
assert.ok(music[3] === "1030" && Number(music[8]) > 10);
|
||||
a.xt("gl", partyJoin[4], 386);
|
||||
assert.deepStrictEqual((await a.nextXt("gl")).slice(8, 10), ["26", "24135"]);
|
||||
a.xt("scp", partyJoin[4], hostable[9], 24135, 24162, 1, music[9]); // 1 is not a name
|
||||
assert.deepStrictEqual((await a.nextXt("scp")).slice(2), ["0", "INV"]);
|
||||
a.xt("scp", partyJoin[4], hostable[9], 24135, 24162, 24186, music[9]);
|
||||
assert.deepStrictEqual((await a.nextXt("cu")).slice(2, 4), ["3", String(annLogin.params.diamondsCount - 2)]);
|
||||
const hosting = await a.nextXt("scp");
|
||||
assert.deepStrictEqual(hosting.slice(2, 4), ["1", "1"]);
|
||||
assert.ok(Number(hosting[4]) > 7000);
|
||||
const own = await a.nextXt("rj");
|
||||
// the party's name is three string ids; its music is in the join message.
|
||||
assert.deepStrictEqual([own[3], own[14], own[19]], ["ppartyAnn", "24135|24162|24186", music[9]]);
|
||||
await a.nextXt("rp");
|
||||
assert.strictEqual((await a.nextXt("sjp"))[2], "1");
|
||||
a.xt("au", own[4], 1, 400, 400, 14, 1);
|
||||
a.xt("scp", own[4], hostable[9], 24135, 24162, 24186, music[9]);
|
||||
assert.deepStrictEqual((await a.nextXt("scp")).slice(2), ["0", "EXISTS"]);
|
||||
|
||||
b.xt("slp", 1, 0, 200);
|
||||
const hostedList = await b.untilXt("slp");
|
||||
assert.deepStrictEqual(hostedList.slice(2, 3).concat(hostedList.slice(6, 11)), ["1", "1", annLogin.params.uuid, "24135|24162|24186", "127.0.0.1", hostable[9]]);
|
||||
b.xt("sphp", 1, annLogin.params.uuid);
|
||||
assert.ok(Number((await b.nextXt("sphp"))[2]) > 7000);
|
||||
b.xt("spn", 1, annLogin.params.uuid);
|
||||
assert.deepStrictEqual((await b.nextXt("spn")).slice(2), ["1", annLogin.params.uuid, "127.0.0.1"]);
|
||||
b.xt("sjp", 1, annLogin.params.uuid);
|
||||
assert.deepStrictEqual((await b.nextXt("rj")).slice(2, 4), ["1", "ppartyAnn"]);
|
||||
await b.nextXt("rp");
|
||||
await b.nextXt("ac"); // Ann, already there
|
||||
await b.nextXt("il");
|
||||
assert.strictEqual((await b.nextXt("sjp"))[2], "1");
|
||||
b.xt("au", own[4], 1, 420, 420, 14, 1);
|
||||
await a.untilXt("ac");
|
||||
await a.nextXt("il");
|
||||
|
||||
// --- chat commands: answered in a popup, never shown to the room
|
||||
say(a, own[4], "!online");
|
||||
assert.deepStrictEqual((await a.nextXt("xtl")).slice(2), ["2 playing: Ann, Ben"]); // a plain message box
|
||||
assert.strictEqual((await a.nextXt("uc"))[3], "!online"); // the sender's own bubble
|
||||
say(a, own[4], "!!! wow");
|
||||
assert.strictEqual((await b.untilXt("uc"))[3], "!!! wow"); // not a command: just chat
|
||||
await a.nextXt("uc");
|
||||
say(a, own[4], "!roll");
|
||||
assert.match((await b.nextXt("uc"))[3], /^\(rolls a dice: [1-6]\)$/);
|
||||
await a.nextXt("uc");
|
||||
|
||||
// --- outfits: what the animal wears, saved and put back on
|
||||
a.xt("gl", own[4], 5);
|
||||
const shop = await a.nextXt("gl");
|
||||
a.xt("ib", own[4], 5, 1, shop[9], 0, 0, -1, "");
|
||||
const hat = (await a.nextXt("il"))[9];
|
||||
await a.nextXt("ib");
|
||||
a.xt("iu", own[4], 1, 0, hat);
|
||||
await a.nextXt("iu");
|
||||
await a.nextXt("il");
|
||||
await b.untilXt("il");
|
||||
say(a, own[4], "!outfit save hat");
|
||||
assert.strictEqual((await a.nextXt("xtl"))[2], "Outfit hat saved (1 items).");
|
||||
await a.nextXt("uc");
|
||||
a.xt("iu", own[4], 0, 1, hat);
|
||||
await a.nextXt("iu");
|
||||
const off = await a.nextXt("il"); // her own game hears it too
|
||||
assert.deepStrictEqual([off[2], off[7], off[8], off[9]], ["3", "0", "1", hat]);
|
||||
assert.strictEqual((await b.nextXt("il"))[8], "0"); // ben sees it come off
|
||||
say(a, own[4], "!outfit wear hat");
|
||||
// "3": what is worn changed, [.., onCount, offCount, (inv, def)...]
|
||||
const worn = await a.nextXt("il");
|
||||
assert.deepStrictEqual([worn[2], worn[7], worn[8], worn[9]], ["3", "1", "0", hat]);
|
||||
assert.strictEqual((await a.nextXt("xtl"))[2], "Wearing hat.");
|
||||
await a.nextXt("uc");
|
||||
assert.deepStrictEqual((await b.nextXt("il")).slice(8, 10), ["1", shop[9]]); // and back on
|
||||
|
||||
// --- Jam-A-Grams: a card, a stamp, typed words and the hat as a gift
|
||||
a.xt("gl", own[4], 10);
|
||||
const cards = await a.nextXt("gl");
|
||||
assert.ok(cards[3] === "1033" && Number(cards[8]) > 100 && cards[9] === "1");
|
||||
a.xt("gl", own[4], 44);
|
||||
const stamps = await a.nextXt("gl");
|
||||
a.xt("es", own[4], "Ben", cards[9], 9999, 2, "hello", 0, 0, 0); // no such stamp
|
||||
assert.deepStrictEqual((await a.nextXt("es")).slice(2), ["0"]);
|
||||
a.xt("es", own[4], "Ben", cards[9], stamps[9], 2, "A hat for you!", 1, hat, 0);
|
||||
// the hat leaves Ann's inventory with the card.
|
||||
const sent = await a.nextXt("il");
|
||||
assert.deepStrictEqual([sent[2], sent[7], sent[8], sent[9]], ["2", "0", "1", hat]);
|
||||
assert.deepStrictEqual((await a.nextXt("es")).slice(2), ["1"]);
|
||||
const pushed = await b.untilXt("ep");
|
||||
assert.deepStrictEqual(pushed.slice(3, 10), ["Ann", cards[9], stamps[9], "0", "A hat for you!", "1", shop[9]]);
|
||||
b.xt("el", own[4], 0);
|
||||
const inbox = await b.nextXt("el");
|
||||
assert.deepStrictEqual([inbox[2], inbox.length], ["1", 3 + 17]);
|
||||
b.xt("er", own[4], pushed[2]);
|
||||
assert.deepStrictEqual((await b.nextXt("er")).slice(2), [pushed[2], "1"]);
|
||||
b.xt("eg", own[4], pushed[2], 1);
|
||||
assert.deepStrictEqual((await b.nextXt("il")).slice(2, 3).concat((await b.nextXt("eg")).slice(2)), ["2", pushed[2], "1"]);
|
||||
b.xt("eg", own[4], pushed[2], 1); // the gift is taken only once
|
||||
assert.deepStrictEqual((await b.nextXt("eg")).slice(2), [pushed[2], "0"]);
|
||||
b.xt("ed", own[4], pushed[2]);
|
||||
assert.deepStrictEqual((await b.nextXt("ed")).slice(2), ["1", "1", pushed[2]]);
|
||||
b.xt("ei", own[4], 2); // ben takes Jam-A-Grams from nobody now
|
||||
assert.deepStrictEqual((await b.nextXt("ei")).slice(2), ["1"]);
|
||||
a.xt("es", own[4], "Ben", cards[9], stamps[9], 2, "again", 0, 0, 0);
|
||||
assert.deepStrictEqual((await a.nextXt("es")).slice(2), ["-2"]);
|
||||
b.xt("ei", own[4], 0);
|
||||
await b.nextXt("ei");
|
||||
|
||||
// A secret valentine: the receiver is not told who sent it, the server knows.
|
||||
a.xt("es", own[4], "Ben", cards[9], stamps[9], 2, "GUESS WHO", 0, 0, 1);
|
||||
assert.deepStrictEqual((await a.nextXt("es")).slice(2), ["1"]);
|
||||
const valentine = await b.nextXt("ep");
|
||||
assert.deepStrictEqual([valentine[3], valentine[7], valentine[18]], ["", "GUESS WHO", "1"]); // no name; special type 1
|
||||
b.xt("fr", own[4], "Secret Valentine", 14); // reported under the name the game shows
|
||||
assert.deepStrictEqual((await b.nextXt("fr")).slice(2), ["1"]);
|
||||
const aboutValentine = (await panel("reports", undefined, admin)).data.reports;
|
||||
assert.deepStrictEqual([aboutValentine[0].reporter, aboutValentine[0].target, aboutValentine[0].reason], ["Ben", "Ann", "Inappropriate Jam-A-Gram"]);
|
||||
await panel("report", {id: aboutValentine[0].id}, admin);
|
||||
b.xt("ed", own[4], valentine[2]);
|
||||
await b.nextXt("ed");
|
||||
|
||||
// --- Jammer Walls: the wallpapers a wall cannot be drawn without, and their buttons
|
||||
a.xt("gl", own[4], 314);
|
||||
const wallpapers = await a.nextXt("gl");
|
||||
a.xt("gl", own[4], 313);
|
||||
const wallpaperButtons = await a.nextXt("gl");
|
||||
assert.ok(wallpapers[3] === "1033" && Number(wallpapers[8]) > 19 && wallpapers[8] === wallpaperButtons[8]); // 19: a new wall's wallpaper
|
||||
a.xt("gl", own[4], 646);
|
||||
assert.ok(Number((await a.nextXt("gl"))[8]) > 10);
|
||||
a.xt("dmi", own[4], "Ben"); // masterpieces hung on the wall: none, but it waits to hear
|
||||
assert.deepStrictEqual((await a.nextXt("dmi")).slice(2), ["0"]);
|
||||
a.xt("crg", own[4], "jammerwall", benLogin.params.uuid, annLogin.params.uuid, "report");
|
||||
assert.deepStrictEqual((await a.nextXt("crg")).slice(2), ["1", "0", "0"]); // found, not liked by me, no likes
|
||||
a.xt("crp", own[4], "jammerwall", benLogin.params.uuid, annLogin.params.uuid);
|
||||
assert.deepStrictEqual((await a.nextXt("crp")).slice(2), ["1"]);
|
||||
a.xt("crp", own[4], "jammerwall", benLogin.params.uuid, annLogin.params.uuid); // one like each
|
||||
assert.deepStrictEqual((await a.nextXt("crp")).slice(2), ["0"]);
|
||||
b.xt("crg", own[4], "jammerwall", benLogin.params.uuid, benLogin.params.uuid, "report");
|
||||
assert.deepStrictEqual((await b.nextXt("crg")).slice(2), ["1", "0", "1"]);
|
||||
|
||||
// --- Jammer Walls: a token over the socket, then JSON over HTTP
|
||||
a.xt("wsg", own[4], "Ben");
|
||||
assert.deepStrictEqual((await a.nextXt("wsg")).slice(2), ["2"]); // open to everyone
|
||||
a.xt("wt", own[4], "Ben");
|
||||
const token = await a.nextXt("wt");
|
||||
assert.deepStrictEqual([token[2], token[4], token[5], token[6]], ["1", "1", "1", "Ben"]);
|
||||
assert.deepStrictEqual(await wall({cmd: "GET", t: "nonsense"}), {s: false, e: "token"});
|
||||
const before = await wall({cmd: "GET", t: token[3]});
|
||||
assert.deepStrictEqual([before.s, before.r, before.p.bg, before.p.visits], [true, [], "19", 0]);
|
||||
const put = await wall({cmd: "PUT", t: token[3], m: "Nice wall, Ben!", s: 2, c: 3, ai: 1, ac: [1, 2, 3], ae: 4, ap: 5, l: 0, aci: -1, sid: 999});
|
||||
assert.strictEqual(put.PUT.s, true);
|
||||
assert.deepStrictEqual([put.GET.r.length, put.GET.r[0].m, put.GET.r[0].un, put.GET.r[0].uid, put.GET.r[0].x], [1, "Nice wall, Ben!", "Ann", annLogin.params.dbUserId, put.x]);
|
||||
assert.strictEqual((await wall({cmd: "CHK", t: token[3]})).t, put.t);
|
||||
a.xt("wci", own[4], "Ben");
|
||||
assert.deepStrictEqual((await a.nextXt("wci")).slice(2), ["1"]);
|
||||
b.xt("wt", own[4], "Ben");
|
||||
const ownToken = (await b.nextXt("wt"))[3];
|
||||
b.xt("wps", own[4], JSON.stringify({bg: "7", tag: "hello there", visits: 5000}));
|
||||
assert.deepStrictEqual((await b.nextXt("wps")).slice(2), ["1"]);
|
||||
const mine = await wall({cmd: "GET", t: ownToken});
|
||||
assert.deepStrictEqual([mine.p.bg, mine.p.tag, mine.p.visits, mine.r.length], ["7", "hello there", 1, 1]); // visits are not the owner's to set
|
||||
assert.deepStrictEqual(await wall({cmd: "CLW", t: token[3]}), {s: false}); // only the owner clears a wall
|
||||
assert.deepStrictEqual(await wall({cmd: "DEL", t: ownToken, x: put.x}), {s: true});
|
||||
assert.strictEqual((await wall({cmd: "GET", t: ownToken})).r.length, 0);
|
||||
b.xt("wss", own[4], 0); // locked
|
||||
assert.deepStrictEqual((await b.nextXt("wss")).slice(2), ["1"]);
|
||||
assert.deepStrictEqual(await wall({cmd: "GET", t: token[3]}), {s: false, e: "token"});
|
||||
a.xt("wt", own[4], "Ben");
|
||||
assert.deepStrictEqual((await a.nextXt("wt")).slice(2), ["-1"]);
|
||||
b.xt("wss", own[4], 2);
|
||||
await b.nextXt("wss");
|
||||
|
||||
// --- reports: the reason, what was typed, and what the reported player had been saying
|
||||
say(b, own[4], "something rude");
|
||||
await b.nextXt("uc");
|
||||
await a.untilXt("uc");
|
||||
a.xt("xrd", own[4], "Ben", 2, "He keeps saying rude things in my party");
|
||||
a.xt("fr", own[4], "Ben", 2);
|
||||
assert.deepStrictEqual((await a.nextXt("fr")).slice(2), ["1"]);
|
||||
const waiting = (await panel("reports", undefined, admin)).data;
|
||||
assert.strictEqual(waiting.open, 1);
|
||||
assert.strictEqual(waiting.reports.length, 1);
|
||||
assert.deepStrictEqual([waiting.reports[0].reporter, waiting.reports[0].target, waiting.reports[0].reason, waiting.reports[0].detail, waiting.reports[0].room],
|
||||
["Ann", "Ben", "Bad words", "He keeps saying rude things in my party", "ppartyAnn"]);
|
||||
assert.match(waiting.reports[0].context, /something rude/);
|
||||
assert.strictEqual((await panel("overview", undefined, admin)).data.stats.reports, 1);
|
||||
assert.strictEqual((await panel("report", {id: waiting.reports[0].id}, admin)).status, 200);
|
||||
assert.strictEqual((await panel("reports", undefined, admin)).data.open, 0);
|
||||
assert.strictEqual((await panel("reports?handled=1", undefined, admin)).data.reports.length, 2); // this one and the valentine
|
||||
|
||||
// --- blocking: no chat from them, out of my party and my den, and out of sight if I say so
|
||||
a.xt("bb", own[4], "Ben");
|
||||
assert.deepStrictEqual((await a.nextXt("bb")).slice(2), ["Ben", "1"]);
|
||||
// ben is sent back to the township: a room change he did not ask for.
|
||||
const sentHome = await b.untilXt("rj");
|
||||
assert.deepStrictEqual(sentHome.slice(2, 4), ["1", TOWNSHIP]);
|
||||
const home = sentHome[4]; // the township emptied meanwhile, so it is a new room
|
||||
await b.nextXt("rp");
|
||||
assert.deepStrictEqual((await a.nextXt("ar")).slice(2), [String(benLogin.params.userId)]);
|
||||
b.xt("au", home, 1, 300, 300, 14, 1);
|
||||
b.xt("sjp", home, annLogin.params.uuid);
|
||||
assert.deepStrictEqual((await b.nextXt("sjp")).slice(2), ["0", "BLK"]);
|
||||
b.xt("slp", home, 0, 200);
|
||||
assert.deepStrictEqual((await b.nextXt("slp")).slice(2, 4), ["1", "0"]); // nor is it listed for him
|
||||
b.xt("dj", home, "denAnn", 1, -1);
|
||||
assert.strictEqual((await b.nextXt("rj"))[2], "0");
|
||||
b.xt("wt", home, "Ann");
|
||||
assert.deepStrictEqual((await b.nextXt("wt")).slice(2), ["-1"]);
|
||||
|
||||
a.xt("rj", own[4], TOWNSHIP, 1, 0, 0);
|
||||
await a.untilXt("rj");
|
||||
await a.nextXt("rp");
|
||||
await a.nextXt("ac"); // ben is drawn: blocked, but not hidden yet
|
||||
await a.nextXt("il");
|
||||
a.xt("au", home, 1, 500, 500, 14, 1);
|
||||
await b.untilXt("ac");
|
||||
await b.nextXt("il");
|
||||
say(b, home, "can you hear me");
|
||||
await b.nextXt("uc");
|
||||
say(a, home, "hello");
|
||||
assert.strictEqual((await a.nextXt("uc"))[3], "hello"); // ben's line never came
|
||||
assert.strictEqual((await b.nextXt("uc"))[3], "hello"); // though he still hears Ann
|
||||
say(a, home, "!hideblocked on");
|
||||
assert.deepStrictEqual((await a.nextXt("ar")).slice(2), [String(benLogin.params.userId)]);
|
||||
assert.strictEqual((await a.nextXt("xtl"))[2], "Players you have blocked are now hidden from you.");
|
||||
await a.nextXt("uc");
|
||||
b.xt("au", home, 2, 310, 310, 320, 320, 14, 0); // ben walks about: nothing for Ann
|
||||
a.xt("zg", home);
|
||||
const vars = await a.nextXt("zg");
|
||||
assert.strictEqual(vars[vars.indexOf("9001", 3) + 2], "1");
|
||||
a.xt("zs", home, 9001, 0, 1); // the settings window's switch, off again
|
||||
assert.deepStrictEqual((await a.nextXt("ac")).slice(2, 3), [String(benLogin.params.userId)]);
|
||||
await a.nextXt("il");
|
||||
assert.deepStrictEqual((await a.nextXt("zs")).slice(2), ["9001", "0", "0"]);
|
||||
a.xt("bu", home, "Ben");
|
||||
assert.deepStrictEqual((await a.nextXt("bu")).slice(2), ["Ben", "1"]);
|
||||
|
||||
// blocking someone standing in my den puts them outside, with the game's own notice.
|
||||
b.xt("dj", home, "denAnn", 1, -1);
|
||||
const denId = (await b.untilXt("rj"))[4];
|
||||
await b.nextXt("rp");
|
||||
await b.nextXt("ds");
|
||||
a.xt("bb", home, "Ben");
|
||||
await a.untilXt("bb");
|
||||
await b.nextXt("dpk");
|
||||
assert.deepStrictEqual((await b.nextXt("rj")).slice(2, 4), ["1", TOWNSHIP]);
|
||||
await b.nextXt("rp");
|
||||
a.xt("bu", home, "Ben");
|
||||
await a.untilXt("bu");
|
||||
|
||||
// --- den layouts: save, clear, load; and copying a den one stands in
|
||||
a.xt("dj", home, "denAnn", 1, -1);
|
||||
const annDen = (await a.untilXt("rj"))[4];
|
||||
await a.nextXt("rp");
|
||||
await a.nextXt("ds");
|
||||
a.xt("au", annDen, 1, 200, 200, 14, 1);
|
||||
a.xt("gl", annDen, 9);
|
||||
const denShop = await a.nextXt("gl");
|
||||
a.xt("db", annDen, 0, 9, denShop[9], 0, 0, 0, 0, "");
|
||||
await a.nextXt("db");
|
||||
const chair = denItems(await a.nextXt("di")).find(item => item.def === denShop[9]).inv;
|
||||
a.xt("ds", annDen, 1, 0, chair, 1, 120, 340, 1, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
await a.nextXt("dss");
|
||||
say(a, annDen, "!den save cosy");
|
||||
assert.strictEqual((await a.nextXt("xtl"))[2], "Den layout cosy saved (1 items).");
|
||||
await a.nextXt("uc");
|
||||
a.xt("de", annDen);
|
||||
await a.nextXt("de");
|
||||
await a.nextXt("di");
|
||||
say(a, annDen, "!den load cosy");
|
||||
assert.deepStrictEqual(denItems(await a.nextXt("di")).find(item => item.inv === chair), {inv: chair, def: denShop[9], placed: "1"}); // placed again
|
||||
assert.deepStrictEqual((await a.nextXt("ds")).slice(2, 10), ["1", "0", "0", chair, denShop[9], "1", "120", "340"]);
|
||||
assert.strictEqual((await a.nextXt("xtl"))[2], "Den layout cosy loaded.");
|
||||
await a.nextXt("uc");
|
||||
|
||||
b.xt("dj", home, "denAnn", 1, -1);
|
||||
await b.untilXt("rj");
|
||||
await b.nextXt("rp");
|
||||
await b.nextXt("ac"); // Ann, at home
|
||||
await b.nextXt("il");
|
||||
await b.nextXt("ds");
|
||||
say(b, annDen, "!den copy");
|
||||
const copied = denItems(await b.nextXt("di")); // ben had no such chair: he has one now, placed
|
||||
assert.deepStrictEqual(copied.map(item => [item.def, item.placed]), [[denShop[9], "1"]]);
|
||||
assert.strictEqual((await b.nextXt("xtl"))[2], "Your den now looks like this one.");
|
||||
await b.nextXt("uc");
|
||||
|
||||
// --- the panel: announcements, gifts, what an account owns, the ban list
|
||||
const announced = await panel("announce", {text: "Party at Ann's den"}, admin);
|
||||
assert.deepStrictEqual(announced.data, {ok: "Shown to 1 player."}); // Ann has walked about; Ben has not moved in the den yet
|
||||
assert.strictEqual((await a.untilXt("ua"))[1], "Party at Ann's den");
|
||||
const rooms = (await panel("messages", undefined, admin)).data.rooms;
|
||||
assert.deepStrictEqual(rooms.find(room => room.name === "denAnn"), {name: "denAnn", title: "Ann's Den", players: 2});
|
||||
assert.strictEqual((await panel("announce", {text: "nobody there", room: "no.such#1"}, admin)).data.ok, "Shown to 0 players.");
|
||||
|
||||
// gifts come as Jam-A-Grams from Animal Jam HQ. diamonds: the client is
|
||||
// told a code was redeemed, asks for its cards and opens a gift popup.
|
||||
assert.strictEqual((await panel("account", {username: "Ben", action: "gift", kind: "diamonds", amount: 7, text: "7 for you"}, admin)).status, 200);
|
||||
assert.deepStrictEqual((await b.untilXt("grc")).slice(2), ["1", "", "0"]);
|
||||
b.xt("el", annDen, 0); // the inbox does not list it
|
||||
assert.strictEqual((await b.nextXt("el"))[2], "0");
|
||||
b.xt("el", annDen, 1); // the popups' request does
|
||||
const popupCards = await b.nextXt("el");
|
||||
// sender, message (not starting with a number), type 9 = diamonds, amount, sender type 2 = opens as a popup
|
||||
assert.deepStrictEqual([popupCards[2], popupCards[4], popupCards[8], popupCards[9], popupCards[10], popupCards[16]],
|
||||
["1", "Burrow HQ", "Gift: 7 for you", "9", "7", "2"]);
|
||||
b.xt("eg", annDen, popupCards[3], 1);
|
||||
assert.deepStrictEqual((await b.nextXt("cu")).slice(2), ["3", String(benLogin.params.diamondsCount + 7), "0"]);
|
||||
assert.deepStrictEqual((await b.nextXt("eg")).slice(2), [popupCards[3], "1"]);
|
||||
b.xt("el", annDen, 1);
|
||||
assert.strictEqual((await b.nextXt("el"))[2], "0"); // answered, so gone
|
||||
// an item waits in the inbox, from "the voice": the name is string 15964, "Animal Jam HQ".
|
||||
assert.strictEqual((await panel("account", {username: "Ben", action: "gift", kind: "den", id: Number(denShop[9])}, admin)).status, 200);
|
||||
const hqCard = await b.nextXt("ep");
|
||||
assert.deepStrictEqual([hqCard[3], hqCard[7], hqCard[8], hqCard[9], hqCard[15]], ["15964", "A gift for you!", "3", denShop[9], "1"]);
|
||||
b.xt("eg", annDen, hqCard[2], 1);
|
||||
assert.strictEqual((await b.nextXt("di"))[3], "2");
|
||||
assert.deepStrictEqual((await b.nextXt("eg")).slice(2), [hqCard[2], "1"]);
|
||||
assert.strictEqual((await panel("account", {username: "Ben", action: "gift", kind: "den", id: 99999999}, admin)).status, 400);
|
||||
assert.strictEqual((await panel("account", {username: "Ben", action: "gift", kind: "tickets", amount: 3}, admin)).status, 200); // no card for tickets
|
||||
assert.deepStrictEqual((await b.nextXt("cu")).slice(2, 3), ["1"]);
|
||||
assert.strictEqual((await panel("account", {username: "Ben", action: "gift", kind: "achievement", id: 99}, admin)).status, 200);
|
||||
assert.strictEqual((await panel("account", {username: "Ben", action: "gift", kind: "achievement", id: 99}, admin)).status, 400); // already has it
|
||||
assert.match((await panel("account", {username: "Cat", action: "gift", kind: "adopt", id: "all"}, admin)).data.ok, /^Cat has \d+ more/);
|
||||
|
||||
const owned = (await panel("owned?username=Ben", undefined, admin)).data;
|
||||
assert.deepStrictEqual([owned.animals.length, owned.denItemsTotal, owned.denItems[0].count, owned.clothingTotal, owned.currency.diamonds],
|
||||
[1, 2, 2, 1, benLogin.params.diamondsCount + 7]);
|
||||
assert.ok(owned.achievements >= 1 && owned.clothing[0].name.length > 0);
|
||||
|
||||
assert.deepStrictEqual((await panel("bans", undefined, admin)).data.accounts, []);
|
||||
await panel("account", {username: "Cat", action: "ban", hours: 0}, admin);
|
||||
await panel("account", {username: "Ben", action: "silence", hours: 1}, admin);
|
||||
const disciplined = (await panel("bans", undefined, admin)).data.accounts;
|
||||
assert.deepStrictEqual(disciplined.map(entry => [entry.username, entry.banned, entry.silenced > 1700]), [["Ben", 0, true], ["Cat", -1, false]]);
|
||||
|
||||
// --- the panel's Debug page: into a room nothing leads to, and sale dates off
|
||||
const debug = (await panel("debug", undefined, admin)).data;
|
||||
assert.ok(debug.players.includes("Ann") && debug.rooms.length > 400 && debug.everythingOnSale === false);
|
||||
assert.match(debug.rooms.find(room => room.path === "epic_dens/room_solarcade2").note, /Epic Dens/);
|
||||
assert.strictEqual((await panel("debug", {action: "teleport", username: "Ann", room: "epic_dens/room_solarcade2"}, admin)).status, 200);
|
||||
assert.strictEqual((await a.untilXt("rj"))[3].split("#")[0], "epic_dens.room_solarcade2");
|
||||
assert.strictEqual((await panel("debug", {action: "teleport", username: "Ann", room: "no/such_room"}, admin)).status, 400);
|
||||
assert.strictEqual((await panel("debug", {action: "teleport", username: "Cat", room: "jamaa_township/room_main"}, admin)).status, 400); // not playing
|
||||
// den items out of season have dates in the pack clients get; with the switch on, none do.
|
||||
const zlib = require("zlib");
|
||||
const amf3 = require("../lib/amf3.js");
|
||||
const cdn = require("../lib/cdn.js");
|
||||
const dated = async pack => Object.values(amf3.decode(zlib.inflateRawSync(Buffer.from(
|
||||
await (await fetch(`${BASE}/${cdn.hashedPath(`defPacks/${pack}`)}`)).arrayBuffer())))).filter(def => Number(def.availabilityEndTime) > 0).length;
|
||||
assert.ok(await dated(1030) > 0);
|
||||
assert.strictEqual((await panel("debug", {action: "everythingOnSale", on: true}, admin)).status, 200);
|
||||
assert.strictEqual(await dated(1030), 0);
|
||||
await panel("debug", {action: "everythingOnSale", on: false}, admin);
|
||||
assert.ok(await dated(1030) > 0);
|
||||
|
||||
a.socket.destroy();
|
||||
b.socket.destroy();
|
||||
};
|
||||
|
||||
harness.withServer("feature test", HTTP_PORT, GAME_PORT, run).catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
"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 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;
|
||||
}
|
||||
}
|
||||
|
||||
const postJson = (url, body) => fetch(url, {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json", "Origin": "null"},
|
||||
body: JSON.stringify(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 = {GameClient, postJson, withServer};
|
||||
+206
@@ -0,0 +1,206 @@
|
||||
"use strict";
|
||||
|
||||
// end-to-end check of the small comforts added on 2026-10-11: bigger
|
||||
// limits, the newer chat commands, whispers, names typed over, looks per
|
||||
// room, eggs that hatch at once. simulated players, a real server.
|
||||
|
||||
const assert = require("assert");
|
||||
const harness = require("./harness.js");
|
||||
|
||||
const HTTP_PORT = 18085;
|
||||
const GAME_PORT = 19344;
|
||||
const BASE = `http://127.0.0.1:${HTTP_PORT}`;
|
||||
const TOWNSHIP = "jamaa_township.room_main#1";
|
||||
const {postJson} = harness;
|
||||
|
||||
const say = (client, roomId, text) =>
|
||||
client.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[${text}%0]]></txt></body></msg>`);
|
||||
// what a command's message box said.
|
||||
const told = async client => (await client.untilXt("xtl"))[2];
|
||||
|
||||
// logs in and asks for the township, as the game always does first.
|
||||
// returns where the server put them.
|
||||
const arrive = async username => {
|
||||
const auth = await (await postJson(`${BASE}/authenticate`, {username, password: "Password01"})).json();
|
||||
const client = new harness.GameClient(GAME_PORT);
|
||||
await client.connect();
|
||||
const login = await client.logIn(username, auth.auth_token);
|
||||
assert.strictEqual(login.status, "1");
|
||||
client.xt("rj", 1, TOWNSHIP, 1, 0, 0);
|
||||
const joined = await client.untilXt("rj");
|
||||
const file = (await client.untilXt("rp"))[2];
|
||||
client.xt("au", joined[4], 1, 400, 400, 14, 1);
|
||||
return {client, login, roomId: joined[4], room: joined[3], file};
|
||||
};
|
||||
|
||||
const run = async () => {
|
||||
for (const username of ["Ann", "Ben"]) {
|
||||
const response = await fetch(`${BASE}/api/register`, {method: "POST", headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({username, password: "Password01", avatarType: 1, agreed: true})});
|
||||
assert.strictEqual(response.status, 200);
|
||||
}
|
||||
let {client: a, login, roomId, room} = await arrive("Ann");
|
||||
const {client: b, roomId: benRoom} = await arrive("Ben");
|
||||
await a.untilXt("ac");
|
||||
assert.strictEqual(room, TOWNSHIP);
|
||||
assert.strictEqual(login.params.pendingFlags & 2, 2); // the client's bigger inventories
|
||||
|
||||
// --- !go: by short name, by a room's own name, and not to nowhere
|
||||
say(a, roomId, "!go nowhere");
|
||||
assert.match(await told(a), /no place called nowhere/);
|
||||
say(a, roomId, "!go list");
|
||||
assert.match(await told(a), /township.*sarepia/);
|
||||
say(a, roomId, "!go sarepia");
|
||||
let moved = await a.untilXt("rj");
|
||||
assert.strictEqual(moved[3], "sarepia.room_main#1");
|
||||
assert.strictEqual((await a.untilXt("rp"))[2], "sarepia.room_main");
|
||||
roomId = moved[4];
|
||||
|
||||
// --- a look for this room only, and for no other
|
||||
say(a, roomId, "!theme here fall2022");
|
||||
assert.strictEqual((await a.untilXt("rp"))[2], "theme_1636.sarepia.room_main");
|
||||
say(a, roomId, "!theme here easter");
|
||||
assert.match(await told(a), /Use: !theme/);
|
||||
say(a, roomId, "!go sarepia.flag_shop");
|
||||
moved = await a.untilXt("rj");
|
||||
assert.strictEqual((await a.untilXt("rp"))[2], "sarepia.flag_shop");
|
||||
say(a, moved[4], "!go sarepia");
|
||||
moved = await a.untilXt("rj");
|
||||
assert.strictEqual((await a.untilXt("rp"))[2], "theme_1636.sarepia.room_main"); // remembered
|
||||
roomId = moved[4];
|
||||
say(a, roomId, "!theme here off");
|
||||
assert.strictEqual((await a.untilXt("rp"))[2], "sarepia.room_main");
|
||||
|
||||
// --- whispers: buddies only; a popup from afar, a bubble for two in one room
|
||||
say(a, roomId, "!w Ben Psst, over HERE");
|
||||
assert.match(await told(a), /not one of your buddies/);
|
||||
a.xt("ba", roomId, "Ben");
|
||||
await b.untilXt("ba");
|
||||
b.xt("bc", benRoom, "Ann", 1);
|
||||
await a.untilXt("bs");
|
||||
say(a, roomId, "!w Ben Psst, over HERE");
|
||||
assert.deepStrictEqual((await b.untilXt("xw")).slice(2), ["0", "Ann", "Psst, over HERE"]); // from afar: a box; capitals kept
|
||||
assert.match(await told(a), /Whispered to Ben/);
|
||||
say(b, benRoom, "!go sarepia");
|
||||
const benMoved = await b.untilXt("rj");
|
||||
await b.untilXt("rp");
|
||||
b.xt("au", benMoved[4], 1, 300, 300, 14, 1);
|
||||
await a.untilXt("ac");
|
||||
say(b, benMoved[4], "!w ann hello");
|
||||
assert.deepStrictEqual((await a.untilXt("xw")).slice(2), ["1"]); // in one room: the next bubble is a green one
|
||||
assert.deepStrictEqual((await a.nextXt("uc")).slice(3), ["hello", "0"]);
|
||||
|
||||
// --- names typed over in the switcher windows: an animal's, a pet's
|
||||
a.xt("xrn", roomId, "a", 1, "Sir Fluffy Paws");
|
||||
assert.strictEqual((await a.untilXt("ad"))[15], "Sir Fluffy Paws");
|
||||
assert.deepStrictEqual((await a.untilXt("xrn")).slice(2), ["a", "1", "1", "Sir Fluffy Paws"]);
|
||||
a.xt("xrn", roomId, "a", 1, "<b>");
|
||||
assert.deepStrictEqual((await a.untilXt("xrn")).slice(2), ["a", "1", "0", "Sir Fluffy Paws"]);
|
||||
a.xt("xrn", roomId, "p", 999, "Biscuit");
|
||||
assert.deepStrictEqual((await a.untilXt("xrn")).slice(2, 5), ["p", "999", "0"]);
|
||||
say(a, roomId, "!name Nope"); // no longer a command: just something said
|
||||
assert.strictEqual((await a.untilXt("uc"))[3], "!name Nope");
|
||||
|
||||
// --- clothes: everything off and back
|
||||
const give = async query => {
|
||||
const found = (await (await fetch(`${BASE}/api/search?q=${query}&kind=clothing`)).json()).results[0];
|
||||
assert.strictEqual((await fetch(`${BASE}/api/give`, {method: "POST", headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({username: "Ann", kind: "clothing", id: found.id, colorIndex: 0})})).status, 200);
|
||||
return (await a.untilXt("il"))[9]; // its inventory id
|
||||
};
|
||||
const hat = await give("top+hat");
|
||||
const scarf = await give("scarf");
|
||||
a.xt("iu", roomId, 2, 0, hat, scarf);
|
||||
await a.untilXt("iu");
|
||||
await a.untilXt("il");
|
||||
say(a, roomId, "!outfit off");
|
||||
let changed = await a.untilXt("il");
|
||||
assert.deepStrictEqual([changed[2], changed[7], changed[8]], ["3", "0", "2"]);
|
||||
assert.match(await told(a), /Everything is off/);
|
||||
say(a, roomId, "!outfit undo");
|
||||
changed = await a.untilXt("il");
|
||||
assert.deepStrictEqual([changed[2], changed[7], changed[8]], ["3", "2", "0"]);
|
||||
assert.match(await told(a), /Back to what you wore before/);
|
||||
say(a, roomId, "!again");
|
||||
assert.match(await told(a), /Buy something in a shop first/);
|
||||
// A purchase, then more of it: only after a yes to the question.
|
||||
a.xt("gl", roomId, 5);
|
||||
const shop = await a.untilXt("gl");
|
||||
a.xt("ib", roomId, 5, 1, shop[9], 0, 0, -1, "");
|
||||
await a.untilXt("ib");
|
||||
const owned = async () => {
|
||||
a.xt("il", roomId, "Ann", 1, 1);
|
||||
let list = await a.untilXt("il");
|
||||
while (list[2] !== "0") {
|
||||
list = await a.untilXt("il");
|
||||
}
|
||||
return Number(list[8]);
|
||||
};
|
||||
const before = await owned();
|
||||
say(a, roomId, "!again 101");
|
||||
assert.match(await told(a), /from 1 to 100/);
|
||||
say(a, roomId, "!again 3");
|
||||
const question = await a.untilXt("xyn");
|
||||
assert.match(question[3], /Buy 3 more/);
|
||||
a.xt("xyn", roomId, question[2], 0); // no
|
||||
assert.strictEqual(await owned(), before);
|
||||
say(a, roomId, "!again 3");
|
||||
a.xt("xyn", roomId, (await a.untilXt("xyn"))[2], 1); // yes
|
||||
assert.strictEqual(await owned(), before + 3);
|
||||
say(a, roomId, "!help"); // gone: the list is at /commands
|
||||
assert.strictEqual((await a.untilXt("uc"))[3], "!help");
|
||||
assert.match(await (await fetch(`${BASE}/commands`)).text(), /!outfit save NAME/);
|
||||
|
||||
// --- den undo, mail, music
|
||||
say(a, roomId, "!den undo");
|
||||
assert.match(await told(a), /nothing to put back/);
|
||||
say(a, roomId, "!den name Beach House");
|
||||
assert.match(await told(a), /now called Beach House/);
|
||||
b.xt("dj", benMoved[4], "denAnn", 1, -1);
|
||||
assert.strictEqual((await b.untilXt("rj"))[14], "Ann's Beach House");
|
||||
b.xt("rj", 1, "sarepia.room_main#1", 1, 0, 0);
|
||||
await b.untilXt("rp");
|
||||
say(a, roomId, "!mail clear");
|
||||
assert.match(await told(a), /0 read Jam-A-Grams deleted/);
|
||||
say(a, roomId, "!music all");
|
||||
const tracks = await a.untilXt("di");
|
||||
assert.match(await told(a), /66 music tracks added/);
|
||||
assert.ok(Number(tracks[3]) >= 66);
|
||||
say(a, roomId, "!music all");
|
||||
await a.untilXt("di");
|
||||
assert.match(await told(a), /every music track already/);
|
||||
|
||||
// --- an egg is hatched as soon as it is bought (three days by the game's clock)
|
||||
const eggDef = require("../lib/defpacks.js");
|
||||
await eggDef.init();
|
||||
const egg = eggDef.petIds().find(id => eggDef.petDef(id).isEgg === "1");
|
||||
a.xt("pc", roomId, 312, egg, 0, 0, 1, 2, 0);
|
||||
const made = await a.untilXt("pc");
|
||||
assert.strictEqual(made[2], "1");
|
||||
assert.ok(Number(made[10]) <= Date.now() / 1000 - 259200);
|
||||
|
||||
// --- she starts in the township as ever, in a look picked at random if she asked for one
|
||||
say(a, roomId, "!theme random on");
|
||||
assert.match(await told(a), /picked at random/);
|
||||
a.socket.destroy();
|
||||
await new Promise(resolve => setTimeout(resolve, 200));
|
||||
const again = await arrive("Ann");
|
||||
assert.match(again.file, /^theme_\d+\.jamaa_township\.room_main/);
|
||||
again.client.socket.destroy();
|
||||
await new Promise(resolve => setTimeout(resolve, 200));
|
||||
|
||||
// --- "start in your own den" (asked for at sign-in): the game asks for the township and is put in the den
|
||||
const denAuth = await (await postJson(`${BASE}/authenticate`, {username: "Ann", password: "Password01", login_choices: {startInDen: true}})).json();
|
||||
const home = new harness.GameClient(GAME_PORT);
|
||||
await home.connect();
|
||||
await home.logIn("Ann", denAuth.auth_token);
|
||||
home.xt("rj", 1, TOWNSHIP, 1, 0, 0);
|
||||
assert.strictEqual((await home.untilXt("rj"))[3], "denAnn");
|
||||
home.socket.destroy();
|
||||
b.socket.destroy();
|
||||
};
|
||||
|
||||
harness.withServer("comforts test", HTTP_PORT, GAME_PORT, run).catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,328 @@
|
||||
"use strict";
|
||||
|
||||
// end-to-end check of what was brought back from the game's files: showcase
|
||||
// dens, animals and dens out of season, added dens and parties, the shops
|
||||
// of odd items, rooms shown as another version of themselves. simulated
|
||||
// players, a real server.
|
||||
|
||||
const assert = require("assert");
|
||||
const zlib = require("zlib");
|
||||
const amf3 = require("../lib/amf3.js");
|
||||
const cdn = require("../lib/cdn.js");
|
||||
const harness = require("./harness.js");
|
||||
|
||||
const HTTP_PORT = 18082;
|
||||
const GAME_PORT = 19341;
|
||||
const BASE = `http://127.0.0.1:${HTTP_PORT}`;
|
||||
const TOWNSHIP = "jamaa_township.room_main#1";
|
||||
const {postJson} = harness;
|
||||
|
||||
const arrive = async (username, password) => {
|
||||
const auth = await (await postJson(`${BASE}/authenticate`, {username, password})).json();
|
||||
const client = new harness.GameClient(GAME_PORT);
|
||||
await client.connect();
|
||||
const login = await client.logIn(username, auth.auth_token);
|
||||
assert.strictEqual(login.status, "1");
|
||||
client.xt("rj", 1, TOWNSHIP, 1, 0, 0);
|
||||
const roomId = (await client.untilXt("rj"))[4];
|
||||
await client.untilXt("rp");
|
||||
client.xt("au", roomId, 1, 400, 400, 14, 1);
|
||||
return {client, login, roomId};
|
||||
};
|
||||
|
||||
// A defPack as clients get it from this server, as its rows.
|
||||
const pack = async id => Object.values(amf3.decode(zlib.inflateRawSync(Buffer.from(
|
||||
await (await fetch(`${BASE}/${cdn.hashedPath(`defPacks/${id}`)}`)).arrayBuffer()))));
|
||||
const byId = (rows, id) => rows.find(row => String(row.id) === String(id));
|
||||
|
||||
const run = async () => {
|
||||
const registerJson = body => fetch(`${BASE}/api/register`, {method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({avatarType: 1, agreed: true, ...body})});
|
||||
for (const username of ["Ann", "Ben"]) {
|
||||
assert.strictEqual((await registerJson({username, password: "Password01"})).status, 200);
|
||||
}
|
||||
const {client: a, roomId} = await arrive("Ann", "Password01");
|
||||
|
||||
// --- Epic Dens: twenty names; asking for the den of one leads into its room
|
||||
a.xt("dh", roomId);
|
||||
const epic = await a.nextXt("dh");
|
||||
assert.strictEqual(epic[2], "20");
|
||||
assert.strictEqual(new Set(epic.slice(3)).size, 20);
|
||||
a.xt("dj", roomId, `den${epic[3]}`, 1, -1);
|
||||
const showcase = await a.untilXt("rj");
|
||||
assert.match(showcase[3], /^epic_dens\.room_\w+#1$/);
|
||||
assert.strictEqual(showcase[14], epic[3]); // the name in the corner of the screen
|
||||
assert.match((await a.nextXt("rp"))[2], /^epic_dens\.room_/);
|
||||
// the AJHQ button is party 36: one more showcase den, not one of the twenty.
|
||||
a.xt("sj", showcase[4], 36);
|
||||
const featured = await a.untilXt("rj");
|
||||
assert.match(featured[3], /^party36_\d+$/);
|
||||
assert.ok(!epic.slice(3).includes(featured[14]));
|
||||
assert.match((await a.nextXt("rp"))[2], /^epic_dens\.room_/);
|
||||
assert.strictEqual(byId(await pack(1047), 36).titleStrId, "8700"); // "Epic Dens"
|
||||
|
||||
// --- nothing is out of season among animals, pets and dens
|
||||
for (const id of [1003, 1046, 1040]) {
|
||||
assert.deepStrictEqual((await pack(id)).filter(def => Number(def.availabilityStartTime) > 0 || Number(def.availabilityEndTime) > 0), []);
|
||||
}
|
||||
|
||||
// --- the four draft dens: in the pack, named, and for sale
|
||||
const dens = await pack(1040);
|
||||
assert.deepStrictEqual([62, 63, 64, 65].map(id => byId(dens, id).roomDefId), ["130", "187", "186", "441"]);
|
||||
const strings = amf3.decode(zlib.inflateRawSync(Buffer.from(await (await fetch(`${BASE}/${cdn.hashedPath("defPacks/10230")}`)).arrayBuffer())));
|
||||
assert.strictEqual(strings[byId(dens, 62).titleStrRef], "Castle (2010 draft)");
|
||||
assert.strictEqual(strings[157], "Small House"); // and the game's own are as they were
|
||||
// the den switcher asks for the slot it wants filled, and the den's id is that slot.
|
||||
a.xt("db", featured[4], -1, 0, 65, 3, 0);
|
||||
assert.strictEqual((await a.untilXt("db"))[2], "1");
|
||||
const owned = await a.nextXt("dl");
|
||||
assert.deepStrictEqual(owned.slice(2), ["2", "0", owned[4], "3", "65"]);
|
||||
a.xt("db", featured[4], -1, 0, 62, 3, 0); // a slot already taken: the first free one instead
|
||||
await a.untilXt("db");
|
||||
assert.deepStrictEqual((await a.nextXt("dl")).slice(7), ["1", "62"]);
|
||||
a.xt("dc", featured[4], 3);
|
||||
await a.nextXt("dc");
|
||||
a.xt("dj", featured[4], "denAnn", 1, -1);
|
||||
await a.untilXt("rj");
|
||||
assert.strictEqual((await a.nextXt("rp"))[2], "player_den.room_main_epicpalace");
|
||||
|
||||
// --- four more parties, in the rooms nothing used
|
||||
a.xt("sl", roomId);
|
||||
const parties = await a.untilXt("sl");
|
||||
for (const id of ["54", "55", "56", "57"]) {
|
||||
assert.ok(parties.includes(id));
|
||||
}
|
||||
a.xt("sj", roomId, 56);
|
||||
await a.untilXt("rj");
|
||||
assert.strictEqual((await a.nextXt("rp"))[2], "party.venue_pl_res_bakery");
|
||||
|
||||
// --- the shops of odd items: Beta furniture in the chamber base, the Founders' Hat in the archives
|
||||
const denItems = await pack(1030);
|
||||
a.xt("gl", roomId, 396);
|
||||
const oddDenItems = (await a.nextXt("gl")).slice(9);
|
||||
assert.ok(oddDenItems.length > 200);
|
||||
// what the shop really sold comes first (lib/shopstock.js), then the Beta set.
|
||||
assert.strictEqual(byId(denItems, oddDenItems[0]).abbrName, "ChamberLamp");
|
||||
assert.match(byId(denItems, oddDenItems.find(id => !/^Chamber/.test(byId(denItems, id).abbrName))).abbrName, /^Beta/);
|
||||
assert.ok(oddDenItems.some(id => /^Beta/.test(byId(denItems, id).abbrName)));
|
||||
assert.ok(oddDenItems.includes("3123")); // TestCloud
|
||||
assert.ok(oddDenItems.every(id => /^Chamber/.test(byId(denItems, id).abbrName) || byId(denItems, id).availabilityEndTime === "0"));
|
||||
a.xt("gl", roomId, 666);
|
||||
assert.ok((await a.nextXt("gl")).slice(9).includes("215"));
|
||||
|
||||
// --- extra den music: den items like the official tracks, their audio cut out of the game's files, in no shop
|
||||
const track = byId(denItems, 6001);
|
||||
assert.deepStrictEqual([track.abbrName, track.typeCat, track.sortCat, strings[track.nameStrId]], ["XtraNarration", "4", "4", "Narration"]);
|
||||
assert.ok(byId(denItems, 6011));
|
||||
const mp3 = Buffer.from(await (await fetch(`${BASE}/${cdn.hashedPath("audio/XtraUnnamed.mp3")}`)).arrayBuffer());
|
||||
assert.ok(mp3.length > 3000 && mp3[0] === 0xFF && (mp3[1] & 0xE0) === 0xE0); // an MP3 frame
|
||||
for (const shop of [12, 51, 63, 85, 396]) {
|
||||
a.xt("gl", roomId, shop);
|
||||
assert.ok(!(await a.nextXt("gl")).slice(9).some(id => Number(id) >= 6001 && Number(id) <= 6011));
|
||||
}
|
||||
a.xt("gl", roomId, 401); // nor among the tracks a hosted party can play
|
||||
assert.ok(!(await a.nextXt("gl")).slice(9).includes("6001"));
|
||||
|
||||
// --- a room shown as its other version: same room, another file
|
||||
const month = new Date().getUTCMonth() + 1;
|
||||
a.xt("rj", roomId, "appondale.room_museum#1", 1, 0, 0);
|
||||
assert.strictEqual((await a.untilXt("rj"))[3], "appondale.room_museum#1");
|
||||
assert.strictEqual((await a.nextXt("rp"))[2], month % 2 === 0 ? "appondale.room_museum_ant" : "appondale.room_museum");
|
||||
|
||||
// --- mannequins: a den item that wears clothing of its owner's
|
||||
a.xt("ib", roomId, 666, 1, 215, 0, 0); // the Founders' Hat, a head item
|
||||
const hat = (await a.untilXt("il"))[9];
|
||||
await a.untilXt("ib");
|
||||
a.xt("db", roomId, 0, 12, 3433, 0, 0); // arctic Wolf Mannequin
|
||||
assert.strictEqual((await a.untilXt("db"))[2], "1");
|
||||
// the owner's list: eight fields, the ten of a mannequin (all 0 = bare, the animal's own colours), one more.
|
||||
const listed = await a.nextXt("di");
|
||||
assert.deepStrictEqual(listed.slice(5), [listed[5], "3433", "0", "0", "true", "", "-1", "", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"]);
|
||||
const mannequin = listed[5];
|
||||
a.xt("dj", roomId, "denAnn", 1, -1);
|
||||
const den = (await a.untilXt("rj"))[4];
|
||||
await a.untilXt("ds");
|
||||
// placed, coloured, wearing the hat. the hat offered as a tail piece is not taken.
|
||||
a.xt("ds", den, 1, 0, mannequin, 1, 300, 400, 0, "off", 111, 222, 0, 333, 0, hat, 0, 0, 0, hat);
|
||||
assert.deepStrictEqual((await a.nextXt("dss")).slice(2), [mannequin]);
|
||||
a.xt("di", den);
|
||||
assert.deepStrictEqual((await a.nextXt("di")).slice(13, 24), ["111", "222", "0", "333", "0", "0", "0", "0", "0", hat, "0"]);
|
||||
// A visitor is told what the hat is: its def and colour, then its id.
|
||||
const {client: b, roomId: benRoom} = await arrive("Ben", "Password01");
|
||||
b.xt("dj", benRoom, "denAnn", 1, -1);
|
||||
const seen = await b.untilXt("ds");
|
||||
assert.deepStrictEqual(seen.slice(5), [mannequin, "3433", "1", "300", "400", "0", "0", "", "", "-1", "",
|
||||
"111", "222", "0", "333", "0", "0", "0", "0", "0", "215", "392491620", hat, "0"]);
|
||||
// --- playing as an alpha: the client is told which character stands in for the animal
|
||||
const say = (client, room, text) => client.send(`<msg t='sys'><body action='pubMsg' r='${room}'><txt><![CDATA[${text}%0]]></txt></body></msg>`);
|
||||
a.xt("au", den, 1, 300, 300, 14, 1); // Ann has walked in: others see her
|
||||
await b.untilXt("ac");
|
||||
say(a, den, "!become liza");
|
||||
const disguised = await a.untilXt("dph");
|
||||
assert.deepStrictEqual(disguised.slice(2), ["1", disguised[3], "1", "21"]);
|
||||
// ben has her animal put on his screen afresh, and the disguise after it.
|
||||
assert.strictEqual((await b.untilXt("ac"))[2], disguised[3]);
|
||||
assert.deepStrictEqual((await b.untilXt("dph")).slice(2), ["1", disguised[3], "1", "21"]);
|
||||
assert.match((await a.untilXt("xtl"))[2], /^Done/);
|
||||
say(a, den, "!become nobody");
|
||||
assert.match((await a.untilXt("xtl"))[2], /no character called nobody/);
|
||||
say(a, den, "!become off");
|
||||
assert.deepStrictEqual((await a.untilXt("dph")).slice(2), ["1", disguised[3], "0", "2"]);
|
||||
await b.untilXt("ac");
|
||||
|
||||
// the hat recycled: the mannequin is bare again.
|
||||
a.xt("ir", den, hat);
|
||||
await a.untilXt("ir");
|
||||
await a.nextXt("il");
|
||||
a.xt("di", den);
|
||||
assert.strictEqual((await a.nextXt("di"))[22], "0");
|
||||
|
||||
// --- a player who is not in the game: their card still shows who they are
|
||||
assert.strictEqual((await registerJson({username: "Cat", password: "Password01"})).status, 200);
|
||||
const {client: c, roomId: catRoom} = await arrive("Cat", "Password01");
|
||||
c.xt("pc", catRoom, 312, 1, 0, 0, 15386, 15428, 0); // a pet, so there is one to list
|
||||
await c.untilXt("pc");
|
||||
c.socket.destroy();
|
||||
await new Promise(resolve => setTimeout(resolve, 200));
|
||||
b.xt("ag", benRoom, "cat", 1);
|
||||
const card = await b.untilXt("ag");
|
||||
assert.deepStrictEqual(card.slice(2, 5), ["Cat", card[3], "0"]); // found, offline
|
||||
b.xt("al", benRoom, "Cat");
|
||||
const animals = await b.nextXt("al");
|
||||
assert.deepStrictEqual(animals.slice(2, 4), ["Cat", "1"]);
|
||||
b.xt("ad", benRoom, "Cat", animals[4], 2);
|
||||
const animal = await b.nextXt("ad");
|
||||
assert.deepStrictEqual([animal[2], animal[9]], ["Cat", animals[4]]);
|
||||
assert.deepStrictEqual((await b.nextXt("il")).slice(2, 6), ["1", "0", animals[4], "Cat"]); // what it wears
|
||||
b.xt("pl", benRoom, "Cat");
|
||||
assert.deepStrictEqual((await b.nextXt("pl")).slice(2, 5), ["1", "Cat", "1"]);
|
||||
// A buddy request and a Jam-A-Gram for them wait until they are back.
|
||||
b.xt("ba", benRoom, "Cat");
|
||||
assert.deepStrictEqual((await b.nextXt("ba")).slice(2), ["1", "Cat", "1"]); // sent
|
||||
b.xt("gl", benRoom, 10);
|
||||
const cards = (await b.nextXt("gl")).slice(9);
|
||||
b.xt("gl", benRoom, 44);
|
||||
const stamps = (await b.nextXt("gl")).slice(9);
|
||||
b.xt("es", benRoom, "Cat", cards[0], stamps[0], 0, "see you soon", 0, 0, 0);
|
||||
assert.strictEqual((await b.untilXt("es"))[2], "1");
|
||||
const {client: c2, login: catLogin, roomId: catRoom2} = await arrive("Cat", "Password01");
|
||||
assert.strictEqual(catLogin.params.numUnreadECards, 1);
|
||||
assert.deepStrictEqual((await c2.untilXt("ba")).slice(2), ["0", "Ben", "1"]); // asked, now that Cat is here
|
||||
c2.xt("bc", catRoom2, "Ben", 1);
|
||||
assert.deepStrictEqual((await c2.untilXt("bs")).slice(3, 4), ["Ben"]);
|
||||
assert.deepStrictEqual((await b.untilXt("bs")).slice(3, 4), ["Cat"]);
|
||||
|
||||
// --- masterpieces: painted, posted, framed, reviewed, hung
|
||||
const panel = async (pathname, body, cookie) => {
|
||||
const response = await fetch(`${BASE}/admin/api/${pathname}`, {
|
||||
method: body === undefined ? "GET" : "POST",
|
||||
headers: {"Content-Type": "application/json", ...(cookie ? {Cookie: cookie} : {})},
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
});
|
||||
const picture = (response.headers.get("content-type") || "").startsWith("image/");
|
||||
return {status: response.status, data: picture ? Buffer.from(await response.arrayBuffer()) : await response.json(),
|
||||
cookie: (response.headers.get("set-cookie") || "").split(";")[0]};
|
||||
};
|
||||
const admin = (await panel("setup", {password: "admin-password-1"})).cookie;
|
||||
const post = (token, picture) => {
|
||||
const form = new FormData();
|
||||
form.append("authToken", token);
|
||||
form.append("image", new Blob([picture], {type: "image/jpeg"}), "ArtStudioImage");
|
||||
return fetch(`${BASE}/game/mp`, {method: "POST", body: form}).then(response => response.json());
|
||||
};
|
||||
// the least a JPEG can be and pass for one: a header segment, a frame
|
||||
// header (100 by 100), the start of the picture data, some of it, the end.
|
||||
const jpeg = Buffer.concat([Buffer.from([0xFF, 0xD8, 0xFF, 0xE0, 0, 16]), Buffer.alloc(14),
|
||||
Buffer.from([0xFF, 0xC0, 0, 11, 8, 0, 100, 0, 100, 1, 1, 0x11, 0]), Buffer.from([0xFF, 0xDA, 0, 8, 1, 1, 0, 0, 63, 0]),
|
||||
Buffer.alloc(400, 7), Buffer.from([0xFF, 0xD9])]);
|
||||
// the frames: 24 of them, each with a name.
|
||||
a.xt("gl", den, 424);
|
||||
const frames = await a.untilXt("gl");
|
||||
assert.deepStrictEqual([frames[8], frames[9], frames[10]], ["24", "4813", "25174"]);
|
||||
// the easel asks for a token; the painting is posted with it, once.
|
||||
// the easel's popup needs Pixel Painting described along with Painting.
|
||||
a.xt("mi", den, 51);
|
||||
const described = await a.untilXt("mi");
|
||||
assert.deepStrictEqual([described[2], described[3], described[3 + 19]], ["2", "51", "139"]);
|
||||
a.xt("mj", den, 51, 0, 0, 0);
|
||||
const easel = (await a.untilXt("mj"))[1];
|
||||
a.xt("mm", easel, 51, "gmtkn", 0, 1);
|
||||
const tokenReply = await a.untilXt("mm");
|
||||
assert.deepStrictEqual([tokenReply[2], tokenReply[3], tokenReply[7]], ["tkn", "1", "1"]);
|
||||
assert.deepStrictEqual(await post("not-a-token", jpeg), {success: false});
|
||||
const posted = await post(tokenReply[5], jpeg);
|
||||
assert.strictEqual(posted.success, true);
|
||||
assert.deepStrictEqual(await post(tokenReply[5], jpeg), {success: false});
|
||||
assert.deepStrictEqual(Buffer.from(await (await fetch(`${BASE}/masterpieces/${posted.uuid}`)).arrayBuffer()), jpeg);
|
||||
// framed (frame 2) for two diamonds: an item, not approved, that will not go on a wall.
|
||||
a.xt("db", den, 0, 0, 221, 2, 1, 1, 0, posted.uuid);
|
||||
const bought = await a.untilXt("db");
|
||||
assert.strictEqual(bought[2], "1");
|
||||
const painting = bought[6];
|
||||
const framed = await a.nextXt("di");
|
||||
const at = framed.indexOf(painting, 5);
|
||||
assert.deepStrictEqual(framed.slice(at, at + 9), [painting, "2725", "0", "2", "false", posted.uuid, String(framed[at + 6]), framed[at + 7], "0"]);
|
||||
assert.match(framed[at + 7], /^[0-9a-f-]{36}$/); // Ann's uuid: she made it
|
||||
a.xt("ds", den, 1, 0, painting, 1, 500, 300, 0, "off", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
assert.deepStrictEqual((await a.untilXt("dss")).slice(2), []);
|
||||
// ben cannot frame Ann's painting.
|
||||
b.xt("db", benRoom, 0, 0, 221, 0, 1, 1, 0, posted.uuid);
|
||||
assert.strictEqual((await b.untilXt("db"))[2], "0");
|
||||
// the panel has it waiting, with the picture; approving tells Ann.
|
||||
const waiting = (await panel("masterpieces", undefined, admin)).data;
|
||||
assert.deepStrictEqual([waiting.review, waiting.waiting.map(entry => [entry.id, entry.creator]), waiting.approved], [true, [[posted.uuid, "Ann"]], []]);
|
||||
assert.deepStrictEqual((await panel(`masterpiece?id=${posted.uuid}`, undefined, admin)).data, jpeg);
|
||||
assert.strictEqual((await panel(`masterpiece?id=${posted.uuid}`)).status, 401);
|
||||
assert.strictEqual((await panel("masterpiece", {id: posted.uuid, action: "approve"}, admin)).status, 200);
|
||||
assert.match((await a.untilXt("ep"))[7], /approved/);
|
||||
const approved = await a.nextXt("di");
|
||||
assert.strictEqual(approved[approved.indexOf(painting, 5) + 4], "true");
|
||||
// hung, once Ann is home from the easel: a visitor is told which painting and whose.
|
||||
a.xt("dj", den, "denAnn", 1, -1);
|
||||
await a.untilXt("ds");
|
||||
a.xt("ds", den, 1, 0, painting, 1, 500, 300, 0, "off", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
assert.deepStrictEqual((await a.untilXt("dss")).slice(2), [painting]);
|
||||
const hung = await b.untilXt("ds");
|
||||
const spot = hung.indexOf(painting, 5);
|
||||
assert.deepStrictEqual(hung.slice(spot, spot + 11), [painting, "2725", "1", "500", "300", "2", "0", "", posted.uuid, framed[at + 6], framed[at + 7]]);
|
||||
b.xt("dmc", benRoom, "Ann", posted.uuid);
|
||||
assert.deepStrictEqual((await b.nextXt("dmc")).slice(2), ["Ann"]);
|
||||
b.xt("dmi", benRoom, "Ann");
|
||||
assert.deepStrictEqual((await b.nextXt("dmi")).slice(2, 8), ["1", "2725", painting, "2", "true", posted.uuid]);
|
||||
// A like from Ben counts once; Ann cannot like her own.
|
||||
b.xt("crp", benRoom, "masterpiece", posted.uuid, "x", "", "2,x,1");
|
||||
assert.strictEqual((await b.nextXt("crp"))[2], "1");
|
||||
b.xt("crp", benRoom, "masterpiece", posted.uuid, "x", "", "2,x,1");
|
||||
assert.strictEqual((await b.nextXt("crp"))[2], "0");
|
||||
a.xt("crg", den, "masterpiece", posted.uuid, "x", "");
|
||||
assert.deepStrictEqual((await a.untilXt("crg")).slice(2), ["1", "0", "1"]);
|
||||
// it hangs in the Masterpiece Gallery party, which is told so with the room.
|
||||
b.xt("sm", benRoom);
|
||||
assert.deepStrictEqual(JSON.parse((await b.nextXt("sm"))[2]).pool.map(entry => [entry.resourceId, entry.userName, entry.frameId]), [[posted.uuid, "Ann", 2]]);
|
||||
b.xt("sj", benRoom, 47);
|
||||
await b.untilXt("rj");
|
||||
assert.strictEqual(JSON.parse((await b.nextXt("rp"))[8]).pool[0].resourceId, posted.uuid);
|
||||
// removed from the panel: gone from Ann's den and things, a token in its place.
|
||||
assert.strictEqual((await panel("masterpiece", {id: posted.uuid, action: "remove"}, admin)).status, 200);
|
||||
const after = await a.untilXt("di");
|
||||
assert.ok(!after.includes(posted.uuid) && after.includes("2947"));
|
||||
assert.strictEqual((await fetch(`${BASE}/masterpieces/${posted.uuid}`)).status, 404);
|
||||
// with review off, a painting framed with that token is approved on the spot.
|
||||
assert.strictEqual((await panel("masterpiece", {action: "review", on: false}, admin)).status, 200);
|
||||
a.xt("mj", den, 51, 0, 0, 0);
|
||||
const easelAgain = (await a.untilXt("mj"))[1];
|
||||
a.xt("mm", easelAgain, 51, "gmtkn", 0, 1);
|
||||
const second = await post((await a.untilXt("mm"))[5], jpeg);
|
||||
a.xt("db", den, 0, 0, 221, 0, 1, 1, 1, second.uuid);
|
||||
assert.strictEqual((await a.untilXt("db"))[2], "1");
|
||||
const last = await a.nextXt("di");
|
||||
assert.ok(!last.includes("2947") && last[last.indexOf(second.uuid) - 1] === "true");
|
||||
|
||||
a.socket.destroy();
|
||||
b.socket.destroy();
|
||||
c2.socket.destroy();
|
||||
};
|
||||
|
||||
harness.withServer("restored features test", HTTP_PORT, GAME_PORT, run).catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
+658
@@ -0,0 +1,658 @@
|
||||
"use strict";
|
||||
|
||||
// end-to-end check against a real server process: plays the launcher's HTTP
|
||||
// calls and then two game clients speaking the SWF's socket protocol.
|
||||
|
||||
const assert = require("assert");
|
||||
const crypto = require("crypto");
|
||||
const harness = require("./harness.js");
|
||||
|
||||
const HTTP_PORT = 18080;
|
||||
const GAME_PORT = 19339;
|
||||
const BASE = `http://127.0.0.1:${HTTP_PORT}`;
|
||||
|
||||
class GameClient extends harness.GameClient {
|
||||
constructor() {
|
||||
super(GAME_PORT);
|
||||
}
|
||||
}
|
||||
|
||||
const {postJson} = harness;
|
||||
|
||||
const run = async () => {
|
||||
// --- launcher HTTP flow
|
||||
const flashVars = await (await fetch(`${BASE}/flashvars`)).json();
|
||||
assert.strictEqual(flashVars.smartfoxPort, String(GAME_PORT));
|
||||
assert.ok(flashVars.content && flashVars.website && flashVars.blueboxServer && flashVars.blueboxPort);
|
||||
|
||||
// --- registration: the web form's API, and no accounts made by logging in
|
||||
assert.match(await (await fetch(`${BASE}/register`)).text(), /Create an account/);
|
||||
const registerJson = body => fetch(`${BASE}/api/register`, {method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({avatarType: 1, agreed: true, ...body})});
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "Alice", password: "Password01"})).status, 401);
|
||||
assert.strictEqual((await registerJson({username: "Alice", password: "Password01"})).status, 200);
|
||||
assert.deepStrictEqual(await (await registerJson({username: "alice", password: "Password01"})).json(), {error: "username_taken"});
|
||||
assert.deepStrictEqual(await (await registerJson({username: "a!", password: "Password01"})).json(), {error: "invalid_username"});
|
||||
assert.deepStrictEqual(await (await registerJson({username: "Shorty", password: "pw"})).json(), {error: "invalid_password"});
|
||||
// no default animal: whoever signs up picks one of the nine on the page.
|
||||
assert.deepStrictEqual(await (await registerJson({username: "Noanimal", password: "Password01", avatarType: undefined})).json(), {error: "choose_animal"});
|
||||
assert.deepStrictEqual(await (await registerJson({username: "Noanimal", password: "Password01", avatarType: 2})).json(), {error: "choose_animal"});
|
||||
assert.match(await (await fetch(`${BASE}/register`)).text(), /Choose an animal/);
|
||||
assert.strictEqual((await fetch(`${BASE}/signup/thumb_wolf.svg`)).headers.get("content-type"), "image/svg+xml");
|
||||
assert.strictEqual((await fetch(`${BASE}/signup/..%2Faccount.html`)).status, 404);
|
||||
for (const [username, password] of [["Bob", "Password02"], ["Carol", "Password03"], ["foo", "Password04"]]) {
|
||||
assert.strictEqual((await registerJson({username, password})).status, 200);
|
||||
}
|
||||
|
||||
let res = await postJson(`${BASE}/authenticate`, {username: "Alice", password: "Password01", domain: "flash", df: "x"});
|
||||
assert.strictEqual(res.status, 200);
|
||||
assert.strictEqual(res.headers.get("access-control-allow-origin"), "null");
|
||||
const alice = await res.json();
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "alice", password: "wrong"})).status, 401);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "constructor", password: "Password01"})).status, 401);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {refresh_token: alice.refresh_token})).status, 200);
|
||||
const bob = await (await postJson(`${BASE}/authenticate`, {username: "Bob", password: "Password02"})).json();
|
||||
|
||||
res = await fetch(`${BASE}/player?domain=flash&client_version=1830`, {headers: {Authorization: `Bearer ${alice.auth_token}`}});
|
||||
assert.strictEqual((await res.json()).screen_name, "Alice");
|
||||
assert.strictEqual((await fetch(`${BASE}/player`, {headers: {Authorization: "Bearer nope"}})).status, 401);
|
||||
|
||||
assert.match(await (await fetch(`${BASE}/gameClient/game/index.html`)).text(), /flashVarsReady/);
|
||||
const swf = Buffer.from(await (await fetch(flashVars.clientURL)).arrayBuffer());
|
||||
assert.ok(["CWS", "ZWS", "FWS"].includes(swf.toString("latin1", 0, 3)));
|
||||
assert.strictEqual((await fetch(`${BASE}/../../etc/passwd`)).status, 404);
|
||||
assert.strictEqual((await fetch(`${BASE}/%2e%2e/%2e%2e/config.js`)).status, 404);
|
||||
|
||||
// --- socket policy request (Flash asks before opening the real connection)
|
||||
const policy = new GameClient();
|
||||
await policy.connect();
|
||||
policy.send("<policy-file-request/>");
|
||||
assert.match(await policy.next(), /cross-domain-policy/);
|
||||
|
||||
// --- the client's Create Account screens: guest zone, name check, create
|
||||
const guest = new GameClient();
|
||||
await guest.connect();
|
||||
guest.send("<msg t='sys'><body action='verChk' r='0'><ver v='165' /></body></msg>");
|
||||
await guest.next();
|
||||
guest.send("<msg t='sys'><body action='rndK' r='-1'></body></msg>");
|
||||
const guestKey = /<k>([0-9a-f]+)<\/k>/.exec(await guest.next())[1];
|
||||
guest.send("<msg t='sys'><body action='login' r='0'><login z='sbiAccountZone'><nick><![CDATA[]]></nick><pword><![CDATA[]]></pword></login></body></msg>");
|
||||
assert.match(await guest.next(), /action='logOK'/);
|
||||
guest.xt("la", 1, 0, "Alice", 0, 0, 0, 0, 1830);
|
||||
assert.deepStrictEqual((await guest.nextXt("la")).slice(2), ["-3"]);
|
||||
guest.xt("la", 1, 0, "Dave", 0, 0, 0, 0, 1830);
|
||||
assert.deepStrictEqual((await guest.nextXt("la")).slice(2), ["1"]);
|
||||
const iv = crypto.randomBytes(16);
|
||||
const cipher = crypto.createCipheriv("aes-256-cbc", crypto.createHash("sha256").update(guestKey).digest(), iv);
|
||||
const encrypted = Buffer.concat([iv, cipher.update("DavePass01"), cipher.final()]).toString("base64");
|
||||
guest.xt("lc", 1, "Dave", encrypted, "2000-01-01", 0, "", 15136, 15224, 15299, 4, 0, "US", 1830);
|
||||
assert.deepStrictEqual((await guest.nextXt("lc")).slice(2, 3), ["1"]);
|
||||
guest.socket.destroy();
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "Dave", password: "DavePass01"})).status, 200);
|
||||
|
||||
// --- first player: login and world entry
|
||||
const a = new GameClient();
|
||||
await a.connect();
|
||||
const bad = new GameClient();
|
||||
await bad.connect();
|
||||
assert.strictEqual((await bad.logIn("Alice", "bogus")).status, "0");
|
||||
bad.socket.destroy();
|
||||
|
||||
const login = await a.logIn("Alice", alice.auth_token);
|
||||
assert.strictEqual(login._cmd, "login");
|
||||
assert.strictEqual(login.status, "1");
|
||||
assert.strictEqual(login.params.userName, "Alice");
|
||||
assert.strictEqual(login.params.gemsCount, 10000000);
|
||||
assert.strictEqual(login.params.pendingFlags & 1, 1);
|
||||
const aliceId = login.params.userId;
|
||||
|
||||
a.xt("al", 1, "Alice");
|
||||
const al = await a.nextXt("al");
|
||||
assert.deepStrictEqual(al.slice(2, 4), ["Alice", "4294967295"]);
|
||||
assert.strictEqual(al[5], "1");
|
||||
|
||||
a.xt("gl", 1, 64);
|
||||
const gl = await a.nextXt("gl");
|
||||
assert.deepStrictEqual(gl.slice(2, 4), ["64", "1003"]);
|
||||
assert.strictEqual(Number(gl[8]), gl.length - 9);
|
||||
|
||||
a.xt("rj", 1, "jamaa_township.room_main#-1", 1, 0, 0);
|
||||
const rj = await a.nextXt("rj");
|
||||
assert.deepStrictEqual(rj.slice(2, 4), ["1", "jamaa_township.room_main#1"]);
|
||||
// the name for the corner of the screen, and 0 for "no string id in its place".
|
||||
assert.deepStrictEqual(rj.slice(14, 16), ["Jamaa Township", "0"]);
|
||||
const roomId = rj[4];
|
||||
const rp = await a.nextXt("rp");
|
||||
assert.deepStrictEqual(rp.slice(1, 4), [roomId, "jamaa_township.room_main", "0"]);
|
||||
|
||||
a.xt("ad", roomId, "Alice", 1, 1);
|
||||
const ad = await a.nextXt("ad");
|
||||
assert.strictEqual(ad[2], "Alice");
|
||||
assert.strictEqual(ad.length, 2 + 15 + 8);
|
||||
assert.deepStrictEqual((await a.nextXt("il")).slice(2, 6), ["0", "0", "1", "Alice"]);
|
||||
a.xt("au", roomId, 1, 500, 400, 14, 1);
|
||||
|
||||
a.xt("rj", roomId, "no_such.room#1", 1, 0, 0);
|
||||
assert.strictEqual((await a.nextXt("rj"))[2], "0");
|
||||
|
||||
// --- second player sees the first, and vice versa
|
||||
const b = new GameClient();
|
||||
await b.connect();
|
||||
const bobId = (await b.logIn("Bob", bob.auth_token)).params.userId;
|
||||
b.xt("rj", 1, "jamaa_township.room_main#1", 1, 0, 0);
|
||||
assert.strictEqual((await b.nextXt("rj"))[4], roomId);
|
||||
await b.nextXt("rp");
|
||||
const ac = await b.nextXt("ac");
|
||||
assert.deepStrictEqual(ac.slice(1, 7), [roomId, String(aliceId), "500", "400", "14", "Alice"]);
|
||||
await b.nextXt("il");
|
||||
|
||||
b.xt("au", roomId, 1, 100, 200, 14, 1);
|
||||
assert.deepStrictEqual((await a.nextXt("ac")).slice(2, 5), [String(bobId), "100", "200"]);
|
||||
await a.nextXt("il");
|
||||
|
||||
b.xt("au", roomId, 2, 110, 210, 120, 220, 14, 0);
|
||||
assert.deepStrictEqual((await a.nextXt("au")).slice(2), ["1", String(bobId), "2", "110", "210", "120", "220", "0"]);
|
||||
b.xt("au", roomId, 999, 1, 1, 14, 0); // malformed: ignored
|
||||
|
||||
b.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[hi & bye%0]]></txt></body></msg>`);
|
||||
assert.deepStrictEqual((await a.nextXt("uc")).slice(1), [roomId, String(bobId), "hi & bye", "0"]);
|
||||
assert.deepStrictEqual((await b.nextXt("uc")).slice(1), [roomId, String(bobId), "hi & bye", "0"]);
|
||||
b.send(`<msg t='sys'><body action='pubMsg' r='${roomId}'><txt><![CDATA[7%2]]></txt></body></msg>`); // emote: not echoed
|
||||
assert.deepStrictEqual((await a.nextXt("uc")).slice(3), ["7", "2"]);
|
||||
|
||||
// --- player cards
|
||||
a.xt("ag", roomId, "bob", 1);
|
||||
const card = await a.nextXt("ag");
|
||||
assert.deepStrictEqual([card[2], card[4], card[21]], ["Bob", "1", String(bobId)]);
|
||||
a.xt("ags", roomId, bobId, 0);
|
||||
assert.strictEqual((await a.nextXt("ag"))[2], "Bob");
|
||||
a.xt("ag", roomId, "nobody", 1);
|
||||
assert.deepStrictEqual((await a.nextXt("ag")).slice(2), ["nobody", "", "3"]);
|
||||
a.xt("sphp", roomId, "x");
|
||||
assert.deepStrictEqual((await a.nextXt("sphp")).slice(2), ["-1"]);
|
||||
|
||||
// --- buddies: request, accept, list, location, block, remove
|
||||
b.xt("ba", roomId, "alice");
|
||||
assert.deepStrictEqual((await a.nextXt("ba")).slice(2), ["0", "Bob", "1"]);
|
||||
assert.deepStrictEqual((await b.nextXt("ba")).slice(2), ["1", "Alice", "1"]);
|
||||
a.xt("bc", roomId, "Bob", 1);
|
||||
const aliceSees = await a.nextXt("bs");
|
||||
assert.deepStrictEqual([aliceSees[3], aliceSees[6], aliceSees[8]], ["Bob", "1", "0"]);
|
||||
const bobSees = await b.nextXt("bs");
|
||||
assert.deepStrictEqual([bobSees[3], bobSees[6], bobSees[8]], ["Alice", "1", "1"]); // 1 = accepted your request
|
||||
a.xt("bl", roomId);
|
||||
assert.deepStrictEqual((await a.nextXt("bl")).slice(2, 5).concat((await a.nextXt("bl")).slice(2)), ["0", "1", "Bob", "1", "0"]);
|
||||
assert.deepStrictEqual((await a.nextXt("xls")).slice(2), ["0"]); // when offline buddies were last seen: none are offline
|
||||
a.xt("br", roomId, "Bob");
|
||||
assert.deepStrictEqual((await a.nextXt("br")).slice(2), ["jamaa_township.room_main#1", "Jamaa Township", "0", "0"]); // last 0: "go to" allowed
|
||||
a.xt("bb", roomId, "Bob");
|
||||
assert.deepStrictEqual((await a.nextXt("bb")).slice(2), ["Bob", "1"]);
|
||||
b.xt("bi", roomId, "Alice");
|
||||
assert.deepStrictEqual((await b.nextXt("bi")).slice(2), ["Alice", "1"]);
|
||||
a.xt("bu", roomId, "Bob");
|
||||
assert.deepStrictEqual((await a.nextXt("bu")).slice(2), ["Bob", "1"]);
|
||||
a.xt("bd", roomId, "Bob");
|
||||
assert.deepStrictEqual((await a.nextXt("bd")).slice(2), ["Bob"]);
|
||||
assert.deepStrictEqual((await b.nextXt("bd")).slice(2), ["Alice"]);
|
||||
|
||||
b.socket.destroy();
|
||||
assert.deepStrictEqual((await a.nextXt("ar")).slice(1), [roomId, String(bobId)]);
|
||||
|
||||
// --- lists, user vars and the den
|
||||
a.xt("gl", roomId, 741);
|
||||
assert.deepStrictEqual((await a.nextXt("gl")).slice(2, 4), ["741", "1000"]);
|
||||
a.xt("zs", roomId, 66, 1, 1);
|
||||
// var 66 at 1 is what the "Welcome to the Club" achievement (def 134) asks for.
|
||||
const clubVar = await a.nextXt("zs");
|
||||
assert.deepStrictEqual([...clubVar.slice(2, 5), clubVar[6]], ["66", "1", "1", "134"]);
|
||||
a.xt("za", roomId, "Alice", -1);
|
||||
const aliceAchievements = await a.nextXt("za");
|
||||
assert.strictEqual(aliceAchievements[2], "Alice");
|
||||
// 134, and "Buddy Added" (def 90) from making friends with Bob above.
|
||||
assert.deepStrictEqual(aliceAchievements.slice(4).filter((_, i) => i % 2 === 1).sort(), ["134", "90"]);
|
||||
// A counter the server keeps is not the client's to set.
|
||||
a.xt("zs", roomId, 1, 999999, 1);
|
||||
assert.deepStrictEqual((await a.nextXt("zs")).slice(2), ["1", "0", "0"]);
|
||||
a.xt("gl", roomId, 627);
|
||||
const pushedVars = await a.nextXt("zg");
|
||||
// 129 and 379: every tutorial marked as seen. 214: the daily wheel never due.
|
||||
const varsById = {};
|
||||
for (let i = 3; i < pushedVars.length; i += 3) {
|
||||
varsById[pushedVars[i]] = pushedVars[i + 2];
|
||||
}
|
||||
assert.strictEqual(Number(pushedVars[2]), Object.keys(varsById).length);
|
||||
// 40: buddies added, counted by the server. 9001: "hide blocked players", off.
|
||||
assert.deepStrictEqual([varsById[66], varsById[129], varsById[214], varsById[379], varsById[40], varsById[9001]], ["1", "65535", "65535", "65535", "1", "0"]);
|
||||
assert.strictEqual((await a.nextXt("gl"))[2], "627");
|
||||
a.xt("dl", roomId);
|
||||
assert.deepStrictEqual((await a.nextXt("dl")).slice(2), ["1", "0", "1"]);
|
||||
a.xt("dj", roomId, "denNobody", 1, -1);
|
||||
assert.strictEqual((await a.nextXt("rj"))[2], "0");
|
||||
a.xt("dj", roomId, "denalice", 1, -1);
|
||||
const denJoin = await a.nextXt("rj");
|
||||
assert.deepStrictEqual([denJoin[2], denJoin[3], denJoin[14], denJoin[15]], ["1", "denAlice", "Alice's Den", "0"]);
|
||||
assert.match((await a.nextXt("rp"))[2], /^player_den\./);
|
||||
assert.deepStrictEqual((await a.nextXt("ds")).slice(2), ["0", "0", "1"]);
|
||||
|
||||
// --- shops, clothing, animals and pets (Carol watches from the same den)
|
||||
const carol = await (await postJson(`${BASE}/authenticate`, {username: "Carol", password: "Password03"})).json();
|
||||
const c = new GameClient();
|
||||
await c.connect();
|
||||
await c.logIn("Carol", carol.auth_token);
|
||||
c.xt("dj", 1, "denAlice", 1, -1);
|
||||
const denId = (await c.nextXt("rj"))[4];
|
||||
await c.nextXt("rp");
|
||||
await c.nextXt("ds");
|
||||
a.xt("au", denId, 1, 300, 300, 14, 1);
|
||||
c.xt("au", denId, 1, 310, 310, 14, 1);
|
||||
await a.nextXt("ac");
|
||||
await a.nextXt("il");
|
||||
await c.nextXt("ac");
|
||||
await c.nextXt("il");
|
||||
|
||||
a.xt("gl", denId, 200);
|
||||
const names = await a.nextXt("gl");
|
||||
assert.deepStrictEqual(names.slice(3, 4).concat(names.slice(8, 10)), ["1023", "88", "15136"]);
|
||||
|
||||
// the den shop inside a den is a "combined" list: kinds, counts, entries.
|
||||
a.xt("gl", denId, 384);
|
||||
const denRoomShop = await a.nextXt("gl");
|
||||
assert.deepStrictEqual(denRoomShop.slice(3, 5).concat(denRoomShop[9]), ["1060", "", "1040"]);
|
||||
assert.ok(Number(denRoomShop[8]) > 50 && denRoomShop[8] === denRoomShop[10] && Number(denRoomShop[10]) === denRoomShop.length - 11);
|
||||
|
||||
a.xt("gl", denId, 5);
|
||||
const shop = await a.nextXt("gl");
|
||||
assert.strictEqual(shop[3], "1000");
|
||||
assert.ok(Number(shop[8]) > 5 && Number(shop[8]) < 200 && Number(shop[8]) === shop.length - 9);
|
||||
const itemDef = shop[9];
|
||||
|
||||
a.xt("ib", denId, 5, 1, itemDef, 0, 0, -1, "");
|
||||
const added = await a.nextXt("il");
|
||||
assert.deepStrictEqual(added.slice(2, 6).concat(added.slice(7)), ["2", "0", "1", "Alice", "1", "0", added[9], itemDef]);
|
||||
const itemInv = added[9];
|
||||
const bought = await a.nextXt("ib");
|
||||
assert.deepStrictEqual(bought.slice(2, 4), ["1", "5"]);
|
||||
assert.ok(Number(bought[4]) <= 10000000);
|
||||
a.xt("ib", denId, 5, 1, 1, 0, 0, -1, ""); // a body part, not clothing
|
||||
assert.strictEqual((await a.nextXt("ib"))[2], "0");
|
||||
|
||||
a.xt("iu", denId, 1, 0, itemInv);
|
||||
assert.strictEqual((await a.nextXt("iu"))[2], "1");
|
||||
// her own game redraws her animal from this, not from the reply.
|
||||
assert.deepStrictEqual((await a.nextXt("il")).slice(2), ["3", "1", "1", "Alice", "0", "1", "0", itemInv, itemDef]);
|
||||
const worn = await c.nextXt("il");
|
||||
assert.deepStrictEqual(worn.slice(2, 6).concat(worn.slice(8, 11)), ["1", "0", "1", "Alice", "1", itemDef, itemInv]);
|
||||
a.xt("il", denId, "Alice", 1, 1);
|
||||
const full = await a.nextXt("il");
|
||||
assert.deepStrictEqual(full.slice(8), ["1", itemDef, itemInv, full[11], "2", "0"]); // "2" = bit 1 = avInvId 1
|
||||
|
||||
// --- trade list: put the item up, see it, a trade request is declined
|
||||
a.xt("ts", denId, 0, 1, 0, itemInv);
|
||||
assert.deepStrictEqual((await a.nextXt("tl")).slice(2, 7), ["Alice", "1", itemDef, itemInv, full[11]]);
|
||||
c.xt("tl", denId, "alice");
|
||||
assert.deepStrictEqual((await c.untilXt("tl")).slice(2, 5), ["Alice", "1", itemDef]);
|
||||
|
||||
// --- a trade: Carol offers an item of hers for Alice's listed one
|
||||
c.xt("ib", denId, 5, 1, shop[10], 0, 0, -1, "");
|
||||
const carolItemInv = (await c.untilXt("il"))[9];
|
||||
await c.nextXt("ib");
|
||||
c.xt("ti", denId, 0, "Alice", 0, 999999, 1, 0, 0, 0, carolItemInv); // not an item Alice has
|
||||
assert.deepStrictEqual((await c.nextXt("ti")).slice(2), ["3", "Alice", "1"]);
|
||||
c.xt("ti", denId, 0, "Alice", 0, itemInv, 1, 0, 0, 0, carolItemInv);
|
||||
const request = await a.nextXt("ti");
|
||||
assert.deepStrictEqual(request.slice(2, 10), ["0", "Carol", "1", request[5], itemInv, "1", "0", "0"]);
|
||||
assert.strictEqual(request[10], shop[10]);
|
||||
a.xt("ti", denId, 1, 0); // declined
|
||||
assert.deepStrictEqual((await c.nextXt("ti")).slice(2), ["2", "Alice", "1"]);
|
||||
c.xt("ti", denId, 0, "Alice", 0, itemInv, 1, 0, 0, 0, carolItemInv);
|
||||
await a.nextXt("ti");
|
||||
a.xt("ti", denId, 1, 1); // accepted
|
||||
assert.deepStrictEqual((await a.nextXt("ti")).slice(2), ["1", "0"]);
|
||||
assert.deepStrictEqual((await c.nextXt("ti")).slice(2), ["1", "0"]);
|
||||
a.xt("ti", denId, 3, 1);
|
||||
c.xt("ti", denId, 3, 1);
|
||||
const carolGot = await c.nextXt("ti");
|
||||
assert.deepStrictEqual(carolGot.slice(2, 7).concat(carolGot.slice(9)), ["1", "1", "1", "0", itemDef, "1", "0", carolItemInv]);
|
||||
const aliceGot = await a.nextXt("ti");
|
||||
assert.deepStrictEqual(aliceGot.slice(2, 7).concat(aliceGot.slice(9)), ["1", "1", "1", "0", shop[10], "1", "0", itemInv]);
|
||||
a.xt("tl", denId, "Alice");
|
||||
assert.deepStrictEqual((await a.nextXt("tl")).slice(2, 4), ["Alice", "0"]); // the traded item left the list
|
||||
const tradedInv = aliceGot[7];
|
||||
|
||||
a.xt("ap", denId, 1, 2, 3, 0);
|
||||
assert.strictEqual((await a.nextXt("ap"))[2], "1");
|
||||
await c.nextXt("ar");
|
||||
assert.deepStrictEqual((await c.nextXt("ac")).slice(12, 15), ["1", "2", "3"]);
|
||||
await c.nextXt("il");
|
||||
|
||||
a.xt("aa", denId, 15136, 15224, 15299, 4, -1, 0, 0);
|
||||
const aa = await a.nextXt("aa");
|
||||
assert.strictEqual(aa[2], "1");
|
||||
a.xt("as", denId, aa[3]);
|
||||
const switched = await a.nextXt("as");
|
||||
assert.deepStrictEqual(switched.slice(2, 4).concat(switched.slice(4, 8)), ["1", String(aliceId), aa[3], aa[4], "-1", "4"]);
|
||||
assert.strictEqual(switched[11], "15136|15224|15299");
|
||||
assert.strictEqual((await c.nextXt("as")).length, switched.length + 7);
|
||||
a.xt("al", denId, "Alice");
|
||||
assert.deepStrictEqual((await a.nextXt("al")).slice(5, 7), ["2", aa[3]]);
|
||||
a.xt("ak", denId, aa[3]); // cannot remove the animal in use
|
||||
assert.strictEqual((await a.nextXt("ak"))[2], "0");
|
||||
|
||||
a.xt("gl", denId, 312);
|
||||
const petShop = await a.nextXt("gl");
|
||||
assert.strictEqual(petShop[3], "1046");
|
||||
assert.strictEqual(Number(petShop[8]) * 2, petShop.length - 9);
|
||||
a.xt("gl", denId, 574);
|
||||
assert.strictEqual((await a.nextXt("gl"))[8], "0");
|
||||
a.xt("pc", denId, 312, petShop[9], 0, 0, 15386, 15428, 0);
|
||||
const pet = await a.nextXt("pc");
|
||||
assert.deepStrictEqual(pet.slice(2, 3).concat(pet.slice(6, 10)), ["1", petShop[9], "0", "0", "15386|15428"]);
|
||||
a.xt("ps", denId, pet[5]);
|
||||
assert.deepStrictEqual((await a.nextXt("ps")).slice(2), ["1", String(aliceId), pet[5]]);
|
||||
assert.deepStrictEqual((await c.nextXt("ps")).slice(2, 8), ["1", String(aliceId), petShop[9], "0", "0", "15386|15428"]);
|
||||
a.xt("pl", denId, "Alice");
|
||||
assert.deepStrictEqual((await a.nextXt("pl")).slice(2, 6), ["1", "Alice", "1", pet[5]]);
|
||||
assert.match((await a.nextXt("pu"))[2], /^4294967295(,4294967295)*$/);
|
||||
|
||||
// --- den items: buy, place (Carol sees it), recycle
|
||||
a.xt("gl", denId, 9);
|
||||
const denShop = await a.nextXt("gl");
|
||||
assert.strictEqual(denShop[3], "1030");
|
||||
assert.ok(Number(denShop[8]) > 5 && Number(denShop[8]) < 200); // the Mystery Emporium's shelf (lib/shopstock.js)
|
||||
a.xt("db", denId, 0, 9, denShop[9], 0, 0, 0, 0, "");
|
||||
assert.deepStrictEqual((await a.nextXt("db")).slice(2, 3), ["1"]);
|
||||
const denItems = await a.nextXt("di");
|
||||
assert.deepStrictEqual(denItems.slice(2, 5).concat(denItems.slice(6, 8)), ["0", "1", "0", denShop[9], "0"]);
|
||||
const denInv = denItems[5];
|
||||
a.xt("ds", denId, 1, 0, denInv, 1, 250, 260, 1, "off", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
assert.deepStrictEqual((await a.nextXt("dss")).slice(2), [denInv]);
|
||||
assert.deepStrictEqual((await c.nextXt("ds")).slice(2, 12), ["1", "0", "0", denInv, denShop[9], "1", "250", "260", "0", "1"]);
|
||||
a.xt("dp", denId, 1, "Carol");
|
||||
assert.deepStrictEqual((await a.nextXt("dp")).slice(2), ["Carol", "2"]); // 2 = open to everyone
|
||||
|
||||
// --- den rooms: buy a second den and switch to it (the visitor follows); lock the den
|
||||
a.xt("gl", denId, 13);
|
||||
const denRooms = await a.nextXt("gl");
|
||||
assert.strictEqual(denRooms[3], "1040");
|
||||
const newDenDef = denRooms.slice(9).find(id => id !== "1");
|
||||
a.xt("db", denId, -1, 13, newDenDef, 0, 0);
|
||||
assert.deepStrictEqual((await a.nextXt("db")).slice(2, 3), ["1"]);
|
||||
const denList = await a.nextXt("dl");
|
||||
assert.deepStrictEqual([denList[2], denList[3], denList[4], denList[6]], ["2", "0", "1", newDenDef]);
|
||||
a.xt("dc", denId, denList[5]);
|
||||
assert.deepStrictEqual((await a.nextXt("dc")).slice(2, 3), [newDenDef]);
|
||||
const moved = await c.nextXt("rp");
|
||||
assert.deepStrictEqual([moved[4], moved[5]], ["2", newDenDef]); // room type 2 = den, then the den type
|
||||
assert.deepStrictEqual((await c.nextXt("ds")).slice(2, 3), ["0"]); // the furniture stayed in the first den
|
||||
assert.deepStrictEqual((await a.nextXt("ds")).slice(2, 3), ["0"]);
|
||||
a.xt("dc", denId, 0);
|
||||
await a.nextXt("dc");
|
||||
await c.nextXt("rp");
|
||||
assert.deepStrictEqual((await c.nextXt("ds")).slice(2, 3), ["1"]);
|
||||
await a.nextXt("ds");
|
||||
a.xt("dp", denId, 0, 0);
|
||||
{
|
||||
const stranger = new GameClient();
|
||||
await stranger.connect();
|
||||
await stranger.logIn("Dave", (await (await postJson(`${BASE}/authenticate`, {username: "Dave", password: "DavePass01"})).json()).auth_token);
|
||||
stranger.xt("dj", 1, "denAlice", 1, -1);
|
||||
assert.strictEqual((await stranger.nextXt("rj"))[2], "0");
|
||||
stranger.socket.destroy();
|
||||
}
|
||||
a.xt("dp", denId, 0, 2);
|
||||
a.xt("dr", denId, 0, denInv);
|
||||
assert.deepStrictEqual((await a.nextXt("dr")).slice(2, 3).concat((await c.nextXt("ds")).slice(2, 3)), ["1", "0"]);
|
||||
await a.nextXt("di"); // what the recycling window waits for
|
||||
|
||||
a.xt("ir", denId, tradedInv);
|
||||
const recycled = await a.nextXt("ir");
|
||||
assert.deepStrictEqual([recycled[2], recycled[4]], ["1", tradedInv]);
|
||||
// the recycling window waits for the list to change before it closes.
|
||||
const gone = await a.nextXt("il");
|
||||
assert.deepStrictEqual([gone[2], gone[5], ...gone.slice(7)], ["2", "Alice", "0", "1", tradedInv]);
|
||||
|
||||
// --- item finder: search by name and id, give to a connected player
|
||||
assert.match(await (await fetch(`${BASE}/shop`)).text(), /Item finder/);
|
||||
const found = await (await fetch(`${BASE}/api/search?q=top+hat&kind=clothing`)).json();
|
||||
assert.ok(found.total > 0 && found.results.every(item => /top/i.test(item.name) && /hat/i.test(item.name)));
|
||||
const hat = found.results[0];
|
||||
assert.strictEqual((await (await fetch(`${BASE}/api/search?q=${hat.id}`)).json()).results[0].id, hat.id);
|
||||
assert.ok((await (await fetch(`${BASE}/api/accounts`)).json()).some(entry => entry.username === "Alice" && entry.online));
|
||||
assert.strictEqual((await fetch(`${BASE}/api/accounts`, {headers: {Origin: "https://example.com"}})).status, 403);
|
||||
const giveJson = body => fetch(`${BASE}/api/give`, {method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify(body)});
|
||||
assert.strictEqual((await giveJson({username: "Alice", kind: "clothing", id: hat.id, colorIndex: 0})).status, 200);
|
||||
const pushed = await a.nextXt("il");
|
||||
assert.deepStrictEqual([pushed[2], pushed[10]], ["2", String(hat.id)]);
|
||||
assert.strictEqual((await giveJson({username: "Alice", kind: "clothing", id: 1})).status, 400);
|
||||
assert.strictEqual((await giveJson({username: "Nobody", kind: "den", id: 6})).status, 404);
|
||||
assert.strictEqual((await giveJson({username: "Alice", kind: "den", id: 6})).status, 200);
|
||||
assert.deepStrictEqual((await a.nextXt("di")).slice(3, 4), ["1"]);
|
||||
|
||||
// --- no game account has admin powers: "foo" is an ordinary player now
|
||||
const foo = await (await postJson(`${BASE}/authenticate`, {username: "foo", password: "Password04"})).json();
|
||||
const f = new GameClient();
|
||||
await f.connect();
|
||||
const fooLogin = await f.logIn("foo", foo.auth_token);
|
||||
assert.strictEqual(fooLogin.params.accountType, 2);
|
||||
f.xt("rj", 1, "jamaa_township.room_main#1", 1, 0, 0);
|
||||
const fooRoom = (await f.nextXt("rj"))[4];
|
||||
await f.nextXt("rp");
|
||||
f.send(`<msg t='sys'><body action='pubMsg' r='${fooRoom}'><txt><![CDATA[!gems alice 5%0]]></txt></body></msg>`);
|
||||
assert.deepStrictEqual((await f.nextXt("uc")).slice(3), ["!gems alice 5", "0"]); // just chat
|
||||
f.xt("fb", fooRoom, "Carol", 7200, 0, "");
|
||||
assert.deepStrictEqual((await f.nextXt("fb")).slice(2), ["0"]);
|
||||
f.xt("fk", fooRoom, "Alice", "");
|
||||
assert.deepStrictEqual((await f.nextXt("fk")).slice(2), ["0"]);
|
||||
|
||||
// --- the admin panel: first-time password, then everything behind it
|
||||
const panel = async (pathname, body, cookie, headers = {}) => {
|
||||
const response = await fetch(`${BASE}/admin/api/${pathname}`, {
|
||||
method: body === undefined ? "GET" : "POST",
|
||||
headers: {"Content-Type": "application/json", ...(cookie ? {Cookie: cookie} : {}), ...headers},
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
});
|
||||
return {status: response.status, data: await response.json(), cookie: (response.headers.get("set-cookie") || "").split(";")[0]};
|
||||
};
|
||||
assert.match(await (await fetch(`${BASE}/admin`)).text(), /Server admin/);
|
||||
assert.deepStrictEqual((await panel("state")).data, {needsSetup: true, needsSetupCode: false, signedIn: false});
|
||||
assert.strictEqual((await panel("overview")).status, 401);
|
||||
assert.strictEqual((await panel("login", {password: "anything"})).status, 401);
|
||||
assert.strictEqual((await panel("setup", {password: "short"})).status, 400);
|
||||
const setup = await panel("setup", {password: "admin-password-1"});
|
||||
assert.strictEqual(setup.status, 200);
|
||||
assert.match(setup.cookie, /^ajc_admin=[0-9a-f]{48}$/);
|
||||
assert.strictEqual((await panel("setup", {password: "another-password"})).status, 409); // only once
|
||||
assert.strictEqual((await panel("login", {password: "wrong-password"})).status, 401);
|
||||
const admin = (await panel("login", {password: "admin-password-1"})).cookie;
|
||||
assert.strictEqual((await panel("state", undefined, admin)).data.signedIn, true);
|
||||
assert.strictEqual((await panel("account", {username: "Alice", action: "kick"}, admin, {Origin: "http://evil.example"})).status, 403);
|
||||
|
||||
const seen = (await panel("overview", undefined, admin)).data;
|
||||
assert.ok(seen.stats.online >= 3 && seen.stats.accounts >= 5 && seen.players.some(player => player.username === "foo"));
|
||||
const listed = (await panel("accounts", undefined, admin)).data.accounts;
|
||||
assert.strictEqual(listed.find(account => account.username === "Alice").online, true);
|
||||
assert.ok((await panel("logs?filter=%5Badmin%5D", undefined, admin)).data.lines.some(line => line.text.includes("admin password chosen")));
|
||||
|
||||
assert.strictEqual((await panel("account", {username: "Nobody", action: "kick"}, admin)).status, 404);
|
||||
assert.strictEqual((await panel("account", {username: "Alice", action: "gems", amount: -5}, admin)).status, 200);
|
||||
assert.deepStrictEqual((await a.untilXt("cu")).slice(2, 3), ["0"]);
|
||||
assert.strictEqual((await panel("account", {username: "Alice", action: "message", text: "hello from the panel"}, admin)).status, 200);
|
||||
|
||||
assert.deepStrictEqual((await a.untilXt("fd")).slice(2, 4), ["fp", "hello from the panel"]);
|
||||
|
||||
// --- last seen: a card carries the time its player left, -2 while they
|
||||
// are online, and the panel can set it for testing
|
||||
const cardOf = async name => {
|
||||
a.xt("ag", denId, name, 0);
|
||||
return Number((await a.untilXt("ag"))[7]);
|
||||
};
|
||||
assert.strictEqual(await cardOf("Alice"), -2);
|
||||
assert.ok(Math.abs(await cardOf("Dave") - Date.now() / 1000) < 600); // he left moments ago
|
||||
const threeDaysAgo = Math.floor(Date.now() / 1000) - 3 * 86400;
|
||||
assert.strictEqual((await panel("account", {username: "Dave", action: "lastSeen", when: threeDaysAgo}, admin)).status, 200);
|
||||
assert.strictEqual(await cardOf("Dave"), threeDaysAgo);
|
||||
assert.strictEqual((await panel("account", {username: "Dave", action: "lastSeen", when: threeDaysAgo + 30 * 86400}, admin)).status, 400); // not the future
|
||||
|
||||
assert.strictEqual((await panel("account", {username: "Carol", action: "ban", hours: 2}, admin)).status, 200);
|
||||
assert.deepStrictEqual((await c.untilXt("fd")).slice(2), ["fb", "1", "7200"]);
|
||||
// A player card asks whether its player is banned, for its red label.
|
||||
a.xt("xbn", denId, "carol");
|
||||
const banned = await a.untilXt("xbn");
|
||||
assert.ok(banned[2] === "Carol" && Number(banned[3]) > 7190 && Number(banned[3]) <= 7200);
|
||||
a.xt("xbn", denId, "Alice");
|
||||
const notBanned = await a.untilXt("xbn");
|
||||
assert.deepStrictEqual(notBanned.slice(2, 4), ["Alice", "0"]);
|
||||
assert.ok(Number(notBanned[4]) > 1700000000); // and when she joined
|
||||
assert.deepStrictEqual(notBanned.slice(5), ["", "early|Early Member", ""]); // no Discord username; the badge of the first hundred accounts; no bio (lib/badges.js)
|
||||
assert.strictEqual((await fetch(`${BASE}/ban-icon.png`)).headers.get("content-type"), "image/png");
|
||||
const carolAgain = new GameClient();
|
||||
await carolAgain.connect();
|
||||
const refused = await carolAgain.logIn("Carol", carol.auth_token);
|
||||
assert.deepStrictEqual([refused.status, refused.statusId], ["0", -15]);
|
||||
carolAgain.socket.destroy();
|
||||
assert.ok((await panel("accounts", undefined, admin)).data.accounts.find(account => account.username === "Carol").banned > 7000);
|
||||
|
||||
// A new username: buddies follow it, the player is disconnected, and the
|
||||
// same password works under the new name.
|
||||
assert.deepStrictEqual((await panel("account", {username: "Bob", action: "rename", newName: "alice"}, admin)).data, {error: "That username is taken."});
|
||||
for (const unusable of ["", " ", "50% off", "tab\there", "x".repeat(101)]) {
|
||||
assert.strictEqual((await panel("account", {username: "Bob", action: "rename", newName: unusable}, admin)).status, 400);
|
||||
}
|
||||
// names sign-up would refuse are fine from the panel, and can log in.
|
||||
for (const odd of ["x", "~*Bob*~ <3", "Ünïcødé 名前", "a name well past twenty characters"]) {
|
||||
assert.strictEqual((await panel("account", {username: "Bob", action: "rename", newName: odd}, admin)).status, 200);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: odd, password: "Password02"})).status, 200);
|
||||
assert.strictEqual((await panel("account", {username: odd, action: "rename", newName: "Bob"}, admin)).status, 200);
|
||||
}
|
||||
assert.strictEqual((await registerJson({username: "x", password: "Password09"})).status, 400); // sign-up rules unchanged
|
||||
const renamed = await panel("account", {username: "Bob", action: "rename", newName: "Robert"}, admin);
|
||||
assert.deepStrictEqual([renamed.status, renamed.data.username], [200, "Robert"]);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "Bob", password: "Password02"})).status, 401);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "robert", password: "Password02"})).status, 200);
|
||||
assert.ok(!(await panel("accounts", undefined, admin)).data.accounts.some(account => account.username === "Bob"));
|
||||
assert.strictEqual((await panel("account", {username: "Robert", action: "rename", newName: "ROBERT"}, admin)).status, 200);
|
||||
assert.strictEqual((await panel("account", {username: "robert", action: "rename", newName: "Bob"}, admin)).status, 200);
|
||||
|
||||
// A new password for a player: the old one and old tokens stop working.
|
||||
assert.strictEqual((await panel("account", {username: "foo", action: "password", password: "short"}, admin)).status, 400);
|
||||
assert.strictEqual((await panel("account", {username: "foo", action: "password", password: "New-password-4"}, admin)).status, 200);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "foo", password: "Password04"})).status, 401);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {refresh_token: foo.refresh_token})).status, 401);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "foo", password: "New-password-4"})).status, 200);
|
||||
assert.strictEqual((await panel("account", {username: "foo", action: "delete"}, admin)).status, 200);
|
||||
assert.strictEqual((await postJson(`${BASE}/authenticate`, {username: "foo", password: "New-password-4"})).status, 401);
|
||||
|
||||
// changing the admin password signs every other session out.
|
||||
assert.strictEqual((await panel("password", {current: "nope", password: "admin-password-2"}, admin)).status, 403);
|
||||
const changed = await panel("password", {current: "admin-password-1", password: "admin-password-2"}, admin);
|
||||
assert.strictEqual(changed.status, 200);
|
||||
assert.strictEqual((await panel("overview", undefined, admin)).status, 401);
|
||||
assert.strictEqual((await panel("overview", undefined, changed.cookie)).status, 200);
|
||||
assert.strictEqual((await panel("logout", {}, changed.cookie)).status, 200);
|
||||
assert.strictEqual((await panel("overview", undefined, changed.cookie)).status, 401);
|
||||
|
||||
// --- diamonds
|
||||
// Items priced in diamonds are bought by their diamond def id: 76 is a
|
||||
// clothing item, 3457 a den item and 3436 a den room.
|
||||
a.xt("gl", denId, 415); // the Diamond Shop's clothing
|
||||
const diamondShop = await a.untilXt("gl");
|
||||
assert.deepStrictEqual(diamondShop.slice(3, 5), ["1054", ""]);
|
||||
assert.ok(Number(diamondShop[8]) > 20 && Number(diamondShop[8]) === diamondShop.length - 9);
|
||||
a.xt("gl", denId, 293);
|
||||
assert.deepStrictEqual((await a.untilXt("gl")).slice(3, 9), ["1054", "", "0", "0", "0", "0"]);
|
||||
// A shop nothing is known of has empty shelves, whatever its kind.
|
||||
for (const [unknownShop, kind] of [[390, "1030"], [338, "1000"], [796, "1054"]]) {
|
||||
a.xt("gl", denId, unknownShop);
|
||||
assert.deepStrictEqual((await a.untilXt("gl")).slice(3, 9), [kind, "", "0", "0", "0", "0"]);
|
||||
}
|
||||
a.xt("gl", denId, 794);
|
||||
assert.deepStrictEqual((await a.untilXt("gl")).slice(8), ["1", "1030", "0"]);
|
||||
a.xt("ib", denId, 11, 1, 76, 0, 1, -1, "");
|
||||
assert.strictEqual((await a.untilXt("il"))[10], "584");
|
||||
assert.deepStrictEqual((await a.untilXt("ib")).slice(2), ["1", "11", "9999999", "3"]);
|
||||
a.xt("db", denId, 0, 234, 3457, 0, 1, 0, 0, "");
|
||||
assert.deepStrictEqual((await a.untilXt("db")).slice(2), ["1", "9999998", "0", "3", "0"]);
|
||||
assert.ok((await a.untilXt("di")).includes("5755"));
|
||||
a.xt("db", denId, -1, 384, 3436, 1, 1);
|
||||
assert.deepStrictEqual((await a.untilXt("db")).slice(2), ["1", "9999991", "0", "3", "0"]);
|
||||
assert.strictEqual((await a.untilXt("dl")).at(-1), "58");
|
||||
a.xt("ib", denId, 11, 1, 3436, 0, 1, -1, ""); // a den room's diamond def is not clothing
|
||||
assert.strictEqual((await a.untilXt("ib"))[2], "0");
|
||||
|
||||
// --- tutorials stay switched off, seasonal themes, custom colour ids
|
||||
a.xt("zs", denId, 379, 2, 1); // the client names the bit it wants set
|
||||
assert.deepStrictEqual((await a.untilXt("zs")).slice(2), ["379", "65535", "0"]);
|
||||
a.xt("rj", denId, "sarepia.room_main#1", 1, 0, 0);
|
||||
await a.untilXt("rj");
|
||||
assert.strictEqual((await a.untilXt("rp"))[2], "sarepia.room_main");
|
||||
const themeJson = theme => fetch(`${BASE}/api/theme`, {method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({username: "Alice", theme})});
|
||||
assert.strictEqual((await themeJson("easter")).status, 400);
|
||||
assert.strictEqual((await themeJson("jamaalidays")).status, 200);
|
||||
// reloaded where she stands, from the December build's files.
|
||||
assert.strictEqual((await a.untilXt("rp"))[2], "theme_1810.sarepia.room_main");
|
||||
// an older design is a build too, or another room file of one.
|
||||
assert.strictEqual((await themeJson("fall2022")).status, 200);
|
||||
assert.strictEqual((await a.untilXt("rp"))[2], "theme_1636.sarepia.room_main");
|
||||
assert.strictEqual((await themeJson("freedom2021")).status, 200);
|
||||
assert.strictEqual((await a.untilXt("rp"))[2], "theme_1824.sarepia.room_main_freedom");
|
||||
assert.strictEqual((await themeJson("friendship2018")).status, 200);
|
||||
assert.strictEqual((await a.untilXt("rp"))[2], "theme_1815.sarepia.room_main"); // not one of its rooms
|
||||
const roomFile = name => `roomDefs/${name}sarepia/${crypto.createHash("md5").update("placeholder").digest("hex")}`;
|
||||
assert.strictEqual((await fetch(`${BASE}/1830/${roomFile("theme_9999/")}`)).status, 404);
|
||||
assert.strictEqual((await themeJson("")).status, 200);
|
||||
assert.strictEqual((await giveJson({username: "Alice", kind: "clothing", id: hat.id, color: "123456789"})).status, 200);
|
||||
await a.untilXt("il");
|
||||
a.xt("il", denId, "Alice", 1, 1);
|
||||
assert.ok((await a.untilXt("il")).includes("123456789"));
|
||||
assert.strictEqual((await giveJson({username: "Alice", kind: "clothing", id: hat.id, color: "-5"})).status, 400);
|
||||
|
||||
// --- the item defs clients get: ocean eyes (314) allowed on every animal
|
||||
const {decode} = require("../lib/amf3.js");
|
||||
const zlib = require("zlib");
|
||||
const itemDefsPath = require("../lib/cdn.js").hashedPath("defPacks/1000");
|
||||
const servedDefs = decode(zlib.inflateRawSync(Buffer.from(await (await fetch(`${BASE}/${itemDefsPath}?v=4`)).arrayBuffer())));
|
||||
const servedById = Object.fromEntries(Object.values(servedDefs).map(def => [def.id, def]));
|
||||
assert.strictEqual(servedById[314].avatarUseFlags, "9007199254740991");
|
||||
// ... and every piece of clothing wearable by every animal.
|
||||
assert.ok(Object.values(servedDefs).filter(def => def.type === "1").every(def => def.avatarUseFlags === "9007199254740991"));
|
||||
assert.strictEqual(servedById[316].avatarUseFlags, "12453376"); // an ocean pattern: untouched
|
||||
assert.strictEqual(Object.keys(servedDefs).length, 4497);
|
||||
a.xt("iu", denId, 1, 0, -314);
|
||||
assert.strictEqual((await a.untilXt("iu"))[2], "1");
|
||||
|
||||
// --- the custom client's login choices: honoured for that session only
|
||||
assert.strictEqual((await (await fetch(`${BASE}/flashvars`)).json()).loginChoices, true);
|
||||
const chosen = await (await postJson(`${BASE}/authenticate`, {username: "Carol", password: "Password03",
|
||||
login_choices: {accountType: 0, isGuide: true, membershipDays: 12, isModerator: "yes"}})).json();
|
||||
// (Carol is banned from the game by now, so only the web side is checked.)
|
||||
assert.strictEqual((await (await fetch(`${BASE}/player`, {headers: {Authorization: `Bearer ${chosen.auth_token}`}})).json()).game_account_type, 0);
|
||||
a.xt("ag", denId, "Carol", 0);
|
||||
assert.deepStrictEqual((await a.untilXt("ag")).slice(5, 7), ["0", "1"]); // account type, guide
|
||||
await postJson(`${BASE}/authenticate`, {username: "Carol", password: "Password03"}); // and back to normal
|
||||
a.xt("ag", denId, "Carol", 0);
|
||||
assert.deepStrictEqual((await a.untilXt("ag")).slice(5, 7), ["2", "0"]);
|
||||
|
||||
// --- custom colours: an id for four RGB values, announced to everyone
|
||||
a.xt("xcc", denId, 0xff8800, 0x123456, 0, 0xffffff);
|
||||
const colour = await a.untilXt("xcc");
|
||||
assert.deepStrictEqual(colour.slice(2), ["1", String(0xFD000000), "16746496", "1193046", "0", "16777215"]);
|
||||
a.xt("xcc", denId, 0xff8800, 0x123456, 0, 0xffffff); // the same colours again
|
||||
assert.strictEqual((await a.untilXt("xcc"))[3], String(0xFD000000));
|
||||
a.xt("xcc", denId, 0x1000000, 0, 0, 0); // not a colour
|
||||
a.xt("ap", denId, 0xFD000000, 0, 0);
|
||||
assert.strictEqual((await a.untilXt("ap"))[2], "1");
|
||||
const late = new GameClient();
|
||||
await late.connect();
|
||||
const dev = await (await postJson(`${BASE}/authenticate`, {username: "Alice", password: "Password01", login_choices: {accountType: 4, membershipDays: 7}})).json();
|
||||
const devLogin = await late.logIn("Alice", dev.auth_token);
|
||||
assert.deepStrictEqual([devLogin.params.accountType, devLogin.params.numDaysLeftOnSubscription, devLogin.params.isGuide, devLogin.params.isModerator], [4, 7, false, false]);
|
||||
assert.deepStrictEqual((await late.untilXt("xcc")).slice(2, 4), ["1", String(0xFD000000)]); // the table at login
|
||||
late.socket.destroy();
|
||||
|
||||
c.socket.destroy();
|
||||
policy.socket.destroy();
|
||||
};
|
||||
|
||||
harness.withServer("smoke test", HTTP_PORT, GAME_PORT, run).catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in new issue
Block a user