Seats are banked in a cookie the server sets, and a lost seat comes back by name to the address it was last used from
A seat lived in the browser's storage alone, and Safari clears that after a week away, or at a word from the person on another device. Now every seat taken is banked as well in an HttpOnly cookie the server writes, which such clearing leaves alone, and the hall takes its seats back from the bank on arrival. For a browser that lost even the cookie, the ledger notes the address each seat was last used from, as a salted hash, at most once in ten minutes, and a name given in the hall or at the duel gets its seats back from the same address, with a new token; where the address differs, two people at the duel share it, or the host gave the seat to a bot, the duel is only counted, and the host's phrase or the keeper's link is the way back. The keeper's script finds a name across duels. The seat endpoints answer only this site's own pages, under a limit of their own. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CCLa2PaEeCj8njQZSWGqHx
This commit is contained in:
1 parent
b8f65a74d3
commit
29a68f4d9d
8 files changed
+443
-13
No files matched your search
@@ -121,3 +121,54 @@ describe('the host and the other seats', () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('a seat a browser lost', () => {
|
||||
it('notes the address a seat is used from, once per change and not on its heels, without waking the duel, and a restart keeps it', () => {
|
||||
const { rooms, room, bo } = table();
|
||||
const seq = room.seq;
|
||||
rooms.seen(room, bo, 'home');
|
||||
rooms.seen(room, bo, 'home');
|
||||
expect(room.seats.find((s) => s.id === 'B')?.addr).toBe('home');
|
||||
expect(room.seq).toBe(seq);
|
||||
rooms.seen(room, 'no-such-token', 'elsewhere');
|
||||
rooms.seen(room, bo, 'office');
|
||||
expect(new Store(dir).read(room.id).filter((l) => l.t === 'seen')).toHaveLength(1);
|
||||
expect(new Rooms(new Store(dir)).get(room.id).seats.find((s) => s.id === 'B')?.addr).toBe('home');
|
||||
});
|
||||
|
||||
it('gives the seat back, under its name, to the address it was last used from, with a new token', () => {
|
||||
const { rooms, room, bo } = table();
|
||||
rooms.seen(room, bo, 'home');
|
||||
const found = rooms.findSeats('bo', 'home');
|
||||
expect(found.elsewhere).toBe(0);
|
||||
expect(found.seated.map((s) => [s.roomId, s.seat])).toEqual([[room.id, 'B']]);
|
||||
expect(rooms.seatOf(room, found.seated[0].token).name).toBe('Bo');
|
||||
expect(() => rooms.seatOf(room, bo)).toThrow(/opens no seat/);
|
||||
});
|
||||
|
||||
it('only counts the duel when the address differs, or another person at it shares the address, or a bot stands in', async () => {
|
||||
const { rooms, room, ann, bo } = table();
|
||||
rooms.seen(room, bo, 'home');
|
||||
expect(rooms.findSeats('Bo', 'away')).toEqual({ seated: [], elsewhere: 1 });
|
||||
rooms.seen(room, ann, 'home');
|
||||
expect(rooms.findSeats('Bo', 'home')).toEqual({ seated: [], elsewhere: 1 });
|
||||
expect(rooms.findSeats('Dee', 'home')).toEqual({ seated: [], elsewhere: 0 });
|
||||
expect(rooms.seatOf(room, bo).id).toBe('B');
|
||||
rooms.standIn(room, ann, 'B');
|
||||
await new Promise<void>((r) => setImmediate(r));
|
||||
expect(rooms.findSeats('Bo', 'home')).toEqual({ seated: [], elsewhere: 1 });
|
||||
expect(rooms.tablesForKeeper('bo')).toMatchObject([{ roomId: room.id, seat: 'B', standIn: true, players: ['Ann'] }]);
|
||||
expect(rooms.tablesForKeeper('Dee')).toEqual([]);
|
||||
});
|
||||
|
||||
it('looks only at the duel named when one is, and passes over a duel that is over', () => {
|
||||
const { rooms, room, bo } = table();
|
||||
rooms.seen(room, bo, 'home');
|
||||
const other = rooms.create('Bo', 3);
|
||||
rooms.seen(other.room, other.token, 'home');
|
||||
expect(rooms.findSeats('Bo', 'home', other.room.id).seated.map((s) => s.roomId)).toEqual([other.room.id]);
|
||||
expect(rooms.findSeats('Bo', 'home').seated.map((s) => s.roomId).sort()).toEqual([other.room.id, room.id].sort());
|
||||
room.over = true;
|
||||
expect(rooms.findSeats('Bo', 'home').seated.map((s) => s.roomId)).toEqual([other.room.id]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user