@caisual/kit 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.js CHANGED
@@ -37,7 +37,7 @@ var RISERVATI = new Set(NOMI_RISERVATI);
37
37
  function risolviModalita(manifest, mode) {
38
38
  const scelta = mode === null ? void 0 : manifest.modes.find((voce) => voce.id === mode);
39
39
  if (mode !== null && scelta === void 0) throw new Error("The selected game mode does not exist.");
40
- return { players: { ...scelta?.players ?? manifest.players }, lobby: scelta?.lobby ?? manifest.lobby };
40
+ return { players: { ...scelta?.players ?? manifest.players } };
41
41
  }
42
42
  function modalitaLocale(manifest, mode) {
43
43
  return risolviModalita(manifest, mode).players.max === 1;
@@ -571,20 +571,25 @@ var NucleoStanza = class _NucleoStanza {
571
571
  if (modalitaLocale(manifest, salvato.mode)) throw Object.assign(new Error(MODE_LOCAL_MESSAGE), { code: "mode_local" });
572
572
  nucleo.dati = salvato;
573
573
  nucleo.tickRateSincronizzato = salvato.tickRate;
574
- const daAggiornare = salvato.ultimoInputAt === void 0 || salvato.ultimoCambioStatoAt === void 0 || salvato.daily === void 0 || salvato.origin === void 0;
574
+ let daAggiornare = salvato.ultimoInputAt === void 0 || salvato.ultimoCambioStatoAt === void 0 || salvato.daily === void 0 || salvato.origin === void 0;
575
575
  salvato.origin ??= "player";
576
+ if (salvato.origin === "matchmaking" && salvato.status === "lobby") {
577
+ salvato.status = "waiting";
578
+ daAggiornare = true;
579
+ }
576
580
  salvato.daily ??= nucleo.contestoGiornaliero();
577
581
  salvato.ultimoInputAt ??= adattatore.ora();
578
582
  salvato.ultimoCambioStatoAt ??= salvato.ultimoInputAt;
579
583
  nucleo.ultimoStatoOsservato = JSON.stringify(salvato.state);
580
584
  await nucleo.riconciliaConnessioni();
585
+ if (salvato.origin === "matchmaking") nucleo.rivalutaAvvio();
581
586
  if (daAggiornare) await nucleo.persisti();
582
587
  }
583
588
  await nucleo.aggiornaProgrammazione();
584
589
  return nucleo;
585
590
  }
