diff --git a/server/src/main.ts b/server/src/main.ts index f01321c..f29bce0 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -2,6 +2,7 @@ import "module-alias/register"; import startWebsocketServer from "./websocket"; +import { GameDB } from "./objects/GameDB"; import { Logger } from "tslog"; import toml from "toml"; import fs from "fs"; @@ -25,5 +26,6 @@ export const log = new Logger({ minLevel: config.log.level, }); +export const games = new GameDB(); startWebsocketServer(); \ No newline at end of file diff --git a/server/src/objects/GameDB.ts b/server/src/objects/GameDB.ts new file mode 100644 index 0000000..7046317 --- /dev/null +++ b/server/src/objects/GameDB.ts @@ -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; + }; +} \ No newline at end of file