@flayerlabs/gamemode-gate 0.1.0 → 0.2.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 (48) hide show
  1. package/README.md +48 -2
  2. package/dist/bearer.d.ts +3 -0
  3. package/dist/bearer.d.ts.map +1 -0
  4. package/dist/bearer.js +8 -0
  5. package/dist/bearer.js.map +1 -0
  6. package/dist/demo.d.ts.map +1 -1
  7. package/dist/demo.js +4 -1
  8. package/dist/demo.js.map +1 -1
  9. package/dist/economy.js +1 -1
  10. package/dist/economy.js.map +1 -1
  11. package/dist/game-registry.d.ts.map +1 -1
  12. package/dist/game-registry.js +2 -7
  13. package/dist/game-registry.js.map +1 -1
  14. package/dist/game-server-awards.d.ts +39 -0
  15. package/dist/game-server-awards.d.ts.map +1 -0
  16. package/dist/game-server-awards.js +123 -0
  17. package/dist/game-server-awards.js.map +1 -0
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/ledger.d.ts +0 -2
  23. package/dist/ledger.d.ts.map +1 -1
  24. package/dist/ledger.js +0 -7
  25. package/dist/ledger.js.map +1 -1
  26. package/dist/room.d.ts +5 -0
  27. package/dist/room.d.ts.map +1 -1
  28. package/dist/room.js +32 -7
  29. package/dist/room.js.map +1 -1
  30. package/dist/server.d.ts +14 -3
  31. package/dist/server.d.ts.map +1 -1
  32. package/dist/server.js +77 -0
  33. package/dist/server.js.map +1 -1
  34. package/dist/store.d.ts +1 -1
  35. package/dist/store.d.ts.map +1 -1
  36. package/dist/store.js +39 -0
  37. package/dist/store.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/bearer.ts +8 -0
  40. package/src/demo.ts +4 -1
  41. package/src/economy.ts +1 -1
  42. package/src/game-registry.ts +2 -8
  43. package/src/game-server-awards.ts +199 -0
  44. package/src/index.ts +8 -0
  45. package/src/ledger.ts +0 -10
  46. package/src/room.ts +47 -6
  47. package/src/server.ts +132 -11
  48. package/src/store.ts +39 -0
package/src/store.ts CHANGED
@@ -10,8 +10,11 @@ import type { Pool, PoolClient } from 'pg';
10
10
  export const SCHEMA = `
11
11
  create table if not exists rounds (
12
12
  id text primary key,
13
+ game_id text not null check (game_id <> ''),
13
14
  wei_per_point numeric(78,0) not null check (wei_per_point > 0),
14
15
  wallet_cap_wei numeric(78,0) not null check (wallet_cap_wei > 0),
16
+ max_points_per_player bigint not null check (max_points_per_player > 0),
17
+ score_authority text not null check (score_authority in ('rules', 'external-server')),
15
18
  pool_id text not null,
16
19
  opens_at bigint not null,
17
20
  closes_at bigint not null,
@@ -29,6 +32,30 @@ create table if not exists rounds (
29
32
  constraint rounds_books_tail check (books_close_at >= closes_at)
30
33
  );
31
34
 
35
+ -- A developer may already have run the first published schema without creating any rounds. Add
36
+ -- the new authority fields in place for that empty setup. Existing round data needs a deliberate
37
+ -- reset because its original reward bound cannot be reconstructed safely.
38
+ alter table rounds
39
+ add column if not exists game_id text check (game_id <> '');
40
+ alter table rounds
41
+ add column if not exists max_points_per_player bigint check (max_points_per_player > 0);
42
+ alter table rounds
43
+ add column if not exists score_authority text check (score_authority in ('rules', 'external-server'));
44
+ do $$
45
+ begin
46
+ if exists (
47
+ select 1 from rounds
48
+ where game_id is null or max_points_per_player is null or score_authority is null
49
+ ) then
50
+ raise exception 'pre-release round rows cannot be upgraded safely'
51
+ using hint = 'Delete the pre-release round data, then run migrate(pool) again.';
52
+ end if;
53
+ end
54
+ $$;
55
+ alter table rounds alter column game_id set not null;
56
+ alter table rounds alter column max_points_per_player set not null;
57
+ alter table rounds alter column score_authority set not null;
58
+
32
59
  create table if not exists balances (
33
60
  round_id text not null references rounds(id) on delete cascade,
34
61
  player text not null,
@@ -61,6 +88,18 @@ create table if not exists claims (
61
88
 
62
89
  create index if not exists claims_by_player on claims (round_id, player) where status = 'held';
63
90
 
91
+ -- Trusted creator servers use one stable event id for every score increment. The event and the
92
+ -- balance update commit together, so a retry can recover the first result without paying twice.
93
+ create table if not exists award_events (
94
+ round_id text not null references rounds(id) on delete cascade,
95
+ event_id varchar(128) not null check (event_id <> ''),
96
+ player text not null,
97
+ points bigint not null check (points > 0),
98
+ total_points bigint not null check (total_points >= points),
99
+ created_at timestamptz not null default now(),
100
+ primary key (round_id, event_id)
101
+ );
102
+
64
103
  -- Which game a coin plays. Addresses are chain-local, so the pin is one row per (chain, coin).
65
104
  create table if not exists registrations (
66
105
  chain_id bigint not null check (chain_id > 0),