@caisual/kit 0.23.1 → 0.25.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/dist/node.js CHANGED
@@ -411,6 +411,7 @@ function seedStanza(roomId) {
411
411
 
412
412
  // src/stanza/nucleo.ts
413
413
  var CHIAVE_NUCLEO = "nucleo";
414
+ var VERSIONE_STATO = 2;
414
415
  var PREFISSO_SAVE = "save:";
415
416
  var LIMITE_FRAME = MASSIMO_BYTE_FRAME_STANZA;
416
417
  var LIMITE_STATO = 512 * 1024;
@@ -568,22 +569,13 @@ var NucleoStanza = class _NucleoStanza {
568
569
  const nucleo = new _NucleoStanza(definizione, manifest, adattatore);
569
570
  const salvato = await adattatore.storage.get(CHIAVE_NUCLEO);
570
571
  if (salvato !== void 0) {
572
+ if (salvato.versione !== VERSIONE_STATO) throw new Error("The saved room format is unsupported. Create a new room.");
571
573
  if (modalitaLocale(manifest, salvato.mode)) throw Object.assign(new Error(MODE_LOCAL_MESSAGE), { code: "mode_local" });
572
574
  nucleo.dati = salvato;
573
575
  nucleo.tickRateSincronizzato = salvato.tickRate;
574
- let daAggiornare = salvato.ultimoInputAt === void 0 || salvato.ultimoCambioStatoAt === void 0 || salvato.daily === void 0 || salvato.origin === void 0;
575
- salvato.origin ??= "player";
576
- if (salvato.origin === "matchmaking" && salvato.status === "lobby") {
577
- salvato.status = "waiting";
578
- daAggiornare = true;
579
- }
580
- salvato.daily ??= nucleo.contestoGiornaliero();
581
- salvato.ultimoInputAt ??= adattatore.ora();
582
- salvato.ultimoCambioStatoAt ??= salvato.ultimoInputAt;
583
576
  nucleo.ultimoStatoOsservato = JSON.stringify(salvato.state);
584
577
  await nucleo.riconciliaConnessioni();
585
578
  if (salvato.origin === "matchmaking") nucleo.rivalutaAvvio();
586
- if (daAggiornare) await nucleo.persisti();
587
579
  }
588
580
  await nucleo.aggiornaProgrammazione();
589
581
  return nucleo;
@@ -608,7 +600,7 @@ var NucleoStanza = class _NucleoStanza {
608
600
  if (modalitaLocale(this.manifest, mode)) throw Object.assign(new Error(MODE_LOCAL_MESSAGE), { code: "mode_local" });
609
601
  const ora = this.adattatore.ora();
610
602
  this.dati = {
611
- versione: 1,
603
+ versione: VERSIONE_STATO,
612
604
  origin,
613
605
  daily: this.contestoGiornaliero(ora),
614
606
  id,
@@ -1381,6 +1373,12 @@ var NucleoStanza = class _NucleoStanza {
1381
1373
  this.adattatore.invia(player.connessione, { t: "voice", op: "gain", gains: { ...gains } });
1382
1374
  }
1383
1375
  }
1376
+ // Un solo punto costruisce l'oggetto rematch: status, welcome e resync devono esporre la stessa scadenza.
1377
+ rivincitaProtocollo() {
1378
+ const dati = this.richiediDati();
1379
+ if (dati.status !== "finished" || dati.rivincita == null || dati.rivincitaFinoA == null) return null;
1380
+ return { keepSetup: dati.rivincita.keepSetup, deadline: dati.rivincitaFinoA };
1381
+ }
1384
1382
  stanzaProtocollo() {
1385
1383
  const dati = this.richiediDati();
1386
1384
  return {
@@ -1389,7 +1387,7 @@ var NucleoStanza = class _NucleoStanza {
1389
1387
  seed: seedStanza(dati.id),
1390
1388
  status: dati.status,
1391
1389
  result: dati.result,
1392
- rematch: dati.status === "finished" ? dati.rivincita ?? null : null,
1390
+ rematch: this.rivincitaProtocollo(),
1393
1391
  mode: dati.mode,
1394
1392
  tick: dati.tick,
1395
1393
  tickRate: dati.tickRate,
@@ -1398,9 +1396,7 @@ var NucleoStanza = class _NucleoStanza {
1398
1396
  configuration: {
1399
1397
  players: { ...this.configurazione.players },
1400
1398
  persistent: this.manifest.persistent === true,
1401
- requestRole: this.definizione.onRoleRequest !== void 0,
1402
- // Campo tenuto per i giochi pubblicati prima della 0.23, che lo leggono per disegnare la sala d'attesa.
1403
- lobby: dati.origin === "player"
1399
+ requestRole: this.definizione.onRoleRequest !== void 0
1404
1400
  }
1405
1401
  };
1406
1402
  }
@@ -1411,7 +1407,7 @@ var NucleoStanza = class _NucleoStanza {
1411
1407
  const dati = this.richiediDati();
1412
1408
  this.broadcast({
1413
1409
  t: "status",
1414
- rematch: dati.status === "finished" ? dati.rivincita ?? null : null,
1410
+ rematch: this.rivincitaProtocollo(),
1415
1411
  status: dati.status,
1416
1412
  countdownAt: dati.countdownAt,
1417
1413
  at,
@@ -1713,194 +1709,61 @@ var NucleoStanza = class _NucleoStanza {
1713
1709
  };
1714
1710
 
1715
1711
  // src/node/websocket.ts
1716
- import { createHash } from "node:crypto";
1717
1712
  import { EventEmitter } from "node:events";
1718
- var GUID_WEBSOCKET = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
1719
- var MASSIMO_MESSAGGIO = 1e6;
1720
- function contieneToken(value, token) {
1721
- return value?.split(",").some((parte) => parte.trim().toLowerCase() === token) === true;
1722
- }
1723
- function chiaveValida(value) {
1724
- if (value === void 0 || !/^[A-Za-z0-9+/]{22}==$/.test(value)) return false;
1725
- return Buffer.from(value, "base64").byteLength === 16;
1726
- }
1727
- function creaFrame(opcode, payload) {
1728
- const primo = Buffer.from([128 | opcode]);
1729
- if (payload.byteLength < 126) {
1730
- return Buffer.concat([primo, Buffer.from([payload.byteLength]), payload]);
1731
- }
1732
- if (payload.byteLength <= 65535) {
1733
- const header2 = Buffer.allocUnsafe(3);
1734
- header2[0] = 126;
1735
- header2.writeUInt16BE(payload.byteLength, 1);
1736
- return Buffer.concat([primo, header2, payload]);
1737
- }
1738
- const header = Buffer.allocUnsafe(9);
1739
- header[0] = 127;
1740
- header.writeBigUInt64BE(BigInt(payload.byteLength), 1);
1741
- return Buffer.concat([primo, header, payload]);
1742
- }
1743
- function testoUtf8(payload) {
1744
- try {
1745
- return new TextDecoder("utf-8", { fatal: true }).decode(payload);
1746
- } catch {
1747
- return null;
1748
- }
1749
- }
1713
+ import WebSocket, { WebSocketServer } from "ws";
1750
1714
  var NodeWebSocket = class extends EventEmitter {
1751
- constructor(socket, head, massimoMessaggio = MASSIMO_MESSAGGIO) {
1715
+ constructor(socket) {
1752
1716
  super();
1753
1717
  this.socket = socket;
1754
- this.massimoMessaggio = massimoMessaggio;
1755
- this.buffer = Buffer.alloc(0);
1756
- this.frammenti = [];
1757
- this.byteFrammenti = 0;
1758
- this.frammentando = false;
1759
- this.chiusuraInviata = false;
1760
- this.terminato = false;
1761
- socket.on("data", (chunk) => this.aggiungi(chunk));
1762
- socket.on("end", () => this.termina());
1763
- socket.on("close", () => this.termina());
1764
- socket.on("error", () => this.termina());
1765
- if (head.byteLength > 0) queueMicrotask(() => this.aggiungi(head));
1766
- }
1767
- send(message) {
1768
- if (this.chiusuraInviata || this.terminato) return;
1769
- this.socket.write(creaFrame(1, Buffer.from(message, "utf8")));
1770
- }
1771
- close(code = 1e3, reason = "") {
1772
- if (this.chiusuraInviata || this.terminato) return;
1773
- const motivo = Buffer.from(reason, "utf8");
1774
- if (motivo.byteLength > 123) throw new RangeError("WebSocket close reasons must be at most 123 bytes.");
1775
- const payload = Buffer.allocUnsafe(2 + motivo.byteLength);
1776
- payload.writeUInt16BE(code, 0);
1777
- motivo.copy(payload, 2);
1778
- this.chiusuraInviata = true;
1779
- this.socket.write(creaFrame(8, payload), () => this.socket.end());
1780
- }
1781
- termina() {
1782
- if (this.terminato) return;
1783
- this.terminato = true;
1784
- this.emit("close");
1785
- }
1786
- erroreProtocollo(code, reason) {
1787
- this.close(code, reason);
1788
- }
1789
- aggiungi(chunk) {
1790
- if (this.terminato) return;
1791
- this.buffer = this.buffer.byteLength === 0 ? chunk : Buffer.concat([this.buffer, chunk]);
1792
- this.leggiFrame();
1793
- }
1794
- leggiFrame() {
1795
- while (!this.terminato && this.buffer.byteLength >= 2) {
1796
- const primo = this.buffer[0] ?? 0;
1797
- const secondo = this.buffer[1] ?? 0;
1798
- const fin = (primo & 128) !== 0;
1799
- const opcode = primo & 15;
1800
- const controllo = opcode >= 8;
1801
- if ((primo & 112) !== 0 || ![0, 1, 8, 9, 10].includes(opcode)) {
1802
- this.erroreProtocollo(1002, "protocol_error");
1803
- return;
1804
- }
1805
- if ((secondo & 128) === 0 || controllo && !fin) {
1806
- this.erroreProtocollo(1002, "protocol_error");
1718
+ socket.on("message", (data, binary) => {
1719
+ if (socket.readyState !== WebSocket.OPEN) return;
1720
+ if (binary) {
1721
+ socket.close(1003, "text_only");
1807
1722
  return;
1808
1723
  }
1809
- let lunghezza = secondo & 127;
1810
- let offset = 2;
1811
- if (lunghezza === 126) {
1812
- if (this.buffer.byteLength < 4) return;
1813
- lunghezza = this.buffer.readUInt16BE(2);
1814
- offset = 4;
1815
- } else if (lunghezza === 127) {
1816
- if (this.buffer.byteLength < 10) return;
1817
- const grande = this.buffer.readBigUInt64BE(2);
1818
- if (grande > BigInt(Number.MAX_SAFE_INTEGER)) {
1819
- this.erroreProtocollo(1009, "message_too_large");
1820
- return;
1821
- }
1822
- lunghezza = Number(grande);
1823
- offset = 10;
1824
- }
1825
- if (controllo && lunghezza > 125) {
1826
- this.erroreProtocollo(1002, "protocol_error");
1827
- return;
1828
- }
1829
- if (this.buffer.byteLength < offset + 4 + lunghezza) return;
1830
- const maschera = this.buffer.subarray(offset, offset + 4);
1831
- const payload = Buffer.from(this.buffer.subarray(offset + 4, offset + 4 + lunghezza));
1832
- this.buffer = this.buffer.subarray(offset + 4 + lunghezza);
1833
- for (let indice = 0; indice < payload.byteLength; indice += 1) {
1834
- payload[indice] = (payload[indice] ?? 0) ^ (maschera[indice % 4] ?? 0);
1835
- }
1836
- if (controllo) {
1837
- this.gestisciControllo(opcode, payload);
1838
- continue;
1839
- }
1840
- this.gestisciDati(opcode, fin, payload);
1841
- }
1724
+ this.emit("message", data.toString());
1725
+ });
1726
+ socket.on("close", () => this.emit("close"));
1727
+ socket.on("error", () => void 0);
1842
1728
  }
1843
- gestisciControllo(opcode, payload) {
1844
- if (opcode === 9) {
1845
- if (!this.chiusuraInviata) this.socket.write(creaFrame(10, payload));
1846
- return;
1847
- }
1848
- if (opcode === 10) return;
1849
- if (payload.byteLength === 1) {
1850
- this.erroreProtocollo(1002, "protocol_error");
1851
- return;
1852
- }
1853
- if (!this.chiusuraInviata) {
1854
- this.chiusuraInviata = true;
1855
- this.socket.write(creaFrame(8, payload), () => this.socket.end());
1856
- } else {
1857
- this.socket.end();
1858
- }
1729
+ send(message) {
1730
+ if (this.socket.readyState === WebSocket.OPEN) this.socket.send(message);
1859
1731
  }
1860
- gestisciDati(opcode, fin, payload) {
1861
- if (opcode === 1 && this.frammentando) {
1862
- this.erroreProtocollo(1002, "protocol_error");
1863
- return;
1864
- }
1865
- if (opcode === 0 && !this.frammentando) {
1866
- this.erroreProtocollo(1002, "protocol_error");
1867
- return;
1868
- }
1869
- if (opcode === 1 && !fin) this.frammentando = true;
1870
- this.frammenti.push(payload);
1871
- this.byteFrammenti += payload.byteLength;
1872
- if (this.byteFrammenti > this.massimoMessaggio) {
1873
- this.erroreProtocollo(1009, "message_too_large");
1874
- return;
1875
- }
1876
- if (!fin) return;
1877
- const completo = this.frammenti.length === 1 ? this.frammenti[0] ?? Buffer.alloc(0) : Buffer.concat(this.frammenti, this.byteFrammenti);
1878
- this.frammenti = [];
1879
- this.byteFrammenti = 0;
1880
- this.frammentando = false;
1881
- const testo = testoUtf8(completo);
1882
- if (testo === null) {
1883
- this.erroreProtocollo(1007, "invalid_utf8");
1884
- return;
1885
- }
1886
- this.emit("message", testo);
1732
+ close(code = 1e3, reason = "") {
1733
+ this.socket.close(code, reason);
1887
1734
  }
1888
1735
  };
1889
1736
  function acceptNodeWebSocket(request, socket, head = Buffer.alloc(0)) {
1890
- const key = request.headers["sec-websocket-key"];
1891
- if (request.method !== "GET" || request.headers.upgrade?.toLowerCase() !== "websocket" || !contieneToken(request.headers.connection, "upgrade") || request.headers["sec-websocket-version"] !== "13" || !chiaveValida(key)) {
1892
- throw new TypeError("The WebSocket upgrade request is invalid.");
1893
- }
1894
- const accept = createHash("sha1").update(key + GUID_WEBSOCKET).digest("base64");
1895
- socket.write(
1896
- `HTTP/1.1 101 Switching Protocols\r
1897
- Upgrade: websocket\r
1898
- Connection: Upgrade\r
1899
- Sec-WebSocket-Accept: ${accept}\r
1900
- \r
1901
- `
1902
- );
1903
- return new NodeWebSocket(socket, head);
1737
+ return new Promise((resolve, reject) => {
1738
+ const server = new WebSocketServer({
1739
+ noServer: true,
1740
+ clientTracking: false,
1741
+ maxPayload: 1e6,
1742
+ perMessageDeflate: false,
1743
+ skipUTF8Validation: false
1744
+ });
1745
+ const aborted = () => reject(new Error("The WebSocket upgrade was interrupted."));
1746
+ socket.once("error", aborted);
1747
+ socket.once("close", aborted);
1748
+ const cleanup = () => {
1749
+ socket.off("error", aborted);
1750
+ socket.off("close", aborted);
1751
+ };
1752
+ server.once("wsClientError", (error) => {
1753
+ cleanup();
1754
+ socket.end("HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n");
1755
+ reject(error);
1756
+ });
1757
+ try {
1758
+ server.handleUpgrade(request, socket, head, (websocket) => {
1759
+ cleanup();
1760
+ resolve(new NodeWebSocket(websocket));
1761
+ });
1762
+ } catch (error) {
1763
+ cleanup();
1764
+ reject(error);
1765
+ }
1766
+ });
1904
1767
  }
1905
1768
 
1906
1769
  // src/node/index.ts
package/dist/runtime.js CHANGED
@@ -392,6 +392,7 @@ function seedStanza(roomId) {
392
392
 
393
393
  // src/stanza/nucleo.ts
394
394
  var CHIAVE_NUCLEO = "nucleo";
395
+ var VERSIONE_STATO = 2;
395
396
  var PREFISSO_SAVE = "save:";
396
397
  var LIMITE_FRAME = MASSIMO_BYTE_FRAME_STANZA;
397
398
  var LIMITE_STATO = 512 * 1024;
@@ -549,22 +550,13 @@ var NucleoStanza = class _NucleoStanza {
549
550
  const nucleo = new _NucleoStanza(definizione, manifest, adattatore);
550
551
  const salvato = await adattatore.storage.get(CHIAVE_NUCLEO);
551
552
  if (salvato !== void 0) {
553
+ if (salvato.versione !== VERSIONE_STATO) throw new Error("The saved room format is unsupported. Create a new room.");
552
554
  if (modalitaLocale(manifest, salvato.mode)) throw Object.assign(new Error(MODE_LOCAL_MESSAGE), { code: "mode_local" });
553
555
  nucleo.dati = salvato;
554
556
  nucleo.tickRateSincronizzato = salvato.tickRate;
555
- let daAggiornare = salvato.ultimoInputAt === void 0 || salvato.ultimoCambioStatoAt === void 0 || salvato.daily === void 0 || salvato.origin === void 0;
556
- salvato.origin ??= "player";
557
- if (salvato.origin === "matchmaking" && salvato.status === "lobby") {
558
- salvato.status = "waiting";
559
- daAggiornare = true;
560
- }
561
- salvato.daily ??= nucleo.contestoGiornaliero();
562
- salvato.ultimoInputAt ??= adattatore.ora();
563
- salvato.ultimoCambioStatoAt ??= salvato.ultimoInputAt;
564
557
  nucleo.ultimoStatoOsservato = JSON.stringify(salvato.state);
565
558
  await nucleo.riconciliaConnessioni();
566
559
  if (salvato.origin === "matchmaking") nucleo.rivalutaAvvio();
567
- if (daAggiornare) await nucleo.persisti();
568
560
  }
569
561
  await nucleo.aggiornaProgrammazione();
570
562
  return nucleo;
@@ -589,7 +581,7 @@ var NucleoStanza = class _NucleoStanza {
589
581
  if (modalitaLocale(this.manifest, mode)) throw Object.assign(new Error(MODE_LOCAL_MESSAGE), { code: "mode_local" });
590
582
  const ora = this.adattatore.ora();
591
583
  this.dati = {
592
- versione: 1,
584
+ versione: VERSIONE_STATO,
593
585
  origin,
594
586
  daily: this.contestoGiornaliero(ora),
595
587
  id,
@@ -1362,6 +1354,12 @@ var NucleoStanza = class _NucleoStanza {
1362
1354
  this.adattatore.invia(player.connessione, { t: "voice", op: "gain", gains: { ...gains } });
1363
1355
  }
1364
1356
  }
1357
+ // Un solo punto costruisce l'oggetto rematch: status, welcome e resync devono esporre la stessa scadenza.
1358
+ rivincitaProtocollo() {
1359
+ const dati = this.richiediDati();
1360
+ if (dati.status !== "finished" || dati.rivincita == null || dati.rivincitaFinoA == null) return null;
1361
+ return { keepSetup: dati.rivincita.keepSetup, deadline: dati.rivincitaFinoA };
1362
+ }
1365
1363
  stanzaProtocollo() {
1366
1364
  const dati = this.richiediDati();
1367
1365
  return {
@@ -1370,7 +1368,7 @@ var NucleoStanza = class _NucleoStanza {
1370
1368
  seed: seedStanza(dati.id),
1371
1369
  status: dati.status,
1372
1370
  result: dati.result,
1373
- rematch: dati.status === "finished" ? dati.rivincita ?? null : null,
1371
+ rematch: this.rivincitaProtocollo(),
1374
1372
  mode: dati.mode,
1375
1373
  tick: dati.tick,
1376
1374
  tickRate: dati.tickRate,
@@ -1379,9 +1377,7 @@ var NucleoStanza = class _NucleoStanza {
1379
1377
  configuration: {
1380
1378
  players: { ...this.configurazione.players },
1381
1379
  persistent: this.manifest.persistent === true,
1382
- requestRole: this.definizione.onRoleRequest !== void 0,
1383
- // Campo tenuto per i giochi pubblicati prima della 0.23, che lo leggono per disegnare la sala d'attesa.
1384
- lobby: dati.origin === "player"
1380
+ requestRole: this.definizione.onRoleRequest !== void 0
1385
1381
  }
1386
1382
  };
1387
1383
  }
@@ -1392,7 +1388,7 @@ var NucleoStanza = class _NucleoStanza {
1392
1388
  const dati = this.richiediDati();
1393
1389
  this.broadcast({
1394
1390
  t: "status",
1395
- rematch: dati.status === "finished" ? dati.rivincita ?? null : null,
1391
+ rematch: this.rivincitaProtocollo(),
1396
1392
  status: dati.status,
1397
1393
  countdownAt: dati.countdownAt,
1398
1394
  at,
@@ -3,7 +3,6 @@ export type TextDictionary = Record<string, string>;
3
3
  export declare function normalizeLanguage(value: unknown): string | null;
4
4
  export declare function manifestLanguages(manifest: {
5
5
  languages?: string[];
6
- language?: string;
7
6
  }): string[];
8
7
  export declare function languageFallbacks(language: string, defaultLanguage?: string): string[];
9
8
  export declare function resolveGameLanguage(preferences: readonly string[], languages?: readonly string[]): string;
@@ -53,8 +53,6 @@ export interface Manifest {
53
53
  screenshots: string[];
54
54
  tags: string[];
55
55
  languages: string[];
56
- /** @deprecated Usa languages; il primo elemento e' il default. */
57
- language: string;
58
56
  platform: Platform;
59
57
  orientation: Orientation;
60
58
  input: Input[];
@@ -68,8 +66,6 @@ export interface Manifest {
68
66
  voice: Voice;
69
67
  modes: ManifestMode[];
70
68
  }
71
- export declare const AVVISO_ISOLATED = "isolated has no effect: games run inside the portal page, which is not cross-origin isolated";
72
- export declare function avvisiManifest(value: unknown): string[];
73
69
  export type EsitoManifest = {
74
70
  ok: true;
75
71
  manifest: Manifest;
@@ -83,4 +79,3 @@ export declare const TETTO_GIOCATORI = 24;
83
79
  * errori. Un agente puo' cosi' correggere il file senza tentativi ripetuti.
84
80
  */
85
81
  export declare function validaManifest(valore: unknown): EsitoManifest;
86
- export declare function validaManifestPubblicazione(valore: unknown): EsitoManifest;
@@ -64,6 +64,7 @@ export interface RoomInvite {
64
64
  export interface RoomMetadata {
65
65
  rematch?: {
66
66
  keepSetup: boolean;
67
+ deadline: number;
67
68
  } | null;
68
69
  mode: string | null;
69
70
  countdownAt: number | null;
@@ -8,7 +8,7 @@ export interface NodeWebSocket {
8
8
  send(message: string): void;
9
9
  close(code?: number, reason?: string): void;
10
10
  }
11
- export declare function acceptNodeWebSocket(request: IncomingMessage, socket: Duplex, head?: Buffer): NodeWebSocket;
11
+ export declare function acceptNodeWebSocket(request: IncomingMessage, socket: Duplex, head?: Buffer): Promise<NodeWebSocket>;
12
12
  export interface NodePlayerIdentity {
13
13
  id: string;
14
14
  name: string;
@@ -1,29 +1,17 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import type { IncomingMessage } from 'node:http';
3
3
  import type { Duplex } from 'node:stream';
4
+ import WebSocket from 'ws';
4
5
  export declare interface NodeWebSocket {
5
6
  on(event: 'message', listener: (message: string) => void): this;
6
7
  on(event: 'close', listener: () => void): this;
7
8
  }
8
- /** WebSocket testuale minimo per server Node, senza estensioni negoziate. */
9
+ /** Mantiene il contratto testuale del kit; ws gestisce il protocollo di rete. */
9
10
  export declare class NodeWebSocket extends EventEmitter {
10
11
  private readonly socket;
11
- private readonly massimoMessaggio;
12
- private buffer;
13
- private frammenti;
14
- private byteFrammenti;
15
- private frammentando;
16
- private chiusuraInviata;
17
- private terminato;
18
- constructor(socket: Duplex, head: Buffer, massimoMessaggio?: number);
12
+ constructor(socket: WebSocket);
19
13
  send(message: string): void;
20
14
  close(code?: number, reason?: string): void;
21
- private termina;
22
- private erroreProtocollo;
23
- private aggiungi;
24
- private leggiFrame;
25
- private gestisciControllo;
26
- private gestisciDati;
27
15
  }
28
- /** Completa un upgrade HTTP gia autorizzato e restituisce il canale testuale. */
29
- export declare function acceptNodeWebSocket(request: IncomingMessage, socket: Duplex, head?: Buffer): NodeWebSocket;
16
+ /** Completa un upgrade HTTP gia' autorizzato. Nessuna compressione negoziata. */
17
+ export declare function acceptNodeWebSocket(request: IncomingMessage, socket: Duplex, head?: Buffer): Promise<NodeWebSocket>;
@@ -37,16 +37,16 @@ export interface RoomConfiguration {
37
37
  };
38
38
  persistent: boolean;
39
39
  requestRole: boolean;
40
- lobby: boolean;
41
40
  }
42
41
  export interface StanzaProtocollo {
43
42
  origin: 'player' | 'matchmaking';
44
- rematch?: {
43
+ rematch: {
45
44
  keepSetup: boolean;
45
+ deadline: number;
46
46
  } | null;
47
- result?: JsonValue;
48
- countdownAt?: number | null;
49
- configuration?: RoomConfiguration;
47
+ result: JsonValue;
48
+ countdownAt: number | null;
49
+ configuration: RoomConfiguration;
50
50
  id: string;
51
51
  seed: number;
52
52
  status: RoomStatus;
@@ -219,23 +219,24 @@ export type MessaggioServerStanza = {
219
219
  code: string | null;
220
220
  } | {
221
221
  t: 'status';
222
- rematch?: {
222
+ rematch: {
223
223
  keepSetup: boolean;
224
+ deadline: number;
224
225
  } | null;
225
226
  status: RoomStatus;
226
227
  at: number;
227
228
  result: JsonValue;
228
- countdownAt?: number | null;
229
+ countdownAt: number | null;
229
230
  } | {
230
231
  t: 'state';
231
- tickRate?: number;
232
+ tickRate: number;
232
233
  tick: number;
233
234
  serverTime: number;
234
235
  base: number;
235
236
  patch: OperazioneDiff[];
236
237
  } | {
237
238
  t: 'snapshot';
238
- tickRate?: number;
239
+ tickRate: number;
239
240
  tick: number;
240
241
  serverTime: number;
241
242
  state: JsonValue;
@@ -74,6 +74,7 @@ export declare class NucleoStanza {
74
74
  private inviaErrore;
75
75
  private giocatoriProtocollo;
76
76
  private inviaWelcome;
77
+ private rivincitaProtocollo;
77
78
  private stanzaProtocollo;
78
79
  private inviaGiocatori;
79
80
  private inviaStatus;
@@ -69,7 +69,7 @@ export interface FinePersistita {
69
69
  at: number;
70
70
  }
71
71
  export interface StatoPersistito {
72
- versione: 1;
72
+ versione: 2;
73
73
  origin: 'player' | 'matchmaking';
74
74
  id: string;
75
75
  mode: string | null;
@@ -82,7 +82,7 @@ export interface StatoPersistito {
82
82
  giocatori: GiocatorePersistito[];
83
83
  result: JsonValue | null;
84
84
  resultAt: number | null;
85
- daily?: import('../daily.js').DailyContext;
85
+ daily: import('../daily.js').DailyContext;
86
86
  rivincita?: {
87
87
  keepSetup: boolean;
88
88
  } | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caisual/kit",
3
- "version": "0.23.1",
3
+ "version": "0.25.0",
4
4
  "description": "Client and server kit for Caisual games",
5
5
  "license": "MIT",
6
6
  "homepage": "https://caisual.com",
@@ -56,17 +56,23 @@
56
56
  }
57
57
  },
58
58
  "types": "./dist/kit.d.ts",
59
+ "scripts": {
60
+ "build": "node build.mjs",
61
+ "prepack": "pnpm build",
62
+ "typecheck": "tsc --noEmit && tsc -p tsconfig.node.json --noEmit",
63
+ "test": "node verifica-dist.mjs && vitest run && WRANGLER_LOG_PATH=/tmp/caisual-kit-wrangler.log vitest run --config vitest.workers.config.ts"
64
+ },
59
65
  "devDependencies": {
66
+ "@caisual/contracts": "workspace:*",
60
67
  "@cloudflare/vitest-pool-workers": "^0.20.3",
61
68
  "@types/node": "^26.2.0",
62
69
  "esbuild": "^0.28.1",
63
70
  "typescript": "^7.0.2",
64
71
  "vitest": "^4.1.10",
65
- "@caisual/contracts": "0.0.0"
72
+ "@types/ws": "^8.18.1",
73
+ "proper-lockfile": "^4.1.2"
66
74
  },
67
- "scripts": {
68
- "build": "node build.mjs",
69
- "typecheck": "tsc --noEmit && tsc -p tsconfig.node.json --noEmit",
70
- "test": "node verifica-dist.mjs && vitest run && WRANGLER_LOG_PATH=/tmp/caisual-kit-wrangler.log vitest run --config vitest.workers.config.ts"
75
+ "dependencies": {
76
+ "ws": "^8.21.0"
71
77
  }
72
- }
78
+ }