586
591
  static verificaManifest(manifest) {
587
- if (typeof manifest?.id !== "string" || !Number.isInteger(manifest.players?.min) || !Number.isInteger(manifest.players?.max) || manifest.players.min < 1 || manifest.players.max < manifest.players.min || typeof manifest.lobby !== "boolean" || manifest.persistent !== void 0 && typeof manifest.persistent !== "boolean" || !Array.isArray(manifest.roles) || !Array.isArray(manifest.modes) || manifest.voice !== void 0 && !["none", "room", "team", "proximity"].includes(manifest.voice)) {
592
+ if (typeof manifest?.id !== "string" || !Number.isInteger(manifest.players?.min) || !Number.isInteger(manifest.players?.max) || manifest.players.min < 1 || manifest.players.max < manifest.players.min || manifest.persistent !== void 0 && typeof manifest.persistent !== "boolean" || !Array.isArray(manifest.roles) || !Array.isArray(manifest.modes) || manifest.voice !== void 0 && !["none", "room", "team", "proximity"].includes(manifest.voice)) {
588
593
  throw new TypeError("The room manifest is invalid.");
589
594
  }
590
595
  }
@@ -608,7 +613,7 @@ var NucleoStanza = class _NucleoStanza {
608
613
  daily: this.contestoGiornaliero(ora),
609
614
  id,
610
615
  mode,
611
- status: "lobby",
616
+ status: origin === "matchmaking" ? "waiting" : "lobby",
612
617
  tick: 0,
613
618
  tickRate: this.definizione.tickRate,
614
619
  ultimoInputAt: ora,
@@ -646,15 +651,13 @@ var NucleoStanza = class _NucleoStanza {
646
651
  return true;
647
652
  }
648
653
  get configurazione() {
649
- const mode = risolviModalita(this.manifest, this.dati?.mode ?? null);
650
- return this.dati?.origin === "matchmaking" ? mode : { ...mode, lobby: true };
654
+ return risolviModalita(this.manifest, this.dati?.mode ?? null);
651
655
  }
652
656
  info(playerId) {
653
657
  if (this.dati === null) return null;
654
658
  return {
655
659
  roomId: this.dati.id,
656
660
  origin: this.dati.origin,
657
- lobby: this.configurazione.lobby,
658
661
  status: this.dati.status,
659
662
  players: this.manifest.persistent === true ? this.dati.giocatori.length : this.dati.giocatori.filter(
660
663
  (player) => player.connected || player.graziaFinoA !== null
@@ -699,10 +702,10 @@ var NucleoStanza = class _NucleoStanza {
699
702
  }
700
703
  puoEntrare(identity) {
701
704
  if (this.dati === null) return { ok: false, code: "room_not_found" };
702
- if (this.dati.status === "ended") return { ok: false, code: "room_ended" };
705
+ if (this.dati.status === "ended" || this.dati.origin === "matchmaking" && this.dati.status === "finished") return { ok: false, code: "room_ended" };
703
706
  const esistente = this.dati.giocatori.find((player) => player.id === identity.id);
704
707
  if (esistente !== void 0) return { ok: true };
705
- if (this.configurazione.lobby && !["lobby", "countdown", "finished"].includes(this.dati.status)) {
708
+ if (this.dati?.origin === "player" && !["lobby", "countdown", "finished"].includes(this.dati.status)) {
706
709
  return { ok: false, code: "room_playing" };
707
710
  }
708
711
  if (this.dati.giocatori.length >= this.configurazione.players.max) {
@@ -752,8 +755,6 @@ var NucleoStanza = class _NucleoStanza {
752
755
  }
753
756
  dati.vuotaDa = null;
754
757
  dati.ultimoInputAt = ora;
755
- const primaConnessione = !this.configurazione.lobby && dati.status === "lobby";
756
- if (primaConnessione) dati.status = "playing";
757
758
  if (nuovo) {
758
759
  await this.chiama(
759
760
  this.definizione.onJoin,
@@ -764,10 +765,6 @@ var NucleoStanza = class _NucleoStanza {
764
765
  if (riconnesso) {
765
766
  await this.chiama(this.definizione.onConnection, this.room, copiaGiocatore(player), true);
766
767
  }
767
- if (primaConnessione) {
768
- await this.chiama(this.definizione.onStart, this.room);
769
- this.inviaStatus(ora);
770
- }
771
768
  await this.concludiEvento();
772
769
  if (dati.status !== "ended") {
773
770
  this.inviaWelcome(player);
@@ -846,6 +843,11 @@ var NucleoStanza = class _NucleoStanza {
846
843
  await this.persistiEProgramma();
847
844
  return;
848
845
  }
846
+ if (this.dati.origin === "matchmaking" && (message.t === "ready" || message.t === "restart")) return;
847
+ if (this.dati.origin === "matchmaking" && (message.t === "role" || message.t === "team")) {
848
+ this.inviaErrore(player, "matchmaking_room", "Roles and teams are assigned by the server in matchmaking rooms.");
849
+ return;
850
+ }
849
851
  if (message.t === "restart") {
850
852
  await this.rivincita(player);
851
853
  return;
@@ -966,7 +968,7 @@ var NucleoStanza = class _NucleoStanza {
966
968
  if (this.dati.status === "countdown" && this.dati.countdownAt !== null && this.dati.countdownAt <= ora) {
967
969
  const errore = this.erroreMinimi(this.dati.countdownRivincita);
968
970
  if (errore !== null) {
969
- this.dati.status = "lobby";
971
+ this.dati.status = this.dati.origin === "matchmaking" ? "waiting" : "lobby";
970
972
  this.dati.countdownAt = null;
971
973
  this.broadcast({ t: "error", code: errore.code, message: errore.message });
972
974
  this.inviaStatus(ora);
@@ -1150,6 +1152,7 @@ var NucleoStanza = class _NucleoStanza {
1150
1152
  if (connessi.length < this.configurazione.players.min) {
1151
1153
  return { code: "not_enough_players", message: "The room does not have enough players." };
1152
1154
  }
1155
+ if (this.dati?.origin === "matchmaking") return null;
1153
1156
  if (!saltaPronti && connessi.some((player) => !player.ready)) {
1154
1157
  return { code: "players_not_ready", message: "Every connected player must be ready." };
1155
1158
  }
@@ -1184,8 +1187,13 @@ var NucleoStanza = class _NucleoStanza {
1184
1187
  }
1185
1188
  async avviaRivincita() {
1186
1189
  const dati = this.richiediDati();
1187
- const keepSetup = dati.rivincita?.keepSetup === true;
1188
- dati.status = keepSetup ? "countdown" : this.configurazione.lobby ? "lobby" : "playing";
1190
+ if (dati.origin === "matchmaking") {
1191
+ for (const player of dati.giocatori.filter((item) => !item.connected)) await this.rimuoviGiocatore(player, "timeout");
1192
+ await this.applicaAzioni();
1193
+ if (this.stanzaTerminata()) return;
1194
+ }
1195
+ const keepSetup = dati.origin === "player" && dati.rivincita?.keepSetup === true;
1196
+ dati.status = dati.origin === "matchmaking" ? "waiting" : keepSetup ? "countdown" : "lobby";
1189
1197
  dati.countdownRivincita = keepSetup;
1190
1198
  dati.countdownAt = keepSetup ? this.adattatore.ora() + COUNTDOWN_MS : null;
1191
1199
  dati.rivincitaFinoA = null;
@@ -1197,11 +1205,9 @@ var NucleoStanza = class _NucleoStanza {
1197
1205
  dati.prontiPrecedenti = [];
1198
1206
  await this.chiama(this.definizione.onRestart, this.room);
1199
1207
  await this.applicaAzioni();
1200
- if (dati.status === "playing") {
1201
- await this.chiama(this.definizione.onStart, this.room);
1202
- }
1203
1208
  await this.concludiEvento();
1204
- if (dati.status === "lobby" || dati.status === "playing" || dati.status === "countdown") {
1209
+ this.rivalutaAvvio();
1210
+ if (["waiting", "lobby", "playing", "countdown"].includes(dati.status)) {
1205
1211
  this.inviaSnapshotTutti();
1206
1212
  this.inviaGiocatori();
1207
1213
  this.inviaStatus(this.adattatore.ora());
@@ -1217,12 +1223,12 @@ var NucleoStanza = class _NucleoStanza {
1217
1223
  const dati = this.richiediDati();
1218
1224
  if (dati.status === "countdown") {
1219
1225
  if (this.erroreMinimi(dati.countdownRivincita) === null) return;
1220
- dati.status = "lobby";
1226
+ dati.status = dati.origin === "matchmaking" ? "waiting" : "lobby";
1221
1227
  dati.countdownAt = null;
1222
1228
  this.inviaStatus(this.adattatore.ora());
1223
1229
  return;
1224
1230
  }
1225
- if (dati.status !== "lobby" || this.erroreMinimi() !== null) return;
1231
+ if (!["lobby", "waiting"].includes(dati.status) || this.erroreMinimi() !== null) return;
1226
1232
  dati.status = "countdown";
1227
1233
  dati.countdownRivincita = false;
1228
1234
  dati.countdownAt = this.adattatore.ora() + COUNTDOWN_MS;
@@ -1379,6 +1385,7 @@ var NucleoStanza = class _NucleoStanza {
1379
1385
  const dati = this.richiediDati();
1380
1386
  return {
1381
1387
  id: dati.id,
1388
+ origin: dati.origin,
1382
1389
  seed: seedStanza(dati.id),
1383
1390
  status: dati.status,
1384
1391
  result: dati.result,
@@ -1390,7 +1397,6 @@ var NucleoStanza = class _NucleoStanza {
1390
1397
  countdownAt: dati.countdownAt,
1391
1398
  configuration: {
1392
1399
  players: { ...this.configurazione.players },
1393
- lobby: this.configurazione.lobby,
1394
1400
  persistent: this.manifest.persistent === true,
1395
1401
  requestRole: this.definizione.onRoleRequest !== void 0
1396
1402
  }
@@ -1475,7 +1481,7 @@ var NucleoStanza = class _NucleoStanza {
1475
1481
  async concludiEvento() {
1476
1482
  await this.applicaAzioni();
1477
1483
  if (this.dati === null || this.dati.status === "ended") return;
1478
- if (this.dati.status === "finished" && this.dati.rivincita !== null && this.prontiRivincita()) {
1484
+ if (this.dati.origin === "player" && this.dati.status === "finished" && this.dati.rivincita !== null && this.prontiRivincita()) {
1479
1485
  await this.avviaRivincita();
1480
1486
  return;
1481
1487
  }
@@ -1573,10 +1579,11 @@ var NucleoStanza = class _NucleoStanza {
1573
1579
  const dati = this.richiediDati();
1574
1580
  if (dati.status === "ended") return;
1575
1581
  const giaFinita = dati.status === "finished";
1582
+ if (dati.origin === "matchmaking" && record(result)?.error === void 0) rematch = true;
1576
1583
  dati.status = rematch ? "finished" : "ended";
1577
1584
  dati.rivincita = rematch ? { keepSetup: typeof rematch === "object" && rematch.keepSetup === true } : null;
1578
1585
  dati.prontiPrecedenti = rematch ? dati.giocatori.filter((p) => p.ready).map((p) => p.id) : [];
1579
- dati.rivincitaFinoA = rematch ? this.adattatore.ora() + ATTESA_RIVINCITA_MS : null;
1586
+ dati.rivincitaFinoA = rematch ? this.adattatore.ora() + (dati.origin === "matchmaking" ? 8e3 : ATTESA_RIVINCITA_MS) : null;
1580
1587
  dati.timer = [];
1581
1588
  if (rematch) for (const player of dati.giocatori) player.ready = false;
1582
1589
  dati.countdownAt = null;
@@ -1654,6 +1661,10 @@ var NucleoStanza = class _NucleoStanza {
1654
1661
  async terminaSeInattiva() {
1655
1662
  if (this.dati?.status === "finished") {
1656
1663
  if (this.adattatore.ora() < (this.dati.rivincitaFinoA ?? 0)) return false;
1664
+ if (this.dati.origin === "matchmaking") {
1665
+ await this.avviaRivincita();
1666
+ return false;
1667
+ }
1657
1668
  await this.terminaInterna(this.dati.result);
1658
1669
  return true;
1659
1670
  }
package/dist/runtime.js CHANGED
@@ -37,7 +37,7 @@ var RISERVATI = new Set(NOMI_RISERVATI);
37
37
  function risolviModalita(manifest, mode) {
38
38
  const scelta = mode === null ? void 0 : manifest.modes.find((voce) => voce.id === mode);
39
39
  if (mode !== null && scelta === void 0) throw new Error("The selected game mode does not exist.");
40
- return { players: { ...scelta?.players ?? manifest.players }, lobby: scelta?.lobby ?? manifest.lobby };
40
+ return { players: { ...scelta?.players ?? manifest.players } };
41
41
  }
42
42
  function modalitaLocale(manifest, mode) {
43
43
  return risolviModalita(manifest, mode).players.max === 1;
@@ -552,20 +552,25 @@ var NucleoStanza = class _NucleoStanza {
552
552
  if (modalitaLocale(manifest, salvato.mode)) throw Object.assign(new Error(MODE_LOCAL_MESSAGE), { code: "mode_local" });
553
553
  nucleo.dati = salvato;
554
554
  nucleo.tickRateSincronizzato = salvato.tickRate;
555
- const daAggiornare = salvato.ultimoInputAt === void 0 || salvato.ultimoCambioStatoAt === void 0 || salvato.daily === void 0 || salvato.origin === void 0;
555
+ let daAggiornare = salvato.ultimoInputAt === void 0 || salvato.ultimoCambioStatoAt === void 0 || salvato.daily === void 0 || salvato.origin === void 0;
556
556
  salvato.origin ??= "player";
557
+ if (salvato.origin === "matchmaking" && salvato.status === "lobby") {
558
+ salvato.status = "waiting";
559
+ daAggiornare = true;
560
+ }
557
561
  salvato.daily ??= nucleo.contestoGiornaliero();
558
562
  salvato.ultimoInputAt ??= adattatore.ora();
559
563
  salvato.ultimoCambioStatoAt ??= salvato.ultimoInputAt;
560
564
  nucleo.ultimoStatoOsservato = JSON.stringify(salvato.state);
561
565
  await nucleo.riconciliaConnessioni();
566
+ if (salvato.origin === "matchmaking") nucleo.rivalutaAvvio();
562
567
  if (daAggiornare) await nucleo.persisti();
563
568
  }
564
569
  await nucleo.aggiornaProgrammazione();
565
570
  return nucleo;
566
571
  }
567
572
  static verificaManifest(manifest) {
568
- if (typeof manifest?.id !== "string" || !Number.isInteger(manifest.players?.min) || !Number.isInteger(manifest.players?.max) || manifest.players.min < 1 || manifest.players.max < manifest.players.min || typeof manifest.lobby !== "boolean" || manifest.persistent !== void 0 && typeof manifest.persistent !== "boolean" || !Array.isArray(manifest.roles) || !Array.isArray(manifest.modes) || manifest.voice !== void 0 && !["none", "room", "team", "proximity"].includes(manifest.voice)) {
573
+ if (typeof manifest?.id !== "string" || !Number.isInteger(manifest.players?.min) || !Number.isInteger(manifest.players?.max) || manifest.players.min < 1 || manifest.players.max < manifest.players.min || manifest.persistent !== void 0 && typeof manifest.persistent !== "boolean" || !Array.isArray(manifest.roles) || !Array.isArray(manifest.modes) || manifest.voice !== void 0 && !["none", "room", "team", "proximity"].includes(manifest.voice)) {
569
574
  throw new TypeError("The room manifest is invalid.");
570
575
  }
571
576
  }
@@ -589,7 +594,7 @@ var NucleoStanza = class _NucleoStanza {
589
594
  daily: this.contestoGiornaliero(ora),
590
595
  id,
591
596
  mode,
592
- status: "lobby",
597
+ status: origin === "matchmaking" ? "waiting" : "lobby",
593
598
  tick: 0,
594
599
  tickRate: this.definizione.tickRate,
595
600
  ultimoInputAt: ora,
@@ -627,15 +632,13 @@ var NucleoStanza = class _NucleoStanza {
627
632
  return true;
628
633
  }
629
634
  get configurazione() {
630
- const mode = risolviModalita(this.manifest, this.dati?.mode ?? null);
631
- return this.dati?.origin === "matchmaking" ? mode : { ...mode, lobby: true };
635
+ return risolviModalita(this.manifest, this.dati?.mode ?? null);
632
636
  }
633
637
  info(playerId) {
634
638
  if (this.dati === null) return null;
635
639
  return {
636
640
  roomId: this.dati.id,
637
641
  origin: this.dati.origin,
638
- lobby: this.configurazione.lobby,
639
642
  status: this.dati.status,
640
643
  players: this.manifest.persistent === true ? this.dati.giocatori.length : this.dati.giocatori.filter(
641
644
  (player) => player.connected || player.graziaFinoA !== null
@@ -680,10 +683,10 @@ var NucleoStanza = class _NucleoStanza {
680
683
  }
681
684
  puoEntrare(identity) {
682
685
  if (this.dati === null) return { ok: false, code: "room_not_found" };
683
- if (this.dati.status === "ended") return { ok: false, code: "room_ended" };
686
+ if (this.dati.status === "ended" || this.dati.origin === "matchmaking" && this.dati.status === "finished") return { ok: false, code: "room_ended" };
684
687
  const esistente = this.dati.giocatori.find((player) => player.id === identity.id);
685
688
  if (esistente !== void 0) return { ok: true };
686
- if (this.configurazione.lobby && !["lobby", "countdown", "finished"].includes(this.dati.status)) {
689
+ if (this.dati?.origin === "player" && !["lobby", "countdown", "finished"].includes(this.dati.status)) {
687
690
  return { ok: false, code: "room_playing" };
688
691
  }
689
692
  if (this.dati.giocatori.length >= this.configurazione.players.max) {
@@ -733,8 +736,6 @@ var NucleoStanza = class _NucleoStanza {
733
736
  }
734
737
  dati.vuotaDa = null;
735
738
  dati.ultimoInputAt = ora;
736
- const primaConnessione = !this.configurazione.lobby && dati.status === "lobby";
737
- if (primaConnessione) dati.status = "playing";
738
739
  if (nuovo) {
739
740
  await this.chiama(
740
741
  this.definizione.onJoin,
@@ -745,10 +746,6 @@ var NucleoStanza = class _NucleoStanza {
745
746
  if (riconnesso) {
746
747
  await this.chiama(this.definizione.onConnection, this.room, copiaGiocatore(player), true);
747
748
  }
748
- if (primaConnessione) {
749
- await this.chiama(this.definizione.onStart, this.room);
750
- this.inviaStatus(ora);
751
- }
752
749
  await this.concludiEvento();
753
750
  if (dati.status !== "ended") {
754
751
  this.inviaWelcome(player);
@@ -827,6 +824,11 @@ var NucleoStanza = class _NucleoStanza {
827
824
  await this.persistiEProgramma();
828
825
  return;
829
826
  }
827
+ if (this.dati.origin === "matchmaking" && (message.t === "ready" || message.t === "restart")) return;
828
+ if (this.dati.origin === "matchmaking" && (message.t === "role" || message.t === "team")) {
829
+ this.inviaErrore(player, "matchmaking_room", "Roles and teams are assigned by the server in matchmaking rooms.");
830
+ return;
831
+ }
830
832
  if (message.t === "restart") {
831
833
  await this.rivincita(player);
832
834
  return;
@@ -947,7 +949,7 @@ var NucleoStanza = class _NucleoStanza {
947
949
  if (this.dati.status === "countdown" && this.dati.countdownAt !== null && this.dati.countdownAt <= ora) {
948
950
  const errore = this.erroreMinimi(this.dati.countdownRivincita);
949
951
  if (errore !== null) {
950
- this.dati.status = "lobby";
952
+ this.dati.status = this.dati.origin === "matchmaking" ? "waiting" : "lobby";
951
953
  this.dati.countdownAt = null;
952
954
  this.broadcast({ t: "error", code: errore.code, message: errore.message });
953
955
  this.inviaStatus(ora);
@@ -1131,6 +1133,7 @@ var NucleoStanza = class _NucleoStanza {
1131
1133
  if (connessi.length < this.configurazione.players.min) {
1132
1134
  return { code: "not_enough_players", message: "The room does not have enough players." };
1133
1135
  }
1136
+ if (this.dati?.origin === "matchmaking") return null;
1134
1137
  if (!saltaPronti && connessi.some((player) => !player.ready)) {
1135
1138
  return { code: "players_not_ready", message: "Every connected player must be ready." };
1136
1139
  }
@@ -1165,8 +1168,13 @@ var NucleoStanza = class _NucleoStanza {
1165
1168
  }
1166
1169
  async avviaRivincita() {
1167
1170
  const dati = this.richiediDati();
1168
- const keepSetup = dati.rivincita?.keepSetup === true;
1169
- dati.status = keepSetup ? "countdown" : this.configurazione.lobby ? "lobby" : "playing";
1171
+ if (dati.origin === "matchmaking") {
1172
+ for (const player of dati.giocatori.filter((item) => !item.connected)) await this.rimuoviGiocatore(player, "timeout");
1173
+ await this.applicaAzioni();
1174
+ if (this.stanzaTerminata()) return;
1175
+ }
1176
+ const keepSetup = dati.origin === "player" && dati.rivincita?.keepSetup === true;
1177
+ dati.status = dati.origin === "matchmaking" ? "waiting" : keepSetup ? "countdown" : "lobby";
1170
1178
  dati.countdownRivincita = keepSetup;
1171
1179
  dati.countdownAt = keepSetup ? this.adattatore.ora() + COUNTDOWN_MS : null;
1172
1180
  dati.rivincitaFinoA = null;
@@ -1178,11 +1186,9 @@ var NucleoStanza = class _NucleoStanza {
1178
1186
  dati.prontiPrecedenti = [];
1179
1187
  await this.chiama(this.definizione.onRestart, this.room);
1180
1188
  await this.applicaAzioni();
1181
- if (dati.status === "playing") {
1182
- await this.chiama(this.definizione.onStart, this.room);
1183
- }
1184
1189
  await this.concludiEvento();
1185
- if (dati.status === "lobby" || dati.status === "playing" || dati.status === "countdown") {
1190
+ this.rivalutaAvvio();
1191
+ if (["waiting", "lobby", "playing", "countdown"].includes(dati.status)) {
1186
1192
  this.inviaSnapshotTutti();
1187
1193
  this.inviaGiocatori();
1188
1194
  this.inviaStatus(this.adattatore.ora());
@@ -1198,12 +1204,12 @@ var NucleoStanza = class _NucleoStanza {
1198
1204
  const dati = this.richiediDati();
1199
1205
  if (dati.status === "countdown") {
1200
1206
  if (this.erroreMinimi(dati.countdownRivincita) === null) return;
1201
- dati.status = "lobby";
1207
+ dati.status = dati.origin === "matchmaking" ? "waiting" : "lobby";
1202
1208
  dati.countdownAt = null;
1203
1209
  this.inviaStatus(this.adattatore.ora());
1204
1210
  return;
1205
1211
  }
1206
- if (dati.status !== "lobby" || this.erroreMinimi() !== null) return;
1212
+ if (!["lobby", "waiting"].includes(dati.status) || this.erroreMinimi() !== null) return;
1207
1213
  dati.status = "countdown";
1208
1214
  dati.countdownRivincita = false;
1209
1215
  dati.countdownAt = this.adattatore.ora() + COUNTDOWN_MS;
@@ -1360,6 +1366,7 @@ var NucleoStanza = class _NucleoStanza {
1360
1366
  const dati = this.richiediDati();
1361
1367
  return {
1362
1368
  id: dati.id,
1369
+ origin: dati.origin,
1363
1370
  seed: seedStanza(dati.id),
1364
1371
  status: dati.status,
1365
1372
  result: dati.result,
@@ -1371,7 +1378,6 @@ var NucleoStanza = class _NucleoStanza {
1371
1378
  countdownAt: dati.countdownAt,
1372
1379
  configuration: {
1373
1380
  players: { ...this.configurazione.players },
1374
- lobby: this.configurazione.lobby,
1375
1381
  persistent: this.manifest.persistent === true,
1376
1382
  requestRole: this.definizione.onRoleRequest !== void 0
1377
1383
  }
@@ -1456,7 +1462,7 @@ var NucleoStanza = class _NucleoStanza {
1456
1462
  async concludiEvento() {
1457
1463
  await this.applicaAzioni();
1458
1464
  if (this.dati === null || this.dati.status === "ended") return;
1459
- if (this.dati.status === "finished" && this.dati.rivincita !== null && this.prontiRivincita()) {
1465
+ if (this.dati.origin === "player" && this.dati.status === "finished" && this.dati.rivincita !== null && this.prontiRivincita()) {
1460
1466
  await this.avviaRivincita();
1461
1467
  return;
1462
1468
  }
@@ -1554,10 +1560,11 @@ var NucleoStanza = class _NucleoStanza {
1554
1560
  const dati = this.richiediDati();
1555
1561
  if (dati.status === "ended") return;
1556
1562
  const giaFinita = dati.status === "finished";
1563
+ if (dati.origin === "matchmaking" && record(result)?.error === void 0) rematch = true;
1557
1564
  dati.status = rematch ? "finished" : "ended";
1558
1565
  dati.rivincita = rematch ? { keepSetup: typeof rematch === "object" && rematch.keepSetup === true } : null;
1559
1566
  dati.prontiPrecedenti = rematch ? dati.giocatori.filter((p) => p.ready).map((p) => p.id) : [];
1560
- dati.rivincitaFinoA = rematch ? this.adattatore.ora() + ATTESA_RIVINCITA_MS : null;
1567
+ dati.rivincitaFinoA = rematch ? this.adattatore.ora() + (dati.origin === "matchmaking" ? 8e3 : ATTESA_RIVINCITA_MS) : null;
1561
1568
  dati.timer = [];
1562
1569
  if (rematch) for (const player of dati.giocatori) player.ready = false;
1563
1570
  dati.countdownAt = null;
@@ -1635,6 +1642,10 @@ var NucleoStanza = class _NucleoStanza {
1635
1642
  async terminaSeInattiva() {
1636
1643
  if (this.dati?.status === "finished") {
1637
1644
  if (this.adattatore.ora() < (this.dati.rivincitaFinoA ?? 0)) return false;
1645
+ if (this.dati.origin === "matchmaking") {
1646
+ await this.avviaRivincita();
1647
+ return false;
1648
+ }
1638
1649
  await this.terminaInterna(this.dati.result);
1639
1650
  return true;
1640
1651
  }
@@ -17,11 +17,6 @@ export interface ManifestTeams {
17
17
  min: number;
18
18
  max: number;
19
19
  }
20
- export interface ManifestMatchmaking {
21
- defaults?: Record<string, string | number>;
22
- key: string[];
23
- timeoutMs: number;
24
- }
25
20
  export interface ManifestRequires {
26
21
  webgl2: boolean;
27
22
  webgpu: boolean;
@@ -33,12 +28,10 @@ export interface ManifestRequires {
33
28
  export interface ManifestMode {
34
29
  id: string;
35
30
  players?: ManifestPlayers;
36
- lobby?: boolean;
37
- matchmaking?: ManifestMatchmaking;
31
+ matchmaking?: boolean;
38
32
  }
39
33
  export interface ModalitaRisolta {
40
34
  players: ManifestPlayers;
41
- lobby: boolean;
42
35
  }
43
36
  export type ManifestModalita = ModalitaRisolta & {
44
37
  modes: ManifestMode[];
@@ -69,7 +62,6 @@ export interface Manifest {
69
62
  network: string[];
70
63
  requires: ManifestRequires;
71
64
  players: ManifestPlayers;
72
- lobby: boolean;
73
65
  persistent: boolean;
74
66
  roles: ManifestRole[];
75
67
  teams: ManifestTeams | null;
@@ -21,7 +21,7 @@ export interface SaveInfo {
21
21
  bytes: number;
22
22
  updatedAt: number;
23
23
  }
24
- export type RoomStatus = 'lobby' | 'countdown' | 'playing' | 'finished' | 'ended';
24
+ export type RoomStatus = 'waiting' | 'lobby' | 'countdown' | 'playing' | 'finished' | 'ended';
25
25
  export interface RoomPlayer {
26
26
  id: string;
27
27
  name: string;
@@ -85,6 +85,7 @@ export interface Room {
85
85
  readonly tickRate: number;
86
86
  readonly latency: number | null;
87
87
  readonly seed: number;
88
+ readonly origin: 'player' | 'matchmaking';
88
89
  readonly status: RoomStatus;
89
90
  readonly players: readonly RoomPlayer[];
90
91
  readonly you: string;
@@ -112,13 +113,7 @@ export interface Room {
112
113
  }
113
114
  export interface MatchOptions {
114
115
  mode: string;
115
- key: Record<string, string | number>;
116
116
  signal?: AbortSignal;
117
- onWaiting?(waiting: {
118
- players: number;
119
- min: number;
120
- max: number;
121
- }): void;
122
117
  }
123
118
  export interface Rooms {
124
119
  reload(): void;
@@ -20,7 +20,6 @@ export interface NodeRoomManifest {
20
20
  min: number;
21
21
  max: number;
22
22
  };
23
- lobby: boolean;
24
23
  persistent?: boolean;
25
24
  roles: Array<{
26
25
  id: string;
@@ -37,7 +36,6 @@ export interface NodeRoomManifest {
37
36
  min: number;
38
37
  max: number;
39
38
  };
40
- lobby?: boolean;
41
39
  }>;
42
40
  voice?: 'none' | 'room' | 'team' | 'proximity';
43
41
  }
@@ -49,7 +47,6 @@ export type NodeRoomJoinResult = {
49
47
  };
50
48
  export interface NodeRoomInfo {
51
49
  origin: 'player' | 'matchmaking';
52
- lobby: boolean;
53
50
  roomId: string;
54
51
  status: RoomStatus;
55
52
  players: number;
@@ -35,11 +35,11 @@ export interface RoomConfiguration {
35
35
  min: number;
36
36
  max: number;
37
37
  };
38
- lobby: boolean;
39
38
  persistent: boolean;
40
39
  requestRole: boolean;
41
40
  }
42
41
  export interface StanzaProtocollo {
42
+ origin: 'player' | 'matchmaking';
43
43
  rematch?: {
44
44
  keepSetup: boolean;
45
45
  } | null;
@@ -7,7 +7,6 @@ export interface RoomManifest {
7
7
  min: number;
8
8
  max: number;
9
9
  };
10
- lobby: boolean;
11
10
  persistent?: boolean;
12
11
  roles: Array<{
13
12
  id: string;
@@ -24,7 +23,6 @@ export interface RoomManifest {
24
23
  min: number;
25
24
  max: number;
26
25
  };
27
- lobby?: boolean;
28
26
  }>;
29
27
  voice?: 'none' | 'room' | 'team' | 'proximity';
30
28
  }
@@ -51,7 +49,6 @@ export interface Esito {
51
49
  }
52
50
  export interface InfoStanza {
53
51
  origin: 'player' | 'matchmaking';
54
- lobby: boolean;
55
52
  roomId: string;
56
53
  status: RoomStatus;
57
54
  players: number;
@@ -5,7 +5,7 @@ export type JsonValue = null | boolean | number | string | JsonValue[] | {
5
5
  export type RematchOptions = boolean | {
6
6
  keepSetup?: boolean;
7
7
  };
8
- export type RoomStatus = 'lobby' | 'countdown' | 'playing' | 'finished' | 'ended';
8
+ export type RoomStatus = 'waiting' | 'lobby' | 'countdown' | 'playing' | 'finished' | 'ended';
9
9
  export type VoiceMode = 'none' | 'room' | 'team' | 'proximity';
10
10
  export type LeaveReason = 'left' | 'timeout' | 'kicked';
11
11
  export interface Player {
@@ -6,7 +6,6 @@ export interface ManifestStanza {
6
6
  min: number;
7
7
  max: number;
8
8
  };
9
- lobby: boolean;
10
9
  persistent?: boolean;
11
10
  roles: Array<{
12
11
  id: string;
@@ -23,7 +22,6 @@ export interface ManifestStanza {
23
22
  min: number;
24
23
  max: number;
25
24
  };
26
- lobby?: boolean;
27
25
  }>;
28
26
  voice?: 'none' | 'room' | 'team' | 'proximity';
29
27
  }
@@ -120,7 +118,6 @@ export type EsitoAscolto = {
120
118
  };
121
119
  export interface InfoStanza {
122
120
  origin: 'player' | 'matchmaking';
123
- lobby: boolean;
124
121
  roomId: string;
125
122
  status: RoomStatus;
126
123
  players: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caisual/kit",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "Client and server kit for Caisual games",
5
5
  "license": "MIT",
6
6
  "homepage": "https://caisual.com",