diff --git a/Binato.js b/Binato.js index df17b04..3b35a96 100644 --- a/Binato.js +++ b/Binato.js @@ -10,7 +10,7 @@ const app = require("express")(), serverHandler = require("./server/serverHandler.js"), config = require("./config.json"); -if (config.prometheusEnabled) { +if (config.prometheus.enabled) { // We only need to require this if prom metrics are on. const prom = require("prom-client"); @@ -26,10 +26,10 @@ if (config.prometheusEnabled) { res.end(await register.metrics()); }); - prometheusApp.listen(config.prometheusPort, () => consoleHelper.printBancho(`Prometheus metrics listening at port ${config.prometheusPort}`)); + prometheusApp.listen(config.prometheus.port, () => consoleHelper.printBancho(`Prometheus metrics listening at port ${config.prometheus.port}`)); } else consoleHelper.printWarn("Prometheus is disabled!"); -if (config.compression) { +if (config.express.compression) { app.use(require("compression")()); consoleHelper.printBancho("Compression is enabled."); } else consoleHelper.printWarn("Compression is disabled!"); @@ -76,4 +76,4 @@ app.use((req, res) => { }); }); -app.listen(config.port, () => consoleHelper.printBancho(`Binato is up! Listening at port ${config.port}`)); \ No newline at end of file +app.listen(config.express.port, () => consoleHelper.printBancho(`Binato is up! Listening at port ${config.express.port}`)); \ No newline at end of file diff --git a/config.example.json b/config.example.json index f9f605f..c683920 100644 --- a/config.example.json +++ b/config.example.json @@ -1,17 +1,25 @@ { - "port": 5001, - "compression": true, - "prometheusEnabled": false, - "prometheusPort": 1234, - "redisEnabled": false, - "redisAddress": "127.0.0.1", - "redisPort": 6379, - "redisDatabase": 0, - "redisPassword": "", - "databaseAddress": "127.0.0.1", - "databasePort": 3306, - "databaseUsername": "username", - "databasePassword": "password", - "databaseName": "osu!", - "databaseKey": "examplekey" + "express": { + "port": 5001, + "compression": true + }, + "prometheus": { + "enabled": false, + "port": 9100 + }, + "redis": { + "enabled": false, + "address": "127.0.0.1", + "port": 6379, + "password": "", + "database": 0 + }, + "database": { + "address": "127.0.0.1", + "port": 3306, + "username": "username", + "password": "password", + "name": "osu!", + "key": "examplekey" + } } \ No newline at end of file diff --git a/server/loginHelper.js b/server/loginHelper.js index 94e8ebd..ee28314 100644 --- a/server/loginHelper.js +++ b/server/loginHelper.js @@ -20,7 +20,7 @@ module.exports = { return requiredPWChangeResponse(); } else { - if (aes256.decrypt(config.databaseKey, userDBData.password) !== loginInfo.password) return incorrectLoginResponse(); + if (aes256.decrypt(config.database.key, userDBData.password) !== loginInfo.password) return incorrectLoginResponse(); } return null; diff --git a/server/serverHandler.js b/server/serverHandler.js index f8fe042..080c8e6 100644 --- a/server/serverHandler.js +++ b/server/serverHandler.js @@ -22,7 +22,7 @@ global.botUser = global.users.add("bot", new User(3, "SillyBot", "bot")); global.botUser.location[0] = 50; global.botUser.location[1] = -32; -global.DatabaseHelper = new DatabaseHelperClass(config.databaseAddress, config.databasePort, config.databaseUsername, config.databasePassword, config.databaseName); +global.DatabaseHelper = new DatabaseHelperClass(config.database.address, config.database.port, config.database.username, config.database.password, config.database.name); async function subscribeToChannel(channelName = "", callback = function(message) {}) { // Dup and connect new client for channel subscription (required) @@ -34,11 +34,11 @@ async function subscribeToChannel(channelName = "", callback = function(message) } // Do redis if it's enabled -if (config.redisEnabled) { +if (config.redis.enabled) { (async () => { const { createClient } = require("redis"); global.promClient = createClient({ - url: `redis://${config.redisPassword.replaceAll(" ", "") == "" ? "" : `${config.redisPassword}@`}${config.redisAddress}:${config.redisPort}/${config.redisDatabase}` + url: `redis://${config.redis.password.replaceAll(" ", "") == "" ? "" : `${config.redis.password}@`}${config.redis.address}:${config.redis.port}/${config.redis.database}` }); global.promClient.on('error', e => consoleHelper.printBancho(e));