homegames-common 1.0.8 → 1.1.0
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 +35 -91
- 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,8 @@ const authWorkflow = (authPath) => new Promise((resolve, reject) => {
|
|
|
598
607
|
});
|
|
599
608
|
});
|
|
600
609
|
|
|
610
|
+
const log = process.env.LOGGER_LOCATION ? require(process.env.LOGGER_LOCATION) : { info: (msg) => console.log(msg), error: (msg) => console.error(msg)};
|
|
611
|
+
|
|
601
612
|
const getConfigValue = (key, _default = undefined) => {
|
|
602
613
|
const config = getConfig();
|
|
603
614
|
|
|
@@ -608,15 +619,16 @@ const getConfigValue = (key, _default = undefined) => {
|
|
|
608
619
|
} else if (envValue === 'false') {
|
|
609
620
|
envValue = false;
|
|
610
621
|
}
|
|
611
|
-
|
|
622
|
+
log.info(`Using environment value: ${envValue} for key: ${key}`);
|
|
612
623
|
return envValue;
|
|
613
624
|
}
|
|
614
625
|
if (config[key] === undefined && _default === undefined) {
|
|
615
626
|
throw new Error(`No value for ${key} found in config`);
|
|
616
627
|
} else if (config[key] === undefined && _default !== undefined) {
|
|
628
|
+
log.info(`Using default value (${_default}) for ${key}`);
|
|
617
629
|
return _default;
|
|
618
630
|
}
|
|
619
|
-
|
|
631
|
+
log.info(`Found value ${config[key]} for ${key} in config`);
|
|
620
632
|
return config[key];
|
|
621
633
|
};
|
|
622
634
|
|
|
@@ -633,7 +645,7 @@ const getConfig = () => {
|
|
|
633
645
|
|
|
634
646
|
for (let i = 0; i < options.length; i++) {
|
|
635
647
|
if (fs.existsSync(`${options[i]}/config.json`)) {
|
|
636
|
-
|
|
648
|
+
log.info(`Found config at ${options[i]}`);
|
|
637
649
|
_config = JSON.parse(fs.readFileSync(`${options[i]}/config.json`));
|
|
638
650
|
break;
|
|
639
651
|
}
|
|
@@ -643,8 +655,8 @@ const getConfig = () => {
|
|
|
643
655
|
_config = DEFAULT_CONFIG;
|
|
644
656
|
}
|
|
645
657
|
|
|
646
|
-
|
|
647
|
-
|
|
658
|
+
log.info('Using config: ');
|
|
659
|
+
log.info(_config);
|
|
648
660
|
|
|
649
661
|
cachedConfig = _config;
|
|
650
662
|
|
|
@@ -663,105 +675,37 @@ const msgToString = (msg) => {
|
|
|
663
675
|
return typeof msg === 'object' ? JSON.stringify(msg) : msg;
|
|
664
676
|
};
|
|
665
677
|
|
|
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
678
|
const getAppDataPath = () => {
|
|
745
679
|
if (!process) {
|
|
746
680
|
// this shouldnt be called if running in browser
|
|
747
681
|
return '';
|
|
748
682
|
}
|
|
749
683
|
|
|
684
|
+
let _path;
|
|
750
685
|
switch (process.platform) {
|
|
751
686
|
case "darwin": {
|
|
752
|
-
|
|
687
|
+
_path = process.env.HOME ? path.join(process.env.HOME, "Library", "Application Support", "homegames") : __dirname;
|
|
688
|
+
break;
|
|
753
689
|
}
|
|
754
690
|
case "win32": {
|
|
755
|
-
|
|
691
|
+
_path = process.env.APPDATA ? path.join(process.env.APPDATA, "homegames") : __dirname;
|
|
692
|
+
break;
|
|
756
693
|
}
|
|
757
694
|
case "linux": {
|
|
758
|
-
|
|
695
|
+
_path = process.env.HOME ? path.join(process.env.HOME, ".homegames") : __dirname;
|
|
696
|
+
break;
|
|
759
697
|
}
|
|
760
698
|
default: {
|
|
761
699
|
console.log("Unsupported platform!");
|
|
762
700
|
process.exit(1);
|
|
763
701
|
}
|
|
764
702
|
}
|
|
703
|
+
|
|
704
|
+
if (!fs.existsSync(_path)) {
|
|
705
|
+
fs.mkdirSync(_path);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
return _path;
|
|
765
709
|
}
|
|
766
710
|
|
|
767
711
|
module.exports = {
|