diff --git a/JavascriptServer/config.js b/JavascriptServer/config.js index 7481fa0..d810257 100644 --- a/JavascriptServer/config.js +++ b/JavascriptServer/config.js @@ -1,4 +1,5 @@ // get the command line arguments +import { mergeDeep } from '#util/deep_merge'; import trace from '#util/logging'; import chalk from 'chalk'; import minimist from 'minimist'; @@ -58,6 +59,11 @@ const prod_config = { port: args.port || 1337, ws_port: args.ws_port || 3000, + + room: { + rooms_path: './rooms' + }, + ssl_enabled: false, ssl_cert_path: '/etc/letsencrypt/live/example.com/cert.pem', ssl_key_path: '/etc/letsencrypt/live/example.com/privkey.pem', @@ -99,16 +105,16 @@ const env = args.env || 'dev'; const config = {}; -Object.assign(config, common_config); +mergeDeep(config, common_config); if (env === 'production' || env === 'prod' || args.prod) { - Object.assign(config, prod_config); + mergeDeep(config, prod_config); } else if (env === 'development' || env === 'dev' || args.dev) { - Object.assign(config, dev_config); + mergeDeep(config, dev_config); } else { - Object.assign(config, default_config); + mergeDeep(config, default_config); } diff --git a/JavascriptServer/internal/util/deep_merge.js b/JavascriptServer/internal/util/deep_merge.js new file mode 100644 index 0000000..a870b73 --- /dev/null +++ b/JavascriptServer/internal/util/deep_merge.js @@ -0,0 +1,36 @@ +// Copied from stack overflow lmao +// (https://stackoverflow.com/questions/27936772/how-to-deep-merge-instead-of-shallow-merge) + +/** + * Simple object check. + * @param item + * @returns {boolean} + */ +export function isObject(item) { + return (item && typeof item === 'object' && !Array.isArray(item)); +} + +/** +* Deep merge two objects. +* @param target +* @param ...sources +*/ +export function mergeDeep(target, ...sources) { + if (!sources.length) + return target; + const source = sources.shift(); + + if (isObject(target) && isObject(source)) { + for (const key in source) { + if (isObject(source[key])) { + if (!target[key]) + Object.assign(target, { [key]: {} }); + mergeDeep(target[key], source[key]); + } else { + Object.assign(target, { [key]: source[key] }); + } + } + } + + return mergeDeep(target, ...sources); +} diff --git a/Release/GMClient.zip b/Release/GMClient.zip index 1739b40..4229e38 100644 Binary files a/Release/GMClient.zip and b/Release/GMClient.zip differ diff --git a/Release/JSServer.zip b/Release/JSServer.zip index 3901607..a5c18c8 100644 Binary files a/Release/JSServer.zip and b/Release/JSServer.zip differ diff --git a/Release/TSServer.zip b/Release/TSServer.zip index 06823b9..07a3353 100644 Binary files a/Release/TSServer.zip and b/Release/TSServer.zip differ diff --git a/Release/Warp.yymps b/Release/Warp.yymps index 1739b40..4229e38 100644 Binary files a/Release/Warp.yymps and b/Release/Warp.yymps differ diff --git a/TypescriptServer/src/config.ts b/TypescriptServer/src/config.ts index 501ed60..dbe9be1 100644 --- a/TypescriptServer/src/config.ts +++ b/TypescriptServer/src/config.ts @@ -1,4 +1,5 @@ // get the command line arguments +import { mergeDeep } from '#util/deep_merge'; import trace from '#util/logging'; import chalk from 'chalk'; import minimist from 'minimist'; @@ -22,7 +23,7 @@ const common_config = { room: { // .yy room loading - rooms_path: '../Client/rooms', + rooms_path: '../Client/rooms', // (overriden in prod config) warn_on_unknown_entity: true, starting_room: 'Test Room', @@ -58,6 +59,11 @@ const prod_config = { port: args.port || 1337, ws_port: args.ws_port || 3000, + + room: { + rooms_path: './rooms' + }, + ssl_enabled: false, ssl_cert_path: '/etc/letsencrypt/live/example.com/cert.pem', ssl_key_path: '/etc/letsencrypt/live/example.com/privkey.pem', @@ -110,16 +116,16 @@ const env = args.env || 'dev' const config:any = {}; -Object.assign(config, common_config); +mergeDeep(config, common_config); if (env === 'production' || env === 'prod' || args.prod) { - Object.assign(config, prod_config); + mergeDeep(config, prod_config); } else if (env === 'development' || env === 'dev' || args.dev) { - Object.assign(config, dev_config); + mergeDeep(config, dev_config); } else { - Object.assign(config, default_config); + mergeDeep(config, default_config); } diff --git a/TypescriptServer/src/internal/util/deep_merge.ts b/TypescriptServer/src/internal/util/deep_merge.ts new file mode 100644 index 0000000..e4c128f --- /dev/null +++ b/TypescriptServer/src/internal/util/deep_merge.ts @@ -0,0 +1,34 @@ +// Copied from stack overflow lmao +// (https://stackoverflow.com/questions/27936772/how-to-deep-merge-instead-of-shallow-merge) + +/** + * Simple object check. + * @param item + * @returns {boolean} + */ +export function isObject(item) { + return (item && typeof item === 'object' && !Array.isArray(item)); +} + +/** +* Deep merge two objects. +* @param target +* @param ...sources +*/ +export function mergeDeep(target:object, ...sources) { + if (!sources.length) return target; + const source = sources.shift(); + + if (isObject(target) && isObject(source)) { + for (const key in source) { + if (isObject(source[key])) { + if (!target[key]) Object.assign(target, { [key]: {} }); + mergeDeep(target[key], source[key]); + } else { + Object.assign(target, { [key]: source[key] }); + } + } + } + + return mergeDeep(target, ...sources); +} \ No newline at end of file