@caisual/kit 0.5.0 → 0.8.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 (54) hide show
  1. package/dist/kit.d.ts +2 -175
  2. package/dist/kit.js +1418 -48
  3. package/dist/node.d.ts +1 -88
  4. package/dist/node.js +128 -31
  5. package/dist/overlay.d.ts +1 -0
  6. package/dist/overlay.js +1846 -0
  7. package/dist/runtime.d.ts +1 -111
  8. package/dist/runtime.js +160 -32
  9. package/dist/server.d.ts +1 -71
  10. package/dist/server.js +1 -0
  11. package/dist/types/api.d.ts +25 -0
  12. package/dist/types/contracts/biglietto.d.ts +24 -0
  13. package/dist/types/contracts/device.d.ts +66 -0
  14. package/dist/types/contracts/firma.d.ts +21 -0
  15. package/dist/types/contracts/index.d.ts +10 -0
  16. package/dist/types/contracts/keys.d.ts +59 -0
  17. package/dist/types/contracts/manifest.d.ts +118 -0
  18. package/dist/types/contracts/overlay-boards.d.ts +3 -0
  19. package/dist/types/contracts/overlay.d.ts +215 -0
  20. package/dist/types/contracts/runtime.d.ts +70 -0
  21. package/dist/types/contracts/server-js.d.ts +11 -0
  22. package/dist/types/contracts/slug.d.ts +5 -0
  23. package/dist/types/contracts/token-crew.d.ts +21 -0
  24. package/dist/types/daily.d.ts +3 -0
  25. package/dist/types/errors.d.ts +6 -0
  26. package/dist/types/handshake.d.ts +26 -0
  27. package/dist/types/http.d.ts +3 -0
  28. package/dist/types/index.d.ts +217 -0
  29. package/dist/types/kit.d.ts +26 -0
  30. package/dist/types/node/index.d.ts +96 -0
  31. package/dist/types/node/websocket.d.ts +29 -0
  32. package/dist/types/overlay/boards.d.ts +48 -0
  33. package/dist/types/overlay/bridge.d.ts +3 -0
  34. package/dist/types/overlay/host-bridge.d.ts +58 -0
  35. package/dist/types/overlay/i18n.d.ts +122 -0
  36. package/dist/types/overlay/index.d.ts +9 -0
  37. package/dist/types/overlay/shortcut.d.ts +4 -0
  38. package/dist/types/overlay/styles.d.ts +1 -0
  39. package/dist/types/overlay/ui-model.d.ts +45 -0
  40. package/dist/types/overlay/ui.d.ts +80 -0
  41. package/dist/types/overlay/voice-panel.d.ts +13 -0
  42. package/dist/types/protocollo.d.ts +257 -0
  43. package/dist/types/runtime/index.d.ts +127 -0
  44. package/dist/types/server/index.d.ts +72 -0
  45. package/dist/types/session/index.d.ts +49 -0
  46. package/dist/types/session/resume.d.ts +13 -0
  47. package/dist/types/standalone.d.ts +14 -0
  48. package/dist/types/stanza/index.d.ts +3 -0
  49. package/dist/types/stanza/json.d.ts +18 -0
  50. package/dist/types/stanza/nucleo.d.ts +97 -0
  51. package/dist/types/stanza/tipi.d.ts +134 -0
  52. package/dist/types/stanza-client/index.d.ts +24 -0
  53. package/dist/types/voce/index.d.ts +124 -0
  54. package/package.json +10 -2
