From 3c56bba515a7badad5940422fb105a8f9e2c5b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Dahlgren?= Date: Sat, 10 Jul 2021 15:38:50 +0200 Subject: [PATCH] Remove global config variable from server file --- lib/server.js | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/server.js b/lib/server.js index 98deb30..7c785a0 100644 --- a/lib/server.js +++ b/lib/server.js @@ -5,8 +5,6 @@ var slugify = require('slugify') var ArmaServer = require('arma-server') -var config = require('../config.js') - var queryInterval = 5000 var queryTypes = { arma1: 'arma', @@ -19,18 +17,6 @@ var queryTypes = { ofpresistance: 'operationflashpoint' } -var createServerTitle = function (title) { - if (config.prefix) { - title = config.prefix + title - } - - if (config.suffix) { - title = title + config.suffix - } - - return title -} - var Server = function (config, logs, options) { this.config = config this.logs = logs @@ -39,6 +25,18 @@ var Server = function (config, logs, options) { Server.prototype = new events.EventEmitter() +Server.prototype.createServerTitle = function (title) { + if (this.config.prefix) { + title = this.config.prefix + title + } + + if (this.config.suffix) { + title = title + this.config.suffix + } + + return title +} + Server.prototype.generateId = function () { return slugify(this.title).replace(/\./g, '-') } @@ -76,7 +74,7 @@ Server.prototype.queryStatus = function () { var self = this Gamedig.query( { - type: queryTypes[config.game], + type: queryTypes[this.config.game], host: '127.0.0.1', port: self.port }, @@ -100,8 +98,8 @@ Server.prototype.queryStatus = function () { Server.prototype.getParameters = function () { var parameters = [] - if (config.parameters && Array.isArray(config.parameters)) { - parameters = parameters.concat(config.parameters) + if (this.config.parameters && Array.isArray(this.config.parameters)) { + parameters = parameters.concat(this.config.parameters) } if (this.parameters && Array.isArray(this.parameters)) { @@ -114,8 +112,8 @@ Server.prototype.getParameters = function () { Server.prototype.getAdditionalConfigurationOptions = function () { var additionalConfigurationOptions = '' - if (config.additionalConfigurationOptions) { - additionalConfigurationOptions += config.additionalConfigurationOptions + if (this.config.additionalConfigurationOptions) { + additionalConfigurationOptions += this.config.additionalConfigurationOptions } if (this.additionalConfigurationOptions) { @@ -137,16 +135,16 @@ Server.prototype.start = function () { var parameters = this.getParameters() var server = new ArmaServer.Server({ additionalConfigurationOptions: this.getAdditionalConfigurationOptions(), - admins: config.admins, + admins: this.config.admins, allowedFilePatching: this.allowed_file_patching || 1, battleEye: this.battle_eye ? 1 : 0, config: this.id, disableVoN: this.von ? 0 : 1, - game: config.game, + game: this.config.game, filePatching: this.file_patching || false, forcedDifficulty: this.forcedDifficulty || null, headlessClients: this.number_of_headless_clients > 0 ? ['127.0.0.1'] : null, - hostname: createServerTitle(this.title), + hostname: this.createServerTitle(this.title), localClient: this.number_of_headless_clients > 0 ? ['127.0.0.1'] : null, missions: this.missions, mods: this.mods, @@ -159,7 +157,7 @@ Server.prototype.start = function () { platform: this.config.type, players: this.max_players, port: this.port, - serverMods: config.serverMods, + serverMods: this.config.serverMods, verifySignatures: this.verify_signatures ? 2 : 0 }) server.writeServerConfig() @@ -204,7 +202,7 @@ Server.prototype.startHeadlessClients = function () { var headlessClientInstances = _.times(this.number_of_headless_clients, function (i) { var headless = new ArmaServer.Headless({ filePatching: self.file_patching, - game: config.game, + game: self.config.game, host: '127.0.0.1', mods: self.mods, parameters: parameters,