homegames-common 0.3.0 → 0.3.2
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 +28 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -15,6 +15,22 @@ const getUserHash = (username) => {
|
|
|
15
15
|
return crypto.createHash('md5').update(username).digest('hex');
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
const DEFAULT_CONFIG = {
|
|
19
|
+
"LINK_ENABLED": true,
|
|
20
|
+
"HOMENAMES_PORT": 7400,
|
|
21
|
+
"HOME_PORT": 9801,
|
|
22
|
+
"LOG_LEVEL": "INFO",
|
|
23
|
+
"GAME_SERVER_PORT_RANGE_MIN": 8300,
|
|
24
|
+
"GAME_SERVER_PORT_RANGE_MAX": 8400,
|
|
25
|
+
"IS_DEMO": false,
|
|
26
|
+
"BEZEL_SIZE_Y": 15,
|
|
27
|
+
"BEZEL_SIZE_X": 15,
|
|
28
|
+
"DOWNLOADED_GAME_DIRECTORY": "hg-games",
|
|
29
|
+
"LOG_PATH": "hg_log.txt",
|
|
30
|
+
"LOCAL_GAME_DIRECTORY": "local-games",
|
|
31
|
+
"PUBLIC_GAMES": false
|
|
32
|
+
};
|
|
33
|
+
|
|
18
34
|
const getLocalIP = () => {
|
|
19
35
|
const ifaces = os.networkInterfaces();
|
|
20
36
|
let localIP;
|
|
@@ -609,7 +625,7 @@ const getConfig = () => {
|
|
|
609
625
|
}
|
|
610
626
|
|
|
611
627
|
const options = [process.cwd(), require.main.filename, process.mainModule.filename, __dirname]
|
|
612
|
-
let _config =
|
|
628
|
+
let _config = null;
|
|
613
629
|
|
|
614
630
|
for (let i = 0; i < options.length; i++) {
|
|
615
631
|
if (fs.existsSync(`${options[i]}/config.json`)) {
|
|
@@ -619,6 +635,13 @@ const getConfig = () => {
|
|
|
619
635
|
}
|
|
620
636
|
}
|
|
621
637
|
|
|
638
|
+
if (!_config) {
|
|
639
|
+
_config = DEFAULT_CONFIG;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
console.log('Using config: ');
|
|
643
|
+
console.log(_config);
|
|
644
|
+
|
|
622
645
|
cachedConfig = _config;
|
|
623
646
|
|
|
624
647
|
return _config;
|
|
@@ -645,7 +668,7 @@ const log = {
|
|
|
645
668
|
return;
|
|
646
669
|
}
|
|
647
670
|
|
|
648
|
-
const logPath = getConfigValue('LOG_PATH');
|
|
671
|
+
const logPath = getConfigValue('LOG_PATH', 'hg_log.txt');
|
|
649
672
|
|
|
650
673
|
const msgString = `[HOMEGAMES-INFO][${new Date().toTimeString()}] ${msgToString(msg)}${explanation ? ':' + os.EOL + msgToString(explanation) : ''}${os.EOL}${os.EOL}`;
|
|
651
674
|
fs.appendFile(logPath, msgString, (err) => {
|
|
@@ -663,7 +686,7 @@ const log = {
|
|
|
663
686
|
return;
|
|
664
687
|
}
|
|
665
688
|
|
|
666
|
-
const logPath = getConfigValue('LOG_PATH');
|
|
689
|
+
const logPath = getConfigValue('LOG_PATH', 'hg_log.txt');
|
|
667
690
|
|
|
668
691
|
const msgString = `[HOMEGAMES-ERROR][${new Date().toTimeString()}] ${msgToString(msg)}${explanation ? ':' + os.EOL + msgToString(explanation) : ''}${os.EOL}${os.EOL}`;
|
|
669
692
|
fs.appendFile(logPath, msgString, (err) => {
|
|
@@ -676,7 +699,8 @@ const log = {
|
|
|
676
699
|
debug: (msg, explanation) => {
|
|
677
700
|
const logLevel = getLogLevel();
|
|
678
701
|
const required = getLogLevel('DEBUG');
|
|
679
|
-
|
|
702
|
+
|
|
703
|
+
const logPath = getConfigValue('LOG_PATH', 'hg_log.txt');
|
|
680
704
|
|
|
681
705
|
if (logLevel < required) {
|
|
682
706
|
return;
|