From 9f6339ce486a7dbc2cfa782a7bea14ff54a05d68 Mon Sep 17 00:00:00 2001 From: Holly Date: Sun, 27 Nov 2022 17:36:55 +0000 Subject: [PATCH] Config interface --- Binato.ts | 3 ++- server/BanchoServer.ts | 3 ++- server/interfaces/Config.ts | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 server/interfaces/Config.ts diff --git a/Binato.ts b/Binato.ts index d47715c..46aeae5 100644 --- a/Binato.ts +++ b/Binato.ts @@ -9,12 +9,13 @@ if (!existsSync("./config.json")) { } import { ChatHistory } from "./server/ChatHistory"; +import { Config } from "./server/interfaces/Config"; import compression from "compression"; import express from "express"; import { HandleRequest, GetSharedContent } from "./server/BanchoServer"; import { SharedContent } from "./server/interfaces/SharedContent"; import { Registry, collectDefaultMetrics } from "prom-client"; -const config:any = JSON.parse(readFileSync(__dirname + "/config.json").toString()); +const config:Config = JSON.parse(readFileSync(__dirname + "/config.json").toString()) as Config; // Pull out shared data from BanchoServer const sharedContent:SharedContent = GetSharedContent(); diff --git a/server/BanchoServer.ts b/server/BanchoServer.ts index 1cefd5e..dc7b06a 100644 --- a/server/BanchoServer.ts +++ b/server/BanchoServer.ts @@ -1,3 +1,4 @@ +import { Config } from "./interfaces/Config"; import { ConsoleHelper } from "../ConsoleHelper"; import { Channel } from "./objects/Channel"; import { ChatManager } from "./ChatManager"; @@ -14,7 +15,7 @@ import { User } from "./objects/User"; import { DataStreamArray } from "./objects/DataStreamArray"; import { MultiplayerManager } from "./MultiplayerManager"; import { SharedContent } from "./interfaces/SharedContent"; -const config:any = JSON.parse(readFileSync("./config.json").toString()); +const config:Config = JSON.parse(readFileSync("./config.json").toString()) as Config; // TODO: Port osu-packet to TypeScript const osu = require("osu-packet"); diff --git a/server/interfaces/Config.ts b/server/interfaces/Config.ts new file mode 100644 index 0000000..d6d44f1 --- /dev/null +++ b/server/interfaces/Config.ts @@ -0,0 +1,39 @@ +export interface Config { + express:ExpressConfigSection, + prometheus:PrometheusConfigSection, + redis:RedisConfigSection, + database:DatabaseConfigSection +} + +interface ExpressConfigSection { + port:number, + compression:boolean +} + +interface PrometheusConfigSection { + enabled:boolean, + port:number +} + +interface RedisConfigSection { + enabled:boolean, + address:string, + port:number, + database:number, + password:string +} + +interface DatabaseConfigSection { + address:string, + port:number, + username:string, + password:string, + name:string, + pbkdf2:PBKDF2DatabaseConfigSection, + key:string +} + +interface PBKDF2DatabaseConfigSection { + itterations:number, + keylength:number +} \ No newline at end of file