@caisual/kit 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +6 -9
  2. package/dist/host.d.ts +1 -0
  3. package/dist/host.js +169 -0
  4. package/dist/kit.js +2 -4
  5. package/dist/kit.js.map +4 -4
  6. package/dist/node.js +164 -409
  7. package/dist/runtime.js +212 -251
  8. package/dist/types/api.d.ts +1 -1
  9. package/dist/types/contracts/connessione.d.ts +1 -0
  10. package/dist/types/contracts/giornata.d.ts +1 -0
  11. package/dist/types/contracts/index.d.ts +3 -2
  12. package/dist/types/contracts/manifest.d.ts +6 -41
  13. package/dist/types/contracts/network-budget.d.ts +53 -0
  14. package/dist/types/contracts/versioni.d.ts +0 -1
  15. package/dist/types/crew/index.d.ts +4 -0
  16. package/dist/types/handshake.d.ts +0 -4
  17. package/dist/types/{overlay/host-bridge.d.ts → host/index.d.ts} +60 -37
  18. package/dist/types/index.d.ts +64 -50
  19. package/dist/types/node/index.d.ts +6 -23
  20. package/dist/types/protocollo.d.ts +1 -20
  21. package/dist/types/runtime/index.d.ts +4 -11
  22. package/dist/types/runtime/network-probe.d.ts +4 -0
  23. package/dist/types/server/index.d.ts +0 -10
  24. package/dist/types/stanza/nucleo.d.ts +8 -16
  25. package/dist/types/stanza/tipi.d.ts +4 -19
  26. package/dist/types/voce/index.d.ts +0 -1
  27. package/package.json +15 -17
  28. package/dist/overlay.d.ts +0 -1
  29. package/dist/overlay.js +0 -2157
  30. package/dist/overlay.js.map +0 -7
  31. package/dist/types/contracts/overlay.d.ts +0 -235
  32. package/dist/types/contracts/replay.d.ts +0 -83
  33. package/dist/types/overlay/bridge.d.ts +0 -3
  34. package/dist/types/overlay/i18n.d.ts +0 -128
  35. package/dist/types/overlay/index.d.ts +0 -9
  36. package/dist/types/overlay/locale.d.ts +0 -4
  37. package/dist/types/overlay/shortcut.d.ts +0 -4
  38. package/dist/types/overlay/styles.d.ts +0 -1
  39. package/dist/types/overlay/ui-model.d.ts +0 -53
  40. package/dist/types/overlay/ui.d.ts +0 -81
  41. package/dist/types/overlay/voice-panel.d.ts +0 -13
  42. package/dist/types/replay/index.d.ts +0 -65
  43. package/dist/types/session/index.d.ts +0 -49
  44. package/dist/types/session/resume.d.ts +0 -13
package/dist/runtime.js CHANGED
@@ -40,14 +40,9 @@ function risolviModalita(manifest, mode) {
40
40
  return { players: { ...scelta?.players ?? manifest.players }, lobby: scelta?.lobby ?? manifest.lobby };
41
41
  }
42
42
  function modalitaLocale(manifest, mode) {
43
- return mode !== null && manifest.modes.some((voce) => voce.id === mode && voce.execution === "local");
43
+ return risolviModalita(manifest, mode).players.max === 1;
44
44
  }
45
-
46
- // ../contracts/src/replay.ts
47
- var REPLAY_MAX_BYTES = 10 * 1024 * 1024;
48
- var REPLAY_MAX_DURATION_MS = 30 * 60 * 1e3;
49
- var REPLAY_CHUNK_BYTES = 512 * 1024;
50
- var REPLAY_RETENTION_MS = 30 * 24 * 60 * 60 * 1e3;
45
+ var MODE_LOCAL_MESSAGE = "Single-player modes run in the browser and have no room.";
51
46
 
52
47
  // ../contracts/src/room-limits.ts
53
48
  var MASSIMO_BYTE_FRAME_STANZA = 64 * 1024;
@@ -91,6 +86,80 @@ var LimiteMessaggiStanza = class {
91
86
  }
92
87
  };
93
88
 
89
+ // ../contracts/src/network-budget.ts
90
+ var NETWORK_BUDGET = Object.freeze({
91
+ recipientBytesPerSecond: 1e5,
92
+ roomBytesPerSecond: 2e6,
93
+ warningRatio: 0.8,
94
+ windowMs: 5e3,
95
+ blockingWindows: 3
96
+ });
97
+ var NETWORK_GUIDANCE = `Multiplayer budget: ${NETWORK_BUDGET.recipientBytesPerSecond / 1e3} kB/s per recipient, ${NETWORK_BUDGET.roomBytesPerSecond / 1e6} MB/s per room, before compression over 5 seconds. At 20 updates/s, budget ${NETWORK_BUDGET.recipientBytesPerSecond / 2e4} kB per update. Keep visual trails and animation on the client. Warnings start at 80%. Publication measures your server automatically; repeated excess in real matches blocks new rooms only. Game input: 30 messages/s per connection.`;
98
+ function networkLevel(measurement) {
99
+ const ratio = Math.max(
100
+ measurement.recipientBytesPerSecond / NETWORK_BUDGET.recipientBytesPerSecond,
101
+ measurement.roomBytesPerSecond / NETWORK_BUDGET.roomBytesPerSecond
102
+ );
103
+ return ratio > 1 ? "exceeded" : ratio >= NETWORK_BUDGET.warningRatio ? "warning" : "ok";
104
+ }
105
+ var NetworkMeter = class {
106
+ events = [];
107
+ head = 0;
108
+ recipients = /* @__PURE__ */ new Map();
109
+ total = 0;
110
+ peak = { recipientBytesPerSecond: 0, roomBytesPerSecond: 0 };
111
+ checkAt = null;
112
+ violations = 0;
113
+ blocked = false;
114
+ encoder = new TextEncoder();
115
+ record(recipient, text, now = Date.now()) {
116
+ this.advance(now);
117
+ const bytes = this.encoder.encode(text).byteLength;
118
+ this.events.push({ at: now, recipient, bytes });
119
+ const recipientBytes = (this.recipients.get(recipient) ?? 0) + bytes;
120
+ this.recipients.set(recipient, recipientBytes);
121
+ this.total += bytes;
122
+ this.peak.recipientBytesPerSecond = Math.max(this.peak.recipientBytesPerSecond, this.rate(recipientBytes));
123
+ this.peak.roomBytesPerSecond = Math.max(this.peak.roomBytesPerSecond, this.rate(this.total));
124
+ }
125
+ sample(now = Date.now()) {
126
+ this.advance(now);
127
+ return { current: this.current(), peak: { ...this.peak }, consecutiveViolations: this.violations, blocked: this.blocked };
128
+ }
129
+ rate(bytes) {
130
+ return Math.ceil(bytes * 1e3 / NETWORK_BUDGET.windowMs);
131
+ }
132
+ current() {
133
+ let maximum = 0;
134
+ for (const bytes of this.recipients.values()) maximum = Math.max(maximum, bytes);
135
+ return { recipientBytesPerSecond: this.rate(maximum), roomBytesPerSecond: this.rate(this.total) };
136
+ }
137
+ advance(now) {
138
+ this.checkAt ??= now;
139
+ this.expire(now - NETWORK_BUDGET.windowMs, false);
140
+ if (now - this.checkAt >= NETWORK_BUDGET.windowMs) {
141
+ if (now - this.checkAt >= NETWORK_BUDGET.windowMs * 2) this.violations = 0;
142
+ this.violations = networkLevel(this.current()) === "exceeded" ? this.violations + 1 : 0;
143
+ this.blocked ||= this.violations >= NETWORK_BUDGET.blockingWindows;
144
+ this.checkAt = now;
145
+ }
146
+ this.expire(now - NETWORK_BUDGET.windowMs, true);
147
+ if (this.head > 1024) {
148
+ this.events = this.events.slice(this.head);
149
+ this.head = 0;
150
+ }
151
+ }
152
+ expire(cutoff, inclusive) {
153
+ while (this.head < this.events.length && (inclusive ? this.events[this.head].at <= cutoff : this.events[this.head].at < cutoff)) {
154
+ const event = this.events[this.head++];
155
+ this.total -= event.bytes;
156
+ const remaining = this.recipients.get(event.recipient) - event.bytes;
157
+ if (remaining === 0) this.recipients.delete(event.recipient);
158
+ else this.recipients.set(event.recipient, remaining);
159
+ }
160
+ }
161
+ };
162
+
94
163
  // src/daily.ts
95
164
  function prossimaMezzanotteUtc(ora) {
96
165
  return (Math.floor(ora / 864e5) + 1) * 864e5;
@@ -327,8 +396,6 @@ var PREFISSO_SAVE = "save:";
327
396
  var LIMITE_FRAME = MASSIMO_BYTE_FRAME_STANZA;
328
397
  var LIMITE_STATO = 512 * 1024;
329
398
  var LIMITE_SAVE = 256 * 1024;
330
- var LIMITE_DEPOSITO = 256 * 1024;
331
- var LIMITE_OPERAZIONI_DEPOSITO = 120;
332
399
  var GRAZIA_MS = 6e4;
333
400
  var STANZA_VUOTA_MS = 5 * 6e4;
334
401
  var ATTESA_RIVINCITA_MS = 2 * 6e4;
@@ -341,16 +408,7 @@ function scadenzaInattivita(ultimoEvento, durata) {
341
408
  return Math.ceil((ultimoEvento + durata) / BLOCCO_INATTIVITA_MS) * BLOCCO_INATTIVITA_MS;
342
409
  }
343
410
  var CHIAVE = /^[a-z0-9][a-z0-9_-]{0,31}$/;
344
- var PREFISSO_CHIAVE = /^[a-z0-9_-]{0,32}$/;
345
411
  var GAME_DEFINITION = /* @__PURE__ */ Symbol.for("@caisual/kit/game-definition");
346
- var CODICI_DEPOSITO = /* @__PURE__ */ new Set([
347
- "store_invalid_key",
348
- "store_too_large",
349
- "store_full",
350
- "store_not_integer",
351
- "store_unavailable",
352
- "store_rate_limited"
353
- ]);
354
412
  function record(value) {
355
413
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
356
414
  }
@@ -388,7 +446,6 @@ var NucleoStanza = class _NucleoStanza {
388
446
  this.adattatore = adattatore;
389
447
  this.dati = null;
390
448
  this.frequenza = new LimiteMessaggiStanza();
391
- this.frequenzaDeposito = [];
392
449
  this.kickRichiesti = /* @__PURE__ */ new Set();
393
450
  this.voceGuadagniCambiati = /* @__PURE__ */ new Map();
394
451
  this.fineRichiesta = null;
@@ -439,11 +496,6 @@ var NucleoStanza = class _NucleoStanza {
439
496
  get players() {
440
497
  return nucleo.richiediDati().giocatori.map(copiaGiocatore);
441
498
  },
442
- get host() {
443
- const dati = nucleo.richiediDati();
444
- const host = dati.giocatori.find((player) => player.id === dati.hostId);
445
- return host === void 0 ? null : copiaGiocatore(host);
446
- },
447
499
  broadcast(message) {
448
500
  nucleo.broadcastCreatore(message);
449
501
  },
@@ -468,23 +520,6 @@ var NucleoStanza = class _NucleoStanza {
468
520
  load(key) {
469
521
  return nucleo.caricaSave(key);
470
522
  },
471
- shared: {
472
- get(key) {
473
- return nucleo.leggiDeposito(key);
474
- },
475
- set(key, value) {
476
- return nucleo.scriviDeposito(key, value);
477
- },
478
- delete(key) {
479
- return nucleo.eliminaDeposito(key);
480
- },
481
- list(prefix) {
482
- return nucleo.elencaDeposito(prefix);
483
- },
484
- increment(key, amount = 1) {
485
- return nucleo.incrementaDeposito(key, amount);
486
- }
487
- },
488
523
  schedule(milliseconds, handler, payload) {
489
524
  nucleo.pianifica(milliseconds, handler, payload);
490
525
  },
@@ -514,9 +549,11 @@ var NucleoStanza = class _NucleoStanza {
514
549
  const nucleo = new _NucleoStanza(definizione, manifest, adattatore);
515
550
  const salvato = await adattatore.storage.get(CHIAVE_NUCLEO);
516
551
  if (salvato !== void 0) {
552
+ if (modalitaLocale(manifest, salvato.mode)) throw Object.assign(new Error(MODE_LOCAL_MESSAGE), { code: "mode_local" });
517
553
  nucleo.dati = salvato;
518
554
  nucleo.tickRateSincronizzato = salvato.tickRate;
519
- const daAggiornare = salvato.ultimoInputAt === void 0 || salvato.ultimoCambioStatoAt === void 0 || salvato.daily === void 0;
555
+ const daAggiornare = salvato.ultimoInputAt === void 0 || salvato.ultimoCambioStatoAt === void 0 || salvato.daily === void 0 || salvato.origin === void 0;
556
+ salvato.origin ??= "player";
520
557
  salvato.daily ??= nucleo.contestoGiornaliero();
521
558
  salvato.ultimoInputAt ??= adattatore.ora();
522
559
  salvato.ultimoCambioStatoAt ??= salvato.ultimoInputAt;
@@ -542,13 +579,13 @@ var NucleoStanza = class _NucleoStanza {
542
579
  get esiste() {
543
580
  return this.dati !== null;
544
581
  }
545
- async crea(id, mode, _creator) {
582
+ async crea(id, mode, _creator, origin = "player") {
546
583
  if (this.dati !== null) return false;
547
- risolviModalita(this.manifest, mode);
548
- if (modalitaLocale(this.manifest, mode)) throw new Error("Local modes cannot create rooms.");
584
+ if (modalitaLocale(this.manifest, mode)) throw Object.assign(new Error(MODE_LOCAL_MESSAGE), { code: "mode_local" });
549
585
  const ora = this.adattatore.ora();
550
586
  this.dati = {
551
587
  versione: 1,
588
+ origin,
552
589
  daily: this.contestoGiornaliero(ora),
553
590
  id,
554
591
  mode,
@@ -559,13 +596,11 @@ var NucleoStanza = class _NucleoStanza {
559
596
  ultimoCambioStatoAt: ora,
560
597
  state: {},
561
598
  giocatori: [],
562
- hostId: null,
563
599
  result: null,
564
600
  resultAt: null,
565
601
  countdownAt: null,
566
602
  timer: [],
567
603
  prossimoTimerId: 1,
568
- punteggi: [],
569
604
  fineInCoda: null,
570
605
  vuotaDa: ora,
571
606
  cancellaDopoFlush: false,
@@ -593,12 +628,14 @@ var NucleoStanza = class _NucleoStanza {
593
628
  }
594
629
  get configurazione() {
595
630
  const mode = risolviModalita(this.manifest, this.dati?.mode ?? null);
596
- return mode.players.max === 1 ? { ...mode, lobby: false } : mode;
631
+ return this.dati?.origin === "matchmaking" ? mode : { ...mode, lobby: true };
597
632
  }
598
633
  info(playerId) {
599
634
  if (this.dati === null) return null;
600
635
  return {
601
636
  roomId: this.dati.id,
637
+ origin: this.dati.origin,
638
+ lobby: this.configurazione.lobby,
602
639
  status: this.dati.status,
603
640
  players: this.manifest.persistent === true ? this.dati.giocatori.length : this.dati.giocatori.filter(
604
641
  (player) => player.connected || player.graziaFinoA !== null
@@ -632,7 +669,7 @@ var NucleoStanza = class _NucleoStanza {
632
669
  if (ascoltatore === void 0 || speaker === void 0 || listener === speakerId) {
633
670
  return { ok: false, reason: "unknown" };
634
671
  }
635
- if (mode === "team" && ascoltatore.role !== "spectator" && ascoltatore.team !== speaker.team) {
672
+ if (mode === "team" && ascoltatore.team !== speaker.team) {
636
673
  return { ok: false, reason: "team" };
637
674
  }
638
675
  if ((dati.voceGuadagni?.[listener]?.[speakerId] ?? 1) <= 0) {
@@ -646,12 +683,15 @@ var NucleoStanza = class _NucleoStanza {
646
683
  if (this.dati.status === "ended") return { ok: false, code: "room_ended" };
647
684
  const esistente = this.dati.giocatori.find((player) => player.id === identity.id);
648
685
  if (esistente !== void 0) return { ok: true };
649
- if (this.configurazione.lobby && !["lobby", "finished"].includes(this.dati.status)) {
686
+ if (this.configurazione.lobby && !["lobby", "countdown", "finished"].includes(this.dati.status)) {
650
687
  return { ok: false, code: "room_playing" };
651
688
  }
652
689
  if (this.dati.giocatori.length >= this.configurazione.players.max) {
653
690
  return { ok: false, code: "room_full" };
654
691
  }
692
+ if (this.manifest.roles.length > 0 && this.ruoloAutomatico() === null) {
693
+ return { ok: false, code: "room_full" };
694
+ }
655
695
  return { ok: true };
656
696
  }
657
697
  async entra(identity, connessione) {
@@ -691,7 +731,6 @@ var NucleoStanza = class _NucleoStanza {
691
731
  player.connessione = connessione;
692
732
  player.seq = 0;
693
733
  }
694
- dati.hostId ??= player.id;
695
734
  dati.vuotaDa = null;
696
735
  dati.ultimoInputAt = ora;
697
736
  const primaConnessione = !this.configurazione.lobby && dati.status === "lobby";
@@ -708,7 +747,6 @@ var NucleoStanza = class _NucleoStanza {
708
747
  }
709
748
  if (primaConnessione) {
710
749
  await this.chiama(this.definizione.onStart, this.room);
711
- this.iniziaReplay();
712
750
  this.inviaStatus(ora);
713
751
  }
714
752
  await this.concludiEvento();
@@ -716,6 +754,7 @@ var NucleoStanza = class _NucleoStanza {
716
754
  this.inviaWelcome(player);
717
755
  this.inviaSnapshotTutti();
718
756
  this.inviaGiocatori();
757
+ this.rivalutaAvvio();
719
758
  }
720
759
  await this.persistiEProgramma();
721
760
  return { ok: true };
@@ -729,10 +768,9 @@ var NucleoStanza = class _NucleoStanza {
729
768
  player.connected = false;
730
769
  player.connessione = null;
731
770
  player.graziaFinoA = this.adattatore.ora() + GRAZIA_MS;
732
- if (this.dati.status === "finished" || this.manifest.persistent === true && this.dati.status === "lobby") player.ready = false;
771
+ if (this.dati.status === "finished" || this.manifest.persistent === true && ["lobby", "countdown"].includes(this.dati.status)) player.ready = false;
733
772
  this.frequenza.delete(connessione);
734
- if (this.dati.hostId === player.id) this.assegnaHost();
735
- this.verificaCountdown();
773
+ this.rivalutaAvvio();
736
774
  await this.chiama(this.definizione.onConnection, this.room, copiaGiocatore(player), false);
737
775
  await this.concludiEvento();
738
776
  this.inviaGiocatori();
@@ -799,6 +837,7 @@ var NucleoStanza = class _NucleoStanza {
799
837
  this.dati.ultimoInputAt = ora;
800
838
  player.ready = message.ready;
801
839
  this.inviaGiocatori();
840
+ this.rivalutaAvvio();
802
841
  await this.persistiEProgramma();
803
842
  return;
804
843
  }
@@ -840,12 +879,6 @@ var NucleoStanza = class _NucleoStanza {
840
879
  await this.persistiEProgramma();
841
880
  return;
842
881
  }
843
- if (message.t === "start") {
844
- if (!this.inLobby(player)) return;
845
- this.dati.ultimoInputAt = ora;
846
- await this.avviaCountdown(player);
847
- return;
848
- }
849
882
  if (message.t === "msg") {
850
883
  if (!Number.isSafeInteger(message.seq) || message.seq < 1) {
851
884
  await this.messaggioErrato(player);
@@ -859,11 +892,6 @@ var NucleoStanza = class _NucleoStanza {
859
892
  return;
860
893
  }
861
894
  player.seq = seq;
862
- if (player.role === "spectator") {
863
- this.inviaErrore(player, "spectator", "Spectators cannot send game input.");
864
- await this.persistiEProgramma();
865
- return;
866
- }
867
895
  if (this.dati.status === "finished") return;
868
896
  this.dati.ultimoInputAt = ora;
869
897
  await this.chiama(
@@ -928,7 +956,6 @@ var NucleoStanza = class _NucleoStanza {
928
956
  this.dati.ultimoInputAt = ora;
929
957
  this.dati.countdownAt = null;
930
958
  await this.chiama(this.definizione.onStart, this.room);
931
- this.iniziaReplay();
932
959
  this.inviaStatus(ora);
933
960
  }
934
961
  }
@@ -957,9 +984,8 @@ var NucleoStanza = class _NucleoStanza {
957
984
  await this.persistiEProgramma();
958
985
  return dati.flushInAttesa;
959
986
  }
960
- if (dati.punteggi.length === 0 && dati.fineInCoda === null) return null;
961
- dati.flushInAttesa = { id: crypto.randomUUID(), scores: dati.punteggi, ended: dati.fineInCoda };
962
- dati.punteggi = [];
987
+ if (dati.fineInCoda === null) return null;
988
+ dati.flushInAttesa = { id: crypto.randomUUID(), ended: dati.fineInCoda };
963
989
  dati.fineInCoda = null;
964
990
  await this.persistiEProgramma();
965
991
  return dati.flushInAttesa;
@@ -973,10 +999,8 @@ var NucleoStanza = class _NucleoStanza {
973
999
  async flush() {
974
1000
  const dati = this.richiediDati();
975
1001
  const esito = {
976
- scores: dati.punteggi.map((score) => ({ ...score })),
977
1002
  ended: dati.fineInCoda === null ? null : { result: dati.fineInCoda.result, at: dati.fineInCoda.at }
978
1003
  };
979
- dati.punteggi = [];
980
1004
  dati.fineInCoda = null;
981
1005
  if (dati.cancellaDopoFlush && dati.status === "ended") {
982
1006
  const chiavi = await this.adattatore.storage.list();
@@ -1001,13 +1025,12 @@ var NucleoStanza = class _NucleoStanza {
1001
1025
  if (player.connessione !== null) this.frequenza.delete(player.connessione);
1002
1026
  player.connessione = null;
1003
1027
  player.graziaFinoA = ora + GRAZIA_MS;
1004
- if (dati.status === "finished" || this.manifest.persistent === true && dati.status === "lobby") player.ready = false;
1028
+ if (dati.status === "finished" || this.manifest.persistent === true && ["lobby", "countdown"].includes(dati.status)) player.ready = false;
1005
1029
  disconnessi.push(player);
1006
1030
  }
1007
1031
  }
1008
1032
  if (disconnessi.length > 0) {
1009
- this.assegnaHost();
1010
- this.verificaCountdown();
1033
+ this.rivalutaAvvio();
1011
1034
  for (const player of disconnessi) {
1012
1035
  await this.chiama(this.definizione.onConnection, this.room, copiaGiocatore(player), false);
1013
1036
  }
@@ -1030,7 +1053,7 @@ var NucleoStanza = class _NucleoStanza {
1030
1053
  const mancaB = countB < b.min ? 0 : 1;
1031
1054
  return mancaA - mancaB || countA - countB;
1032
1055
  });
1033
- return candidati[0]?.id ?? "spectator";
1056
+ return candidati[0]?.id ?? null;
1034
1057
  }
1035
1058
  squadraAutomatica() {
1036
1059
  if (this.manifest.teams === null) return null;
@@ -1053,39 +1076,37 @@ var NucleoStanza = class _NucleoStanza {
1053
1076
  }
1054
1077
  cambiaRuolo(player, roleId) {
1055
1078
  const ruolo = this.manifest.roles.find((item) => item.id === roleId);
1056
- if (ruolo === void 0 && roleId !== "spectator") {
1079
+ if (ruolo === void 0) {
1057
1080
  return { code: "invalid_role", message: "This role does not exist." };
1058
1081
  }
1059
1082
  const occupati = this.richiediDati().giocatori.filter(
1060
1083
  (item) => item.id !== player.id && item.role === roleId
1061
1084
  ).length;
1062
- if (ruolo?.max !== void 0 && occupati >= ruolo.max) {
1085
+ if (ruolo.max !== void 0 && occupati >= ruolo.max) {
1063
1086
  return { code: "role_full", message: "This role is full." };
1064
1087
  }
1065
1088
  const ruoloPrecedente = player.role;
1066
1089
  const squadraPrecedente = player.team;
1067
1090
  player.role = roleId;
1068
- if (roleId === "spectator") player.team = null;
1069
- else if (player.team === null) player.team = this.squadraAutomatica();
1091
+ if (player.team === null) player.team = this.squadraAutomatica();
1070
1092
  if (this.richiediDati().status === "lobby") player.ready = false;
1071
1093
  if (player.role !== ruoloPrecedente || player.team !== squadraPrecedente) {
1072
1094
  this.rivediVoce();
1073
1095
  }
1074
1096
  this.inviaGiocatori();
1097
+ this.rivalutaAvvio();
1075
1098
  return null;
1076
1099
  }
1077
1100
  cambiaSquadra(player, team) {
1078
1101
  if (this.manifest.teams === null || !Number.isInteger(team) || team < 1 || team > this.manifest.teams.max) {
1079
1102
  return { code: "invalid_team", message: "This team does not exist." };
1080
1103
  }
1081
- if (player.role === "spectator") {
1082
- return { code: "spectator", message: "Spectators cannot join a team." };
1083
- }
1084
1104
  const squadraPrecedente = player.team;
1085
1105
  player.team = team;
1086
1106
  if (this.richiediDati().status === "lobby") player.ready = false;
1087
1107
  if (player.team !== squadraPrecedente) this.rivediVoce();
1088
1108
  this.inviaGiocatori();
1109
+ this.rivalutaAvvio();
1089
1110
  return null;
1090
1111
  }
1091
1112
  impostaRuoloDalServer(playerId, roleId) {
@@ -1107,21 +1128,20 @@ var NucleoStanza = class _NucleoStanza {
1107
1128
  }
1108
1129
  erroreMinimi(saltaPronti = false) {
1109
1130
  const connessi = this.richiediDati().giocatori.filter((player) => player.connected);
1110
- const attivi = connessi.filter((player) => player.role !== "spectator");
1111
- if (attivi.length < this.configurazione.players.min) {
1131
+ if (connessi.length < this.configurazione.players.min) {
1112
1132
  return { code: "not_enough_players", message: "The room does not have enough players." };
1113
1133
  }
1114
1134
  if (!saltaPronti && connessi.some((player) => !player.ready)) {
1115
1135
  return { code: "players_not_ready", message: "Every connected player must be ready." };
1116
1136
  }
1117
1137
  for (const role of this.manifest.roles) {
1118
- if (attivi.filter((player) => player.role === role.id).length < role.min) {
1138
+ if (connessi.filter((player) => player.role === role.id).length < role.min) {
1119
1139
  return { code: "role_minimum", message: `Role ${role.id} does not meet its minimum.` };
1120
1140
  }
1121
1141
  }
1122
1142
  if (this.manifest.teams !== null) {
1123
- const squadre = new Set(attivi.map((player) => player.team).filter((team) => team !== null));
1124
- if (attivi.some((player) => player.team === null) || squadre.size < this.manifest.teams.min) {
1143
+ const squadre = new Set(connessi.map((player) => player.team).filter((team) => team !== null));
1144
+ if (connessi.some((player) => player.team === null) || squadre.size < this.manifest.teams.min) {
1125
1145
  return { code: "team_minimum", message: "The room does not have enough teams." };
1126
1146
  }
1127
1147
  }
@@ -1133,32 +1153,20 @@ var NucleoStanza = class _NucleoStanza {
1133
1153
  this.inviaErrore(player, "rematch_unavailable", "This room is not waiting for a rematch.");
1134
1154
  return;
1135
1155
  }
1136
- if (this.configurazione.players.max === 1) {
1137
- await this.avviaRivincita();
1138
- return;
1139
- }
1140
- if (player.role !== "spectator" && !player.ready) {
1141
- player.ready = true;
1142
- this.inviaGiocatori();
1143
- if (dati.rivincita?.autoStart && this.prontiRivincita()) await this.avviaRivincita();
1144
- else await this.persistiEProgramma();
1145
- return;
1146
- }
1147
- if (dati.hostId !== player.id) return;
1148
- if (!this.prontiRivincita(dati.rivincita?.autoStart === true)) {
1149
- this.inviaErrore(player, "players_not_ready", "Enough connected players must be ready for the rematch.");
1150
- return;
1151
- }
1152
- await this.avviaRivincita();
1156
+ if (player.ready) return;
1157
+ player.ready = true;
1158
+ this.inviaGiocatori();
1159
+ if (this.prontiRivincita()) await this.avviaRivincita();
1160
+ else await this.persistiEProgramma();
1153
1161
  }
1154
- prontiRivincita(anticipata = false) {
1155
- const attivi = this.richiediDati().giocatori.filter((item) => item.connected && item.role !== "spectator");
1156
- return attivi.filter((item) => item.ready).length >= this.configurazione.players.min && (anticipata || attivi.every((item) => item.ready));
1162
+ prontiRivincita() {
1163
+ const attivi = this.richiediDati().giocatori.filter((item) => item.connected);
1164
+ return attivi.filter((item) => item.ready).length >= this.configurazione.players.min && attivi.every((item) => item.ready);
1157
1165
  }
1158
1166
  async avviaRivincita() {
1159
- const dati = this.richiediDati(), solo = this.configurazione.players.max === 1;
1160
- const keepSetup = dati.rivincita?.keepSetup === true && !solo;
1161
- dati.status = solo ? "playing" : keepSetup ? "countdown" : this.configurazione.lobby ? "lobby" : "playing";
1167
+ const dati = this.richiediDati();
1168
+ const keepSetup = dati.rivincita?.keepSetup === true;
1169
+ dati.status = keepSetup ? "countdown" : this.configurazione.lobby ? "lobby" : "playing";
1162
1170
  dati.countdownRivincita = keepSetup;
1163
1171
  dati.countdownAt = keepSetup ? this.adattatore.ora() + COUNTDOWN_MS : null;
1164
1172
  dati.rivincitaFinoA = null;
@@ -1172,7 +1180,6 @@ var NucleoStanza = class _NucleoStanza {
1172
1180
  await this.applicaAzioni();
1173
1181
  if (dati.status === "playing") {
1174
1182
  await this.chiama(this.definizione.onStart, this.room);
1175
- this.iniziaReplay();
1176
1183
  }
1177
1184
  await this.concludiEvento();
1178
1185
  if (dati.status === "lobby" || dati.status === "playing" || dati.status === "countdown") {
@@ -1182,29 +1189,25 @@ var NucleoStanza = class _NucleoStanza {
1182
1189
  }
1183
1190
  await this.persistiEProgramma();
1184
1191
  }
1185
- async avviaCountdown(player) {
1192
+ /**
1193
+ * Nessuno ospita e nessuno preme "inizia": appena tutti i connessi sono pronti e i
1194
+ * minimi di giocatori, ruoli e squadre sono rispettati parte il countdown; se la
1195
+ * condizione cade durante il countdown si torna in lobby.
1196
+ */
1197
+ rivalutaAvvio() {
1186
1198
  const dati = this.richiediDati();
1187
- if (dati.hostId !== player.id) {
1188
- this.inviaErrore(player, "not_host", "Only the host can start the game.");
1189
- return;
1190
- }
1191
- const errore = this.erroreMinimi();
1192
- if (errore !== null) {
1193
- this.inviaErrore(player, errore.code, errore.message);
1199
+ if (dati.status === "countdown") {
1200
+ if (this.erroreMinimi(dati.countdownRivincita) === null) return;
1201
+ dati.status = "lobby";
1202
+ dati.countdownAt = null;
1203
+ this.inviaStatus(this.adattatore.ora());
1194
1204
  return;
1195
1205
  }
1206
+ if (dati.status !== "lobby" || this.erroreMinimi() !== null) return;
1196
1207
  dati.status = "countdown";
1197
1208
  dati.countdownRivincita = false;
1198
1209
  dati.countdownAt = this.adattatore.ora() + COUNTDOWN_MS;
1199
1210
  this.inviaStatus(dati.countdownAt);
1200
- await this.persistiEProgramma();
1201
- }
1202
- verificaCountdown() {
1203
- const dati = this.richiediDati();
1204
- if (dati.status !== "countdown" || this.erroreMinimi(dati.countdownRivincita) === null) return;
1205
- dati.status = "lobby";
1206
- dati.countdownAt = null;
1207
- this.inviaStatus(this.adattatore.ora());
1208
1211
  }
1209
1212
  async messaggioErrato(player) {
1210
1213
  await this.chiudiConnessione(player, 4009, "bad_message");
@@ -1222,7 +1225,6 @@ var NucleoStanza = class _NucleoStanza {
1222
1225
  if (player.connessione !== null) this.frequenza.delete(player.connessione);
1223
1226
  this.rivediVoce();
1224
1227
  this.pulisciGuadagni(player.id);
1225
- if (dati.hostId === player.id) this.assegnaHost();
1226
1228
  if (dati.giocatori.length === 0) dati.vuotaDa = this.adattatore.ora();
1227
1229
  await this.chiama(
1228
1230
  this.definizione.onLeave,
@@ -1230,12 +1232,7 @@ var NucleoStanza = class _NucleoStanza {
1230
1232
  copiaGiocatore({ ...player, connected: false, connessione: null }),
1231
1233
  reason
1232
1234
  );
1233
- this.verificaCountdown();
1234
- }
1235
- assegnaHost() {
1236
- const dati = this.richiediDati();
1237
- const host = dati.giocatori.filter((player) => player.connected).sort((a, b) => a.entratoAt - b.entratoAt)[0];
1238
- dati.hostId = host?.id ?? null;
1235
+ this.rivalutaAvvio();
1239
1236
  }
1240
1237
  async eseguiTimer(timer) {
1241
1238
  const value = this.definizione[timer.handler];
@@ -1301,91 +1298,6 @@ var NucleoStanza = class _NucleoStanza {
1301
1298
  if (!json.ok) throw new Error("The saved value is invalid.");
1302
1299
  return json.valore;
1303
1300
  }
1304
- verificaChiaveDeposito(key) {
1305
- if (typeof key !== "string" || !CHIAVE.test(key)) {
1306
- throw erroreConCodice(
1307
- "store_invalid_key",
1308
- "Shared store keys must use lowercase letters, numbers, underscores, or hyphens."
1309
- );
1310
- }
1311
- }
1312
- verificaPrefissoDeposito(prefix) {
1313
- if (prefix !== void 0 && (typeof prefix !== "string" || !PREFISSO_CHIAVE.test(prefix))) {
1314
- throw erroreConCodice(
1315
- "store_invalid_key",
1316
- "Shared store prefixes may contain lowercase letters, numbers, underscores, or hyphens."
1317
- );
1318
- }
1319
- }
1320
- contaOperazioneDeposito() {
1321
- const ora = this.adattatore.ora();
1322
- this.frequenzaDeposito = this.frequenzaDeposito.filter((at) => ora - at < 6e4);
1323
- if (this.frequenzaDeposito.length >= LIMITE_OPERAZIONI_DEPOSITO) {
1324
- throw erroreConCodice(
1325
- "store_rate_limited",
1326
- "The shared store allows at most 120 operations per minute for each room."
1327
- );
1328
- }
1329
- this.frequenzaDeposito.push(ora);
1330
- }
1331
- async usaDeposito(operazione) {
1332
- this.contaOperazioneDeposito();
1333
- const deposito = this.adattatore.deposito;
1334
- if (deposito === null) {
1335
- throw erroreConCodice("store_unavailable", "The shared store is unavailable.");
1336
- }
1337
- try {
1338
- return await operazione(deposito);
1339
- } catch (cause) {
1340
- const code = cause instanceof Error ? cause.code : void 0;
1341
- if (typeof code === "string" && CODICI_DEPOSITO.has(code)) throw cause;
1342
- throw erroreConCodice("store_unavailable", "The shared store is unavailable.");
1343
- }
1344
- }
1345
- async leggiDeposito(key) {
1346
- this.verificaChiaveDeposito(key);
1347
- const value = await this.usaDeposito((deposito) => deposito.get(key));
1348
- if (value === null) return null;
1349
- try {
1350
- return JSON.parse(JSON.stringify(value));
1351
- } catch {
1352
- throw erroreConCodice("store_unavailable", "The shared store returned invalid data.");
1353
- }
1354
- }
1355
- async scriviDeposito(key, value) {
1356
- this.verificaChiaveDeposito(key);
1357
- const json = analizzaJson(value);
1358
- if (!json.ok || json.bytes > LIMITE_DEPOSITO) {
1359
- throw erroreConCodice(
1360
- "store_too_large",
1361
- "Shared store values must be valid JSON of at most 262144 bytes."
1362
- );
1363
- }
1364
- await this.usaDeposito((deposito) => deposito.set(key, json.valore));
1365
- }
1366
- async eliminaDeposito(key) {
1367
- this.verificaChiaveDeposito(key);
1368
- await this.usaDeposito((deposito) => deposito.delete(key));
1369
- }
1370
- async elencaDeposito(prefix) {
1371
- this.verificaPrefissoDeposito(prefix);
1372
- const keys = await this.usaDeposito((deposito) => deposito.list(prefix));
1373
- if (!Array.isArray(keys) || keys.some((key) => typeof key !== "string" || !CHIAVE.test(key))) {
1374
- throw erroreConCodice("store_unavailable", "The shared store returned invalid keys.");
1375
- }
1376
- return [...keys].sort().slice(0, 4096);
1377
- }
1378
- async incrementaDeposito(key, amount) {
1379
- this.verificaChiaveDeposito(key);
1380
- if (!Number.isSafeInteger(amount)) {
1381
- throw erroreConCodice("store_not_integer", "Shared store increments must be safe integers.");
1382
- }
1383
- const value = await this.usaDeposito((deposito) => deposito.increment(key, amount));
1384
- if (!Number.isSafeInteger(value)) {
1385
- throw erroreConCodice("store_unavailable", "The shared store returned an invalid integer.");
1386
- }
1387
- return value;
1388
- }
1389
1301
  messaggioCreatore(message) {
1390
1302
  const json = analizzaJson(message);
1391
1303
  if (!json.ok) throw new TypeError("Messages must be valid JSON.");
@@ -1412,7 +1324,6 @@ var NucleoStanza = class _NucleoStanza {
1412
1324
  this.adattatore.invia(player.connessione, message);
1413
1325
  }
1414
1326
  }
1415
- if (message.t !== "flush") this.adattatore.pubblica(message);
1416
1327
  }
1417
1328
  inviaErrore(player, code, message) {
1418
1329
  if (player.connected && player.connessione !== null) {
@@ -1457,7 +1368,6 @@ var NucleoStanza = class _NucleoStanza {
1457
1368
  tick: dati.tick,
1458
1369
  tickRate: dati.tickRate,
1459
1370
  serverTime: this.adattatore.ora(),
1460
- host: dati.hostId,
1461
1371
  countdownAt: dati.countdownAt,
1462
1372
  configuration: {
1463
1373
  players: { ...this.configurazione.players },
@@ -1468,7 +1378,7 @@ var NucleoStanza = class _NucleoStanza {
1468
1378
  };
1469
1379
  }
1470
1380
  inviaGiocatori() {
1471
- this.broadcast({ t: "players", players: this.giocatoriProtocollo(), host: this.richiediDati().hostId });
1381
+ this.broadcast({ t: "players", players: this.giocatoriProtocollo() });
1472
1382
  }
1473
1383
  inviaStatus(at) {
1474
1384
  const dati = this.richiediDati();
@@ -1476,7 +1386,6 @@ var NucleoStanza = class _NucleoStanza {
1476
1386
  t: "status",
1477
1387
  rematch: dati.status === "finished" ? dati.rivincita ?? null : null,
1478
1388
  status: dati.status,
1479
- host: dati.hostId,
1480
1389
  countdownAt: dati.countdownAt,
1481
1390
  at,
1482
1391
  result: dati.status === "ended" || dati.status === "finished" ? dati.result : null
@@ -1498,13 +1407,6 @@ var NucleoStanza = class _NucleoStanza {
1498
1407
  dati.statoSincronizzato = copiaJson(dati.state);
1499
1408
  dati.tickSincronizzato = dati.tick;
1500
1409
  }
1501
- iniziaReplay() {
1502
- if (!this.manifest.replays || !this.adattatore.inizioReplay) return;
1503
- const json = analizzaJson(this.richiediDati().state);
1504
- if (!json.ok || json.bytes > LIMITE_STATO) return;
1505
- this.inviaSnapshotTutti();
1506
- this.adattatore.inizioReplay(this.fotografia());
1507
- }
1508
1410
  inviaSnapshotTutti() {
1509
1411
  const dati = this.richiediDati();
1510
1412
  const stato = analizzaJson(dati.state);
@@ -1554,7 +1456,7 @@ var NucleoStanza = class _NucleoStanza {
1554
1456
  async concludiEvento() {
1555
1457
  await this.applicaAzioni();
1556
1458
  if (this.dati === null || this.dati.status === "ended") return;
1557
- if (this.dati.status === "finished" && this.dati.rivincita?.autoStart && this.prontiRivincita()) {
1459
+ if (this.dati.status === "finished" && this.dati.rivincita !== null && this.prontiRivincita()) {
1558
1460
  await this.avviaRivincita();
1559
1461
  return;
1560
1462
  }
@@ -1653,10 +1555,7 @@ var NucleoStanza = class _NucleoStanza {
1653
1555
  if (dati.status === "ended") return;
1654
1556
  const giaFinita = dati.status === "finished";
1655
1557
  dati.status = rematch ? "finished" : "ended";
1656
- dati.rivincita = rematch ? {
1657
- keepSetup: typeof rematch === "object" && rematch.keepSetup === true,
1658
- autoStart: typeof rematch === "object" && rematch.autoStart === true
1659
- } : null;
1558
+ dati.rivincita = rematch ? { keepSetup: typeof rematch === "object" && rematch.keepSetup === true } : null;
1660
1559
  dati.prontiPrecedenti = rematch ? dati.giocatori.filter((p) => p.ready).map((p) => p.id) : [];
1661
1560
  dati.rivincitaFinoA = rematch ? this.adattatore.ora() + ATTESA_RIVINCITA_MS : null;
1662
1561
  dati.timer = [];
@@ -1781,6 +1680,78 @@ var NucleoStanza = class _NucleoStanza {
1781
1680
  }
1782
1681
  };
1783
1682
 
1683
+ // src/runtime/network-probe.ts
1684
+ async function measureNetwork(definition, manifest) {
1685
+ const modes = (manifest.modes.length ? manifest.modes : [{ id: null }]).filter((mode) => !modalitaLocale(manifest, mode.id));
1686
+ const results = [];
1687
+ for (const mode of modes) {
1688
+ const storage = /* @__PURE__ */ new Map();
1689
+ const connections = /* @__PURE__ */ new Set();
1690
+ const meter = new NetworkMeter();
1691
+ let now = Date.now();
1692
+ let interval = definition.tickRate > 0 ? 1e3 / definition.tickRate : 50;
1693
+ let error = null;
1694
+ let playing = false;
1695
+ const adapter = {
1696
+ storage: {
1697
+ async get(key) {
1698
+ return structuredClone(storage.get(key));
1699
+ },
1700
+ async put(key, value) {
1701
+ storage.set(key, structuredClone(value));
1702
+ },
1703
+ async delete(key) {
1704
+ storage.delete(key);
1705
+ },
1706
+ async list(prefix = "") {
1707
+ return new Map([...storage].filter(([key]) => key.startsWith(prefix)));
1708
+ }
1709
+ },
1710
+ invia(connection, message) {
1711
+ if (connections.has(connection)) meter.record(connection, JSON.stringify(message), now);
1712
+ if (message.t === "status" && message.status === "playing") playing = true;
1713
+ 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.";
1714
+ },
1715
+ chiudi(connection) {
1716
+ connections.delete(connection);
1717
+ },
1718
+ connessioniAttive: () => [...connections],
1719
+ ora: () => now,
1720
+ misuraCpu: () => performance.now(),
1721
+ rivediVoce() {
1722
+ },
1723
+ programmaTick(ms) {
1724
+ if (ms !== null) interval = ms;
1725
+ },
1726
+ async programmaSveglia() {
1727
+ }
1728
+ };
1729
+ const room = await NucleoStanza.apri(definition, manifest, adapter);
1730
+ const identity = (n) => ({ id: `probe-${n}`, name: `Player ${n + 1}`, guest: true });
1731
+ await room.crea("publication-probe", mode.id, identity(0), "player");
1732
+ const maximum = ("players" in mode ? mode.players?.max : void 0) ?? manifest.players.max;
1733
+ for (let n = 0; n < maximum; n++) {
1734
+ connections.add(`probe-${n}`);
1735
+ const joined = await room.entra(identity(n), `probe-${n}`);
1736
+ if (!joined.ok) throw new Error("The publication probe could not fill the room.");
1737
+ }
1738
+ if (room.info()?.status === "lobby") {
1739
+ for (const connection of connections) await room.ricevi(connection, JSON.stringify({ t: "ready", ready: true }));
1740
+ }
1741
+ const start = now;
1742
+ while (now - start < 2e4) {
1743
+ now += Math.min(interval, 2e4 - (now - start));
1744
+ await room.sveglia();
1745
+ playing ||= room.info()?.status === "playing";
1746
+ await room.eseguiTick();
1747
+ if (error !== null) throw new Error(error);
1748
+ }
1749
+ if (!playing) throw new Error("The publication probe could not start this room mode. Check lobby roles and teams.");
1750
+ results.push({ mode: mode.id, players: maximum, playing, simulatedSeconds: 20, ...meter.sample(now).peak });
1751
+ }
1752
+ return { modes: results };
1753
+ }
1754
+
1784
1755
  // src/runtime/index.ts
1785
1756
  var CHIAVE_ADATTATORE = "adattatore";
1786
1757
  var ArchivioFacet = class {
@@ -1801,11 +1772,10 @@ var ArchivioFacet = class {
1801
1772
  }
1802
1773
  };
1803
1774
  var AdattatoreFacet = class {
1804
- constructor(archivio, tickRate, deposito) {
1775
+ constructor(archivio, tickRate) {
1805
1776
  this.connessioni = /* @__PURE__ */ new Set();
1806
1777
  this.cpuMessaggiOltreCento = 0;
1807
1778
  this.frames = [];
1808
- this.pubblici = [];
1809
1779
  this.chiusure = [];
1810
1780
  this.sveglia = null;
1811
1781
  this.tick = false;
@@ -1813,7 +1783,6 @@ var AdattatoreFacet = class {
1813
1783
  this.salvato = "";
1814
1784
  this.storage = new ArchivioFacet(archivio);
1815
1785
  this.tickRate = tickRate;
1816
- this.deposito = deposito;
1817
1786
  }
1818
1787
  async ripristina() {
1819
1788
  const dati = await this.storage.get(CHIAVE_ADATTATORE);
@@ -1837,12 +1806,6 @@ var AdattatoreFacet = class {
1837
1806
  invia(connessione, messaggio) {
1838
1807
  this.frames.push({ connessione, testo: JSON.stringify(messaggio) });
1839
1808
  }
1840
- inizioReplay(fotografia) {
1841
- this.pubblici.push(JSON.stringify({ t: "replay-start", ...fotografia }));
1842
- }
1843
- pubblica(messaggio) {
1844
- this.pubblici.push(JSON.stringify(messaggio));
1845
- }
1846
1809
  chiudi(connessione, codice, motivo) {
1847
1810
  this.chiusure.push({ connessione, codice, motivo });
1848
1811
  this.connessioni.delete(connessione);
@@ -1869,7 +1832,6 @@ var AdattatoreFacet = class {
1869
1832
  esito(status) {
1870
1833
  const risultato = {
1871
1834
  frames: this.frames,
1872
- pubblici: this.pubblici,
1873
1835
  chiusure: this.chiusure,
1874
1836
  sveglia: this.sveglia,
1875
1837
  tick: this.tick,
@@ -1878,7 +1840,6 @@ var AdattatoreFacet = class {
1878
1840
  voceRivedi: this.voceRivedi
1879
1841
  };
1880
1842
  this.frames = [];
1881
- this.pubblici = [];
1882
1843
  this.chiusure = [];
1883
1844
  this.voceRivedi = false;
1884
1845
  return risultato;
@@ -1893,8 +1854,7 @@ function creaFacetStanza(DurableObject, definizione, manifest) {
1893
1854
  constructor(stato, ambiente) {
1894
1855
  super(stato, ambiente);
1895
1856
  this.#roomId = typeof stato.id === "string" ? stato.id : stato.id.name ?? stato.id.toString();
1896
- const deposito = ambiente?.DEPOSITO ?? null;
1897
- const adattatore = new AdattatoreFacet(stato.storage, definizione.tickRate, deposito);
1857
+ const adattatore = new AdattatoreFacet(stato.storage, definizione.tickRate);
1898
1858
  this.#adattatore = adattatore;
1899
1859
  const misurata = Object.create(definizione);
1900
1860
  if (definizione.onMessage !== void 0) {
@@ -1929,7 +1889,7 @@ function creaFacetStanza(DurableObject, definizione, manifest) {
1929
1889
  }
1930
1890
  crea(input) {
1931
1891
  return this.#serializza(async (nucleo) => {
1932
- const ok = await nucleo.crea(this.#roomId, input.mode, input.creator);
1892
+ const ok = await nucleo.crea(this.#roomId, input.mode, input.creator, input.origin);
1933
1893
  await this.#adattatore.persisti();
1934
1894
  return {
1935
1895
  ...this.#adattatore.esito(nucleo.info()?.status ?? null),
@@ -1994,5 +1954,6 @@ function creaFacetStanza(DurableObject, definizione, manifest) {
1994
1954
  };
1995
1955
  }
1996
1956
  export {
1997
- creaFacetStanza
1957
+ creaFacetStanza,
1958
+ measureNetwork
1998
1959
  };