-
-
Notifications
You must be signed in to change notification settings - Fork 224
/
main.mjs
65 lines (53 loc) · 1.48 KB
/
main.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {
existsSync,
readFileSync,
} from 'node:fs';
import {
Low,
JSONFile,
} from 'lowdb';
import {
CoreApp,
} from 'hackchat-server';
import {
ChannelCheckInterval,
} from './commands/utility/_Constants.js';
import {
purgeInactiveChannels,
} from './commands/utility/_Channels.js';
// required file paths
const SessionLocation = './session.key';
const SaltLocation = './salt.key';
const AppConfigLocation = './config.json';
// verify required files exist
if (existsSync(SessionLocation) === false) {
throw Error('Missing session key, you may need to run: npm run config');
}
if (existsSync(SaltLocation) === false) {
throw Error('Missing salt key, you may need to run: npm run config');
}
if (existsSync(AppConfigLocation) === false) {
throw Error('Missing config, you may need to run: npm run config');
}
// build main hack chat server
const server = new CoreApp({
configPath: './.hcserver.json',
logErrDetailed: true,
lang: 'en',
});
// load sessoin key data
server.sessionKey = readFileSync(SessionLocation);
// load salt key data
server.saltKey = readFileSync(SaltLocation);
// load the configuration data
const adapter = new JSONFile(AppConfigLocation);
server.appConfig = new Low(adapter);
await server.appConfig.read();
// create channel memory management job
setInterval(() => {
purgeInactiveChannels(server.appConfig.data);
}, ChannelCheckInterval);
// @todo create storage management job
// start the server
server.init();
console.log('Websocket server ready');