@mnbroatch/boardgame.io 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +102 -0
- package/ai/package.json +7 -0
- package/client/package.json +7 -0
- package/core/package.json +7 -0
- package/debug/package.json +7 -0
- package/dist/boardgameio.es.js +14238 -0
- package/dist/boardgameio.js +14277 -0
- package/dist/boardgameio.min.js +16 -0
- package/dist/cjs/Debug-9d141c06.js +9586 -0
- package/dist/cjs/ai-e0e8a768.js +377 -0
- package/dist/cjs/ai.js +20 -0
- package/dist/cjs/client-76dec77b.js +258 -0
- package/dist/cjs/client-a22d7500.js +524 -0
- package/dist/cjs/client.js +26 -0
- package/dist/cjs/core.js +52 -0
- package/dist/cjs/debug.js +18 -0
- package/dist/cjs/filter-player-view-bb02e2f6.js +89 -0
- package/dist/cjs/initialize-267fcd69.js +61 -0
- package/dist/cjs/internal.js +25 -0
- package/dist/cjs/master-2904879d.js +320 -0
- package/dist/cjs/master.js +18 -0
- package/dist/cjs/multiplayer.js +23 -0
- package/dist/cjs/plugin-random-7425844d.js +229 -0
- package/dist/cjs/plugins.js +59 -0
- package/dist/cjs/react-native.js +182 -0
- package/dist/cjs/react.js +727 -0
- package/dist/cjs/reducer-16eec232.js +1203 -0
- package/dist/cjs/server.js +4087 -0
- package/dist/cjs/socketio-7a0837eb.js +478 -0
- package/dist/cjs/testing.js +30 -0
- package/dist/cjs/transport-b1874dfa.js +37 -0
- package/dist/cjs/turn-order-b2ff8740.js +1136 -0
- package/dist/cjs/util-fcfd8fb8.js +140 -0
- package/dist/esm/Debug-0141fe2d.js +9577 -0
- package/dist/esm/ai-5c06e761.js +371 -0
- package/dist/esm/ai.js +8 -0
- package/dist/esm/client-2e653027.js +522 -0
- package/dist/esm/client-5f57c3f2.js +255 -0
- package/dist/esm/client.js +16 -0
- package/dist/esm/core.js +40 -0
- package/dist/esm/debug.js +10 -0
- package/dist/esm/filter-player-view-2c6cc96f.js +87 -0
- package/dist/esm/initialize-11d626ca.js +59 -0
- package/dist/esm/internal.js +10 -0
- package/dist/esm/master-fa8f2e43.js +318 -0
- package/dist/esm/master.js +10 -0
- package/dist/esm/multiplayer.js +14 -0
- package/dist/esm/plugin-random-087f861e.js +226 -0
- package/dist/esm/plugins.js +55 -0
- package/dist/esm/react-native.js +173 -0
- package/dist/esm/react.js +716 -0
- package/dist/esm/reducer-c46da7e5.js +1198 -0
- package/dist/esm/socketio-c22ffa65.js +455 -0
- package/dist/esm/testing.js +26 -0
- package/dist/esm/transport-ce07b771.js +35 -0
- package/dist/esm/turn-order-376d315e.js +1091 -0
- package/dist/esm/util-b6147cef.js +135 -0
- package/dist/types/packages/ai.d.ts +5 -0
- package/dist/types/packages/client.d.ts +3 -0
- package/dist/types/packages/core.d.ts +5 -0
- package/dist/types/packages/debug.d.ts +2 -0
- package/dist/types/packages/internal.d.ts +8 -0
- package/dist/types/packages/master.d.ts +2 -0
- package/dist/types/packages/multiplayer.d.ts +3 -0
- package/dist/types/packages/plugins.d.ts +3 -0
- package/dist/types/packages/react-native.d.ts +2 -0
- package/dist/types/packages/react.d.ts +3 -0
- package/dist/types/packages/server.d.ts +6 -0
- package/dist/types/packages/testing.d.ts +1 -0
- package/dist/types/src/ai/ai.d.ts +53 -0
- package/dist/types/src/ai/ai.test.d.ts +1 -0
- package/dist/types/src/ai/bot.d.ts +40 -0
- package/dist/types/src/ai/mcts-bot.d.ts +60 -0
- package/dist/types/src/ai/random-bot.d.ts +27 -0
- package/dist/types/src/client/client.d.ts +104 -0
- package/dist/types/src/client/client.test.d.ts +1 -0
- package/dist/types/src/client/debug/tests/debug.test.d.ts +1 -0
- package/dist/types/src/client/manager.d.ts +61 -0
- package/dist/types/src/client/react.d.ts +75 -0
- package/dist/types/src/client/react.ssr.test.d.ts +4 -0
- package/dist/types/src/client/react.test.d.ts +1 -0
- package/dist/types/src/client/transport/dummy.d.ts +18 -0
- package/dist/types/src/client/transport/local.d.ts +59 -0
- package/dist/types/src/client/transport/local.test.d.ts +1 -0
- package/dist/types/src/client/transport/socketio.d.ts +45 -0
- package/dist/types/src/client/transport/socketio.test.d.ts +1 -0
- package/dist/types/src/client/transport/transport.d.ts +50 -0
- package/dist/types/src/client/transport/transport.test.d.ts +1 -0
- package/dist/types/src/core/action-creators.d.ts +144 -0
- package/dist/types/src/core/action-types.d.ts +10 -0
- package/dist/types/src/core/backwards-compatibility.d.ts +12 -0
- package/dist/types/src/core/constants.d.ts +6 -0
- package/dist/types/src/core/errors.d.ts +15 -0
- package/dist/types/src/core/flow.d.ts +28 -0
- package/dist/types/src/core/flow.test.d.ts +1 -0
- package/dist/types/src/core/game-methods.d.ts +9 -0
- package/dist/types/src/core/game.d.ts +26 -0
- package/dist/types/src/core/game.test.d.ts +1 -0
- package/dist/types/src/core/initialize.d.ts +9 -0
- package/dist/types/src/core/logger.d.ts +2 -0
- package/dist/types/src/core/player-view.d.ts +7 -0
- package/dist/types/src/core/player-view.test.d.ts +1 -0
- package/dist/types/src/core/reducer.d.ts +155 -0
- package/dist/types/src/core/reducer.test.d.ts +1 -0
- package/dist/types/src/core/turn-order.d.ts +179 -0
- package/dist/types/src/core/turn-order.test.d.ts +8 -0
- package/dist/types/src/lobby/client.d.ts +194 -0
- package/dist/types/src/lobby/client.test.d.ts +1 -0
- package/dist/types/src/lobby/connection.d.ts +44 -0
- package/dist/types/src/lobby/connection.test.d.ts +1 -0
- package/dist/types/src/lobby/create-match-form.d.ts +26 -0
- package/dist/types/src/lobby/login-form.d.ts +23 -0
- package/dist/types/src/lobby/match-instance.d.ts +31 -0
- package/dist/types/src/lobby/react.d.ts +113 -0
- package/dist/types/src/lobby/react.ssr.test.d.ts +4 -0
- package/dist/types/src/lobby/react.test.d.ts +1 -0
- package/dist/types/src/master/filter-player-view.d.ts +96 -0
- package/dist/types/src/master/filter-player-view.test.d.ts +1 -0
- package/dist/types/src/master/master.d.ts +94 -0
- package/dist/types/src/master/master.test.d.ts +1 -0
- package/dist/types/src/plugins/events/events.d.ts +54 -0
- package/dist/types/src/plugins/events/events.test.d.ts +1 -0
- package/dist/types/src/plugins/main.d.ts +75 -0
- package/dist/types/src/plugins/main.test.d.ts +1 -0
- package/dist/types/src/plugins/plugin-events.d.ts +5 -0
- package/dist/types/src/plugins/plugin-immer.d.ts +7 -0
- package/dist/types/src/plugins/plugin-immer.test.d.ts +1 -0
- package/dist/types/src/plugins/plugin-log.d.ts +14 -0
- package/dist/types/src/plugins/plugin-log.test.d.ts +1 -0
- package/dist/types/src/plugins/plugin-player.d.ts +29 -0
- package/dist/types/src/plugins/plugin-player.test.d.ts +1 -0
- package/dist/types/src/plugins/plugin-random.d.ts +4 -0
- package/dist/types/src/plugins/plugin-serializable.d.ts +7 -0
- package/dist/types/src/plugins/plugin-serializable.test.d.ts +1 -0
- package/dist/types/src/plugins/random/random.alea.d.ts +19 -0
- package/dist/types/src/plugins/random/random.d.ts +54 -0
- package/dist/types/src/plugins/random/random.test.d.ts +1 -0
- package/dist/types/src/server/api.d.ts +13 -0
- package/dist/types/src/server/api.test.d.ts +1 -0
- package/dist/types/src/server/auth.d.ts +38 -0
- package/dist/types/src/server/auth.test.d.ts +1 -0
- package/dist/types/src/server/cors.d.ts +4 -0
- package/dist/types/src/server/cors.test.d.ts +1 -0
- package/dist/types/src/server/db/base.d.ts +192 -0
- package/dist/types/src/server/db/flatfile.d.ts +44 -0
- package/dist/types/src/server/db/flatfile.test.d.ts +1 -0
- package/dist/types/src/server/db/index.d.ts +4 -0
- package/dist/types/src/server/db/index.test.d.ts +1 -0
- package/dist/types/src/server/db/inmemory.d.ts +43 -0
- package/dist/types/src/server/db/inmemory.test.d.ts +1 -0
- package/dist/types/src/server/db/localstorage.d.ts +7 -0
- package/dist/types/src/server/db/localstorage.test.d.ts +1 -0
- package/dist/types/src/server/index.d.ts +68 -0
- package/dist/types/src/server/index.test.d.ts +1 -0
- package/dist/types/src/server/transport/pubsub/generic-pub-sub.d.ts +6 -0
- package/dist/types/src/server/transport/pubsub/in-memory-pub-sub.d.ts +7 -0
- package/dist/types/src/server/transport/pubsub/in-memory-pub-sub.test.d.ts +1 -0
- package/dist/types/src/server/transport/socketio-simultaneous.test.d.ts +1 -0
- package/dist/types/src/server/transport/socketio.d.ts +65 -0
- package/dist/types/src/server/transport/socketio.test.d.ts +1 -0
- package/dist/types/src/server/util.d.ts +35 -0
- package/dist/types/src/testing/mock-random.d.ts +15 -0
- package/dist/types/src/testing/mock-random.test.d.ts +1 -0
- package/dist/types/src/types.d.ts +387 -0
- package/internal/package.json +7 -0
- package/master/package.json +7 -0
- package/multiplayer/package.json +7 -0
- package/package.json +211 -0
- package/plugins/package.json +7 -0
- package/react/package.json +7 -0
- package/react-native/package.json +7 -0
- package/server/package.json +6 -0
- package/src/ai/ai.test.ts +433 -0
- package/src/ai/ai.ts +84 -0
- package/src/ai/bot.ts +122 -0
- package/src/ai/mcts-bot.ts +331 -0
- package/src/ai/random-bot.ts +20 -0
- package/src/client/client.test.ts +993 -0
- package/src/client/client.ts +588 -0
- package/src/client/debug/Debug.svelte +239 -0
- package/src/client/debug/Menu.svelte +65 -0
- package/src/client/debug/ai/AI.svelte +215 -0
- package/src/client/debug/ai/Options.svelte +48 -0
- package/src/client/debug/info/Info.svelte +22 -0
- package/src/client/debug/info/Item.svelte +24 -0
- package/src/client/debug/log/Log.svelte +157 -0
- package/src/client/debug/log/LogEvent.svelte +149 -0
- package/src/client/debug/log/LogMetadata.svelte +7 -0
- package/src/client/debug/log/PhaseMarker.svelte +27 -0
- package/src/client/debug/log/TurnMarker.svelte +23 -0
- package/src/client/debug/main/ClientSwitcher.svelte +59 -0
- package/src/client/debug/main/Controls.svelte +58 -0
- package/src/client/debug/main/Hotkey.svelte +84 -0
- package/src/client/debug/main/InteractiveFunction.svelte +85 -0
- package/src/client/debug/main/Main.svelte +121 -0
- package/src/client/debug/main/Move.svelte +68 -0
- package/src/client/debug/main/PlayerInfo.svelte +70 -0
- package/src/client/debug/mcts/Action.svelte +22 -0
- package/src/client/debug/mcts/MCTS.svelte +78 -0
- package/src/client/debug/mcts/Table.svelte +98 -0
- package/src/client/debug/tests/JSONTree.mock.svelte +3 -0
- package/src/client/debug/tests/debug.test.ts +183 -0
- package/src/client/debug/utils/shortcuts.js +50 -0
- package/src/client/debug/utils/shortcuts.test.js +49 -0
- package/src/client/manager.ts +177 -0
- package/src/client/react-native.js +136 -0
- package/src/client/react-native.test.js +229 -0
- package/src/client/react.ssr.test.tsx +24 -0
- package/src/client/react.test.tsx +213 -0
- package/src/client/react.tsx +192 -0
- package/src/client/transport/dummy.ts +19 -0
- package/src/client/transport/local.test.ts +353 -0
- package/src/client/transport/local.ts +230 -0
- package/src/client/transport/socketio.test.ts +328 -0
- package/src/client/transport/socketio.ts +210 -0
- package/src/client/transport/transport.test.ts +27 -0
- package/src/client/transport/transport.ts +95 -0
- package/src/core/action-creators.ts +159 -0
- package/src/core/action-types.ts +18 -0
- package/src/core/backwards-compatibility.ts +23 -0
- package/src/core/constants.ts +6 -0
- package/src/core/errors.ts +35 -0
- package/src/core/flow.test.ts +2433 -0
- package/src/core/flow.ts +897 -0
- package/src/core/game-methods.ts +9 -0
- package/src/core/game.test.ts +286 -0
- package/src/core/game.ts +114 -0
- package/src/core/initialize.ts +77 -0
- package/src/core/logger.test.js +90 -0
- package/src/core/logger.ts +18 -0
- package/src/core/player-view.test.ts +50 -0
- package/src/core/player-view.ts +39 -0
- package/src/core/reducer.test.ts +991 -0
- package/src/core/reducer.ts +532 -0
- package/src/core/turn-order.test.ts +1123 -0
- package/src/core/turn-order.ts +473 -0
- package/src/lobby/client.test.ts +385 -0
- package/src/lobby/client.ts +358 -0
- package/src/lobby/connection.test.ts +207 -0
- package/src/lobby/connection.ts +162 -0
- package/src/lobby/create-match-form.tsx +122 -0
- package/src/lobby/login-form.tsx +75 -0
- package/src/lobby/match-instance.tsx +135 -0
- package/src/lobby/react.ssr.test.tsx +22 -0
- package/src/lobby/react.test.tsx +594 -0
- package/src/lobby/react.tsx +402 -0
- package/src/master/filter-player-view.test.ts +381 -0
- package/src/master/filter-player-view.ts +102 -0
- package/src/master/master.test.ts +1068 -0
- package/src/master/master.ts +492 -0
- package/src/plugins/events/events.test.ts +108 -0
- package/src/plugins/events/events.ts +209 -0
- package/src/plugins/main.test.ts +411 -0
- package/src/plugins/main.ts +314 -0
- package/src/plugins/plugin-events.ts +40 -0
- package/src/plugins/plugin-immer.test.ts +86 -0
- package/src/plugins/plugin-immer.ts +37 -0
- package/src/plugins/plugin-log.test.ts +37 -0
- package/src/plugins/plugin-log.ts +40 -0
- package/src/plugins/plugin-player.test.ts +172 -0
- package/src/plugins/plugin-player.ts +100 -0
- package/src/plugins/plugin-random.ts +40 -0
- package/src/plugins/plugin-serializable.test.ts +40 -0
- package/src/plugins/plugin-serializable.ts +55 -0
- package/src/plugins/random/random.alea.ts +109 -0
- package/src/plugins/random/random.test.ts +167 -0
- package/src/plugins/random/random.ts +198 -0
- package/src/server/api.test.ts +1699 -0
- package/src/server/api.ts +527 -0
- package/src/server/auth.test.ts +275 -0
- package/src/server/auth.ts +89 -0
- package/src/server/cors.test.ts +121 -0
- package/src/server/cors.ts +7 -0
- package/src/server/db/base.ts +296 -0
- package/src/server/db/flatfile.test.ts +221 -0
- package/src/server/db/flatfile.ts +228 -0
- package/src/server/db/index.test.ts +8 -0
- package/src/server/db/index.ts +12 -0
- package/src/server/db/inmemory.test.ts +143 -0
- package/src/server/db/inmemory.ts +143 -0
- package/src/server/db/localstorage.test.ts +73 -0
- package/src/server/db/localstorage.ts +44 -0
- package/src/server/index.test.ts +265 -0
- package/src/server/index.ts +175 -0
- package/src/server/transport/pubsub/generic-pub-sub.ts +11 -0
- package/src/server/transport/pubsub/in-memory-pub-sub.test.ts +47 -0
- package/src/server/transport/pubsub/in-memory-pub-sub.ts +28 -0
- package/src/server/transport/socketio-simultaneous.test.ts +603 -0
- package/src/server/transport/socketio.test.ts +303 -0
- package/src/server/transport/socketio.ts +279 -0
- package/src/server/util.ts +85 -0
- package/src/testing/mock-random.test.ts +45 -0
- package/src/testing/mock-random.ts +27 -0
- package/src/types.ts +511 -0
- package/testing/package.json +7 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import type { Object } from 'ts-toolbelt';
|
|
2
|
+
import type { State, Server, LogEntry } from '../../types';
|
|
3
|
+
export declare enum Type {
|
|
4
|
+
SYNC = 0,
|
|
5
|
+
ASYNC = 1
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Type guard that checks if a storage implementation is synchronous.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isSynchronous(storageAPI: Sync | Async): storageAPI is Sync;
|
|
11
|
+
/**
|
|
12
|
+
* Indicates which fields the fetch operation should return.
|
|
13
|
+
*/
|
|
14
|
+
export interface FetchOpts {
|
|
15
|
+
state?: boolean;
|
|
16
|
+
log?: boolean;
|
|
17
|
+
metadata?: boolean;
|
|
18
|
+
initialState?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Data that can be retrieved from a database fetch query
|
|
22
|
+
*/
|
|
23
|
+
export interface FetchFields {
|
|
24
|
+
state: State;
|
|
25
|
+
log: LogEntry[];
|
|
26
|
+
metadata: Server.MatchData;
|
|
27
|
+
initialState: State;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The result of the fetch operation.
|
|
31
|
+
*/
|
|
32
|
+
export declare type FetchResult<O extends FetchOpts> = Object.Pick<FetchFields, Object.SelectKeys<O, true>>;
|
|
33
|
+
/**
|
|
34
|
+
* Options passed when listing matches.
|
|
35
|
+
*/
|
|
36
|
+
export interface ListMatchesOpts {
|
|
37
|
+
gameName?: string;
|
|
38
|
+
where?: {
|
|
39
|
+
isGameover?: boolean;
|
|
40
|
+
updatedBefore?: number;
|
|
41
|
+
updatedAfter?: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Use ListMatchesOpts instead
|
|
46
|
+
*/
|
|
47
|
+
export interface ListGamesOpts {
|
|
48
|
+
gameName?: string;
|
|
49
|
+
where?: {
|
|
50
|
+
isGameover?: boolean;
|
|
51
|
+
updatedBefore?: number;
|
|
52
|
+
updatedAfter?: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Options passed when creating a new match.
|
|
57
|
+
*/
|
|
58
|
+
export interface CreateMatchOpts {
|
|
59
|
+
initialState: State;
|
|
60
|
+
metadata: Server.MatchData;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @deprecated Use CreateMatchOpts instead
|
|
64
|
+
*/
|
|
65
|
+
export interface CreateGameOpts {
|
|
66
|
+
initialState: State;
|
|
67
|
+
metadata: Server.MatchData;
|
|
68
|
+
}
|
|
69
|
+
export declare abstract class Async {
|
|
70
|
+
type(): Type;
|
|
71
|
+
/**
|
|
72
|
+
* Connect.
|
|
73
|
+
*/
|
|
74
|
+
abstract connect(): any;
|
|
75
|
+
/**
|
|
76
|
+
* Create a new match.
|
|
77
|
+
*
|
|
78
|
+
* This might just need to call setState and setMetadata in
|
|
79
|
+
* most implementations.
|
|
80
|
+
*
|
|
81
|
+
* However, it exists as a separate call so that the
|
|
82
|
+
* implementation can provision things differently when
|
|
83
|
+
* a match is created. For example, it might stow away the
|
|
84
|
+
* initial match state in a separate field for easier retrieval.
|
|
85
|
+
*/
|
|
86
|
+
createMatch(matchID: string, opts: CreateMatchOpts): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Create a new game.
|
|
89
|
+
*
|
|
90
|
+
* This might just need to call setState and setMetadata in
|
|
91
|
+
* most implementations.
|
|
92
|
+
*
|
|
93
|
+
* However, it exists as a separate call so that the
|
|
94
|
+
* implementation can provision things differently when
|
|
95
|
+
* a game is created. For example, it might stow away the
|
|
96
|
+
* initial game state in a separate field for easier retrieval.
|
|
97
|
+
*
|
|
98
|
+
* @deprecated Use createMatch instead, if implemented
|
|
99
|
+
*/
|
|
100
|
+
createGame?(matchID: string, opts: CreateGameOpts): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Update the game state.
|
|
103
|
+
*
|
|
104
|
+
* If passed a deltalog array, setState should append its contents to the
|
|
105
|
+
* existing log for this game.
|
|
106
|
+
*/
|
|
107
|
+
abstract setState(matchID: string, state: State, deltalog?: LogEntry[]): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Update the game metadata.
|
|
110
|
+
*/
|
|
111
|
+
abstract setMetadata(matchID: string, metadata: Server.MatchData): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Fetch the game state.
|
|
114
|
+
*/
|
|
115
|
+
abstract fetch<O extends FetchOpts>(matchID: string, opts: O): Promise<FetchResult<O>>;
|
|
116
|
+
/**
|
|
117
|
+
* Remove the game state.
|
|
118
|
+
*/
|
|
119
|
+
abstract wipe(matchID: string): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Return all matches.
|
|
122
|
+
*/
|
|
123
|
+
listMatches(opts?: ListMatchesOpts): Promise<string[]>;
|
|
124
|
+
/**
|
|
125
|
+
* Return all games.
|
|
126
|
+
*
|
|
127
|
+
* @deprecated Use listMatches instead, if implemented
|
|
128
|
+
*/
|
|
129
|
+
listGames?(opts?: ListGamesOpts): Promise<string[]>;
|
|
130
|
+
}
|
|
131
|
+
export declare abstract class Sync {
|
|
132
|
+
type(): Type;
|
|
133
|
+
/**
|
|
134
|
+
* Connect.
|
|
135
|
+
*/
|
|
136
|
+
connect(): void;
|
|
137
|
+
/**
|
|
138
|
+
* Create a new match.
|
|
139
|
+
*
|
|
140
|
+
* This might just need to call setState and setMetadata in
|
|
141
|
+
* most implementations.
|
|
142
|
+
*
|
|
143
|
+
* However, it exists as a separate call so that the
|
|
144
|
+
* implementation can provision things differently when
|
|
145
|
+
* a match is created. For example, it might stow away the
|
|
146
|
+
* initial match state in a separate field for easier retrieval.
|
|
147
|
+
*/
|
|
148
|
+
createMatch(matchID: string, opts: CreateMatchOpts): void;
|
|
149
|
+
/**
|
|
150
|
+
* Create a new game.
|
|
151
|
+
*
|
|
152
|
+
* This might just need to call setState and setMetadata in
|
|
153
|
+
* most implementations.
|
|
154
|
+
*
|
|
155
|
+
* However, it exists as a separate call so that the
|
|
156
|
+
* implementation can provision things differently when
|
|
157
|
+
* a game is created. For example, it might stow away the
|
|
158
|
+
* initial game state in a separate field for easier retrieval.
|
|
159
|
+
*
|
|
160
|
+
* @deprecated Use createMatch instead, if implemented
|
|
161
|
+
*/
|
|
162
|
+
createGame?(matchID: string, opts: CreateGameOpts): void;
|
|
163
|
+
/**
|
|
164
|
+
* Update the match state.
|
|
165
|
+
*
|
|
166
|
+
* If passed a deltalog array, setState should append its contents to the
|
|
167
|
+
* existing log for this match.
|
|
168
|
+
*/
|
|
169
|
+
abstract setState(matchID: string, state: State, deltalog?: LogEntry[]): void;
|
|
170
|
+
/**
|
|
171
|
+
* Update the match metadata.
|
|
172
|
+
*/
|
|
173
|
+
abstract setMetadata(matchID: string, metadata: Server.MatchData): void;
|
|
174
|
+
/**
|
|
175
|
+
* Fetch the match state.
|
|
176
|
+
*/
|
|
177
|
+
abstract fetch<O extends FetchOpts>(matchID: string, opts: O): FetchResult<O>;
|
|
178
|
+
/**
|
|
179
|
+
* Remove the match state.
|
|
180
|
+
*/
|
|
181
|
+
abstract wipe(matchID: string): void;
|
|
182
|
+
/**
|
|
183
|
+
* Return all matches.
|
|
184
|
+
*/
|
|
185
|
+
listMatches(opts?: ListMatchesOpts): string[];
|
|
186
|
+
/**
|
|
187
|
+
* Return all games.
|
|
188
|
+
*
|
|
189
|
+
* @deprecated Use listMatches instead, if implemented
|
|
190
|
+
*/
|
|
191
|
+
listGames?(opts?: ListGamesOpts): string[];
|
|
192
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as StorageAPI from './base';
|
|
2
|
+
import type { State, Server, LogEntry } from '../../types';
|
|
3
|
+
interface InitOptions {
|
|
4
|
+
dir: string;
|
|
5
|
+
logging?: boolean;
|
|
6
|
+
ttl?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* FlatFile data storage.
|
|
10
|
+
*/
|
|
11
|
+
export declare class FlatFile extends StorageAPI.Async {
|
|
12
|
+
private games;
|
|
13
|
+
private dir;
|
|
14
|
+
private logging?;
|
|
15
|
+
private ttl?;
|
|
16
|
+
private fileQueues;
|
|
17
|
+
constructor({ dir, logging, ttl }: InitOptions);
|
|
18
|
+
private chainRequest;
|
|
19
|
+
private getItem;
|
|
20
|
+
private setItem;
|
|
21
|
+
private removeItem;
|
|
22
|
+
connect(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Create new match.
|
|
25
|
+
*
|
|
26
|
+
* @param matchID
|
|
27
|
+
* @param opts
|
|
28
|
+
* @override
|
|
29
|
+
*/
|
|
30
|
+
createMatch(matchID: string, opts: StorageAPI.CreateMatchOpts): Promise<void>;
|
|
31
|
+
fetch<O extends StorageAPI.FetchOpts>(matchID: string, opts: O): Promise<StorageAPI.FetchResult<O>>;
|
|
32
|
+
clear(): Promise<void>;
|
|
33
|
+
setState(id: string, state: State, deltalog?: LogEntry[]): Promise<any>;
|
|
34
|
+
setMetadata(id: string, metadata: Server.MatchData): Promise<void>;
|
|
35
|
+
wipe(id: string): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* List matches IDs.
|
|
38
|
+
*
|
|
39
|
+
* @param opts
|
|
40
|
+
* @override
|
|
41
|
+
*/
|
|
42
|
+
listMatches(opts?: StorageAPI.ListMatchesOpts): Promise<string[]>;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { State, Server, LogEntry } from '../../types';
|
|
2
|
+
import * as StorageAPI from './base';
|
|
3
|
+
/**
|
|
4
|
+
* InMemory data storage.
|
|
5
|
+
*/
|
|
6
|
+
export declare class InMemory extends StorageAPI.Sync {
|
|
7
|
+
protected state: Map<string, State>;
|
|
8
|
+
protected initial: Map<string, State>;
|
|
9
|
+
protected metadata: Map<string, Server.MatchData>;
|
|
10
|
+
protected log: Map<string, LogEntry[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new InMemory storage.
|
|
13
|
+
*/
|
|
14
|
+
constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Create a new match.
|
|
17
|
+
*
|
|
18
|
+
* @override
|
|
19
|
+
*/
|
|
20
|
+
createMatch(matchID: string, opts: StorageAPI.CreateMatchOpts): void;
|
|
21
|
+
/**
|
|
22
|
+
* Write the match metadata to the in-memory object.
|
|
23
|
+
*/
|
|
24
|
+
setMetadata(matchID: string, metadata: Server.MatchData): void;
|
|
25
|
+
/**
|
|
26
|
+
* Write the match state to the in-memory object.
|
|
27
|
+
*/
|
|
28
|
+
setState(matchID: string, state: State, deltalog?: LogEntry[]): void;
|
|
29
|
+
/**
|
|
30
|
+
* Fetches state for a particular matchID.
|
|
31
|
+
*/
|
|
32
|
+
fetch<O extends StorageAPI.FetchOpts>(matchID: string, opts: O): StorageAPI.FetchResult<O>;
|
|
33
|
+
/**
|
|
34
|
+
* Remove the match state from the in-memory object.
|
|
35
|
+
*/
|
|
36
|
+
wipe(matchID: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Return all keys.
|
|
39
|
+
*
|
|
40
|
+
* @override
|
|
41
|
+
*/
|
|
42
|
+
listMatches(opts?: StorageAPI.ListMatchesOpts): string[];
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/// <reference types="koa__router" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import Koa from 'koa';
|
|
4
|
+
import Router from '@koa/router';
|
|
5
|
+
import type { CorsOptions } from 'cors';
|
|
6
|
+
import { configureRouter, configureApp } from './api';
|
|
7
|
+
import { Auth } from './auth';
|
|
8
|
+
import { SocketIO } from './transport/socketio';
|
|
9
|
+
import type { Server as ServerTypes, Game, StorageAPI } from '../types';
|
|
10
|
+
export declare type KoaServer = ReturnType<Koa['listen']>;
|
|
11
|
+
export { configureRouter };
|
|
12
|
+
export { configureApp };
|
|
13
|
+
interface ServerConfig {
|
|
14
|
+
port?: number;
|
|
15
|
+
callback?: () => void;
|
|
16
|
+
lobbyConfig?: {
|
|
17
|
+
apiPort: number;
|
|
18
|
+
apiCallback?: () => void;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
interface HttpsOptions {
|
|
22
|
+
cert: string;
|
|
23
|
+
key: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Build config object from server run arguments.
|
|
27
|
+
*/
|
|
28
|
+
export declare const createServerRunConfig: (portOrConfig: number | ServerConfig, callback?: () => void) => ServerConfig;
|
|
29
|
+
export declare const getPortFromServer: (server: KoaServer) => string | number | null;
|
|
30
|
+
interface ServerOpts {
|
|
31
|
+
games: Game[];
|
|
32
|
+
origins?: CorsOptions['origin'];
|
|
33
|
+
apiOrigins?: CorsOptions['origin'];
|
|
34
|
+
db?: StorageAPI.Async | StorageAPI.Sync;
|
|
35
|
+
transport?: SocketIO;
|
|
36
|
+
uuid?: () => string;
|
|
37
|
+
authenticateCredentials?: ServerTypes.AuthenticateCredentials;
|
|
38
|
+
generateCredentials?: ServerTypes.GenerateCredentials;
|
|
39
|
+
https?: HttpsOptions;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Instantiate a game server.
|
|
43
|
+
*
|
|
44
|
+
* @param games - The games that this server will handle.
|
|
45
|
+
* @param db - The interface with the database.
|
|
46
|
+
* @param transport - The interface with the clients.
|
|
47
|
+
* @param authenticateCredentials - Function to test player credentials.
|
|
48
|
+
* @param origins - Allowed origins to use this server, e.g. `['http://localhost:3000']`.
|
|
49
|
+
* @param apiOrigins - Allowed origins to use the Lobby API, defaults to `origins`.
|
|
50
|
+
* @param generateCredentials - Method for API to generate player credentials.
|
|
51
|
+
* @param https - HTTPS configuration options passed through to the TLS module.
|
|
52
|
+
* @param lobbyConfig - Configuration options for the Lobby API server.
|
|
53
|
+
*/
|
|
54
|
+
export declare function Server({ games, db, transport, https, uuid, origins, apiOrigins, generateCredentials, authenticateCredentials, }: ServerOpts): {
|
|
55
|
+
app: ServerTypes.App;
|
|
56
|
+
db: StorageAPI.Async | StorageAPI.Sync;
|
|
57
|
+
auth: Auth;
|
|
58
|
+
router: Router<any, ServerTypes.AppCtx>;
|
|
59
|
+
transport: SocketIO;
|
|
60
|
+
run: (portOrConfig: number | ServerConfig, callback?: () => void) => Promise<{
|
|
61
|
+
apiServer: import("http").Server;
|
|
62
|
+
appServer: import("http").Server;
|
|
63
|
+
}>;
|
|
64
|
+
kill: (servers: {
|
|
65
|
+
apiServer?: KoaServer;
|
|
66
|
+
appServer: KoaServer;
|
|
67
|
+
}) => void;
|
|
68
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GenericPubSub } from './generic-pub-sub';
|
|
2
|
+
export declare class InMemoryPubSub<T> implements GenericPubSub<T> {
|
|
3
|
+
callbacks: Map<string, ((payload: T) => void)[]>;
|
|
4
|
+
publish(channelId: string, payload: T): void;
|
|
5
|
+
subscribe(channelId: string, callback: (payload: T) => void): void;
|
|
6
|
+
unsubscribeAll(channelId: string): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { CorsOptions } from 'cors';
|
|
3
|
+
import type IOTypes from 'socket.io';
|
|
4
|
+
import type { ServerOptions as HttpsOptions } from 'https';
|
|
5
|
+
import PQueue from 'p-queue';
|
|
6
|
+
import { Master } from '../../master/master';
|
|
7
|
+
import type { TransportAPI as MasterTransport } from '../../master/master';
|
|
8
|
+
import type { Game, Server } from '../../types';
|
|
9
|
+
import type { GenericPubSub } from './pubsub/generic-pub-sub';
|
|
10
|
+
import type { IntermediateTransportData } from '../../master/master';
|
|
11
|
+
/**
|
|
12
|
+
* API that's exposed by SocketIO for the Master to send
|
|
13
|
+
* information to the clients.
|
|
14
|
+
*/
|
|
15
|
+
export declare const TransportAPI: (matchID: string, socket: IOTypes.Socket, filterPlayerView: any, pubSub: GenericPubSub<IntermediateTransportData>) => MasterTransport;
|
|
16
|
+
export interface SocketOpts {
|
|
17
|
+
https?: HttpsOptions;
|
|
18
|
+
socketOpts?: IOTypes.ServerOptions;
|
|
19
|
+
socketAdapter?: any;
|
|
20
|
+
pubSub?: GenericPubSub<IntermediateTransportData>;
|
|
21
|
+
}
|
|
22
|
+
interface Client {
|
|
23
|
+
matchID: string;
|
|
24
|
+
playerID: string;
|
|
25
|
+
socket: IOTypes.Socket;
|
|
26
|
+
credentials: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Transport interface that uses socket.io
|
|
30
|
+
*/
|
|
31
|
+
export declare class SocketIO {
|
|
32
|
+
protected clientInfo: Map<string, Client>;
|
|
33
|
+
protected roomInfo: Map<string, Set<string>>;
|
|
34
|
+
protected perMatchQueue: Map<string, PQueue>;
|
|
35
|
+
private readonly https;
|
|
36
|
+
private readonly socketAdapter;
|
|
37
|
+
private readonly socketOpts;
|
|
38
|
+
protected pubSub: GenericPubSub<IntermediateTransportData>;
|
|
39
|
+
constructor({ https, socketAdapter, socketOpts, pubSub }?: SocketOpts);
|
|
40
|
+
/**
|
|
41
|
+
* Unregister client data for a socket.
|
|
42
|
+
*/
|
|
43
|
+
private removeClient;
|
|
44
|
+
/**
|
|
45
|
+
* Register client data for a socket.
|
|
46
|
+
*/
|
|
47
|
+
private addClient;
|
|
48
|
+
private subscribePubSubChannel;
|
|
49
|
+
private unsubscribePubSubChannel;
|
|
50
|
+
init(app: Server.App & {
|
|
51
|
+
_io?: IOTypes.Server;
|
|
52
|
+
}, games: Game[], origins?: CorsOptions['origin']): void;
|
|
53
|
+
/**
|
|
54
|
+
* Create a PQueue for a given matchID if none exists and return it.
|
|
55
|
+
* @param matchID
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
getMatchQueue(matchID: string): PQueue;
|
|
59
|
+
/**
|
|
60
|
+
* Delete a PQueue for a given matchID.
|
|
61
|
+
* @param matchID
|
|
62
|
+
*/
|
|
63
|
+
deleteMatchQueue(matchID: string): void;
|
|
64
|
+
}
|
|
65
|
+
export { Master };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Server, State, Game } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new match metadata object.
|
|
4
|
+
*/
|
|
5
|
+
export declare const createMetadata: ({ game, unlisted, setupData, numPlayers, }: {
|
|
6
|
+
game: Game;
|
|
7
|
+
numPlayers: number;
|
|
8
|
+
setupData?: any;
|
|
9
|
+
unlisted?: boolean;
|
|
10
|
+
}) => Server.MatchData;
|
|
11
|
+
/**
|
|
12
|
+
* Creates initial state and metadata for a new match.
|
|
13
|
+
* If the provided `setupData` doesn’t pass the game’s validation,
|
|
14
|
+
* an error object is returned instead.
|
|
15
|
+
*/
|
|
16
|
+
export declare const createMatch: ({ game, numPlayers, setupData, unlisted, }: {
|
|
17
|
+
game: Game;
|
|
18
|
+
numPlayers: number;
|
|
19
|
+
setupData: any;
|
|
20
|
+
unlisted: boolean;
|
|
21
|
+
}) => {
|
|
22
|
+
metadata: Server.MatchData;
|
|
23
|
+
initialState: State;
|
|
24
|
+
} | {
|
|
25
|
+
setupDataError: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Given players, returns the count of players.
|
|
29
|
+
*/
|
|
30
|
+
export declare const getNumPlayers: (players: Server.MatchData['players']) => number;
|
|
31
|
+
/**
|
|
32
|
+
* Given players, tries to find the ID of the first player that can be joined.
|
|
33
|
+
* Returns `undefined` if there’s no available ID.
|
|
34
|
+
*/
|
|
35
|
+
export declare const getFirstAvailablePlayerID: (players: Server.MatchData['players']) => string | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RandomAPI } from '../plugins/random/random';
|
|
2
|
+
import RandomPlugin from '../plugins/plugin-random';
|
|
3
|
+
/**
|
|
4
|
+
* Test helper that creates a plugin to override the built-in random API.
|
|
5
|
+
*
|
|
6
|
+
* @param overrides - A map of method names to mock functions.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const game = {
|
|
10
|
+
* plugins: [
|
|
11
|
+
* MockRandom({ D6: () => 1 }),
|
|
12
|
+
* ],
|
|
13
|
+
* };
|
|
14
|
+
*/
|
|
15
|
+
export declare const MockRandom: (overrides?: Partial<Record<"D4" | "D6" | "D10" | "D12" | "D20" | "Die" | "Number" | "Shuffle", (...args: any[]) => any>>) => Omit<typeof RandomPlugin, 'flush'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|