Add multiplayer rooms and Vercel analytics

This commit is contained in:
2026-10-07 12:28:45 +05:00
parent ce26e6fdbc
commit 48b34db6f1
20 changed files with 2345 additions and 9 deletions

46
tests/multiplayer.test.ts Normal file
View File

@@ -0,0 +1,46 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import {
createRoomSchema,
joinRoomSchema,
roomGuessSchema,
} from "../shared/multiplayer";
const map = "00000000-0000-4000-8000-000000000000";
test("room limits include the owner and stay between 2 and 16", () => {
for (const playerLimit of [2, 16])
assert.equal(
createRoomSchema.parse({
datasetId: map,
difficulty: "normal",
displayName: " Alex ",
playerLimit,
}).displayName,
"Alex",
);
for (const playerLimit of [1, 17, 2.5, "16", null])
assert.equal(
createRoomSchema.safeParse({
datasetId: map,
difficulty: "normal",
displayName: "Alex",
playerLimit,
}).success,
false,
);
});
test("multiplayer names and guesses reject hidden controls, invalid rounds, and non-finite positions", () => {
assert.equal(
joinRoomSchema.parse({ displayName: " Друг " }).displayName,
"Друг",
);
for (const displayName of ["a", "x\nname", "name\u202e", "a".repeat(33)])
assert.equal(joinRoomSchema.safeParse({ displayName }).success, false);
for (const payload of [
{ round: 5, x: 0, z: 0 },
{ round: 0, x: Infinity, z: 0 },
{ round: 0, x: NaN, z: 0 },
{ round: 0, x: 0 },
])
assert.equal(roomGuessSchema.safeParse(payload).success, false);
});