Add a game manager to the server
This commit is contained in:
parent
0ddf5d8a14
commit
6bbd8d68c0
2 changed files with 31 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
import "module-alias/register";
|
import "module-alias/register";
|
||||||
|
|
||||||
import startWebsocketServer from "./websocket";
|
import startWebsocketServer from "./websocket";
|
||||||
|
import { GameDB } from "./objects/GameDB";
|
||||||
import { Logger } from "tslog";
|
import { Logger } from "tslog";
|
||||||
import toml from "toml";
|
import toml from "toml";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
@ -25,5 +26,6 @@ export const log = new Logger({
|
||||||
minLevel: config.log.level,
|
minLevel: config.log.level,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const games = new GameDB();
|
||||||
|
|
||||||
startWebsocketServer();
|
startWebsocketServer();
|
||||||
29
server/src/objects/GameDB.ts
Normal file
29
server/src/objects/GameDB.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { Game } from "./Game";
|
||||||
|
|
||||||
|
export class GameDB {
|
||||||
|
private games: {[index: string]: Game};
|
||||||
|
|
||||||
|
constructor () {
|
||||||
|
this.games = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Determines if a game exists with the provided ID */
|
||||||
|
public has(id: string): boolean {
|
||||||
|
return this.games[id] != null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Get's the Game object associated with the provided ID */
|
||||||
|
public get(id: string): Game {
|
||||||
|
return this.games[id];
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Adds a Game object into the database */
|
||||||
|
public set(game: Game): void {
|
||||||
|
this.games[game.id] = game;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Returns a count of how many games currently exist in the database */
|
||||||
|
public get count() {
|
||||||
|
return Object.keys(this.games).length;
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue