Skip to content

Commit

Permalink
Merge pull request #200 from Dahlgren/feature/server-remove-global-co…
Browse files Browse the repository at this point in the history
…nfig

Remove global config variable from server file
  • Loading branch information
Dahlgren authored Jul 10, 2021
2 parents 931e913 + 3c56bba commit 7b6d0c6
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -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, '-')
}
Expand Down Expand Up @@ -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
},
Expand All @@ -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)) {
Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7b6d0c6

Please sign in to comment.