@caisual/kit 0.24.0 → 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/README.md +1 -1
- package/dist/host.js +6 -7
- package/dist/kit.js +2 -2
- package/dist/kit.js.map +3 -3
- package/dist/node.js +48 -191
- package/dist/runtime.js +4 -14
- package/dist/types/contracts/i18n.d.ts +0 -1
- package/dist/types/contracts/manifest.d.ts +0 -5
- package/dist/types/node/index.d.ts +1 -1
- package/dist/types/node/websocket.d.ts +5 -17
- package/dist/types/protocollo.d.ts +8 -9
- package/dist/types/stanza/tipi.d.ts +2 -2
- package/package.json +7 -2
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:
|
|
603
|
+
versione: VERSIONE_STATO,
|
|
612
604
|
origin,
|
|
613
605
|
daily: this.contestoGiornaliero(ora),
|
|
614
606
|
id,
|
|
@@ -1404,9 +1396,7 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
1404
1396
|
configuration: {
|
|
1405
1397
|
players: { ...this.configurazione.players },
|
|
1406
1398
|
persistent: this.manifest.persistent === true,
|
|
1407
|
-
requestRole: this.definizione.onRoleRequest !== void 0
|
|
1408
|
-
// Campo tenuto per i giochi pubblicati prima della 0.23, che lo leggono per disegnare la sala d'attesa.
|
|
1409
|
-
lobby: dati.origin === "player"
|
|
1399
|
+
requestRole: this.definizione.onRoleRequest !== void 0
|
|
1410
1400
|
}
|
|
1411
1401
|
};
|
|
1412
1402
|
}
|
|
@@ -1719,194 +1709,61 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
1719
1709
|
};
|
|
1720
1710
|
|
|
1721
1711
|
// src/node/websocket.ts
|
|
1722
|
-
import { createHash } from "node:crypto";
|
|
1723
1712
|
import { EventEmitter } from "node:events";
|
|
1724
|
-
|
|
1725
|
-
var MASSIMO_MESSAGGIO = 1e6;
|
|
1726
|
-
function contieneToken(value, token) {
|
|
1727
|
-
return value?.split(",").some((parte) => parte.trim().toLowerCase() === token) === true;
|
|
1728
|
-
}
|
|
1729
|
-
function chiaveValida(value) {
|
|
1730
|
-
if (value === void 0 || !/^[A-Za-z0-9+/]{22}==$/.test(value)) return false;
|
|
1731
|
-
return Buffer.from(value, "base64").byteLength === 16;
|
|
1732
|
-
}
|
|
1733
|
-
function creaFrame(opcode, payload) {
|
|
1734
|
-
const primo = Buffer.from([128 | opcode]);
|
|
1735
|
-
if (payload.byteLength < 126) {
|
|
1736
|
-
return Buffer.concat([primo, Buffer.from([payload.byteLength]), payload]);
|
|
1737
|
-
}
|
|
1738
|
-
if (payload.byteLength <= 65535) {
|
|
1739
|
-
const header2 = Buffer.allocUnsafe(3);
|
|
1740
|
-
header2[0] = 126;
|
|
1741
|
-
header2.writeUInt16BE(payload.byteLength, 1);
|
|
1742
|
-
return Buffer.concat([primo, header2, payload]);
|
|
1743
|
-
}
|
|
1744
|
-
const header = Buffer.allocUnsafe(9);
|
|
1745
|
-
header[0] = 127;
|
|
1746
|
-
header.writeBigUInt64BE(BigInt(payload.byteLength), 1);
|
|
1747
|
-
return Buffer.concat([primo, header, payload]);
|
|
1748
|
-
}
|
|
1749
|
-
function testoUtf8(payload) {
|
|
1750
|
-
try {
|
|
1751
|
-
return new TextDecoder("utf-8", { fatal: true }).decode(payload);
|
|
1752
|
-
} catch {
|
|
1753
|
-
return null;
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1713
|
+
import WebSocket, { WebSocketServer } from "ws";
|
|
1756
1714
|
var NodeWebSocket = class extends EventEmitter {
|
|
1757
|
-
constructor(socket
|
|
1715
|
+
constructor(socket) {
|
|
1758
1716
|
super();
|
|
1759
1717
|
this.socket = socket;
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
this.frammentando = false;
|
|
1765
|
-
this.chiusuraInviata = false;
|
|
1766
|
-
this.terminato = false;
|
|
1767
|
-
socket.on("data", (chunk) => this.aggiungi(chunk));
|
|
1768
|
-
socket.on("end", () => this.termina());
|
|
1769
|
-
socket.on("close", () => this.termina());
|
|
1770
|
-
socket.on("error", () => this.termina());
|
|
1771
|
-
if (head.byteLength > 0) queueMicrotask(() => this.aggiungi(head));
|
|
1772
|
-
}
|
|
1773
|
-
send(message) {
|
|
1774
|
-
if (this.chiusuraInviata || this.terminato) return;
|
|
1775
|
-
this.socket.write(creaFrame(1, Buffer.from(message, "utf8")));
|
|
1776
|
-
}
|
|
1777
|
-
close(code = 1e3, reason = "") {
|
|
1778
|
-
if (this.chiusuraInviata || this.terminato) return;
|
|
1779
|
-
const motivo = Buffer.from(reason, "utf8");
|
|
1780
|
-
if (motivo.byteLength > 123) throw new RangeError("WebSocket close reasons must be at most 123 bytes.");
|
|
1781
|
-
const payload = Buffer.allocUnsafe(2 + motivo.byteLength);
|
|
1782
|
-
payload.writeUInt16BE(code, 0);
|
|
1783
|
-
motivo.copy(payload, 2);
|
|
1784
|
-
this.chiusuraInviata = true;
|
|
1785
|
-
this.socket.write(creaFrame(8, payload), () => this.socket.end());
|
|
1786
|
-
}
|
|
1787
|
-
termina() {
|
|
1788
|
-
if (this.terminato) return;
|
|
1789
|
-
this.terminato = true;
|
|
1790
|
-
this.emit("close");
|
|
1791
|
-
}
|
|
1792
|
-
erroreProtocollo(code, reason) {
|
|
1793
|
-
this.close(code, reason);
|
|
1794
|
-
}
|
|
1795
|
-
aggiungi(chunk) {
|
|
1796
|
-
if (this.terminato) return;
|
|
1797
|
-
this.buffer = this.buffer.byteLength === 0 ? chunk : Buffer.concat([this.buffer, chunk]);
|
|
1798
|
-
this.leggiFrame();
|
|
1799
|
-
}
|
|
1800
|
-
leggiFrame() {
|
|
1801
|
-
while (!this.terminato && this.buffer.byteLength >= 2) {
|
|
1802
|
-
const primo = this.buffer[0] ?? 0;
|
|
1803
|
-
const secondo = this.buffer[1] ?? 0;
|
|
1804
|
-
const fin = (primo & 128) !== 0;
|
|
1805
|
-
const opcode = primo & 15;
|
|
1806
|
-
const controllo = opcode >= 8;
|
|
1807
|
-
if ((primo & 112) !== 0 || ![0, 1, 8, 9, 10].includes(opcode)) {
|
|
1808
|
-
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");
|
|
1809
1722
|
return;
|
|
1810
1723
|
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
let lunghezza = secondo & 127;
|
|
1816
|
-
let offset = 2;
|
|
1817
|
-
if (lunghezza === 126) {
|
|
1818
|
-
if (this.buffer.byteLength < 4) return;
|
|
1819
|
-
lunghezza = this.buffer.readUInt16BE(2);
|
|
1820
|
-
offset = 4;
|
|
1821
|
-
} else if (lunghezza === 127) {
|
|
1822
|
-
if (this.buffer.byteLength < 10) return;
|
|
1823
|
-
const grande = this.buffer.readBigUInt64BE(2);
|
|
1824
|
-
if (grande > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
1825
|
-
this.erroreProtocollo(1009, "message_too_large");
|
|
1826
|
-
return;
|
|
1827
|
-
}
|
|
1828
|
-
lunghezza = Number(grande);
|
|
1829
|
-
offset = 10;
|
|
1830
|
-
}
|
|
1831
|
-
if (controllo && lunghezza > 125) {
|
|
1832
|
-
this.erroreProtocollo(1002, "protocol_error");
|
|
1833
|
-
return;
|
|
1834
|
-
}
|
|
1835
|
-
if (this.buffer.byteLength < offset + 4 + lunghezza) return;
|
|
1836
|
-
const maschera = this.buffer.subarray(offset, offset + 4);
|
|
1837
|
-
const payload = Buffer.from(this.buffer.subarray(offset + 4, offset + 4 + lunghezza));
|
|
1838
|
-
this.buffer = this.buffer.subarray(offset + 4 + lunghezza);
|
|
1839
|
-
for (let indice = 0; indice < payload.byteLength; indice += 1) {
|
|
1840
|
-
payload[indice] = (payload[indice] ?? 0) ^ (maschera[indice % 4] ?? 0);
|
|
1841
|
-
}
|
|
1842
|
-
if (controllo) {
|
|
1843
|
-
this.gestisciControllo(opcode, payload);
|
|
1844
|
-
continue;
|
|
1845
|
-
}
|
|
1846
|
-
this.gestisciDati(opcode, fin, payload);
|
|
1847
|
-
}
|
|
1724
|
+
this.emit("message", data.toString());
|
|
1725
|
+
});
|
|
1726
|
+
socket.on("close", () => this.emit("close"));
|
|
1727
|
+
socket.on("error", () => void 0);
|
|
1848
1728
|
}
|
|
1849
|
-
|
|
1850
|
-
if (
|
|
1851
|
-
if (!this.chiusuraInviata) this.socket.write(creaFrame(10, payload));
|
|
1852
|
-
return;
|
|
1853
|
-
}
|
|
1854
|
-
if (opcode === 10) return;
|
|
1855
|
-
if (payload.byteLength === 1) {
|
|
1856
|
-
this.erroreProtocollo(1002, "protocol_error");
|
|
1857
|
-
return;
|
|
1858
|
-
}
|
|
1859
|
-
if (!this.chiusuraInviata) {
|
|
1860
|
-
this.chiusuraInviata = true;
|
|
1861
|
-
this.socket.write(creaFrame(8, payload), () => this.socket.end());
|
|
1862
|
-
} else {
|
|
1863
|
-
this.socket.end();
|
|
1864
|
-
}
|
|
1729
|
+
send(message) {
|
|
1730
|
+
if (this.socket.readyState === WebSocket.OPEN) this.socket.send(message);
|
|
1865
1731
|
}
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
this.erroreProtocollo(1002, "protocol_error");
|
|
1869
|
-
return;
|
|
1870
|
-
}
|
|
1871
|
-
if (opcode === 0 && !this.frammentando) {
|
|
1872
|
-
this.erroreProtocollo(1002, "protocol_error");
|
|
1873
|
-
return;
|
|
1874
|
-
}
|
|
1875
|
-
if (opcode === 1 && !fin) this.frammentando = true;
|
|
1876
|
-
this.frammenti.push(payload);
|
|
1877
|
-
this.byteFrammenti += payload.byteLength;
|
|
1878
|
-
if (this.byteFrammenti > this.massimoMessaggio) {
|
|
1879
|
-
this.erroreProtocollo(1009, "message_too_large");
|
|
1880
|
-
return;
|
|
1881
|
-
}
|
|
1882
|
-
if (!fin) return;
|
|
1883
|
-
const completo = this.frammenti.length === 1 ? this.frammenti[0] ?? Buffer.alloc(0) : Buffer.concat(this.frammenti, this.byteFrammenti);
|
|
1884
|
-
this.frammenti = [];
|
|
1885
|
-
this.byteFrammenti = 0;
|
|
1886
|
-
this.frammentando = false;
|
|
1887
|
-
const testo = testoUtf8(completo);
|
|
1888
|
-
if (testo === null) {
|
|
1889
|
-
this.erroreProtocollo(1007, "invalid_utf8");
|
|
1890
|
-
return;
|
|
1891
|
-
}
|
|
1892
|
-
this.emit("message", testo);
|
|
1732
|
+
close(code = 1e3, reason = "") {
|
|
1733
|
+
this.socket.close(code, reason);
|
|
1893
1734
|
}
|
|
1894
1735
|
};
|
|
1895
1736
|
function acceptNodeWebSocket(request, socket, head = Buffer.alloc(0)) {
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
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
|
+
});
|
|
1910
1767
|
}
|
|
1911
1768
|
|
|
1912
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:
|
|
584
|
+
versione: VERSIONE_STATO,
|
|
593
585
|
origin,
|
|
594
586
|
daily: this.contestoGiornaliero(ora),
|
|
595
587
|
id,
|
|
@@ -1385,9 +1377,7 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
1385
1377
|
configuration: {
|
|
1386
1378
|
players: { ...this.configurazione.players },
|
|
1387
1379
|
persistent: this.manifest.persistent === true,
|
|
1388
|
-
requestRole: this.definizione.onRoleRequest !== void 0
|
|
1389
|
-
// Campo tenuto per i giochi pubblicati prima della 0.23, che lo leggono per disegnare la sala d'attesa.
|
|
1390
|
-
lobby: dati.origin === "player"
|
|
1380
|
+
requestRole: this.definizione.onRoleRequest !== void 0
|
|
1391
1381
|
}
|
|
1392
1382
|
};
|
|
1393
1383
|
}
|
|
@@ -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;
|
|
@@ -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
|
-
/**
|
|
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
|
-
|
|
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
|
|
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,17 +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;
|
|
46
45
|
deadline: number;
|
|
47
46
|
} | null;
|
|
48
|
-
result
|
|
49
|
-
countdownAt
|
|
50
|
-
configuration
|
|
47
|
+
result: JsonValue;
|
|
48
|
+
countdownAt: number | null;
|
|
49
|
+
configuration: RoomConfiguration;
|
|
51
50
|
id: string;
|
|
52
51
|
seed: number;
|
|
53
52
|
status: RoomStatus;
|
|
@@ -220,24 +219,24 @@ export type MessaggioServerStanza = {
|
|
|
220
219
|
code: string | null;
|
|
221
220
|
} | {
|
|
222
221
|
t: 'status';
|
|
223
|
-
rematch
|
|
222
|
+
rematch: {
|
|
224
223
|
keepSetup: boolean;
|
|
225
224
|
deadline: number;
|
|
226
225
|
} | null;
|
|
227
226
|
status: RoomStatus;
|
|
228
227
|
at: number;
|
|
229
228
|
result: JsonValue;
|
|
230
|
-
countdownAt
|
|
229
|
+
countdownAt: number | null;
|
|
231
230
|
} | {
|
|
232
231
|
t: 'state';
|
|
233
|
-
tickRate
|
|
232
|
+
tickRate: number;
|
|
234
233
|
tick: number;
|
|
235
234
|
serverTime: number;
|
|
236
235
|
base: number;
|
|
237
236
|
patch: OperazioneDiff[];
|
|
238
237
|
} | {
|
|
239
238
|
t: 'snapshot';
|
|
240
|
-
tickRate
|
|
239
|
+
tickRate: number;
|
|
241
240
|
tick: number;
|
|
242
241
|
serverTime: number;
|
|
243
242
|
state: JsonValue;
|
|
@@ -69,7 +69,7 @@ export interface FinePersistita {
|
|
|
69
69
|
at: number;
|
|
70
70
|
}
|
|
71
71
|
export interface StatoPersistito {
|
|
72
|
-
versione:
|
|
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
|
|
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.
|
|
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",
|
|
@@ -68,6 +68,11 @@
|
|
|
68
68
|
"@types/node": "^26.2.0",
|
|
69
69
|
"esbuild": "^0.28.1",
|
|
70
70
|
"typescript": "^7.0.2",
|
|
71
|
-
"vitest": "^4.1.10"
|
|
71
|
+
"vitest": "^4.1.10",
|
|
72
|
+
"@types/ws": "^8.18.1",
|
|
73
|
+
"proper-lockfile": "^4.1.2"
|
|
74
|
+
},
|
|
75
|
+
"dependencies": {
|
|
76
|
+
"ws": "^8.21.0"
|
|
72
77
|
}
|
|
73
78
|
}
|