Genesis
This commit is contained in:
34
src/config.js
Normal file
34
src/config.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const CONFIG_PATH = path.join(__dirname, '..', 'config.json');
|
||||
|
||||
function loadConfig() {
|
||||
if (!fs.existsSync(CONFIG_PATH)) {
|
||||
throw new Error(`Config file not found: ${CONFIG_PATH}`);
|
||||
}
|
||||
|
||||
const raw = fs.readFileSync(CONFIG_PATH, 'utf-8');
|
||||
const config = JSON.parse(raw);
|
||||
|
||||
// Validate required fields
|
||||
if (!config.server || !config.server.host || !config.server.port) {
|
||||
throw new Error('config.json must specify server.host and server.port');
|
||||
}
|
||||
if (!config.server.version) {
|
||||
throw new Error('config.json must specify server.version');
|
||||
}
|
||||
if (!config.auth || !config.auth.username) {
|
||||
throw new Error('config.json must specify auth.username');
|
||||
}
|
||||
|
||||
// Apply defaults
|
||||
config.proxy = Object.assign({ host: '0.0.0.0', port: 25566, onlineMode: false, maxClients: 1 }, config.proxy);
|
||||
config.bot = Object.assign({ antiAfk: true, antiAfkInterval: 30000, viewDistance: 10 }, config.bot);
|
||||
config.cache = Object.assign({ maxChunks: 1024, trackEntities: true }, config.cache);
|
||||
config.auth.auth = config.auth.auth || 'offline';
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
module.exports = { loadConfig };
|
||||
Reference in New Issue
Block a user