package/dist/runtime.d.ts CHANGED
@@ -1,111 +1 @@
1
- import type { FotografiaStanza } from '../protocollo.js';
2
- import type { GameDefinition, JsonValue, RoomStatus } from './server.js';
3
- export interface RoomManifest {
4
- id: string;
5
- players: {
6
- min: number;
7
- max: number;
8
- };
9
- lobby: boolean;
10
- persistent?: boolean;
11
- roles: Array<{
12
- id: string;
13
- min: number;
14
- max?: number;
15
- }>;
16
- teams: {
17
- min: number;
18
- max: number;
19
- } | null;
20
- modes: Array<{
21
- id: string;
22
- }>;
23
- voice?: 'none' | 'room' | 'team' | 'proximity';
24
- }
25
- export interface IdentitaGiocatore {
26
- id: string;
27
- name: string;
28
- guest: boolean;
29
- }
30
- export interface Esito {
31
- frames: Array<{
32
- connessione: string;
33
- testo: string;
34
- }>;
35
- pubblici: string[];
36
- chiusure: Array<{
37
- connessione: string;
38
- codice: number;
39
- motivo: string;
40
- }>;
41
- sveglia: number | null;
42
- tick: boolean;
43
- tickRate: number;
44
- status: RoomStatus | null;
45
- }
46
- export interface InfoStanza {
47
- roomId: string;
48
- status: RoomStatus;
49
- players: number;
50
- max: number;
51
- mode: string | null;
52
- member: boolean;
53
- }
54
- export type EsitoIngresso = {
55
- ok: true;
56
- } | {
57
- ok: false;
58
- code: 'room_not_found' | 'room_full' | 'room_ended' | 'room_playing';
59
- };
60
- export interface EsitoFlush {
61
- scores: Array<{
62
- playerId: string;
63
- board: string;
64
- score: number;
65
- daily: boolean;
66
- }>;
67
- ended: {
68
- result: JsonValue;
69
- at: number;
70
- } | null;
71
- }
72
- export interface FacetStanza {
73
- crea(input: {
74
- mode: string | null;
75
- creator: IdentitaGiocatore;
76
- }): Promise<Esito & {
77
- ok: boolean;
78
- }>;
79
- info(playerId?: string): Promise<InfoStanza | null>;
80
- fotografia(): Promise<FotografiaStanza | null>;
81
- puoEntrare(identita: IdentitaGiocatore): Promise<EsitoIngresso>;
82
- entra(identita: IdentitaGiocatore, connessione: string): Promise<Esito>;
83
- ricevi(connessione: string, testo: string): Promise<Esito>;
84
- disconnetti(connessione: string): Promise<Esito>;
85
- tick(): Promise<Esito>;
86
- sveglia(): Promise<Esito>;
87
- flush(): Promise<EsitoFlush>;
88
- }
89
- export interface StorageFacet {
90
- get<T>(chiave: string): Promise<T | undefined>;
91
- put(chiave: string, valore: unknown): Promise<void>;
92
- delete(chiave: string): Promise<boolean>;
93
- list<T>(opzioni?: {
94
- prefix?: string;
95
- }): Promise<Map<string, T>>;
96
- }
97
- export interface StatoFacet {
98
- readonly id: string | {
99
- readonly name?: string;
100
- toString(): string;
101
- };
102
- readonly storage: StorageFacet;
103
- blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
104
- }
105
- export interface ClasseBaseFacet {
106
- new (stato: StatoFacet, ambiente: unknown): object;
107
- }
108
- export interface ClasseFacetStanza {
109
- new (stato: StatoFacet, ambiente: unknown): FacetStanza;
110
- }
111
- export declare function creaFacetStanza(DurableObject: ClasseBaseFacet, definizione: GameDefinition, manifest: RoomManifest): ClasseFacetStanza;
1
+ export * from './types/runtime/index.js';
package/dist/runtime.js CHANGED
@@ -1,3 +1,48 @@
1
+ // ../contracts/src/slug.ts
2
+ var NOMI_RISERVATI = [
3
+ "www",
4
+ "api",
5
+ "app",
6
+ "play",
7
+ "live",
8
+ "multi",
9
+ "cdn",
10
+ "assets",
11
+ "static",
12
+ "mail",
13
+ "mx",
14
+ "ns1",
15
+ "ns2",
16
+ "autodiscover",
17
+ "_dmarc",
18
+ "admin",
19
+ "login",
20
+ "account",
21
+ "auth",
22
+ "pay",
23
+ "secure",
24
+ "support",
25
+ "help",
26
+ "blog",
27
+ "status",
28
+ "dev",
29
+ "staging",
30
+ "test",
31
+ "caisual",
32
+ "shipz"
33
+ ];
34
+ var RISERVATI = new Set(NOMI_RISERVATI);
35
+
36
+ // ../contracts/src/manifest.ts
37
+ function risolviModalita(manifest, mode) {
38
+ const scelta = mode === null ? void 0 : manifest.modes.find((voce) => voce.id === mode);
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 };
41
+ }
42
+ function modalitaLocale(manifest, mode) {
43
+ return mode !== null && manifest.modes.some((voce) => voce.id === mode && voce.execution === "local");
44
+ }
45
+
1
46
  // src/stanza/json.ts
