homegames-common 1.0.9 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +38 -88
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -15,19 +15,28 @@ const getUserHash = (username) => {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
const DEFAULT_CONFIG = {
|
|
18
|
-
"LINK_ENABLED": true,
|
|
19
18
|
"HTTPS_ENABLED": true,
|
|
19
|
+
"LINK_ENABLED": true,
|
|
20
20
|
"HOMENAMES_PORT": 7400,
|
|
21
21
|
"HOME_PORT": 9801,
|
|
22
22
|
"LOG_LEVEL": "INFO",
|
|
23
23
|
"GAME_SERVER_PORT_RANGE_MIN": 8300,
|
|
24
24
|
"GAME_SERVER_PORT_RANGE_MAX": 8400,
|
|
25
25
|
"IS_DEMO": false,
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
26
|
+
"BEZEL_SIZE_X": 9,
|
|
27
|
+
"BEZEL_SIZE_Y": 9,
|
|
28
|
+
"HOTLOAD_ENABLED": false,
|
|
29
|
+
"PERFORMANCE_PROFILING": false,
|
|
29
30
|
"DOWNLOADED_GAME_DIRECTORY": "hg-games",
|
|
30
|
-
"LOG_PATH": "
|
|
31
|
+
"LOG_PATH": "homegames_log.txt",
|
|
32
|
+
"PUBLIC_GAMES": false,
|
|
33
|
+
"ERROR_REPORTING": true,
|
|
34
|
+
"ERROR_REPORTING_ENDPOINT": "https://api.homegames.io/bugs",
|
|
35
|
+
"CERT_DOMAIN": "homegames.link",
|
|
36
|
+
"TESTS_ENABLED": true,
|
|
37
|
+
"API_URL": "https://api.homegames.io",
|
|
38
|
+
"LINK_PROXY_URL": "wss://public.homegames.link:81",
|
|
39
|
+
"LINK_URL": "wss://homegames.link"
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
const getLocalIP = () => {
|
|
@@ -598,6 +607,23 @@ const authWorkflow = (authPath) => new Promise((resolve, reject) => {
|
|
|
598
607
|
});
|
|
599
608
|
});
|
|
600
609
|
|
|
610
|
+
let electronLog = null;
|
|
611
|
+
try {
|
|
612
|
+
electronLog = require('electron-log');
|
|
613
|
+
} catch (err) {
|
|
614
|
+
console.log('not running with electron');
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
const defaultLog = { info: (msg) => console.log(msg), error: (msg) => console.error(msg)};
|
|
618
|
+
|
|
619
|
+
const log = electronLog == null ?
|
|
620
|
+
(
|
|
621
|
+
process.env.LOGGER_LOCATION ?
|
|
622
|
+
require(process.env.LOGGER_LOCATION) : defaultLog
|
|
623
|
+
) : electronLog;
|
|
624
|
+
|
|
625
|
+
log.info('doing this');
|
|
626
|
+
|
|
601
627
|
const getConfigValue = (key, _default = undefined) => {
|
|
602
628
|
const config = getConfig();
|
|
603
629
|
|
|
@@ -608,15 +634,16 @@ const getConfigValue = (key, _default = undefined) => {
|
|
|
608
634
|
} else if (envValue === 'false') {
|
|
609
635
|
envValue = false;
|
|
610
636
|
}
|
|
611
|
-
|
|
637
|
+
log.info(`Using environment value: ${envValue} for key: ${key}`);
|
|
612
638
|
return envValue;
|
|
613
639
|
}
|
|
614
640
|
if (config[key] === undefined && _default === undefined) {
|
|
615
641
|
throw new Error(`No value for ${key} found in config`);
|
|
616
642
|
} else if (config[key] === undefined && _default !== undefined) {
|
|
643
|
+
log.info(`Using default value (${_default}) for ${key}`);
|
|
617
644
|
return _default;
|
|
618
645
|
}
|
|
619
|
-
|
|
646
|
+
log.info(`Found value ${config[key]} for ${key} in config`);
|
|
620
647
|
return config[key];
|
|
621
648
|
};
|
|
622
649
|
|
|
@@ -633,7 +660,7 @@ const getConfig = () => {
|
|
|
633
660
|
|
|
634
661
|
for (let i = 0; i < options.length; i++) {
|
|
635
662
|
if (fs.existsSync(`${options[i]}/config.json`)) {
|
|
636
|
-
|
|
663
|
+
log.info(`Found config at ${options[i]}`);
|
|
637
664
|
_config = JSON.parse(fs.readFileSync(`${options[i]}/config.json`));
|
|
638
665
|
break;
|
|
639
666
|
}
|
|
@@ -643,8 +670,8 @@ const getConfig = () => {
|
|
|
643
670
|
_config = DEFAULT_CONFIG;
|
|
644
671
|
}
|
|
645
672
|
|
|
646
|
-
|
|
647
|
-
|
|
673
|
+
log.info('Using config: ');
|
|
674
|
+
log.info(_config);
|
|
648
675
|
|
|
649
676
|
cachedConfig = _config;
|
|
650
677
|
|
|
@@ -663,84 +690,6 @@ const msgToString = (msg) => {
|
|
|
663
690
|
return typeof msg === 'object' ? JSON.stringify(msg) : msg;
|
|
664
691
|
};
|
|
665
692
|
|
|
666
|
-
let electronLogger = null;
|
|
667
|
-
|
|
668
|
-
if (process.env.LOGGER_LOCATION) {
|
|
669
|
-
try {
|
|
670
|
-
electronLogger = require(process.env.LOGGER_LOCATION);
|
|
671
|
-
} catch (err) {
|
|
672
|
-
console.log('Logger not using electron. Logging to file.');
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
const log = {
|
|
677
|
-
info: (msg, explanation = null) => {
|
|
678
|
-
if (electronLogger) {
|
|
679
|
-
electronLogger.info(msgToString(msg));
|
|
680
|
-
}// else {
|
|
681
|
-
const logLevel = getLogLevel();
|
|
682
|
-
const required = getLogLevel('INFO');
|
|
683
|
-
|
|
684
|
-
if (logLevel < required) {
|
|
685
|
-
// return;
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
const logPath = path.join(getAppDataPath(), 'hg-log.txt');//getConfigValue('LOG_PATH', 'hg_log.txt');
|
|
689
|
-
|
|
690
|
-
const msgString = `[HOMEGAMES-INFO][${new Date().toTimeString()}] ${msgToString(msg)}${explanation ? ':' + os.EOL + msgToString(explanation) : ''}${os.EOL}${os.EOL}`;
|
|
691
|
-
fs.appendFile(logPath, msgString, (err) => {
|
|
692
|
-
if (err) {
|
|
693
|
-
console.error('failed log');
|
|
694
|
-
console.log(err);
|
|
695
|
-
}
|
|
696
|
-
});
|
|
697
|
-
//}
|
|
698
|
-
},
|
|
699
|
-
error: (msg, explanation) => {
|
|
700
|
-
if (electronLogger) {
|
|
701
|
-
electronLogger.error(msgToString(msg));
|
|
702
|
-
}// else {
|
|
703
|
-
const logLevel = getLogLevel();
|
|
704
|
-
const required = getLogLevel('INFO');
|
|
705
|
-
|
|
706
|
-
if (logLevel < required) {
|
|
707
|
-
// return;
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
//const logPath = getConfigValue('LOG_PATH', 'hg_log.txt');
|
|
711
|
-
const logPath = path.join(getAppDataPath(), 'hg-log.txt');//getConfigValue('LOG_PATH', 'hg_log.txt');
|
|
712
|
-
|
|
713
|
-
const msgString = `[HOMEGAMES-ERROR][${new Date().toTimeString()}] ${msgToString(msg)}${explanation ? ':' + os.EOL + msgToString(explanation) : ''}${os.EOL}${os.EOL}`;
|
|
714
|
-
fs.appendFile(logPath, msgString, (err) => {
|
|
715
|
-
if (err) {
|
|
716
|
-
console.error('failed log');
|
|
717
|
-
console.log(err);
|
|
718
|
-
}
|
|
719
|
-
});
|
|
720
|
-
//}
|
|
721
|
-
},
|
|
722
|
-
debug: (msg, explanation) => {
|
|
723
|
-
const logLevel = getLogLevel();
|
|
724
|
-
const required = getLogLevel('DEBUG');
|
|
725
|
-
|
|
726
|
-
const logPath = getConfigValue('LOG_PATH', 'hg_log.txt');
|
|
727
|
-
|
|
728
|
-
if (logLevel < required) {
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
const msgString = `[HOMEGAMES-DEBUG][${new Date().toTimeString()}] ${msgToString(msg)}${explanation ? ':' + os.EOL + msgToString(explanation) : ''}${os.EOL}${os.EOL}`;
|
|
733
|
-
fs.appendFile(logPath, msgString, (err) => {
|
|
734
|
-
if (err) {
|
|
735
|
-
console.error('failed log');
|
|
736
|
-
console.log(err);
|
|
737
|
-
}
|
|
738
|
-
});
|
|
739
|
-
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
}
|
|
743
|
-
|
|
744
693
|
const getAppDataPath = () => {
|
|
745
694
|
if (!process) {
|
|
746
695
|
// this shouldnt be called if running in browser
|
|
@@ -791,3 +740,4 @@ module.exports = {
|
|
|
791
740
|
getAppDataPath
|
|
792
741
|
};
|
|
793
742
|
|
|
743
|
+
|