@caisual/kit 0.25.0 → 0.25.1

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/runtime.js CHANGED
@@ -401,6 +401,7 @@ var GRAZIA_MS = 6e4;
401
401
  var STANZA_VUOTA_MS = 5 * 6e4;
402
402
  var ATTESA_RIVINCITA_MS = 2 * 6e4;
403
403
  var COUNTDOWN_MS = 3e3;
404
+ var INTERVALLO_SALVATAGGIO_MS = 5e3;
404
405
  var RIPOSO_TICK_MS = 3e4;
405
406
  var INATTIVITA_MS = 10 * 6e4;
406
407
  var SCADENZA_PERSISTENTE_MS = 30 * 24 * 60 * 6e4;
@@ -452,9 +453,9 @@ var NucleoStanza = class _NucleoStanza {
452
453
  this.fineRichiesta = null;
453
454
  this.applicandoAzioni = false;
454
455
  this.ultimoStatoOsservato = "";
455
- this.tickRateSincronizzato = null;
456
- this.voceDaPersistire = false;
456
+ this.salvataggioImmediato = false;
457
457
  const nucleo = this;
458
+ this.tickRate = definizione.tickRate;
458
459
  const daily = {
459
460
  get day() {
460
461
  return nucleo.richiediDati().daily.day;
@@ -483,7 +484,7 @@ var NucleoStanza = class _NucleoStanza {
483
484
  return nucleo.richiediDati().tick;
484
485
  },
485
486
  get tickRate() {
486
- return nucleo.richiediDati().tickRate;
487
+ return nucleo.tickRate;
487
488
  },
488
489
  get result() {
489
490
  return nucleo.richiediDati().result;
@@ -553,10 +554,10 @@ var NucleoStanza = class _NucleoStanza {
553
554
  if (salvato.versione !== VERSIONE_STATO) throw new Error("The saved room format is unsupported. Create a new room.");
554
555
  if (modalitaLocale(manifest, salvato.mode)) throw Object.assign(new Error(MODE_LOCAL_MESSAGE), { code: "mode_local" });
555
556
  nucleo.dati = salvato;
556
- nucleo.tickRateSincronizzato = salvato.tickRate;
557
557
  nucleo.ultimoStatoOsservato = JSON.stringify(salvato.state);
558
558
  await nucleo.riconciliaConnessioni();
559
559
  if (salvato.origin === "matchmaking") nucleo.rivalutaAvvio();
560
+ if (salvato.status === "playing" && nucleo.tickRate > 0) nucleo.inviaSnapshotTutti();
560
561
  }
561
562
  await nucleo.aggiornaProgrammazione();
562
563
  return nucleo;
@@ -588,7 +589,6 @@ var NucleoStanza = class _NucleoStanza {
588
589
  mode,
589
590
  status: origin === "matchmaking" ? "waiting" : "lobby",
590
591
  tick: 0,
591
- tickRate: this.definizione.tickRate,
592
592
  ultimoInputAt: ora,
593
593
  ultimoCambioStatoAt: ora,
594
594
  state: {},
@@ -603,8 +603,6 @@ var NucleoStanza = class _NucleoStanza {
603
603
  cancellaDopoFlush: false,
604
604
  tickSincronizzato: 0,
605
605
  statoSincronizzato: {},
606
- durateCpu: [],
607
- cpuOltreCento: 0,
608
606
  voceGuadagni: {}
609
607
  };
610
608
  await this.chiama(this.definizione.onCreate, this.room);
@@ -745,7 +743,7 @@ var NucleoStanza = class _NucleoStanza {
745
743
  this.inviaGiocatori();
746
744
  this.rivalutaAvvio();
747
745
  }
748
- await this.persistiEProgramma();
746
+ await this.persistiEProgramma(true);
749
747
  return { ok: true };
750
748
  }
751
749
  async disconnetti(connessione) {
@@ -763,7 +761,7 @@ var NucleoStanza = class _NucleoStanza {
763
761
  await this.chiama(this.definizione.onConnection, this.room, copiaGiocatore(player), false);
764
762
  await this.concludiEvento();
765
763
  this.inviaGiocatori();
766
- await this.persistiEProgramma();
764
+ await this.persistiEProgramma(true);
767
765
  }
768
766
  async ricevi(connessione, frame, limiteVerificato = false) {
769
767
  if (this.dati === null || this.dati.status === "ended") return;
@@ -901,7 +899,7 @@ var NucleoStanza = class _NucleoStanza {
901
899
  await this.messaggioErrato(player);
902
900
  }
903
901
  async eseguiTick() {
904
- if (this.dati === null || this.dati.status !== "playing" || this.dati.tickRate === 0) return;
902
+ if (this.dati === null || this.dati.status !== "playing" || this.tickRate === 0) return;
905
903
  if (await this.terminaSeInattiva()) return;
906
904
  if (!this.serveTick()) {
907
905
  await this.persistiEProgramma();
@@ -909,14 +907,11 @@ var NucleoStanza = class _NucleoStanza {
909
907
  }
910
908
  const dati = this.dati;
911
909
  dati.tick++;
912
- const inizio = this.adattatore.misuraCpu();
913
910
  await this.chiama(
914
911
  this.definizione.onTick,
915
912
  this.room,
916
- 1 / dati.tickRate
913
+ 1 / this.tickRate
917
914
  );
918
- const durata = Math.max(0, this.adattatore.misuraCpu() - inizio);
919
- this.registraCpu(durata);
920
915
  await this.applicaAzioni();
921
916
  if (dati.status === "ended") return;
922
917
  this.inviaGuadagniCambiati();
@@ -924,13 +919,14 @@ var NucleoStanza = class _NucleoStanza {
924
919
  if (stato === null || this.stanzaTerminata()) return;
925
920
  dati.state = stato.valore;
926
921
  this.inviaDiff();
927
- if (dati.tick % 100 === 0 || this.voceDaPersistire) await this.persisti();
928
- await this.aggiornaProgrammazione();
922
+ await this.persistiEProgramma();
929
923
  }
930
924
  async sveglia() {
931
925
  if (this.dati === null || this.dati.status === "ended") return;
926
+ if (await this.terminaSeVuota()) return;
932
927
  if (await this.terminaSeInattiva()) return;
933
928
  const ora = this.adattatore.ora();
929
+ const statoPrima = this.dati.status;
934
930
  const scaduti = this.dati.giocatori.filter(
935
931
  (player) => !player.connected && player.graziaFinoA !== null && player.graziaFinoA <= ora
936
932
  );
@@ -964,13 +960,10 @@ var NucleoStanza = class _NucleoStanza {
964
960
  }
965
961
  }
966
962
  await this.concludiEvento();
967
- if (!this.stanzaTerminata() && this.dati.giocatori.length === 0 && this.dati.vuotaDa !== null && this.dati.vuotaDa + STANZA_VUOTA_MS <= ora) {
968
- this.dati.cancellaDopoFlush = true;
969
- await this.terminaInterna(null);
970
- }
963
+ await this.terminaSeVuota();
971
964
  if (scaduti.length > 0) this.inviaGiocatori();
972
965
  await this.concludiEvento();
973
- await this.persistiEProgramma();
966
+ await this.persistiEProgramma(scaduti.length > 0 || this.dati.status !== statoPrima);
974
967
  }
975
968
  async preparaFlush() {
976
969
  const dati = this.richiediDati();
@@ -1030,7 +1023,7 @@ var NucleoStanza = class _NucleoStanza {
1030
1023
  }
1031
1024
  await this.concludiEvento();
1032
1025
  this.inviaGiocatori();
1033
- await this.persistiEProgramma();
1026
+ await this.persistiEProgramma(true);
1034
1027
  }
1035
1028
  }
1036
1029
  ruoloAutomatico() {
@@ -1085,6 +1078,7 @@ var NucleoStanza = class _NucleoStanza {
1085
1078
  if (player.team === null) player.team = this.squadraAutomatica();
1086
1079
  if (this.richiediDati().status === "lobby") player.ready = false;
1087
1080
  if (player.role !== ruoloPrecedente || player.team !== squadraPrecedente) {
1081
+ this.salvataggioImmediato = true;
1088
1082
  this.rivediVoce();
1089
1083
  }
1090
1084
  this.inviaGiocatori();
@@ -1098,7 +1092,10 @@ var NucleoStanza = class _NucleoStanza {
1098
1092
  const squadraPrecedente = player.team;
1099
1093
  player.team = team;
1100
1094
  if (this.richiediDati().status === "lobby") player.ready = false;
1101
- if (player.team !== squadraPrecedente) this.rivediVoce();
1095
+ if (player.team !== squadraPrecedente) {
1096
+ this.salvataggioImmediato = true;
1097
+ this.rivediVoce();
1098
+ }
1102
1099
  this.inviaGiocatori();
1103
1100
  this.rivalutaAvvio();
1104
1101
  return null;
@@ -1220,6 +1217,7 @@ var NucleoStanza = class _NucleoStanza {
1220
1217
  const indice = dati.giocatori.findIndex((item) => item.id === player.id);
1221
1218
  if (indice < 0) return;
1222
1219
  dati.giocatori.splice(indice, 1);
1220
+ this.salvataggioImmediato = true;
1223
1221
  if (player.connessione !== null) this.frequenza.delete(player.connessione);
1224
1222
  this.rivediVoce();
1225
1223
  this.pulisciGuadagni(player.id);
@@ -1371,7 +1369,7 @@ var NucleoStanza = class _NucleoStanza {
1371
1369
  rematch: this.rivincitaProtocollo(),
1372
1370
  mode: dati.mode,
1373
1371
  tick: dati.tick,
1374
- tickRate: dati.tickRate,
1372
+ tickRate: this.tickRate,
1375
1373
  serverTime: this.adattatore.ora(),
1376
1374
  countdownAt: dati.countdownAt,
1377
1375
  configuration: {
@@ -1398,12 +1396,11 @@ var NucleoStanza = class _NucleoStanza {
1398
1396
  inviaDiff() {
1399
1397
  const dati = this.richiediDati();
1400
1398
  const patch = creaDiff(dati.statoSincronizzato, dati.state);
1401
- if (patch.length === 0 && this.tickRateSincronizzato === dati.tickRate) return;
1402
- this.tickRateSincronizzato = dati.tickRate;
1399
+ if (patch.length === 0) return;
1403
1400
  this.broadcast({
1404
1401
  t: "state",
1405
1402
  tick: dati.tick,
1406
- tickRate: dati.tickRate,
1403
+ tickRate: this.tickRate,
1407
1404
  base: dati.tickSincronizzato,
1408
1405
  serverTime: this.adattatore.ora(),
1409
1406
  patch
@@ -1418,10 +1415,9 @@ var NucleoStanza = class _NucleoStanza {
1418
1415
  dati.state = stato.valore;
1419
1416
  dati.statoSincronizzato = copiaJson(stato.valore);
1420
1417
  dati.tickSincronizzato = dati.tick;
1421
- this.tickRateSincronizzato = dati.tickRate;
1422
1418
  this.broadcast({
1423
1419
  t: "snapshot",
1424
- tickRate: dati.tickRate,
1420
+ tickRate: this.tickRate,
1425
1421
  tick: dati.tick,
1426
1422
  serverTime: this.adattatore.ora(),
1427
1423
  state: stato.valore
@@ -1469,7 +1465,7 @@ var NucleoStanza = class _NucleoStanza {
1469
1465
  if (stato === null || this.stanzaTerminata()) return;
1470
1466
  const precedente = JSON.stringify(this.dati.statoSincronizzato);
1471
1467
  this.dati.state = stato.valore;
1472
- if ((this.dati.tickRate === 0 || this.dati.status !== "playing") && stato.testo !== precedente) {
1468
+ if ((this.tickRate === 0 || this.dati.status !== "playing") && stato.testo !== precedente) {
1473
1469
  this.dati.tick++;
1474
1470
  this.inviaDiff();
1475
1471
  }
@@ -1506,7 +1502,7 @@ var NucleoStanza = class _NucleoStanza {
1506
1502
  const precedente = dati.voceGuadagni[playerId]?.[altroId] ?? 1;
1507
1503
  if (precedente === valore) return;
1508
1504
  if (precedente > 0 && valore === 0) this.rivediVoce();
1509
- this.voceDaPersistire = true;
1505
+ this.salvataggioImmediato = true;
1510
1506
  if (valore === 1) {
1511
1507
  const riga = dati.voceGuadagni[playerId];
1512
1508
  if (riga !== void 0) {
@@ -1539,15 +1535,12 @@ var NucleoStanza = class _NucleoStanza {
1539
1535
  pulisciGuadagni(playerId) {
1540
1536
  const guadagni = this.richiediDati().voceGuadagni;
1541
1537
  if (guadagni === void 0) return;
1542
- let cambiato = Object.hasOwn(guadagni, playerId);
1543
1538
  delete guadagni[playerId];
1544
1539
  this.voceGuadagniCambiati.delete(playerId);
1545
1540
  for (const [altroId, riga] of Object.entries(guadagni)) {
1546
- cambiato = Object.hasOwn(riga, playerId) || cambiato;
1547
1541
  delete riga[playerId];
1548
1542
  if (Object.keys(riga).length === 0) delete guadagni[altroId];
1549
1543
  }
1550
- if (cambiato) this.voceDaPersistire = true;
1551
1544
  }
1552
1545
  async terminaPerStato(code) {
1553
1546
  const dati = this.richiediDati();
@@ -1558,7 +1551,8 @@ var NucleoStanza = class _NucleoStanza {
1558
1551
  const dati = this.richiediDati();
1559
1552
  if (dati.status === "ended") return;
1560
1553
  const giaFinita = dati.status === "finished";
1561
- if (dati.origin === "matchmaking" && record(result)?.error === void 0) rematch = true;
1554
+ if (dati.giocatori.length === 0) rematch = false;
1555
+ else if (dati.origin === "matchmaking" && record(result)?.error === void 0) rematch = true;
1562
1556
  dati.status = rematch ? "finished" : "ended";
1563
1557
  dati.rivincita = rematch ? { keepSetup: typeof rematch === "object" && rematch.keepSetup === true } : null;
1564
1558
  dati.prontiPrecedenti = rematch ? dati.giocatori.filter((p) => p.ready).map((p) => p.id) : [];
@@ -1601,41 +1595,34 @@ var NucleoStanza = class _NucleoStanza {
1601
1595
  }
1602
1596
  await this.persistiEProgramma();
1603
1597
  }
1604
- registraCpu(durata) {
1605
- const dati = this.richiediDati();
1606
- dati.durateCpu.push(durata);
1607
- if (dati.durateCpu.length > 50) dati.durateCpu.shift();
1608
- dati.cpuOltreCento = durata > 100 ? dati.cpuOltreCento + 1 : 0;
1609
- if (dati.cpuOltreCento >= 20) {
1610
- this.fineRichiesta = { result: { error: "cpu_budget" }, rematch: false };
1611
- return;
1612
- }
1613
- if (dati.durateCpu.length === 50) {
1614
- const media = dati.durateCpu.reduce((somma, value) => somma + value, 0) / 50;
1615
- if (media > 20 && dati.tickRate > 5) {
1616
- dati.tickRate = Math.max(5, Math.floor(dati.tickRate / 2));
1617
- dati.durateCpu = [];
1618
- this.broadcast({
1619
- t: "error",
1620
- code: "tick_rate_reduced",
1621
- message: `Tick rate reduced to ${dati.tickRate} because the game exceeded its CPU budget.`
1622
- });
1598
+ async persistiEProgramma(immediato = false) {
1599
+ const dati = this.dati;
1600
+ const ora = this.adattatore.ora();
1601
+ const tick = this.serveTick(ora);
1602
+ if (dati !== null && (!tick || immediato || this.salvataggioImmediato || ora >= (dati.prossimoSalvataggioAt ?? 0))) {
1603
+ const scadenzaPrima = dati.prossimoSalvataggioAt;
1604
+ dati.prossimoSalvataggioAt = ora + INTERVALLO_SALVATAGGIO_MS;
1605
+ try {
1606
+ await this.adattatore.storage.put(CHIAVE_NUCLEO, dati);
1607
+ } catch (errore) {
1608
+ dati.prossimoSalvataggioAt = scadenzaPrima;
1609
+ this.salvataggioImmediato = true;
1610
+ throw errore;
1623
1611
  }
1612
+ this.salvataggioImmediato = false;
1624
1613
  }
1614
+ await this.aggiornaProgrammazione(tick);
1625
1615
  }
1626
- async persisti() {
1627
- if (this.dati !== null) {
1628
- await this.adattatore.storage.put(CHIAVE_NUCLEO, this.dati);
1629
- this.voceDaPersistire = false;
1630
- }
1631
- }
1632
- async persistiEProgramma() {
1633
- await this.persisti();
1634
- await this.aggiornaProgrammazione();
1616
+ serveTick(ora = this.adattatore.ora()) {
1617
+ const dati = this.dati;
1618
+ return dati !== null && dati.status === "playing" && this.tickRate > 0 && dati.giocatori.some((player) => player.connected) && ora - Math.max(dati.ultimoInputAt, dati.ultimoCambioStatoAt) < RIPOSO_TICK_MS;
1635
1619
  }
1636
- serveTick() {
1620
+ async terminaSeVuota() {
1637
1621
  const dati = this.dati;
1638
- return dati !== null && dati.status === "playing" && dati.tickRate > 0 && dati.giocatori.some((player) => player.connected) && this.adattatore.ora() - Math.max(dati.ultimoInputAt, dati.ultimoCambioStatoAt) < RIPOSO_TICK_MS;
1622
+ if (dati === null || dati.status === "ended" || dati.giocatori.length > 0 || dati.vuotaDa === null || dati.vuotaDa + STANZA_VUOTA_MS > this.adattatore.ora()) return false;
1623
+ dati.cancellaDopoFlush = true;
1624
+ await this.terminaInterna(null);
1625
+ return true;
1639
1626
  }
1640
1627
  async terminaSeInattiva() {
1641
1628
  if (this.dati?.status === "finished") {
@@ -1656,15 +1643,13 @@ var NucleoStanza = class _NucleoStanza {
1656
1643
  await this.terminaInterna({ error: "idle" });
1657
1644
  return true;
1658
1645
  }
1659
- async aggiornaProgrammazione() {
1646
+ async aggiornaProgrammazione(tick = this.serveTick()) {
1660
1647
  if (this.dati === null || this.dati.status === "ended") {
1661
1648
  this.adattatore.programmaTick(null);
1662
1649
  await this.adattatore.programmaSveglia(null);
1663
1650
  return;
1664
1651
  }
1665
- this.adattatore.programmaTick(
1666
- this.serveTick() ? 1e3 / this.dati.tickRate : null
1667
- );
1652
+ this.adattatore.programmaTick(tick ? 1e3 / this.tickRate : null);
1668
1653
  const prossime = [];
1669
1654
  if (this.dati.status === "finished") prossime.push(this.dati.rivincitaFinoA ?? this.adattatore.ora());
1670
1655
  if (this.manifest.persistent === true) {
@@ -1698,7 +1683,7 @@ async function measureNetwork(definition, manifest) {
1698
1683
  const connections = /* @__PURE__ */ new Set();
1699
1684
  const meter = new NetworkMeter();
1700
1685
  let now = Date.now();
1701
- let interval = definition.tickRate > 0 ? 1e3 / definition.tickRate : 50;
1686
+ const interval = definition.tickRate > 0 ? 1e3 / definition.tickRate : 50;
1702
1687
  let error = null;
1703
1688
  let playing = false;
1704
1689
  const adapter = {
@@ -1719,18 +1704,16 @@ async function measureNetwork(definition, manifest) {
1719
1704
  invia(connection, message) {
1720
1705
  if (connections.has(connection)) meter.record(connection, JSON.stringify(message), now);
1721
1706
  if (message.t === "status" && message.status === "playing") playing = true;
1722
- if (message.t === "error" || message.t === "status" && message.result !== null && typeof message.result === "object" && !Array.isArray(message.result) && ["callback_error", "state_too_large", "state_invalid", "cpu_budget"].includes(String(message.result.error))) error = "The server reported an error during the publication probe.";
1707
+ if (message.t === "error" || message.t === "status" && message.result !== null && typeof message.result === "object" && !Array.isArray(message.result) && ["callback_error", "state_too_large", "state_invalid"].includes(String(message.result.error))) error = "The server reported an error during the publication probe.";
1723
1708
  },
1724
1709
  chiudi(connection) {
1725
1710
  connections.delete(connection);
1726
1711
  },
1727
1712
  connessioniAttive: () => [...connections],
1728
1713
  ora: () => now,
1729
- misuraCpu: () => performance.now(),
1730
1714
  rivediVoce() {
1731
1715
  },
1732
- programmaTick(ms) {
1733
- if (ms !== null) interval = ms;
1716
+ programmaTick() {
1734
1717
  },
1735
1718
  async programmaSveglia() {
1736
1719
  }
@@ -1782,8 +1765,8 @@ var ArchivioFacet = class {
1782
1765
  };
1783
1766
  var AdattatoreFacet = class {
1784
1767
  constructor(archivio, tickRate) {
1768
+ this.tickRate = tickRate;
1785
1769
  this.connessioni = /* @__PURE__ */ new Set();
1786
- this.cpuMessaggiOltreCento = 0;
1787
1770
  this.frames = [];
1788
1771
  this.chiusure = [];
1789
1772
  this.sveglia = null;
@@ -1791,22 +1774,15 @@ var AdattatoreFacet = class {
1791
1774
  this.voceRivedi = false;
1792
1775
  this.salvato = "";
1793
1776
  this.storage = new ArchivioFacet(archivio);
1794
- this.tickRate = tickRate;
1795
1777
  }
1796
1778
  async ripristina() {
1797
1779
  const dati = await this.storage.get(CHIAVE_ADATTATORE);
1798
1780
  if (dati === void 0) return;
1799
1781
  for (const connessione of dati.connessioni) this.connessioni.add(connessione);
1800
- this.tickRate = dati.tickRate;
1801
- this.cpuMessaggiOltreCento = dati.cpuMessaggiOltreCento;
1802
- this.salvato = JSON.stringify(dati);
1782
+ this.salvato = JSON.stringify({ connessioni: dati.connessioni });
1803
1783
  }
1804
1784
  async persisti() {
1805
- const dati = {
1806
- connessioni: [...this.connessioni],
1807
- tickRate: this.tickRate,
1808
- cpuMessaggiOltreCento: this.cpuMessaggiOltreCento
1809
- };
1785
+ const dati = { connessioni: [...this.connessioni] };
1810
1786
  const testo = JSON.stringify(dati);
1811
1787
  if (testo === this.salvato) return;
1812
1788
  await this.storage.put(CHIAVE_ADATTATORE, dati);
@@ -1825,15 +1801,11 @@ var AdattatoreFacet = class {
1825
1801
  ora() {
1826
1802
  return Date.now();
1827
1803
  }
1828
- misuraCpu() {
1829
- return performance.now();
1830
- }
1831
1804
  rivediVoce() {
1832
1805
  this.voceRivedi = true;
1833
1806
  }
1834
1807
  programmaTick(intervalloMs) {
1835
1808
  this.tick = intervalloMs !== null;
1836
- if (intervalloMs !== null) this.tickRate = 1e3 / intervalloMs;
1837
1809
  }
1838
1810
  async programmaSveglia(ora) {
1839
1811
  this.sveglia = ora;
@@ -1865,22 +1837,9 @@ function creaFacetStanza(DurableObject, definizione, manifest) {
1865
1837
  this.#roomId = typeof stato.id === "string" ? stato.id : stato.id.name ?? stato.id.toString();
1866
1838
  const adattatore = new AdattatoreFacet(stato.storage, definizione.tickRate);
1867
1839
  this.#adattatore = adattatore;
1868
- const misurata = Object.create(definizione);
1869
- if (definizione.onMessage !== void 0) {
1870
- misurata.onMessage = async (room, player, messaggio) => {
1871
- const inizio = adattatore.misuraCpu();
1872
- try {
1873
- await definizione.onMessage?.(room, player, messaggio);
1874
- } finally {
1875
- const durata = Math.max(0, adattatore.misuraCpu() - inizio);
1876
- adattatore.cpuMessaggiOltreCento = durata > 100 ? adattatore.cpuMessaggiOltreCento + 1 : 0;
1877
- if (adattatore.cpuMessaggiOltreCento >= 20) room.end({ error: "cpu_budget" });
1878
- }
1879
- };
1880
- }
1881
1840
  this.#pronto = stato.blockConcurrencyWhile(async () => {
1882
1841
  await adattatore.ripristina();
1883
- return NucleoStanza.apri(misurata, manifest, adattatore);
1842
+ return NucleoStanza.apri(definizione, manifest, adattatore);
1884
1843
  });
1885
1844
  }
1886
1845
  // Le RPC possono intercalarsi durante un await del creatore: ogni Esito deve restare del suo evento.
@@ -24,7 +24,7 @@ export type VersionNumber = number & {
24
24
  * il numero di versione, questo URL potrebbe servire codice di un altro gioco
25
25
  * dentro l'origine della vittima:
26
26
  *
27
- * https://vittima.caisual.app/rt/v1/<n-di-un-altro-gioco>/index.html
27
+ * https://vittima.caisual.app/rt/v2/<n-di-un-altro-gioco>/index.html
28
28
  *
29
29
  * Con `games/<slug>/<n>/...`, `play` prende lo slug dall'hostname e cerca solo
30
30
  * sotto quel prefisso. I file dell'attaccante non esistono quindi nell'origine
@@ -18,14 +18,14 @@
18
18
  * versione vecchia della trasformazione su un artefatto che non e' cambiato, e
19
19
  * non ci sarebbe modo di invalidarle se non a mano.
20
20
  *
21
- * Mettendo la versione nell'URL il problema sparisce: una trasformazione nuova
22
- * e' `rt/v2`, cioe' un URL nuovo, e le due non si incontrano mai. L'artefatto su
23
- * R2 resta intatto in entrambi i casi.
21
+ * Ogni trasformazione ha una versione nell'URL. Il passaggio a `rt/v2`
22
+ * rende disponibile il segnale di apertura anche con una copia v1 in cache.
23
+ * L'artefatto su R2 resta intatto.
24
24
  */
25
- /** Versioni di runtime che sappiamo servire. Non se ne toglie mai una. */
26
- declare const RUNTIME_VERSIONS: readonly ['v1'];
27
- export type RuntimeVersion = (typeof RUNTIME_VERSIONS)[number];
28
- export declare function isRuntimeVersion(value: string): value is RuntimeVersion;
25
+ /** Versione usata per i link generati oggi. */
26
+ declare const CURRENT_RUNTIME = "v2";
27
+ export type RuntimeVersion = typeof CURRENT_RUNTIME;
28
+ export declare const isRuntimeVersion: (value: string) => value is RuntimeVersion;
29
29
  /**
30
30
  * Path di un file di gioco sull'origine di `play`.
31
31
  * Forma: `/rt/{runtime}/{n}/{path}`.
@@ -84,6 +84,7 @@ export interface HostBridgeInput {
84
84
  onRoom(room: {
85
85
  code: string;
86
86
  } | null): void;
87
+ onApertura?(): void;
87
88
  crew?: CrewOspite;
88
89
  creaCanale?(): MessageChannel;
89
90
  }
@@ -64,8 +64,9 @@ export interface FotografiaStanza {
64
64
  /**
65
65
  * Operazioni voce del client. Ogni richiesta porta `r`, un intero crescente per
66
66
  * connessione: la risposta del server ripete lo stesso `r`. Gli op `session`,
67
- * `subscribe`, `answer` e `close` esistono solo con trasporto `sfu`; `publish` e
68
- * `signal` solo con trasporto `mesh` (sviluppo locale).
67
+ * `subscribe`, `answer` e `close` esistono solo con trasporto `sfu`; `signal` solo
68
+ * con trasporto `mesh` (sviluppo locale). `publish` annuncia il microfono agli altri
69
+ * in tutti e due: con `sfu` va mandato a connessione fatta.
69
70
  */
70
71
  export type MessaggioClientVoce = {
71
72
  t: 'voice';
@@ -7,14 +7,14 @@ export declare class NucleoStanza {
7
7
  private readonly adattatore;
8
8
  private dati;
9
9
  private readonly room;
10
+ private readonly tickRate;
10
11
  private readonly frequenza;
11
12
  private readonly kickRichiesti;
12
13
  private readonly voceGuadagniCambiati;
13
14
  private fineRichiesta;
14
15
  private applicandoAzioni;
15
16
  private ultimoStatoOsservato;
16
- private tickRateSincronizzato;
17
- private voceDaPersistire;
17
+ private salvataggioImmediato;
18
18
  private constructor();
19
19
  static apri(definizione: unknown, manifest: ManifestStanza, adattatore: AdattatoreStanza): Promise<NucleoStanza>;
20
20
  private static verificaManifest;
@@ -92,10 +92,9 @@ export declare class NucleoStanza {
92
92
  private pulisciGuadagni;
93
93
  private terminaPerStato;
94
94
  private terminaInterna;
95
- private registraCpu;
96
- private persisti;
97
95
  private persistiEProgramma;
98
96
  private serveTick;
97
+ private terminaSeVuota;
99
98
  private terminaSeInattiva;
100
99
  private aggiornaProgrammazione;
101
100
  }
@@ -38,7 +38,6 @@ export interface AdattatoreStanza {
38
38
  connessioniAttive(): readonly string[];
39
39
  ora(): number;
40
40
  giorno?(ora: number): string;
41
- misuraCpu(): number;
42
41
  rivediVoce(): void;
43
42
  programmaTick(intervalloMs: number | null): void;
44
43
  programmaSveglia(ora: number | null): Promise<void>;
@@ -75,7 +74,7 @@ export interface StatoPersistito {
75
74
  mode: string | null;
76
75
  status: RoomStatus;
77
76
  tick: number;
78
- tickRate: number;
77
+ prossimoSalvataggioAt?: number;
79
78
  ultimoInputAt: number;
80
79
  ultimoCambioStatoAt: number;
81
80
  state: JsonValue;
@@ -100,8 +99,6 @@ export interface StatoPersistito {
100
99
  cancellaDopoFlush: boolean;
101
100
  tickSincronizzato: number;
102
101
  statoSincronizzato: JsonValue;
103
- durateCpu: number[];
104
- cpuOltreCento: number;
105
102
  voceGuadagni?: Record<string, Record<string, number>>;
106
103
  }
107
104
  export type EsitoIngresso = {
@@ -53,6 +53,8 @@ export declare class VoceClient implements Voice {
53
53
  private timerConnessione;
54
54
  private cancellaAttesaConnessione;
55
55
  private timerRiconnessione;
56
+ private timerAbbonamento;
57
+ private tentativoAbbonamento;
56
58
  private ultimoAudioMic;
57
59
  private sequenzaRichieste;
58
60
  private generazione;
@@ -88,6 +90,7 @@ export declare class VoceClient implements Voice {
88
90
  private attendiConnessione;
89
91
  private accodaRiconciliazione;
90
92
  private riconciliaSfu;
93
+ private riprovaAbbonamento;
91
94
  private riconciliaMesh;
92
95
  private creaMesh;
93
96
  private offriMesh;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caisual/kit",
3
- "version": "0.25.0",
3
+ "version": "0.25.1",
4
4
  "description": "Client and server kit for Caisual games",
5
5
  "license": "MIT",
6
6
  "homepage": "https://caisual.com",
@@ -64,13 +64,13 @@
64
64
  },
65
65
  "devDependencies": {
66
66
  "@caisual/contracts": "workspace:*",
67
- "@cloudflare/vitest-pool-workers": "^0.20.3",
67
+ "@cloudflare/vitest-plugin": "^1.8.3",
68
68
  "@types/node": "^26.2.0",
69
+ "@types/ws": "^8.18.1",
69
70
  "esbuild": "^0.28.1",
71
+ "proper-lockfile": "^4.1.2",
70
72
  "typescript": "^7.0.2",
71
- "vitest": "^4.1.10",
72
- "@types/ws": "^8.18.1",
73
- "proper-lockfile": "^4.1.2"
73
+ "vitest": "^4.1.10"
74
74
  },
75
75
  "dependencies": {
76
76
  "ws": "^8.21.0"