tickflare 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/CHANGELOG.md +233 -0
  2. package/LICENSE +21 -0
  3. package/README.md +110 -2
  4. package/dist/binary.d.ts +91 -0
  5. package/dist/binary.js +466 -0
  6. package/dist/binary.js.map +1 -0
  7. package/dist/client/accounts.d.ts +193 -0
  8. package/dist/client/accounts.js +306 -0
  9. package/dist/client/accounts.js.map +1 -0
  10. package/dist/client/draft.d.ts +17 -0
  11. package/dist/client/draft.js +133 -0
  12. package/dist/client/draft.js.map +1 -0
  13. package/dist/client/index.d.ts +161 -0
  14. package/dist/client/index.js +436 -0
  15. package/dist/client/index.js.map +1 -0
  16. package/dist/client/interpolate.d.ts +31 -0
  17. package/dist/client/interpolate.js +59 -0
  18. package/dist/client/interpolate.js.map +1 -0
  19. package/dist/client/lockstep.d.ts +86 -0
  20. package/dist/client/lockstep.js +339 -0
  21. package/dist/client/lockstep.js.map +1 -0
  22. package/dist/client/matchmaking.d.ts +21 -0
  23. package/dist/client/matchmaking.js +55 -0
  24. package/dist/client/matchmaking.js.map +1 -0
  25. package/dist/client/pacer.d.ts +22 -0
  26. package/dist/client/pacer.js +65 -0
  27. package/dist/client/pacer.js.map +1 -0
  28. package/dist/client/predict.d.ts +75 -0
  29. package/dist/client/predict.js +203 -0
  30. package/dist/client/predict.js.map +1 -0
  31. package/dist/client/token.d.ts +10 -0
  32. package/dist/client/token.js +15 -0
  33. package/dist/client/token.js.map +1 -0
  34. package/dist/lockstep.d.ts +154 -0
  35. package/dist/lockstep.js +140 -0
  36. package/dist/lockstep.js.map +1 -0
  37. package/dist/patch.d.ts +54 -0
  38. package/dist/patch.js +186 -0
  39. package/dist/patch.js.map +1 -0
  40. package/dist/protocol.d.ts +230 -0
  41. package/dist/protocol.js +50 -0
  42. package/dist/protocol.js.map +1 -0
  43. package/dist/server/accounts.d.ts +320 -0
  44. package/dist/server/accounts.js +1223 -0
  45. package/dist/server/accounts.js.map +1 -0
  46. package/dist/server/delta.d.ts +50 -0
  47. package/dist/server/delta.js +426 -0
  48. package/dist/server/delta.js.map +1 -0
  49. package/dist/server/frames.d.ts +15 -0
  50. package/dist/server/frames.js +23 -0
  51. package/dist/server/frames.js.map +1 -0
  52. package/dist/server/gateway.d.ts +80 -0
  53. package/dist/server/gateway.js +144 -0
  54. package/dist/server/gateway.js.map +1 -0
  55. package/dist/server/index.d.ts +21 -0
  56. package/dist/server/index.js +22 -0
  57. package/dist/server/index.js.map +1 -0
  58. package/dist/server/limiter.d.ts +12 -0
  59. package/dist/server/limiter.js +43 -0
  60. package/dist/server/limiter.js.map +1 -0
  61. package/dist/server/lockstep.d.ts +126 -0
  62. package/dist/server/lockstep.js +544 -0
  63. package/dist/server/lockstep.js.map +1 -0
  64. package/dist/server/matches.d.ts +31 -0
  65. package/dist/server/matches.js +69 -0
  66. package/dist/server/matches.js.map +1 -0
  67. package/dist/server/matchmaker.d.ts +121 -0
  68. package/dist/server/matchmaker.js +479 -0
  69. package/dist/server/matchmaker.js.map +1 -0
  70. package/dist/server/room.d.ts +383 -0
  71. package/dist/server/room.js +1766 -0
  72. package/dist/server/room.js.map +1 -0
  73. package/dist/server/signals.d.ts +18 -0
  74. package/dist/server/signals.js +37 -0
  75. package/dist/server/signals.js.map +1 -0
  76. package/dist/server/storage.d.ts +117 -0
  77. package/dist/server/storage.js +330 -0
  78. package/dist/server/storage.js.map +1 -0
  79. package/dist/server/tokens.d.ts +74 -0
  80. package/dist/server/tokens.js +117 -0
  81. package/dist/server/tokens.js.map +1 -0
  82. package/dist/server/tracked.d.ts +47 -0
  83. package/dist/server/tracked.js +270 -0
  84. package/dist/server/tracked.js.map +1 -0
  85. package/dist/world.d.ts +20 -0
  86. package/dist/world.js +21 -0
  87. package/dist/world.js.map +1 -0
  88. package/package.json +74 -4
  89. package/src/binary.ts +496 -0
  90. package/src/client/accounts.ts +423 -0
  91. package/src/client/draft.ts +138 -0
  92. package/src/client/index.ts +573 -0
  93. package/src/client/interpolate.ts +60 -0
  94. package/src/client/lockstep.ts +398 -0
  95. package/src/client/matchmaking.ts +61 -0
  96. package/src/client/pacer.ts +67 -0
  97. package/src/client/predict.ts +239 -0
  98. package/src/client/token.ts +22 -0
  99. package/src/lockstep.ts +285 -0
  100. package/src/patch.ts +188 -0
  101. package/src/protocol.ts +260 -0
  102. package/src/server/accounts.ts +1474 -0
  103. package/src/server/delta.ts +467 -0
  104. package/src/server/frames.ts +23 -0
  105. package/src/server/gateway.ts +213 -0
  106. package/src/server/index.ts +85 -0
  107. package/src/server/limiter.ts +41 -0
  108. package/src/server/lockstep.ts +611 -0
  109. package/src/server/matches.ts +99 -0
  110. package/src/server/matchmaker.ts +537 -0
  111. package/src/server/room.ts +1867 -0
  112. package/src/server/signals.ts +46 -0
  113. package/src/server/storage.ts +392 -0
  114. package/src/server/tokens.ts +184 -0
  115. package/src/server/tracked.ts +260 -0
  116. package/src/world.ts +29 -0
  117. package/tools/rooms-report.mjs +168 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchmaker.js","sourceRoot":"","sources":["../../src/server/matchmaker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAmB,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAwC5F;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAgB,UAAiC,SAAQ,aAAkB;IAC/E,yBAAyB;IACf,SAAS,GAAG,CAAC,CAAC;IAExB;;;OAGG;IACO,UAAU,CAAqB;IAEzC;;;;OAIG;IACO,SAAS,GAAG,CAAC,CAAC;IAExB;;;;;OAKG;IACO,SAAS,GAAG,QAAQ,CAAC;IAE/B;;;;OAIG;IACO,kBAAkB,GA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SAAS,CAAC;IACnB,CAAC;CACF;AAED,SAAS,cAAc,CAAC,KAAgB;IACtC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,IAAI,IAAwB,CAAC;IAC7B,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACxB,IAAI,IAAI,KAAK,SAAS,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAE;YAAE,IAAI,GAAG,IAAI,CAAC;IACnE,CAAC;IACD,OAAO,IAA6C,CAAC;AACvD,CAAC;AAED,4DAA4D;AAC5D,SAAS,UAAU,CAAC,MAA8B;IAChD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,IAAI,IAAwB,CAAC;IAC7B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QAC3C,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACzB,IAAI,IAAI,KAAK,SAAS,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAE;YAAE,IAAI,GAAG,KAAK,CAAC;IACpE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,383 @@
1
+ import { DurableObject } from "cloudflare:workers";
2
+ import { type MatchResult, type Player } from "../protocol.js";
3
+ import { type RoomNamespace } from "./gateway.js";
4
+ /** Thrown by a hook to refuse a command, a join or a leave. The reason is sent to the client. */
5
+ export declare class Rejection extends Error {
6
+ /** Sent to the client as the reason. */
7
+ readonly reason: string;
8
+ constructor(reason: string);
9
+ }
10
+ /** What `act` reports: the hook's changes were committed, or it was refused and why. */
11
+ export type ActOutcome = {
12
+ /** The hook's changes were committed and sent. */
13
+ ok: true;
14
+ } | {
15
+ /** The hook was refused: nothing it did was kept. */
16
+ ok: false;
17
+ /** What it passed to `reject()`, or `internal_error` if it threw. */
18
+ reason: string;
19
+ };
20
+ /** What one room or matchmaker asks of another over RPC. @internal */
21
+ export type RoomCall = {
22
+ op: "arrive";
23
+ roomId: string;
24
+ playerId: string;
25
+ carry: unknown;
26
+ } | {
27
+ op: "signal";
28
+ from: string | null;
29
+ data: unknown;
30
+ } | {
31
+ op: "reserve";
32
+ roomId: string;
33
+ players: string[];
34
+ teams?: string[][];
35
+ };
36
+ /** Refuse what the current hook was asked to do. Everything the hook changed is rolled back. */
37
+ export declare function reject(reason: string): never;
38
+ /**
39
+ * An authoritative game room: one Durable Object per room.
40
+ *
41
+ * Event mode (the default) has no tick loop. The room wakes when a player
42
+ * connects, sends a command, drops or leaves, or when a timer fires. It runs
43
+ * the matching hook, saves what changed and sends each connected player their
44
+ * view of the state. Between events it hibernates while the WebSockets stay
45
+ * open, and rebuilds itself from storage on the next event.
46
+ *
47
+ * State sync adds a simulation: set `tickRate` and the room calls `onTick`
48
+ * that many times a second while players are connected, sending each player
49
+ * only what changed in their view since the previous tick.
50
+ *
51
+ * Hooks are synchronous and change `this.state` in place. The state must be
52
+ * JSON-serializable. A hook that calls `reject()` or throws leaves no trace:
53
+ * state, seats and timers go back to what they were.
54
+ */
55
+ export declare abstract class Room<State, Command = unknown, Env = Cloudflare.Env> extends DurableObject<Env> {
56
+ #private;
57
+ /** How many distinct players may hold a seat at once. */
58
+ protected maxPlayers: number;
59
+ /** Longest client frame accepted, in characters. */
60
+ protected maxMessageLength: number;
61
+ /**
62
+ * How long a disconnected player keeps their seat, in milliseconds. When it
63
+ * runs out, `onLeave` is called and the seat is given up, as if the player
64
+ * had left; a later connection from them is a new join. The default,
65
+ * `Infinity`, keeps seats until the player leaves or is removed, which is
66
+ * what a game played over days wants. A real-time room should set it, or
67
+ * closed tabs fill the room for good.
68
+ */
69
+ protected seatTimeoutMs: number;
70
+ /**
71
+ * How many frames a second one player may send, and also how many they may
72
+ * send in a single burst. Frames over the limit are refused with
73
+ * `rate_limited` and never reach `parseCommand`. `Infinity` turns it off.
74
+ */
75
+ protected maxCommandsPerSecond: number;
76
+ /**
77
+ * Where `finishMatch` announces a finished match. Set it to a Queue binding:
78
+ * `protected override matchQueue = this.env.MATCHES;`
79
+ */
80
+ protected matchQueue: Queue<MatchResult> | undefined;
81
+ /**
82
+ * Where `finishMatch` stores the replay it is given, if any. Set it to an R2
83
+ * binding: `protected override matchBucket = this.env.REPLAYS;`
84
+ */
85
+ protected matchBucket: R2Bucket | undefined;
86
+ /**
87
+ * Where the other rooms are, for `movePlayer` and `signal`: the Durable
88
+ * Object namespace they live in, usually this room's own.
89
+ * `protected override rooms = this.env.ROOMS;`
90
+ */
91
+ protected rooms: RoomNamespace | undefined;
92
+ /** Simulation rate in ticks per second. 0, the default, is event mode: no tick loop. */
93
+ protected tickRate: number;
94
+ /**
95
+ * While the room is ticking, how often the state is written to storage, in
96
+ * milliseconds. It is also written whenever the simulation stops. A room
97
+ * that is torn down mid-simulation (a deploy, a crash) resumes from the
98
+ * last write.
99
+ */
100
+ protected saveIntervalMs: number;
101
+ /**
102
+ * While the room is ticking, how long a connection may send nothing, not
103
+ * a command and not a keepalive, before it is taken for dead and closed
104
+ * with `CloseCode.Silent`. The player is then away, as after any other
105
+ * drop: `onDisconnect` runs and their seat timeout starts.
106
+ *
107
+ * A room ticks for as long as someone is connected, and is billed for it.
108
+ * A connection whose other end is gone without the room being told would
109
+ * keep it awake for nobody, and this is what ends that. Tickflare's
110
+ * clients send a keepalive every 25 seconds, so the default of two
111
+ * minutes never closes one that is there; a client of your own has to
112
+ * send `ping` at least this often. 0 never closes a connection for
113
+ * silence. A room that is not ticking never does either: it is asleep.
114
+ */
115
+ protected silentAfterMs: number;
116
+ /**
117
+ * Whether the kernel follows what each hook writes to the state, rather
118
+ * than turning the whole state into JSON after every hook to see what
119
+ * changed and to be able to undo it. On by default: a hook then costs what
120
+ * it touches, not what the state weighs.
121
+ *
122
+ * It means that inside a hook other than `onTick`, `this.state` and
123
+ * everything reached through it are proxies of the state's objects. They
124
+ * read and write like the objects themselves, with two exceptions: a proxy
125
+ * is not `===` to an object that did not come from the state, and
126
+ * `structuredClone` refuses one. `plain(value)` gives the object underneath
127
+ * for those. Reach the state through `this.state` in every hook, rather
128
+ * than through a reference kept from an earlier one: a change made through
129
+ * such a reference is not seen until the next tick or save, and is not
130
+ * undone if the hook is refused.
131
+ *
132
+ * Set to false to have every hook work on the plain state, at the old cost.
133
+ */
134
+ protected trackChanges: boolean;
135
+ /**
136
+ * The authoritative state. Change it only inside hooks, through
137
+ * `this.state`: see `trackChanges` for what a hook is handed.
138
+ */
139
+ protected get state(): State;
140
+ /** Replaces the whole state. Like any other change, only inside hooks. */
141
+ protected set state(value: State);
142
+ constructor(ctx: DurableObjectState, env: Env);
143
+ /** The state of a brand new room. */
144
+ protected abstract initialState(): State;
145
+ /**
146
+ * Turn an untrusted client payload into a command. Check everything here:
147
+ * `raw` is whatever the client sent. Throwing refuses the command.
148
+ */
149
+ protected abstract parseCommand(raw: unknown): Command;
150
+ /** Apply a command. Call `reject()` to refuse it. */
151
+ protected abstract onCommand(player: Player, command: Command): void;
152
+ /** A player takes a seat for the first time. Call `reject()` to turn them away. */
153
+ protected onJoin(_player: Player): void;
154
+ /** A seated player's last connection closed. They keep their seat. */
155
+ protected onDisconnect(_player: Player): void;
156
+ /** A seated player connected again after being fully disconnected. */
157
+ protected onReconnect(_player: Player): void;
158
+ /**
159
+ * A player is giving up their seat: they asked to leave, or they stayed
160
+ * disconnected for longer than `seatTimeoutMs`. Tidy up after them here;
161
+ * they are removed when this returns. Call `reject()` to make them stay.
162
+ */
163
+ protected onLeave(_player: Player): void;
164
+ /**
165
+ * The last seat was given up: nobody is in the room any more, whichever way
166
+ * they went (they left, stayed away too long, were removed, or moved to
167
+ * another room). `this.players` is empty. Nothing ends a room by itself, so
168
+ * this is where to say what becomes of it: `deleteRoom()`, a timer that
169
+ * deletes it unless somebody comes back, or nothing, for a room that waits
170
+ * for its next players. Not called for a room nobody ever sat in.
171
+ *
172
+ * It runs as a hook of its own, straight after the one that emptied the
173
+ * room. If it fails it alone is undone: the players are still gone.
174
+ */
175
+ protected onEmpty(): void;
176
+ /** A timer set with `setTimer(name, ...)` ran out. */
177
+ protected onTimer(_name: string): void;
178
+ /**
179
+ * Advance the simulation by one step of `dt` seconds (always `1 / tickRate`).
180
+ * Runs `tickRate` times a second while the room is ticking.
181
+ */
182
+ protected onTick(_dt: number): void;
183
+ /**
184
+ * Whether the simulation should be running. Checked after every event and
185
+ * every tick, so base it on the state, e.g. `this.state.phase === "playing"`.
186
+ * While it returns false the room behaves as in event mode and can
187
+ * hibernate. The room does not tick while nobody is connected, unless
188
+ * `ticksWhileEmpty()` says so.
189
+ */
190
+ protected shouldTick(): boolean;
191
+ /**
192
+ * Whether the simulation keeps running while nobody is connected, for a
193
+ * match that has to reach its end whoever is watching. `shouldTick()` has
194
+ * to agree. Checked like `shouldTick()`, so base it on the state.
195
+ *
196
+ * Give such a room an end. It is awake, and billed, for every second it
197
+ * ticks, and nobody is there to notice one that never stops: have `onTick`
198
+ * finish or delete the room when the match is over or has run too long.
199
+ * After a deploy or a crash it carries on from its last save within
200
+ * twenty seconds.
201
+ */
202
+ protected ticksWhileEmpty(): boolean;
203
+ /**
204
+ * A plain HTTP request for this room, sent to `{prefix}/{roomId}/...` and
205
+ * already authenticated by the gateway. For reading from the room, e.g. a
206
+ * replay or a scoreboard: changes made to the state here are not saved or
207
+ * sent to anyone.
208
+ */
209
+ protected onHttp(_request: Request, _player: Player): Response | Promise<Response>;
210
+ /** What `player` is allowed to see. Defaults to the whole state. */
211
+ protected view(_player: Player): unknown;
212
+ /** Everyone with a seat, in join order. */
213
+ protected get players(): Player[];
214
+ /** Number of state changes so far. */
215
+ protected get seq(): number;
216
+ /** Number of ticks run so far. */
217
+ protected get tick(): number;
218
+ /** The id this room is reached under, once someone has connected through the gateway. */
219
+ protected get roomId(): string | null;
220
+ /**
221
+ * The players a matchmaker reserved this room for, or null if it was not
222
+ * reserved. Only they can take a seat (players handed over from another
223
+ * room aside), so a match can start once all of them have joined.
224
+ */
225
+ protected get invited(): readonly string[] | null;
226
+ /**
227
+ * The sides the matchmaker split the invited players into, each a list of
228
+ * player ids, or null if it did not: see `Matchmaker.teams`.
229
+ */
230
+ protected get teams(): readonly (readonly string[])[] | null;
231
+ /**
232
+ * Have what the current hook changes written to storage as soon as the hook
233
+ * returns, instead of at the next save interval. Only matters while the
234
+ * room is ticking; outside the simulation every change is written at once.
235
+ * Use it when the hook also writes to the room's database itself, so the
236
+ * two cannot come apart. Call from inside a hook.
237
+ */
238
+ protected saveNow(): void;
239
+ /**
240
+ * Announce that a match is over. `result` is yours to define (winner,
241
+ * scores, ...). It is put on `matchQueue` together with the room id and the
242
+ * players, for a queue consumer such as `recordMatches` to store. Pass a
243
+ * `replay` to have it written to `matchBucket` first; the message then
244
+ * carries its key. Call from inside a hook.
245
+ *
246
+ * The announcement is saved with the room and sent after the hook has
247
+ * committed. If sending fails it is tried again on the room's next event.
248
+ */
249
+ protected finishMatch(result?: Record<string, unknown>, replay?: unknown): void;
250
+ /**
251
+ * Hand a player over to another room, for worlds that are split across
252
+ * rooms. Their seat here is given up; once the other room has accepted
253
+ * them, their connection is closed with `CloseCode.Moved` and the client
254
+ * reconnects there by itself. `carry` (JSON) is delivered to the other
255
+ * room's `onArrive`: put in it whatever the player takes along. Remove
256
+ * their part of this room's state yourself. Call from inside a hook, and
257
+ * set `rooms`.
258
+ *
259
+ * A player who is not connected at that moment is sent on when they next
260
+ * connect here.
261
+ */
262
+ protected movePlayer(playerId: string, toRoomId: string, carry?: unknown): void;
263
+ /**
264
+ * Deliver a player to another room, through `roomsFor`. If it throws, the
265
+ * handover is tried again on this room's next event.
266
+ */
267
+ protected handOver(roomId: string, playerId: string, carry: unknown): Promise<void>;
268
+ /**
269
+ * A player handed over by another room takes their seat. `carry` is what
270
+ * that room passed to `movePlayer`. Defaults to treating them as a new
271
+ * player.
272
+ */
273
+ protected onArrive(player: Player, _carry: unknown): void;
274
+ /**
275
+ * Send a message to one player, outside the state: an event they should
276
+ * hear about once ("you were hit", a result with more in it than an ack),
277
+ * or a stream you keep in step yourself. The client receives it in
278
+ * `onMessage`.
279
+ *
280
+ * Messages go out when the event that sent them is over, in the order they
281
+ * were sent: after the state frame that event caused, or in a ticking room
282
+ * after the tick's patch. A message sent while handling a command can so
283
+ * arrive before the next tick shows the command's effect. A message to a
284
+ * player who is not connected is dropped, and so is everything a hook sent
285
+ * if that hook is refused. Unlike the state, nothing is sent again on
286
+ * reconnect: send what a returning player needs from `onReconnect`.
287
+ */
288
+ protected send(playerId: string, message: unknown): void;
289
+ /** `send` to every player who is connected. */
290
+ protected broadcast(message: unknown): void;
291
+ /**
292
+ * Run `task` once this event is over, outside the hook: for talking to the
293
+ * world, which hooks cannot do because they are synchronous. Writing to
294
+ * D1, calling another Durable Object, `fetch`. Dropped if the hook is
295
+ * refused. Not awaited by anything and not retried: failures are logged.
296
+ * To change the state with what comes back, use `act`; to be sure it gets
297
+ * done across restarts, keep what is owed in the state and a timer that
298
+ * tries again.
299
+ */
300
+ protected defer(task: () => unknown): void;
301
+ /**
302
+ * Run `hook` like any other hook, from code that is not one: the end of a
303
+ * deferred task, a promise that resolved, an RPC method of your own. Its
304
+ * changes are committed and sent, or all taken back if it throws or calls
305
+ * `reject()`, which is what the returned outcome reports.
306
+ */
307
+ protected act(hook: () => void): Promise<ActOutcome>;
308
+ /**
309
+ * Send a message to another room, which receives it in `onSignal`. It goes
310
+ * out once after this hook has committed. It is not saved and not retried:
311
+ * use it for things that are replaced by the next one anyway, such as a
312
+ * snapshot of what is near a border. Call from inside a hook, and set
313
+ * `rooms`.
314
+ *
315
+ * With `onlyIfWatched`, a room that reports nobody connected is left alone
316
+ * for two seconds at a time, so an empty neighbour is not kept awake.
317
+ */
318
+ protected signal(roomId: string, data: unknown, options?: {
319
+ onlyIfWatched?: boolean;
320
+ }): void;
321
+ /**
322
+ * Deliver a signal to another room, through `roomsFor`, resolving to
323
+ * whether anyone is connected there.
324
+ */
325
+ protected relay(roomId: string, data: unknown): Promise<boolean>;
326
+ /** Another room sent this one a message with `signal`. */
327
+ protected onSignal(_fromRoomId: string, _data: unknown): void;
328
+ /**
329
+ * How rooms and matchmakers reach each other over RPC: handing a player
330
+ * over, delivering a signal, reserving a room for a match. Reserved for
331
+ * Tickflare: don't call it, and don't name a method of your own `tickflare`.
332
+ * @internal
333
+ */
334
+ tickflare(call: RoomCall): Promise<unknown>;
335
+ /**
336
+ * The namespace the room called `roomId` lives in. Defaults to `rooms`.
337
+ * Override it when handovers and signals go to rooms of more than one
338
+ * class, e.g. by the id's prefix.
339
+ */
340
+ protected roomsFor(_roomId: string): RoomNamespace | undefined;
341
+ /**
342
+ * Run `onTimer(name)` once, `delayMs` from now. A timer with the same name
343
+ * is replaced. Returns the time it fires in epoch milliseconds, which you
344
+ * can put in the state to show a countdown. Call from inside a hook.
345
+ *
346
+ * Timers are saved with the room, so they survive hibernation and restarts.
347
+ */
348
+ protected setTimer(name: string, delayMs: number): number;
349
+ /**
350
+ * End this room for good. Shortly after the current event, everyone still
351
+ * connected is disconnected with `CloseCode.Removed` and the reason
352
+ * `"room_deleted"`, and everything the room stored is deleted: its state,
353
+ * seats and timers, a lockstep recording, and any tables of your own. With
354
+ * nothing stored the Durable Object itself ceases to exist.
355
+ *
356
+ * What the room still owes is delivered first: a finished match's result,
357
+ * a player on their way to another room. Until it is, the room stays.
358
+ * Work passed to `defer()` that is still running is given ten seconds to
359
+ * finish.
360
+ *
361
+ * The room id is not used up. Someone who comes to it later finds a new,
362
+ * empty room. Call from inside a hook.
363
+ */
364
+ protected deleteRoom(): void;
365
+ /** Cancel a timer. Does nothing if it is not set. Call from inside a hook. */
366
+ protected clearTimer(name: string): void;
367
+ /**
368
+ * Take a player's seat away and close their connection with
369
+ * `CloseCode.Removed` and `reason`. `onLeave` is not called: clean up their
370
+ * part of the state yourself. Call from inside a hook.
371
+ */
372
+ protected removePlayer(playerId: string, reason?: string): void;
373
+ /** Durable Object entry point for connections and HTTP requests from the gateway. Tickflare's: override `onHttp` instead. */
374
+ fetch(request: Request): Promise<Response>;
375
+ /** Durable Object entry point for incoming frames. Tickflare's: override `parseCommand` and `onCommand` instead. */
376
+ webSocketMessage(ws: WebSocket, message: string | ArrayBuffer): Promise<void>;
377
+ /** Durable Object entry point for closed connections. Tickflare's: override `onDisconnect` instead. */
378
+ webSocketClose(ws: WebSocket, code: number, reason: string): Promise<void>;
379
+ /** Durable Object entry point for broken connections. Tickflare's: override `onDisconnect` instead. */
380
+ webSocketError(ws: WebSocket): Promise<void>;
381
+ /** Durable Object entry point for the alarm that drives timers and retries. Tickflare's: override `onTimer` instead. */
382
+ alarm(): Promise<void>;
383
+ }