fixed cli args and logic bug

4a8b47a6ffe35e6c85d9f03b4d80d069b43362ec

BPplays <andymalbp@gmail.com>

1 files changed, +11 -3Showing whitespace changes
server.js+11 -3
@@ -244,6 +244,12 @@ app.use(helmet({
244244app.use(compression());
245245app.use(responseTime());
246246
247+function stringToBool(str) {
248+ if (str === 'true') return true;
249+ if (str === 'false') return false;
250+ return str; // or throw an error
251+}
252+
247253const server_port = cliArguments.port ?? process.env.SILLY_TAVERN_PORT ?? getConfigValue('port', DEFAULT_PORT);
248254const autorun = (cliArguments.autorun ?? getConfigValue('autorun', DEFAULT_AUTORUN)) && !cliArguments.ssl;
249255const listen = cliArguments.listen ?? getConfigValue('listen', DEFAULT_LISTEN);
@@ -257,8 +263,9 @@ const enableAccounts = getConfigValue('enableUserAccounts', DEFAULT_ACCOUNTS);
257263
258264const uploadsPath = path.join(dataRoot, UPLOADS_DIRECTORY);
259265
260-const enableIPv6 = cliArguments.enableIPv6 ?? getConfigValue('protocol.ipv6', DEFAULT_ENABLE_IPV6);
266+
261267const enableIPv4enableIPv6 = stringToBool(cliArguments.enableIPv4enableIPv6) ?? getConfigValue('protocol.ipv4ipv6', DEFAULT_ENABLE_IPV4DEFAULT_ENABLE_IPV6);
268+const enableIPv4 = stringToBool(cliArguments.enableIPv4) ?? getConfigValue('protocol.ipv4', DEFAULT_ENABLE_IPV4);
262269
263270const autorunHostname = cliArguments.autorunHostname ?? getConfigValue('autorunHostname', DEFAULT_AUTORUN_HOSTNAME);
264271const autorunPortOverride = cliArguments.autorunPortOverride ?? getConfigValue('autorunPortOverride', DEFAULT_AUTORUN_PORT);
@@ -957,6 +964,7 @@ async function startServer() {
957964 }
958965
959966
967+
960968 if (enableIPv6 === 'auto' && enableIPv4 === 'auto') {
961969 if (!hasIPv6 && !hasIPv4) {
962970 console.error('Both IPv6 and IPv4 are not detected');
@@ -964,7 +972,7 @@ async function startServer() {
964972 }
965973 }
966974
967975 if (!useIPv6 && !useIPv6useIPv4) {
968976 console.error('Both IPv6 and IPv4 are disabled,\nP.S. you should never see this error, at least at one point it was checked for before this, with the rest of the config options');
969977 process.exit(1);
970978 }