tickflare 0.1.0 → 0.3.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.
- package/CHANGELOG.md +18 -0
- package/README.md +5 -2
- package/dist/client/buffered.d.ts +108 -0
- package/dist/client/buffered.js +252 -0
- package/dist/client/buffered.js.map +1 -0
- package/dist/client/clock.d.ts +36 -0
- package/dist/client/clock.js +83 -0
- package/dist/client/clock.js.map +1 -0
- package/dist/client/index.d.ts +83 -5
- package/dist/client/index.js +254 -15
- package/dist/client/index.js.map +1 -1
- package/dist/client/interpolate.d.ts +6 -5
- package/dist/client/interpolate.js +6 -5
- package/dist/client/interpolate.js.map +1 -1
- package/dist/client/lockstep.d.ts +23 -4
- package/dist/client/lockstep.js +47 -4
- package/dist/client/lockstep.js.map +1 -1
- package/dist/client/predict.js +16 -3
- package/dist/client/predict.js.map +1 -1
- package/dist/lockstep.d.ts +43 -4
- package/dist/lockstep.js +33 -0
- package/dist/lockstep.js.map +1 -1
- package/dist/protocol.d.ts +131 -5
- package/dist/protocol.js +16 -3
- package/dist/protocol.js.map +1 -1
- package/dist/server/gateway.d.ts +5 -0
- package/dist/server/gateway.js +14 -0
- package/dist/server/gateway.js.map +1 -1
- package/dist/server/index.d.ts +4 -3
- package/dist/server/index.js +3 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/lockstep.d.ts +30 -4
- package/dist/server/lockstep.js +78 -6
- package/dist/server/lockstep.js.map +1 -1
- package/dist/server/room.d.ts +138 -2
- package/dist/server/room.js +701 -44
- package/dist/server/room.js.map +1 -1
- package/dist/server/schema.d.ts +67 -0
- package/dist/server/schema.js +44 -0
- package/dist/server/schema.js.map +1 -0
- package/dist/server/spectators.d.ts +74 -0
- package/dist/server/spectators.js +190 -0
- package/dist/server/spectators.js.map +1 -0
- package/dist/server/storage.d.ts +13 -1
- package/dist/server/storage.js +23 -5
- package/dist/server/storage.js.map +1 -1
- package/package.json +1 -1
- package/src/client/buffered.ts +294 -0
- package/src/client/clock.ts +86 -0
- package/src/client/index.ts +296 -15
- package/src/client/interpolate.ts +6 -5
- package/src/client/lockstep.ts +68 -7
- package/src/client/predict.ts +16 -3
- package/src/lockstep.ts +67 -4
- package/src/protocol.ts +134 -4
- package/src/server/gateway.ts +14 -0
- package/src/server/index.ts +7 -0
- package/src/server/lockstep.ts +77 -7
- package/src/server/room.ts +735 -45
- package/src/server/schema.ts +101 -0
- package/src/server/spectators.ts +221 -0
- package/src/server/storage.ts +33 -6
package/dist/protocol.d.ts
CHANGED
|
@@ -16,8 +16,17 @@ import type { Patch } from "./patch.js";
|
|
|
16
16
|
*
|
|
17
17
|
* Version 3 adds presence as changes: a `presence` frame can say who is new
|
|
18
18
|
* or different (`set`) and who is gone (`gone`) in place of the whole list.
|
|
19
|
+
*
|
|
20
|
+
* Version 4 adds the room's clock: while the simulation runs, `welcome`
|
|
21
|
+
* says where the clock is (`ms` and `epoch`), and `clock` frames say it
|
|
22
|
+
* again every few seconds, whenever it starts, stops or moves on.
|
|
23
|
+
*
|
|
24
|
+
* Version 5 adds commands that outlive a connection: a client that names
|
|
25
|
+
* itself with `client` in the query is told in `welcome` which of its
|
|
26
|
+
* commands the room has handled (`c`, `from` and `refused`), so that it can
|
|
27
|
+
* send the others again, and the room applies none of them twice.
|
|
19
28
|
*/
|
|
20
|
-
export declare const PROTOCOL_VERSION =
|
|
29
|
+
export declare const PROTOCOL_VERSION = 5;
|
|
21
30
|
/** The keepalive a client sends, as a plain text frame. @internal */
|
|
22
31
|
export declare const PING = "ping";
|
|
23
32
|
/** The runtime's answer to `PING`, sent without waking the room. @internal */
|
|
@@ -40,7 +49,13 @@ export interface Player {
|
|
|
40
49
|
export interface CommandFrame<Command = unknown> {
|
|
41
50
|
/** Frame type. */
|
|
42
51
|
t: "cmd";
|
|
43
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Chosen by the client and echoed in the answer. Unique per connection; a
|
|
54
|
+
* client that names itself (`client` in the query, version 5) numbers its
|
|
55
|
+
* commands and leaves 1, 2, 3 and so on for as long as it lives, across
|
|
56
|
+
* connections, and the room takes one whose `id` is not above the latest it
|
|
57
|
+
* has handled for a command it has seen before.
|
|
58
|
+
*/
|
|
44
59
|
id: number;
|
|
45
60
|
/** The command, as the room's `parseCommand` will receive it. */
|
|
46
61
|
data: Command;
|
|
@@ -68,11 +83,88 @@ export interface WelcomeFrame<View = unknown> {
|
|
|
68
83
|
tick: number;
|
|
69
84
|
/** Ticks a second; 0 in event mode. */
|
|
70
85
|
tickRate: number;
|
|
86
|
+
/**
|
|
87
|
+
* How many times a second the room sends what changed while it ticks, when
|
|
88
|
+
* that is less often than it ticks: see `Room.patchRate`. Absent from a
|
|
89
|
+
* room that sends after every tick. Sent whatever version the client asked
|
|
90
|
+
* for: one that does not know it loses nothing but the hint.
|
|
91
|
+
*/
|
|
92
|
+
patchRate?: number;
|
|
93
|
+
/** Version 4, while the simulation runs: as in `ClockFrame`. Absent while it does not. */
|
|
94
|
+
ms?: number;
|
|
95
|
+
/** Version 4, while the simulation runs: as in `ClockFrame`. */
|
|
96
|
+
epoch?: number;
|
|
97
|
+
/**
|
|
98
|
+
* Version 5, to a client that named itself and that the room knows, on a
|
|
99
|
+
* new connection to a seat the player already had: the `id` of the latest
|
|
100
|
+
* command or leave of that client's the room has handled, applied or
|
|
101
|
+
* refused, or 0 for none. `state` shows every one of them that was
|
|
102
|
+
* applied. What the client sent after it never arrived, or was lost when
|
|
103
|
+
* the room went back to its last save: the client sends those again, in
|
|
104
|
+
* order, before anything new.
|
|
105
|
+
*
|
|
106
|
+
* Absent when the room knows nothing of what the client sent before, and
|
|
107
|
+
* the client gives up waiting for it: the seat is newly taken, the room
|
|
108
|
+
* last heard from another client of the same player, the room does not
|
|
109
|
+
* remember commands, or the `welcome` is one sent on a connection that was
|
|
110
|
+
* open already.
|
|
111
|
+
*/
|
|
112
|
+
c?: number;
|
|
113
|
+
/**
|
|
114
|
+
* With `c`, when the room cannot say what became of the client's earliest
|
|
115
|
+
* commands: it can say of those after this `id`, up to `c`, and not of
|
|
116
|
+
* those up to it. A command the client is still waiting to hear about, and
|
|
117
|
+
* whose `id` is not above this, is given up as one whose outcome is not
|
|
118
|
+
* known. Absent when the room can say of every command up to `c`, which is
|
|
119
|
+
* nearly always: see the protocol reference for when it cannot.
|
|
120
|
+
*/
|
|
121
|
+
from?: number;
|
|
122
|
+
/**
|
|
123
|
+
* With `c`: the latest of those commands that were refused, oldest first,
|
|
124
|
+
* each with the reason its `reject` frame gave, cut to 120 characters.
|
|
125
|
+
* Every other command after `from` and up to `c` was applied. The room
|
|
126
|
+
* remembers the last eight refusals of a client, and leaves this out when
|
|
127
|
+
* there are none.
|
|
128
|
+
*/
|
|
129
|
+
refused?: [id: number, reason: string][];
|
|
71
130
|
/** This player's whole view. */
|
|
72
131
|
state: View;
|
|
73
132
|
/** Everyone with a seat, in join order. */
|
|
74
133
|
players: Player[];
|
|
75
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* First frame on the connection of a spectator, who asked to watch with
|
|
137
|
+
* `spectate=1`, in place of a `welcome`. It says who they are and how the
|
|
138
|
+
* room runs, and nothing of the game: the spectators' view follows in a
|
|
139
|
+
* `state` frame, at once if other spectators have it already, and when its
|
|
140
|
+
* time has come if the room delays its spectators and this is the first to
|
|
141
|
+
* watch. After that the connection carries that view kept up to date with
|
|
142
|
+
* `state` and `patch` frames, who is here as whole `presence` lists, and
|
|
143
|
+
* what the room broadcasts as `msg` frames, each as long after the players
|
|
144
|
+
* were sent it as `delay` says.
|
|
145
|
+
*
|
|
146
|
+
* A spectator has no seat. Anything they send with an `id` is answered with
|
|
147
|
+
* a `reject` whose reason is `spectator`.
|
|
148
|
+
*/
|
|
149
|
+
export interface SpectatingFrame {
|
|
150
|
+
/** Frame type. */
|
|
151
|
+
t: "spectating";
|
|
152
|
+
/** The version of the protocol the room speaks on this connection. */
|
|
153
|
+
v: number;
|
|
154
|
+
/** The spectator's id. They are not among `players`. */
|
|
155
|
+
you: string;
|
|
156
|
+
/** Ticks a second; 0 in event mode. */
|
|
157
|
+
tickRate: number;
|
|
158
|
+
/** As in `WelcomeFrame`. */
|
|
159
|
+
patchRate?: number;
|
|
160
|
+
/** How far behind the room everything on this connection is, in milliseconds. 0 for not at all. */
|
|
161
|
+
delay: number;
|
|
162
|
+
/**
|
|
163
|
+
* Everyone with a seat, as the spectators have last been told. Empty for
|
|
164
|
+
* the first to watch: a `presence` frame follows with the view.
|
|
165
|
+
*/
|
|
166
|
+
players: Player[];
|
|
167
|
+
}
|
|
76
168
|
/**
|
|
77
169
|
* The state changed, and this is the player's whole view: sent when the room
|
|
78
170
|
* does not know what the player holds, or when the view is not an object and
|
|
@@ -150,6 +242,36 @@ export interface AckFrame {
|
|
|
150
242
|
/** In a room that is ticking: the tick the view is now of, whether or not a frame was sent for it. */
|
|
151
243
|
tick?: number;
|
|
152
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Version 4: where the room's clock is. Ticks fall due on a fixed clock, one
|
|
247
|
+
* every `1 / tickRate` seconds from when the simulation started, so a client
|
|
248
|
+
* that knows how long ago one tick was due can tell which tick the room is on
|
|
249
|
+
* at any moment: `tick + (ms + elapsed) * tickRate / 1000`, where `elapsed`
|
|
250
|
+
* is the time since the frame was sent, about half a round trip when it
|
|
251
|
+
* arrives. `RoomClient.serverTick()` works this out.
|
|
252
|
+
*
|
|
253
|
+
* Sent every five seconds while the simulation runs, and at once when it
|
|
254
|
+
* starts, stops, or lets ticks go after a stall. The same reading is in
|
|
255
|
+
* `welcome` for a client that connects while it runs.
|
|
256
|
+
*/
|
|
257
|
+
export interface ClockFrame {
|
|
258
|
+
/** Frame type. */
|
|
259
|
+
t: "clock";
|
|
260
|
+
/** The latest tick the room has run. */
|
|
261
|
+
tick: number;
|
|
262
|
+
/**
|
|
263
|
+
* How long before this frame was sent `tick` fell due, in milliseconds:
|
|
264
|
+
* usually less than one tick, more when the room is running late. Absent
|
|
265
|
+
* when the simulation has stopped, at `tick`, until a frame says otherwise.
|
|
266
|
+
*/
|
|
267
|
+
ms?: number;
|
|
268
|
+
/**
|
|
269
|
+
* Which run of the clock this is. It changes when the simulation starts
|
|
270
|
+
* again, and when the room lets ticks go after a stall; while it stays the
|
|
271
|
+
* same, readings can be averaged.
|
|
272
|
+
*/
|
|
273
|
+
epoch?: number;
|
|
274
|
+
}
|
|
153
275
|
/** The command or leave with this `id` was refused, and nothing changed. */
|
|
154
276
|
export interface RejectFrame {
|
|
155
277
|
/** Frame type. */
|
|
@@ -177,14 +299,18 @@ export interface MessageFrame {
|
|
|
177
299
|
d: unknown;
|
|
178
300
|
}
|
|
179
301
|
/** Every frame a room sends, apart from the `pong` keepalive. */
|
|
180
|
-
export type ServerMessage<View = unknown> = WelcomeFrame<View> | StateFrame<View> | PatchFrame | PresenceFrame | AckFrame | RejectFrame | ErrorFrame | MessageFrame;
|
|
302
|
+
export type ServerMessage<View = unknown> = WelcomeFrame<View> | SpectatingFrame | StateFrame<View> | PatchFrame | PresenceFrame | ClockFrame | AckFrame | RejectFrame | ErrorFrame | MessageFrame;
|
|
181
303
|
/** WebSocket close codes the room uses. The client does not reconnect after those from 4000 to 4099. */
|
|
182
304
|
export declare const CloseCode: {
|
|
183
305
|
/** The same player opened a newer connection. */
|
|
184
306
|
readonly Replaced: 4000;
|
|
185
|
-
/** Every seat is taken. */
|
|
307
|
+
/** Every seat is taken. For a spectator, with the reason `spectators_full`: as many are watching as may. */
|
|
186
308
|
readonly RoomFull: 4001;
|
|
187
|
-
/**
|
|
309
|
+
/**
|
|
310
|
+
* `onJoin` refused the player; the close reason carries why. For a
|
|
311
|
+
* spectator it is `onSpectate` that refused, or the reason is
|
|
312
|
+
* `no_spectators`: the room takes none.
|
|
313
|
+
*/
|
|
188
314
|
readonly JoinRejected: 4002;
|
|
189
315
|
/** The player no longer has a seat: they left, or the room removed them. The close reason says which. */
|
|
190
316
|
readonly Removed: 4003;
|
package/dist/protocol.js
CHANGED
|
@@ -15,8 +15,17 @@
|
|
|
15
15
|
*
|
|
16
16
|
* Version 3 adds presence as changes: a `presence` frame can say who is new
|
|
17
17
|
* or different (`set`) and who is gone (`gone`) in place of the whole list.
|
|
18
|
+
*
|
|
19
|
+
* Version 4 adds the room's clock: while the simulation runs, `welcome`
|
|
20
|
+
* says where the clock is (`ms` and `epoch`), and `clock` frames say it
|
|
21
|
+
* again every few seconds, whenever it starts, stops or moves on.
|
|
22
|
+
*
|
|
23
|
+
* Version 5 adds commands that outlive a connection: a client that names
|
|
24
|
+
* itself with `client` in the query is told in `welcome` which of its
|
|
25
|
+
* commands the room has handled (`c`, `from` and `refused`), so that it can
|
|
26
|
+
* send the others again, and the room applies none of them twice.
|
|
18
27
|
*/
|
|
19
|
-
export const PROTOCOL_VERSION =
|
|
28
|
+
export const PROTOCOL_VERSION = 5;
|
|
20
29
|
/** The keepalive a client sends, as a plain text frame. @internal */
|
|
21
30
|
export const PING = "ping";
|
|
22
31
|
/** The runtime's answer to `PING`, sent without waking the room. @internal */
|
|
@@ -25,9 +34,13 @@ export const PONG = "pong";
|
|
|
25
34
|
export const CloseCode = {
|
|
26
35
|
/** The same player opened a newer connection. */
|
|
27
36
|
Replaced: 4000,
|
|
28
|
-
/** Every seat is taken. */
|
|
37
|
+
/** Every seat is taken. For a spectator, with the reason `spectators_full`: as many are watching as may. */
|
|
29
38
|
RoomFull: 4001,
|
|
30
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* `onJoin` refused the player; the close reason carries why. For a
|
|
41
|
+
* spectator it is `onSpectate` that refused, or the reason is
|
|
42
|
+
* `no_spectators`: the room takes none.
|
|
43
|
+
*/
|
|
31
44
|
JoinRejected: 4002,
|
|
32
45
|
/** The player no longer has a seat: they left, or the room removed them. The close reason says which. */
|
|
33
46
|
Removed: 4003,
|
package/dist/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,qEAAqE;AACrE,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC;AAC3B,8EAA8E;AAC9E,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC;AAwS3B,wGAAwG;AACxG,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,iDAAiD;IACjD,QAAQ,EAAE,IAAI;IACd,4GAA4G;IAC5G,QAAQ,EAAE,IAAI;IACd;;;;OAIG;IACH,YAAY,EAAE,IAAI;IAClB,yGAAyG;IACzG,OAAO,EAAE,IAAI;IACb;;;OAGG;IACH,KAAK,EAAE,IAAI;IACX;;;;OAIG;IACH,MAAM,EAAE,IAAI;CACJ,CAAC;AA8BX,iFAAiF;AACjF,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,IAAI,IAAI,IAAI,IAAI,IAAI,GAAG,IAAI,CAAC;AACrC,CAAC"}
|
package/dist/server/gateway.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { Party } from "./tokens.js";
|
|
2
2
|
/** Header the gateway uses to tell a room who is connecting. Never trusted from the client. */
|
|
3
3
|
export declare const PLAYER_HEADER = "x-tickflare-player";
|
|
4
|
+
/**
|
|
5
|
+
* Header the gateway uses to tell a room who asks to watch it, in place of
|
|
6
|
+
* `PLAYER_HEADER`: see `routeToRoom`. Never trusted from the client.
|
|
7
|
+
*/
|
|
8
|
+
export declare const SPECTATOR_HEADER = "x-tickflare-spectator";
|
|
4
9
|
/** Header the gateway uses to tell a room the id it is known by. */
|
|
5
10
|
export declare const ROOM_HEADER = "x-tickflare-room";
|
|
6
11
|
/** Header the gateway uses to tell a room the player's name, URI-encoded. Never trusted from the client. */
|
package/dist/server/gateway.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/** Header the gateway uses to tell a room who is connecting. Never trusted from the client. */
|
|
2
2
|
export const PLAYER_HEADER = "x-tickflare-player";
|
|
3
|
+
/**
|
|
4
|
+
* Header the gateway uses to tell a room who asks to watch it, in place of
|
|
5
|
+
* `PLAYER_HEADER`: see `routeToRoom`. Never trusted from the client.
|
|
6
|
+
*/
|
|
7
|
+
export const SPECTATOR_HEADER = "x-tickflare-spectator";
|
|
3
8
|
/** Header the gateway uses to tell a room the id it is known by. */
|
|
4
9
|
export const ROOM_HEADER = "x-tickflare-room";
|
|
5
10
|
/** Header the gateway uses to tell a room the player's name, URI-encoded. Never trusted from the client. */
|
|
@@ -42,6 +47,14 @@ export async function routeToRoom(request, options) {
|
|
|
42
47
|
return identity;
|
|
43
48
|
const headers = identityHeaders(request, identity);
|
|
44
49
|
headers.set(ROOM_HEADER, roomId);
|
|
50
|
+
if (upgrade && new URL(request.url).searchParams.get("spectate") === "1") {
|
|
51
|
+
// Someone who asks to watch is named under a header of their own. Cloudflare can leave a
|
|
52
|
+
// busy room on older code for minutes after the Worker in front of it has the new: a room
|
|
53
|
+
// from before there were spectators knows only the player's header, and would seat whoever
|
|
54
|
+
// it names. Without it, such a room turns the request away, and the client tries again.
|
|
55
|
+
headers.delete(PLAYER_HEADER);
|
|
56
|
+
headers.set(SPECTATOR_HEADER, identity.id);
|
|
57
|
+
}
|
|
45
58
|
const stub = options.rooms.get(options.rooms.idFromName(roomId));
|
|
46
59
|
return stub.fetch(new Request(request, { headers }));
|
|
47
60
|
}
|
|
@@ -77,6 +90,7 @@ function checkIdentity(identity) {
|
|
|
77
90
|
function identityHeaders(request, identity) {
|
|
78
91
|
const headers = new Headers(request.headers);
|
|
79
92
|
headers.set(PLAYER_HEADER, identity.id);
|
|
93
|
+
headers.delete(SPECTATOR_HEADER);
|
|
80
94
|
if (identity.name === undefined)
|
|
81
95
|
headers.delete(NAME_HEADER);
|
|
82
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O,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AACvD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,MAAM,EAAE,GAAI,OAA+D,CAAC,EAAE,CAAC;IAC/E,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;IACxC,QAAQ,EAAE,EAAE,SAAS,EAAE,CAAC;QACtB,KAAK,IAAI;YACP,OAAO,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;QAC5C,KAAK,IAAI;YACP,OAAO,KAAK,CAAC;QACf,KAAK,IAAI;YACP,OAAO,SAAS,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;QAC1C,KAAK,IAAI;YACP,OAAO,SAAS,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;QACxC,KAAK,IAAI;YACP,OAAO,IAAI,CAAC;QACd,KAAK,IAAI;YACP,OAAO,KAAK,CAAC;QACf;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -7,15 +7,16 @@
|
|
|
7
7
|
* @module tickflare
|
|
8
8
|
*/
|
|
9
9
|
export { Room, Rejection, reject, type ActOutcome } from "./room.js";
|
|
10
|
+
export { parseWith, type StandardSchemaIssue, type StandardSchemaResult, type StandardSchemaV1 } from "./schema.js";
|
|
10
11
|
export { plain } from "./tracked.js";
|
|
11
12
|
export { LockstepRoom, type LockstepCommand, type LockstepState } from "./lockstep.js";
|
|
12
|
-
export { fingerprint, runReplay, seededRandom, stepThrough, type CatchUp, type LockstepView, type TurnsMessage, type Replay, type SeededRandom, type Simulation, type Snapshot, type TurnEntry, } from "../lockstep.js";
|
|
13
|
+
export { differences, fingerprint, runReplay, seededRandom, stepThrough, type CatchUp, type Desync, type DesyncDifference, type LockstepView, type TurnsMessage, type Replay, type SeededRandom, type Simulation, type Snapshot, type TurnEntry, } from "../lockstep.js";
|
|
13
14
|
export { Matchmaker } from "./matchmaker.js";
|
|
14
15
|
export { createJoinToken, tokenAuth, verifyJoinToken, type JoinTokenClaims, type Party, type TokenAuthOptions, type VerifiedJoinToken, } from "./tokens.js";
|
|
15
16
|
export { cellOf, shardFor, type Cell } from "../world.js";
|
|
16
17
|
export { MATCHES_SCHEMA, recentMatches, recordMatches, type MatchRecord } from "./matches.js";
|
|
17
18
|
export { ACCOUNTS_SCHEMA, AccountError, Accounts, hashPassword, verifyPassword, type AccountsOptions, type DataPolicy, type Identity, type ImportedAccount, type LeaderboardEntry, type LeaderboardPage, type OwnAccount, type PasswordReset, type PublicProfile, } from "./accounts.js";
|
|
18
|
-
export { locationHintFor, routeToMatchmaker, routeToRoom, NAME_HEADER, PLAYER_HEADER, type Authenticated, type MatchmakerRouteOptions, type RoomNamespace, type RouteOptions, } from "./gateway.js";
|
|
19
|
+
export { locationHintFor, routeToMatchmaker, routeToRoom, NAME_HEADER, PLAYER_HEADER, SPECTATOR_HEADER, type Authenticated, type MatchmakerRouteOptions, type RoomNamespace, type RouteOptions, } from "./gateway.js";
|
|
19
20
|
export { applyPatch, diff, type ArrayPatch, type Patch } from "../patch.js";
|
|
20
21
|
export { decodePatchFrame } from "../binary.js";
|
|
21
|
-
export { CloseCode, PROTOCOL_VERSION, type AckFrame, type ClientMessage, type CommandFrame, type ErrorFrame, type LeaveFrame, type MatchFound, type MatchResult, type MessageFrame, type PatchFrame, type Player, type PresenceFrame, type RejectFrame, type ServerMessage, type StateFrame, type WelcomeFrame, } from "../protocol.js";
|
|
22
|
+
export { CloseCode, PROTOCOL_VERSION, type AckFrame, type ClockFrame, type ClientMessage, type CommandFrame, type ErrorFrame, type LeaveFrame, type MatchFound, type MatchResult, type MessageFrame, type PatchFrame, type Player, type PresenceFrame, type RejectFrame, type ServerMessage, type SpectatingFrame, type StateFrame, type WelcomeFrame, } from "../protocol.js";
|
package/dist/server/index.js
CHANGED
|
@@ -7,15 +7,16 @@
|
|
|
7
7
|
* @module tickflare
|
|
8
8
|
*/
|
|
9
9
|
export { Room, Rejection, reject } from "./room.js";
|
|
10
|
+
export { parseWith } from "./schema.js";
|
|
10
11
|
export { plain } from "./tracked.js";
|
|
11
12
|
export { LockstepRoom } from "./lockstep.js";
|
|
12
|
-
export { fingerprint, runReplay, seededRandom, stepThrough, } from "../lockstep.js";
|
|
13
|
+
export { differences, fingerprint, runReplay, seededRandom, stepThrough, } from "../lockstep.js";
|
|
13
14
|
export { Matchmaker } from "./matchmaker.js";
|
|
14
15
|
export { createJoinToken, tokenAuth, verifyJoinToken, } from "./tokens.js";
|
|
15
16
|
export { cellOf, shardFor } from "../world.js";
|
|
16
17
|
export { MATCHES_SCHEMA, recentMatches, recordMatches } from "./matches.js";
|
|
17
18
|
export { ACCOUNTS_SCHEMA, AccountError, Accounts, hashPassword, verifyPassword, } from "./accounts.js";
|
|
18
|
-
export { locationHintFor, routeToMatchmaker, routeToRoom, NAME_HEADER, PLAYER_HEADER, } from "./gateway.js";
|
|
19
|
+
export { locationHintFor, routeToMatchmaker, routeToRoom, NAME_HEADER, PLAYER_HEADER, SPECTATOR_HEADER, } from "./gateway.js";
|
|
19
20
|
export { applyPatch, diff } from "../patch.js";
|
|
20
21
|
export { decodePatchFrame } from "../binary.js";
|
|
21
22
|
export { CloseCode, PROTOCOL_VERSION, } from "../protocol.js";
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAmB,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,YAAY,EAA4C,MAAM,eAAe,CAAC;AACvF,OAAO,EACL,WAAW,EACX,SAAS,EACT,YAAY,EACZ,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAmB,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,SAAS,EAA8E,MAAM,aAAa,CAAC;AACpH,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,YAAY,EAA4C,MAAM,eAAe,CAAC;AACvF,OAAO,EACL,WAAW,EACX,WAAW,EACX,SAAS,EACT,YAAY,EACZ,WAAW,GAWZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,eAAe,EACf,SAAS,EACT,eAAe,GAKhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAa,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAoB,MAAM,cAAc,CAAC;AAC9F,OAAO,EACL,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,cAAc,GAUf,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,aAAa,EACb,gBAAgB,GAKjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,IAAI,EAA+B,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EACL,SAAS,EACT,gBAAgB,GAkBjB,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Desync, type DesyncDifference, type LockstepView, type Replay, type TurnEntry } from "../lockstep.js";
|
|
2
2
|
import type { Player } from "../protocol.js";
|
|
3
3
|
import { Room } from "./room.js";
|
|
4
4
|
/** What a lockstep room keeps: what clients see, and the inputs waiting for the next turn. */
|
|
@@ -52,6 +52,14 @@ export declare abstract class LockstepRoom<Input, Env = Cloudflare.Env> extends
|
|
|
52
52
|
protected tickRate: number;
|
|
53
53
|
/** Inputs one player may send within a single turn. More are refused. */
|
|
54
54
|
protected maxInputsPerTurn: number;
|
|
55
|
+
/**
|
|
56
|
+
* Off in a lockstep room. A turn is recorded as it closes and the room is
|
|
57
|
+
* saved less often, so after a restart the recording holds inputs that the
|
|
58
|
+
* room's own save knows nothing of: one that was sent again would be
|
|
59
|
+
* recorded twice. An input that was in flight when the connection dropped
|
|
60
|
+
* is answered with `disconnected`, as it always was.
|
|
61
|
+
*/
|
|
62
|
+
protected rememberCommands: boolean;
|
|
55
63
|
/**
|
|
56
64
|
* Who keeps time.
|
|
57
65
|
*
|
|
@@ -88,13 +96,29 @@ export declare abstract class LockstepRoom<Input, Env = Cloudflare.Env> extends
|
|
|
88
96
|
protected snapshotIntervalMs: number;
|
|
89
97
|
/** The longest snapshot the room keeps, in characters of JSON. A longer one is refused. */
|
|
90
98
|
protected maxSnapshotLength: number;
|
|
99
|
+
constructor(ctx: DurableObjectState, env: Env);
|
|
91
100
|
/**
|
|
92
101
|
* Turn an untrusted client payload into an input. Every client will feed
|
|
93
102
|
* what this returns to its simulation, so reject anything malformed here.
|
|
94
103
|
*/
|
|
95
104
|
protected abstract parseInput(raw: unknown): Input;
|
|
96
|
-
/**
|
|
97
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Two players reported different hashes for `turn`: their simulations have
|
|
107
|
+
* diverged. `players` are the two. Where they differ is not known yet: see
|
|
108
|
+
* `onDesyncExplained`.
|
|
109
|
+
*/
|
|
110
|
+
protected onDesync(_turn: number, _players: [string, string]): void;
|
|
111
|
+
/**
|
|
112
|
+
* Both players of a desync have sent what their simulations had saved at
|
|
113
|
+
* that turn, and the room has compared the two: `desync.differs` says
|
|
114
|
+
* where they differed. It is in the view too, so every client is told.
|
|
115
|
+
* The place to log it. Not called when a client had nothing to send: a
|
|
116
|
+
* simulation without `save`, or a player who was gone by then.
|
|
117
|
+
*/
|
|
118
|
+
protected onDesyncExplained(_desync: Desync & {
|
|
119
|
+
players: [string, string];
|
|
120
|
+
differs: DesyncDifference[];
|
|
121
|
+
}): void;
|
|
98
122
|
protected initialState(): LockstepState<Input>;
|
|
99
123
|
protected parseCommand(raw: unknown): LockstepCommand<Input>;
|
|
100
124
|
/** The room keeps time only when it is asked to: with players asking, it has no simulation to wake for. */
|
|
@@ -115,7 +139,9 @@ export declare abstract class LockstepRoom<Input, Env = Cloudflare.Env> extends
|
|
|
115
139
|
protected view(): LockstepView<Input>;
|
|
116
140
|
/**
|
|
117
141
|
* `GET …/replay` is the recording, or the end of it for a client that is
|
|
118
|
-
* catching up. `POST …/snapshot` is a player's client sending a snapshot
|
|
142
|
+
* catching up. `POST …/snapshot` is a player's client sending a snapshot,
|
|
143
|
+
* and `POST …/desync` one sending what it had saved at a turn two players
|
|
144
|
+
* disagreed on.
|
|
119
145
|
* If you override this, pass on what is not yours with `super.onHttp`.
|
|
120
146
|
*/
|
|
121
147
|
protected onHttp(request: Request, player: Player): Response | Promise<Response>;
|
package/dist/server/lockstep.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { differences } from "../lockstep.js";
|
|
2
|
+
import { Room, patchEachTick, reject } from "./room.js";
|
|
2
3
|
import { pieces } from "./storage.js";
|
|
3
4
|
/** How many turns' worth of reported hashes are kept for comparison. */
|
|
4
5
|
const HASHES_KEPT = 128;
|
|
@@ -34,6 +35,14 @@ export class LockstepRoom extends Room {
|
|
|
34
35
|
tickRate = 10;
|
|
35
36
|
/** Inputs one player may send within a single turn. More are refused. */
|
|
36
37
|
maxInputsPerTurn = 32;
|
|
38
|
+
/**
|
|
39
|
+
* Off in a lockstep room. A turn is recorded as it closes and the room is
|
|
40
|
+
* saved less often, so after a restart the recording holds inputs that the
|
|
41
|
+
* room's own save knows nothing of: one that was sent again would be
|
|
42
|
+
* recorded twice. An input that was in flight when the connection dropped
|
|
43
|
+
* is answered with `disconnected`, as it always was.
|
|
44
|
+
*/
|
|
45
|
+
rememberCommands = false;
|
|
37
46
|
/**
|
|
38
47
|
* Who keeps time.
|
|
39
48
|
*
|
|
@@ -87,12 +96,31 @@ export class LockstepRoom extends Room {
|
|
|
87
96
|
#hashes = new Map();
|
|
88
97
|
/** For the latest turns a snapshot could be of: the first hash reported, and everyone who reported that one. */
|
|
89
98
|
#vouched = new Map();
|
|
99
|
+
/** What the players of a desync have sent of their simulations at that turn, as JSON text, until both have. */
|
|
100
|
+
#explanations = new Map();
|
|
90
101
|
/** A snapshot that has arrived and waits for the other players to report its hash, and who sent it. */
|
|
91
102
|
#candidate;
|
|
92
103
|
/** Names this run of the room: see `CatchUp.epoch`. */
|
|
93
104
|
#epoch;
|
|
94
|
-
|
|
95
|
-
|
|
105
|
+
constructor(ctx, env) {
|
|
106
|
+
super(ctx, env);
|
|
107
|
+
// The view is one turn: when the room catches up on several, each still needs a frame of its own.
|
|
108
|
+
patchEachTick(this);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Two players reported different hashes for `turn`: their simulations have
|
|
112
|
+
* diverged. `players` are the two. Where they differ is not known yet: see
|
|
113
|
+
* `onDesyncExplained`.
|
|
114
|
+
*/
|
|
115
|
+
onDesync(_turn, _players) { }
|
|
116
|
+
/**
|
|
117
|
+
* Both players of a desync have sent what their simulations had saved at
|
|
118
|
+
* that turn, and the room has compared the two: `desync.differs` says
|
|
119
|
+
* where they differed. It is in the view too, so every client is told.
|
|
120
|
+
* The place to log it. Not called when a client had nothing to send: a
|
|
121
|
+
* simulation without `save`, or a player who was gone by then.
|
|
122
|
+
*/
|
|
123
|
+
onDesyncExplained(_desync) { }
|
|
96
124
|
initialState() {
|
|
97
125
|
const seed = crypto.getRandomValues(new Uint32Array(1))[0];
|
|
98
126
|
return { seed, turn: 0, entries: [], pending: [], desync: null };
|
|
@@ -247,9 +275,9 @@ export class LockstepRoom extends Room {
|
|
|
247
275
|
}
|
|
248
276
|
else if (first.by !== player.id && first.hash !== command.h && !this.state.desync) {
|
|
249
277
|
// It takes two players to disagree: one changing their mind proves nothing.
|
|
250
|
-
this.state.desync = { turn: command.n };
|
|
278
|
+
this.state.desync = { turn: command.n, players: [first.by, player.id] };
|
|
251
279
|
this.#candidate = undefined; // Nobody can say which simulation a snapshot should be of.
|
|
252
|
-
this.onDesync(command.n);
|
|
280
|
+
this.onDesync(command.n, [first.by, player.id]);
|
|
253
281
|
}
|
|
254
282
|
}
|
|
255
283
|
/** Turns between snapshots, or 0 when the room keeps none. */
|
|
@@ -422,6 +450,45 @@ export class LockstepRoom extends Room {
|
|
|
422
450
|
onReconnect(player) {
|
|
423
451
|
this.#event({ player: player.id, event: "reconnect" });
|
|
424
452
|
}
|
|
453
|
+
/**
|
|
454
|
+
* One of the two players of a desync sends what their simulation had saved
|
|
455
|
+
* at that turn. When both have, the room says where the two differ.
|
|
456
|
+
*/
|
|
457
|
+
async #explain(request, params, player) {
|
|
458
|
+
const waiting = () => {
|
|
459
|
+
const desync = this.state.desync;
|
|
460
|
+
return desync?.players?.includes(player.id) && desync.differs === undefined && Number(params.get("turn")) === desync.turn
|
|
461
|
+
? desync
|
|
462
|
+
: undefined;
|
|
463
|
+
};
|
|
464
|
+
// Checked before the body is read, and again after: the other player's may have settled it.
|
|
465
|
+
if (!waiting())
|
|
466
|
+
return new Response("Nothing this room is waiting for", { status: 409 });
|
|
467
|
+
const data = await textUpTo(request, this.maxSnapshotLength * 3);
|
|
468
|
+
if (data === undefined || data.length > this.maxSnapshotLength)
|
|
469
|
+
return new Response("Too long", { status: 413 });
|
|
470
|
+
try {
|
|
471
|
+
JSON.parse(data);
|
|
472
|
+
}
|
|
473
|
+
catch {
|
|
474
|
+
return new Response("Not JSON", { status: 400 });
|
|
475
|
+
}
|
|
476
|
+
const desync = waiting();
|
|
477
|
+
if (!desync)
|
|
478
|
+
return new Response("Nothing this room is waiting for", { status: 409 });
|
|
479
|
+
this.#explanations.set(player.id, data);
|
|
480
|
+
const [one, other] = desync.players.map((id) => this.#explanations.get(id));
|
|
481
|
+
if (one === undefined || other === undefined)
|
|
482
|
+
return new Response("Held until the other player's arrives", { status: 202 });
|
|
483
|
+
this.#explanations.clear();
|
|
484
|
+
const differs = differences(JSON.parse(one), JSON.parse(other));
|
|
485
|
+
await this.act(() => {
|
|
486
|
+
const explained = { ...desync, players: desync.players, differs };
|
|
487
|
+
this.state.desync = explained;
|
|
488
|
+
this.onDesyncExplained(explained);
|
|
489
|
+
});
|
|
490
|
+
return new Response("Compared", { status: 201 });
|
|
491
|
+
}
|
|
425
492
|
/**
|
|
426
493
|
* Closes the turn: whatever arrived since the last one becomes this turn's
|
|
427
494
|
* entries. A turn with something in it is one row in the recording, written
|
|
@@ -459,7 +526,9 @@ export class LockstepRoom extends Room {
|
|
|
459
526
|
}
|
|
460
527
|
/**
|
|
461
528
|
* `GET …/replay` is the recording, or the end of it for a client that is
|
|
462
|
-
* catching up. `POST …/snapshot` is a player's client sending a snapshot
|
|
529
|
+
* catching up. `POST …/snapshot` is a player's client sending a snapshot,
|
|
530
|
+
* and `POST …/desync` one sending what it had saved at a turn two players
|
|
531
|
+
* disagreed on.
|
|
463
532
|
* If you override this, pass on what is not yours with `super.onHttp`.
|
|
464
533
|
*/
|
|
465
534
|
onHttp(request, player) {
|
|
@@ -470,6 +539,9 @@ export class LockstepRoom extends Room {
|
|
|
470
539
|
if (request.method === "POST" && url.pathname.endsWith("/snapshot")) {
|
|
471
540
|
return this.#offered(request, url.searchParams, player);
|
|
472
541
|
}
|
|
542
|
+
if (request.method === "POST" && url.pathname.endsWith("/desync")) {
|
|
543
|
+
return this.#explain(request, url.searchParams, player);
|
|
544
|
+
}
|
|
473
545
|
return new Response("Not found", { status: 404 });
|
|
474
546
|
}
|
|
475
547
|
/** Announces the end of the match and, if `matchBucket` is set, stores the recording as its replay. */
|