Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

A moderator who bans someone on the same address bars themselves #326

Parked opened this
Closed without merging

smith/arm:smith/209-a-moderator-who-bans-someone-on-the-same → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
3 files changed +22 −0
Software/so101/src/accounts.ts +5
@@ -171,6 +171,11 @@ export class Accounts {
171171 return Boolean(this.db.query("SELECT 1 FROM bans WHERE id = ? OR key = ? OR ip = ? LIMIT 1").get(id, name?.toLowerCase() ?? "\0", ip || "\0"));
172172 }
173173
174 /** The address an account was last seen at, or "" when unknown. */
175 addressOf(id: string): string {
176 return this.db.query<{ ip: string }, [string]>("SELECT ip FROM users WHERE id = ?").get(id)?.ip ?? "";
177 }
178
174179 /** Bar a person: their account, their name, and the address and browser they were last seen with. */
175180 ban(who: Person, seen: Pick<Visitor, "ip" | "ua"> | null, by: string): Ban {
176181 const row = this.db.query<UserRow, [string]>("SELECT id, name, ip, ua FROM users WHERE id = ?").get(who.id);
Software/so101/src/lobby.test.ts +11
@@ -700,6 +700,17 @@ describe("lobby", () => {
700700 expect((await enter(port, "another", "203.0.113.66")).status).toBe(200);
701701 });
702702
703 test("a ban that would cover the banner's own address is refused; the owner is never covered", () => {
704 const lobby = new Lobby({ identityKey: KEY, turns: new Turns(), chat: new Chat(), admin: new Admin(), accounts: new Accounts() });
705 const mod = { id: "u-bob", name: "bob", owner: false };
706 const here = { ip: "203.0.113.7", ua: "x", token: null } as any;
707 expect(lobby.banCoversBanner(mod, here, "203.0.113.7")).toBe(true);
708 expect(lobby.banCoversBanner(mod, here, "198.51.100.1")).toBe(false);
709 expect(lobby.banCoversBanner(mod, here, "")).toBe(false);
710 expect(lobby.banCoversBanner({ ...mod, owner: true }, here, "203.0.113.7")).toBe(false);
711 lobby.close();
712 });
713
703714 test("ban: the driver's turn ends at once, the next in line drives, and the banned person is out of the queue and refused", async () => {
704715 const port = await start();
705716 const alice = await join(port, ALICE);
Software/so101/src/lobby.ts +6
@@ -163,6 +163,11 @@ export class Lobby {
163163 return !who.owner && !this.local && this.accounts.banned(who.id, who.name, from?.ip ?? null);
164164 }
165165
166 /** Whether banning a person seen at this address would bar the banner too (the owner is never barred). */
167 banCoversBanner(banner: Person, bannerFrom: Visitor | null, targetIp: string): boolean {
168 return !banner.owner && !this.local && Boolean(targetIp) && targetIp === bannerFrom?.ip;
169 }
170
166171 /** Why this person may not command the arm right now, or null when they may (and then it counts as activity). */
167172 refusal(who: Who, req?: IncomingMessage): { status: number; error: string } | null {
168173 if (this.local) return null;
@@ -378,6 +383,7 @@ export class Lobby {
378383 const person = known ?? (said ? { id, name: said.name, owner: false } : null);
379384 if (!person) return this.send(seat, { type: "error", error: "nobody here by that id" });
380385 if (person.owner) return this.send(seat, { type: "error", error: "the owner cannot be banned" });
386 if (this.banCoversBanner(who, seat.from, target?.from.ip || this.accounts.addressOf(id))) return this.send(seat, { type: "error", error: "that address is yours too: the ban would bar you" });
381387 this.accounts.ban({ id: person.id, name: person.name, owner: false }, target?.from ?? null, who.name);
382388 this.turns.end(id); // their turn ends, or they leave the line
383389 this.broadcast({ type: "said", message: this.chat.system(`${person.name} was banned`) });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs