blob: 8c2225de66b39c471e9a86ed3f06155580ceed99 (
plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
import { join } from 'path';
import {
CommandManager,
ConfigManager,
ImportsManager,
MainServer,
StatsManager,
} from '.';
/**
* The core app builds all required classes and maintains a central
* reference point across the app
* @property {ConfigManager} configManager - Provides loading and saving of the server config
* @property {Object} config - The current json config object
* @property {ImportsManager} dynamicImports - Dynamic require interface allowing hot reloading
* @property {CommandManager} commands - Manages and executes command modules
* @property {StatsManager} stats - Stores and adjusts arbritary stat data
* @property {MainServer} server - Main websocket server reference
* @author Marzavec ( https://github.com/marzavec )
* @version v2.0.0
* @license WTFPL ( http://www.wtfpl.net/txt/copying/ )
*/
class CoreApp {
/**
* Load config then initialize children
* @public
* @return {void}
*/
async init() {
await this.buildConfigManager();
this.buildImportManager();
this.buildCommandsManager();
this.buildStatsManager();
this.buildMainServer();
}
/**
* Creates a new instance of the ConfigManager, loads and checks
* the server config
* @private
* @return {void}
*/
async buildConfigManager() {
this.configManager = new ConfigManager(join(__dirname, '../..'));
this.config = await this.configManager.load();
if (this.config === false) {
console.error('Missing config.json, have you run: npm run config');
process.exit(0);
}
}
/**
* Creates a new instance of the ImportsManager
* @private
* @return {void}
*/
buildImportManager() {
this.dynamicImports = new ImportsManager(join(__dirname, '../..'));
}
/**
* Creates a new instance of the CommandManager and loads the command modules
* @private
* @return {void}
*/
buildCommandsManager() {
this.commands = new CommandManager(this);
this.commands.loadCommands();
}
/**
* Creates a new instance of the StatsManager and sets the server start time
* @private
* @return {void}
*/
buildStatsManager() {
this.stats = new StatsManager(this);
this.stats.set('start-time', process.hrtime());
}
/**
* Creates a new instance of the MainServer
* @private
* @return {void}
*/
buildMainServer() {
this.server = new MainServer(this);
}
}
export { CoreApp };
|