2
47
  function isPlainObject(value) {
3
48
  const prototype = Object.getPrototypeOf(value);
@@ -440,9 +485,8 @@ var NucleoStanza = class _NucleoStanza {
440
485
  }
441
486
  async crea(id, mode, _creator) {
442
487
  if (this.dati !== null) return false;
443
- if (mode !== null && !this.manifest.modes.some((item) => item.id === mode)) {
444
- throw new Error("The selected game mode does not exist.");
445
- }
488
+ risolviModalita(this.manifest, mode);
489
+ if (modalitaLocale(this.manifest, mode)) throw new Error("Local modes cannot create rooms.");
446
490
  const ora = this.adattatore.ora();
447
491
  this.dati = {
448
492
  versione: 1,
@@ -487,6 +531,9 @@ var NucleoStanza = class _NucleoStanza {
487
531
  await this.persistiEProgramma();
488
532
  return true;
489
533
  }
534
+ get configurazione() {
535
+ return risolviModalita(this.manifest, this.dati?.mode ?? null);
536
+ }
490
537
  info(playerId) {
491
538
  if (this.dati === null) return null;
492
539
  return {
@@ -495,7 +542,7 @@ var NucleoStanza = class _NucleoStanza {
495
542
  players: this.manifest.persistent === true ? this.dati.giocatori.length : this.dati.giocatori.filter(
496
543
  (player) => player.connected || player.graziaFinoA !== null
497
544
  ).length,
498
- max: this.manifest.players.max,
545
+ max: this.configurazione.players.max,
499
546
  mode: this.dati.mode,
500
547
  member: playerId === void 0 ? false : this.dati.giocatori.some((player) => player.id === playerId)
501
548
  };
@@ -514,15 +561,34 @@ var NucleoStanza = class _NucleoStanza {
514
561
  );
515
562
  return player === void 0 ? null : copiaGiocatore(player);
516
563
  }
564
+ puoAscoltare(listener, speakers) {
565
+ const mode = this.manifest.voice ?? "none";
566
+ if (mode === "none") return speakers.map(() => ({ ok: false, reason: "mode" }));
567
+ const dati = this.richiediDati();
568
+ const ascoltatore = dati.giocatori.find((player) => player.id === listener);
569
+ return speakers.map((speakerId) => {
570
+ const speaker = dati.giocatori.find((player) => player.id === speakerId);
571
+ if (ascoltatore === void 0 || speaker === void 0 || listener === speakerId) {
572
+ return { ok: false, reason: "unknown" };
573
+ }
574
+ if (mode === "team" && ascoltatore.role !== "spectator" && ascoltatore.team !== speaker.team) {
575
+ return { ok: false, reason: "team" };
576
+ }
577
+ if ((dati.voceGuadagni?.[listener]?.[speakerId] ?? 1) <= 0) {
578
+ return { ok: false, reason: "gain" };
579
+ }
580
+ return { ok: true };
581
+ });
582
+ }
517
583
  puoEntrare(identity) {
518
584
  if (this.dati === null) return { ok: false, code: "room_not_found" };
519
585
  if (this.dati.status === "ended") return { ok: false, code: "room_ended" };
520
586
  const esistente = this.dati.giocatori.find((player) => player.id === identity.id);
521
587
  if (esistente !== void 0) return { ok: true };
522
- if (this.manifest.lobby && this.dati.status !== "lobby") {
588
+ if (this.configurazione.lobby && this.dati.status !== "lobby") {
523
589
  return { ok: false, code: "room_playing" };
524
590
  }
525
- if (this.dati.giocatori.length >= this.manifest.players.max) {
591
+ if (this.dati.giocatori.length >= this.configurazione.players.max) {
526
592
  return { ok: false, code: "room_full" };
527
593
  }
528
594
  return { ok: true };
@@ -565,7 +631,7 @@ var NucleoStanza = class _NucleoStanza {
565
631
  dati.hostId ??= player.id;
566
632
  dati.vuotaDa = null;
567
633
  dati.ultimoInputAt = ora;
568
- const primaConnessione = !this.manifest.lobby && dati.status === "lobby";
634
+ const primaConnessione = !this.configurazione.lobby && dati.status === "lobby";
569
635
  if (primaConnessione) dati.status = "playing";
570
636
  if (nuovo) {
571
637
  await this.chiama(
@@ -671,6 +737,26 @@ var NucleoStanza = class _NucleoStanza {
671
737
  await this.persistiEProgramma();
672
738
  return;
673
739
  }
740
+ if (message.t === "request-role") {
741
+ if (!Number.isSafeInteger(message.r) || message.r < 1 || typeof message.role !== "string") return this.messaggioErrato(player);
742
+ let code = null;
743
+ if (this.dati.status !== "playing" || this.definizione.onRoleRequest === void 0) code = "role_change_unavailable";
744
+ else if (!this.manifest.roles.some((role) => role.id === message.role)) code = "invalid_role";
745
+ else {
746
+ this.dati.ultimoInputAt = ora;
747
+ await this.chiama(this.definizione.onRoleRequest, this.room, copiaGiocatore(player), message.role);
748
+ await this.concludiEvento();
749
+ if (player.role !== message.role) code = "role_change_refused";
750
+ }
751
+ if (player.connected && player.connessione !== null) this.adattatore.invia(player.connessione, {
752
+ t: "role-result",
753
+ r: message.r,
754
+ ok: code === null,
755
+ code
756
+ });
757
+ await this.persistiEProgramma();
758
+ return;
759
+ }
674
760
  if (message.t === "team") {
675
761
  if (!Number.isInteger(message.team)) return this.messaggioErrato(player);
676
762
  if (!this.inLobby(player)) return;
@@ -739,23 +825,8 @@ var NucleoStanza = class _NucleoStanza {
739
825
  this.inviaGuadagniCambiati();
740
826
  const stato = await this.verificaStato();
741
827
  if (stato === null || this.stanzaTerminata()) return;
742
- const cambiato = stato.testo !== JSON.stringify(dati.statoSincronizzato);
743
- if (dati.tick % 100 === 0) {
744
- dati.state = stato.valore;
745
- this.inviaSnapshotTutti();
746
- } else if (cambiato) {
747
- const base = dati.tickSincronizzato;
748
- this.broadcast({
749
- t: "state",
750
- tick: dati.tick,
751
- serverTime: this.adattatore.ora(),
752
- base,
753
- patch: creaDiff(dati.statoSincronizzato, stato.valore)
754
- });
755
- dati.state = stato.valore;
756
- dati.statoSincronizzato = copiaJson(stato.valore);
757
- dati.tickSincronizzato = dati.tick;
758
- }
828
+ dati.state = stato.valore;
829
+ this.inviaDiff();
759
830
  if (dati.tick % 100 === 0 || this.voceDaPersistire) await this.persisti();
760
831
  await this.aggiornaProgrammazione();
761
832
  }
@@ -884,10 +955,15 @@ var NucleoStanza = class _NucleoStanza {
884
955
  if (ruolo?.max !== void 0 && occupati >= ruolo.max) {
885
956
  return { code: "role_full", message: "This role is full." };
886
957
  }
958
+ const ruoloPrecedente = player.role;
959
+ const squadraPrecedente = player.team;
887
960
  player.role = roleId;
888
961
  if (roleId === "spectator") player.team = null;
889
962
  else if (player.team === null) player.team = this.squadraAutomatica();
890
963
  if (this.richiediDati().status === "lobby") player.ready = false;
964
+ if (player.role !== ruoloPrecedente || player.team !== squadraPrecedente) {
965
+ this.rivediVoce();
966
+ }
891
967
  this.inviaGiocatori();
892
968
  return null;
893
969
  }
@@ -898,8 +974,10 @@ var NucleoStanza = class _NucleoStanza {
898
974
  if (player.role === "spectator") {
899
975
  return { code: "spectator", message: "Spectators cannot join a team." };
900
976
  }
977
+ const squadraPrecedente = player.team;
901
978
  player.team = team;
902
979
  if (this.richiediDati().status === "lobby") player.ready = false;
980
+ if (player.team !== squadraPrecedente) this.rivediVoce();
903
981
  this.inviaGiocatori();
904
982
  return null;
905
983
  }
@@ -923,7 +1001,7 @@ var NucleoStanza = class _NucleoStanza {
923
1001
  erroreMinimi() {
924
1002
  const connessi = this.richiediDati().giocatori.filter((player) => player.connected);
925
1003
  const attivi = connessi.filter((player) => player.role !== "spectator");
926
- if (attivi.length < this.manifest.players.min) {
1004
+ if (attivi.length < this.configurazione.players.min) {
927
1005
  return { code: "not_enough_players", message: "The room does not have enough players." };
928
1006
  }
929
1007
  if (connessi.some((player) => !player.ready)) {
@@ -978,6 +1056,7 @@ var NucleoStanza = class _NucleoStanza {
978
1056
  const indice = dati.giocatori.findIndex((item) => item.id === player.id);
979
1057
  if (indice < 0) return;
980
1058
  dati.giocatori.splice(indice, 1);
1059
+ this.rivediVoce();
981
1060
  this.pulisciGuadagni(player.id);
982
1061
  if (dati.hostId === player.id) this.assegnaHost();
983
1062
  if (dati.giocatori.length === 0) dati.vuotaDa = this.adattatore.ora();
@@ -1024,7 +1103,7 @@ var NucleoStanza = class _NucleoStanza {
1024
1103
  });
1025
1104
  }
1026
1105
  accodaPunteggio(playerId, board, score, daily) {
1027
- if (!this.richiediDati().giocatori.some((player) => player.id === playerId)) {
1106
+ if (!this.richiediDati().giocatori.some((player2) => player2.id === playerId)) {
1028
1107
  throw new Error("Player not found.");
1029
1108
  }
1030
1109
  if (!CHIAVE.test(board)) {
@@ -1033,7 +1112,20 @@ var NucleoStanza = class _NucleoStanza {
1033
1112
  if (!Number.isSafeInteger(score) || score < 0) {
1034
1113
  throw new TypeError("Score must be a non-negative safe integer.");
1035
1114
  }
1036
- this.richiediDati().punteggi.push({ playerId, board, score, daily });
1115
+ const submittedAt = this.adattatore.ora();
1116
+ this.richiediDati().punteggi.push({
1117
+ playerId,
1118
+ board,
1119
+ score,
1120
+ daily,
1121
+ submittedAt,
1122
+ day: daily ? giornoUtc(submittedAt) : null
1123
+ });
1124
+ const player = this.richiediDati().giocatori.find((item) => item.id === playerId);
1125
+ if (player.connected && player.connessione !== null) this.adattatore.invia(player.connessione, {
1126
+ t: "score-queued",
1127
+ score: { player: playerId, board, score, day: daily ? giornoUtc(submittedAt) : null, submittedAt }
1128
+ });
1037
1129
  this.broadcast({ t: "flush" });
1038
1130
  }
1039
1131
  richiediFine(result) {
@@ -1210,21 +1302,44 @@ var NucleoStanza = class _NucleoStanza {
1210
1302
  tick: dati.tick,
1211
1303
  tickRate: dati.tickRate,
1212
1304
  serverTime: this.adattatore.ora(),
1213
- host: dati.hostId
1305
+ host: dati.hostId,
1306
+ countdownAt: dati.countdownAt,
1307
+ configuration: {
1308
+ players: { ...this.configurazione.players },
1309
+ lobby: this.configurazione.lobby,
1310
+ persistent: this.manifest.persistent === true,
1311
+ requestRole: this.definizione.onRoleRequest !== void 0
1312
+ }
1214
1313
  };
1215
1314
  }
1216
1315
  inviaGiocatori() {
1217
- this.broadcast({ t: "players", players: this.giocatoriProtocollo() });
1316
+ this.broadcast({ t: "players", players: this.giocatoriProtocollo(), host: this.richiediDati().hostId });
1218
1317
  }
1219
1318
  inviaStatus(at) {
1220
1319
  const dati = this.richiediDati();
1221
1320
  this.broadcast({
1222
1321
  t: "status",
1223
1322
  status: dati.status,
1323
+ host: dati.hostId,
1324
+ countdownAt: dati.countdownAt,
1224
1325
  at,
1225
1326
  result: dati.status === "ended" ? dati.result : null
1226
1327
  });
1227
1328
  }
1329
+ inviaDiff() {
1330
+ const dati = this.richiediDati();
1331
+ const patch = creaDiff(dati.statoSincronizzato, dati.state);
1332
+ if (patch.length === 0) return;
1333
+ this.broadcast({
1334
+ t: "state",
1335
+ tick: dati.tick,
1336
+ base: dati.tickSincronizzato,
1337
+ serverTime: this.adattatore.ora(),
1338
+ patch
1339
+ });
1340
+ dati.statoSincronizzato = copiaJson(dati.state);
1341
+ dati.tickSincronizzato = dati.tick;
1342
+ }
1228
1343
  inviaSnapshotTutti() {
1229
1344
  const dati = this.richiediDati();
1230
1345
  const stato = analizzaJson(dati.state);
@@ -1279,7 +1394,7 @@ var NucleoStanza = class _NucleoStanza {
1279
1394
  this.dati.state = stato.valore;
1280
1395
  if ((this.dati.tickRate === 0 || this.dati.status !== "playing") && stato.testo !== precedente) {
1281
1396
  this.dati.tick++;
1282
- this.inviaSnapshotTutti();
1397
+ this.inviaDiff();
1283
1398
  }
1284
1399
  }
1285
1400
  async verificaStato() {
@@ -1313,6 +1428,7 @@ var NucleoStanza = class _NucleoStanza {
1313
1428
  dati.voceGuadagni ??= {};
1314
1429
  const precedente = dati.voceGuadagni[playerId]?.[altroId] ?? 1;
1315
1430
  if (precedente === valore) return;
1431
+ if (precedente > 0 && valore === 0) this.rivediVoce();
1316
1432
  this.voceDaPersistire = true;
1317
1433
  if (valore === 1) {
1318
1434
  const riga = dati.voceGuadagni[playerId];
@@ -1330,6 +1446,9 @@ var NucleoStanza = class _NucleoStanza {
1330
1446
  this.voceGuadagniCambiati.set(playerId, cambi);
1331
1447
  return cambi;
1332
1448
  }
1449
+ rivediVoce() {
1450
+ if ((this.manifest.voice ?? "none") !== "none") this.adattatore.rivediVoce();
1451
+ }
1333
1452
  inviaGuadagniCambiati() {
1334
1453
  if (this.dati === null || this.voceGuadagniCambiati.size === 0) return;
1335
1454
  for (const [playerId, gains] of this.voceGuadagniCambiati) {
@@ -1377,7 +1496,7 @@ var NucleoStanza = class _NucleoStanza {
1377
1496
  } else if (stato.testo !== JSON.stringify(dati.statoSincronizzato)) {
1378
1497
  dati.tick++;
1379
1498
  dati.state = stato.valore;
1380
- this.inviaSnapshotTutti();
1499
+ this.inviaDiff();
1381
1500
  }
1382
1501
  const fine = { result: dati.result, at: dati.resultAt };
1383
1502
  dati.fineInCoda = fine;
@@ -1496,6 +1615,7 @@ var AdattatoreFacet = class {
1496
1615
  this.chiusure = [];
1497
1616
  this.sveglia = null;
1498
1617
  this.tick = false;
1618
+ this.voceRivedi = false;
1499
1619
  this.salvato = "";
1500
1620
  this.storage = new ArchivioFacet(archivio);
1501
1621
  this.tickRate = tickRate;
@@ -1539,6 +1659,9 @@ var AdattatoreFacet = class {
1539
1659
  misuraCpu() {
1540
1660
  return performance.now();
1541
1661
  }
1662
+ rivediVoce() {
1663
+ this.voceRivedi = true;
1664
+ }
1542
1665
  programmaTick(intervalloMs) {
1543
1666
  this.tick = intervalloMs !== null;
1544
1667
  if (intervalloMs !== null) this.tickRate = 1e3 / intervalloMs;
@@ -1554,11 +1677,13 @@ var AdattatoreFacet = class {
1554
1677
  sveglia: this.sveglia,
1555
1678
  tick: this.tick,
1556
1679
  tickRate: this.tickRate,
1557
- status
1680
+ status,
1681
+ voceRivedi: this.voceRivedi
1558
1682
  };
1559
1683
  this.frames = [];
1560
1684
  this.pubblici = [];
1561
1685
  this.chiusure = [];
1686
+ this.voceRivedi = false;
1562
1687
  return risultato;
1563
1688
  }
1564
1689
  };
@@ -1624,6 +1749,9 @@ function creaFacetStanza(DurableObject, definizione, manifest) {
1624
1749
  puoEntrare(identita) {
1625
1750
  return this.#serializza((nucleo) => nucleo.puoEntrare(identita));
1626
1751
  }
1752
+ puoAscoltare(listener, speakers) {
1753
+ return this.#serializza((nucleo) => nucleo.puoAscoltare(listener, speakers));
1754
+ }
1627
1755
  entra(identita, connessione) {
1628
1756
  return this.#esegui(async (nucleo) => {
1629
1757
  this.#adattatore.connessioni.add(connessione);
package/dist/server.d.ts CHANGED
@@ -1,71 +1 @@
1
- export type JsonValue = null | boolean | number | string | JsonValue[] | {
2
- [key: string]: JsonValue;
3
- };
4
- export type RoomStatus = 'lobby' | 'countdown' | 'playing' | 'ended';
5
- export type VoiceMode = 'none' | 'room' | 'team' | 'proximity';
6
- export type LeaveReason = 'left' | 'timeout' | 'kicked';
7
- export interface SharedGameStore {
8
- get(key: string): Promise<JsonValue | null>;
9
- set(key: string, value: JsonValue): Promise<void>;
10
- delete(key: string): Promise<void>;
11
- list(prefix?: string): Promise<string[]>;
12
- increment(key: string, amount?: number): Promise<number>;
13
- }
14
- export interface Player {
15
- readonly id: string;
16
- readonly name: string;
17
- readonly guest: boolean;
18
- readonly role: string | null;
19
- readonly team: number | null;
20
- readonly connected: boolean;
21
- }
22
- export interface Room<State extends JsonValue = JsonValue> {
23
- readonly id: string;
24
- readonly seed: number;
25
- readonly mode: string | null;
26
- readonly status: RoomStatus;
27
- readonly tick: number;
28
- readonly tickRate: number;
29
- readonly result: JsonValue | null;
30
- state: State;
31
- readonly players: readonly Player[];
32
- readonly host: Player | null;
33
- broadcast(message: JsonValue): void;
34
- send(player: Player | string, message: JsonValue): void;
35
- kick(player: Player | string): void;
36
- setRole(player: Player | string, role: string): void;
37
- setTeam(player: Player | string, team: number): void;
38
- end(result: JsonValue): void;
39
- save(key: string, value: JsonValue): Promise<void>;
40
- load(key: string): Promise<JsonValue | null>;
41
- readonly shared: SharedGameStore;
42
- schedule(milliseconds: number, handler: string, payload: JsonValue): void;
43
- readonly board: {
44
- submit(player: Player | string, board: string, score: number, options?: {
45
- daily?: boolean;
46
- }): void;
47
- };
48
- readonly daily: {
49
- readonly day: string;
50
- readonly seed: number;
51
- };
52
- readonly time: {
53
- now(): number;
54
- };
55
- readonly voice: {
56
- readonly mode: VoiceMode;
57
- setGain(listener: Player | string, speaker: Player | string, gain: number): void;
58
- setProximity(a: Player | string, b: Player | string, gain: number): void;
59
- };
60
- }
61
- export interface GameDefinition<State extends JsonValue = JsonValue> {
62
- tickRate: number;
63
- onCreate?(room: Room<State>): void | Promise<void>;
64
- onStart?(room: Room<State>): void | Promise<void>;
65
- onJoin?(room: Room<State>, player: Player): void | Promise<void>;
66
- onLeave?(room: Room<State>, player: Player, reason: LeaveReason): void | Promise<void>;
67
- onMessage?(room: Room<State>, player: Player, message: JsonValue): void | Promise<void>;
68
- onTick?(room: Room<State>, deltaSeconds: number): void | Promise<void>;
69
- onEnd?(room: Room<State>): void | Promise<void>;
70
- }
71
- export declare function defineGame<State extends JsonValue = JsonValue, const Definition extends GameDefinition<State> = GameDefinition<State>>(definition: Definition): Definition;
1
+ export * from './types/server/index.js';
package/dist/server.js CHANGED
@@ -6,6 +6,7 @@ var CALLBACKS = [
6
6
  "onJoin",
7
7
  "onLeave",
8
8
  "onMessage",
9
+ "onRoleRequest",
9
10
  "onTick",
10
11
  "onEnd"
11
12
  ];
@@ -0,0 +1,25 @@
1
+ import type { BoardResult, BoardTop, JsonValue, Player, SaveInfo } from './index.js';
2
+ import type { GestoreBiglietto } from './handshake.js';
3
+ export interface RispostaMe {
4
+ player: Player;
5
+ game: {
6
+ slug: string;
7
+ };
8
+ day: string;
9
+ seed: number;
10
+ serverTime: number;
11
+ }
12
+ export declare function creaClienteApi(appOrigin: string, fetcher: typeof fetch, biglietto: GestoreBiglietto): {
13
+ me: () => Promise<RispostaMe>;
14
+ saveSet: (key: string, value: JsonValue) => Promise<SaveInfo>;
15
+ saveGet(key: string): Promise<JsonValue | null>;
16
+ saveRemove(key: string): Promise<void>;
17
+ saveList(): Promise<SaveInfo[]>;
18
+ boardSubmit(board: string, score: number, daily: boolean): Promise<BoardResult>;
19
+ boardTop(board: string, opzioni: {
20
+ day?: string;
21
+ daily?: boolean;
22
+ limit?: number;
23
+ guests?: boolean;
24
+ }): Promise<BoardTop>;
25
+ };
@@ -0,0 +1,24 @@
1
+ export type DestinatarioBiglietto = 'portal' | 'live';
2
+ export interface Biglietto {
3
+ sub: string;
4
+ game: string;
5
+ name: string;
6
+ guest: boolean;
7
+ aud: DestinatarioBiglietto;
8
+ iat: number;
9
+ exp: number;
10
+ }
11
+ export interface DatiBiglietto {
12
+ sub: string;
13
+ game: string;
14
+ name: string;
15
+ guest: boolean;
16
+ aud: DestinatarioBiglietto;
17
+ }
18
+ export declare function firmaBiglietto(dati: DatiBiglietto, secret: string, now?: Date): Promise<string>;
19
+ /** Restituisce null senza distinguere quale controllo ha rifiutato il gettone. */
20
+ export declare function verificaBiglietto(token: string, secret: string, atteso: {
21
+ aud: DestinatarioBiglietto;
22
+ game: string;
23
+ now?: Date;
24
+ }): Promise<Biglietto | null>;
@@ -0,0 +1,66 @@
1
+ import type { ManifestRequires } from './manifest.js';
2
+ interface ProbeWebGlContext {
3
+ getExtension(name: string): {
4
+ loseContext(): void;
5
+ } | null;
6
+ }
7
+ interface ProbeCanvas {
8
+ getContext(name: string, options?: {
9
+ failIfMajorPerformanceCaveat?: boolean;
10
+ }): ProbeWebGlContext | null;
11
+ }
12
+ interface ProbeGpuDevice {
13
+ destroy?: () => void;
14
+ }
15
+ interface ProbeGpuAdapter {
16
+ requestDevice(): Promise<ProbeGpuDevice>;
17
+ }
18
+ interface ProbeGpu {
19
+ requestAdapter(): Promise<ProbeGpuAdapter | null>;
20
+ }
21
+ interface ProbeWebAssembly {
22
+ validate(bytes: Uint8Array): boolean;
23
+ Memory: new (descriptor: {
24
+ initial: number;
25
+ maximum: number;
26
+ shared: boolean;
27
+ }) => unknown;
28
+ }
29
+ export interface ProbeGlobals {
30
+ document: {
31
+ createElement(name: 'canvas'): ProbeCanvas;
32
+ };
33
+ navigator: {
34
+ gpu?: ProbeGpu;
35
+ deviceMemory?: number;
36
+ hardwareConcurrency?: number;
37
+ userAgentData?: {
38
+ mobile?: boolean;
39
+ };
40
+ userAgent?: string;
41
+ };
42
+ WebAssembly: ProbeWebAssembly;
43
+ crossOriginIsolated: boolean;
44
+ }
45
+ export interface DeviceReport {
46
+ webgl2: boolean;
47
+ webgpu: boolean;
48
+ wasm: boolean;
49
+ threads: boolean;
50
+ isolated: boolean;
51
+ gpu: 'hardware' | 'software' | 'none';
52
+ memoryMb: number | null;
53
+ cores: number | null;
54
+ mobile: boolean;
55
+ tier: 'low' | 'mid' | 'high';
56
+ }
57
+ export type CompatibilityLevel = 'ok' | 'slow' | 'unsupported';
58
+ export interface CompatibilityVerdict {
59
+ level: CompatibilityLevel;
60
+ missing: string[];
61
+ }
62
+ export declare function deviceTier(report: Omit<DeviceReport, 'tier'>): DeviceReport['tier'];
63
+ export declare function checkCompatibility(requires: ManifestRequires, report: DeviceReport): CompatibilityVerdict;
64
+ export declare function requiresAnything(requires: ManifestRequires): boolean;
65
+ export declare function probeDevice(globals?: Partial<ProbeGlobals>, timeoutMs?: number): Promise<DeviceReport>;
66
+ export {};