diff --git a/lib/battleye.js b/lib/battleye.js new file mode 100644 index 0000000..90846dd --- /dev/null +++ b/lib/battleye.js @@ -0,0 +1,44 @@ +var fs = require('fs') +var path = require('path') + +var BattlEye = function (config, server) { + this.config = config + this.server = server +} + +BattlEye.prototype.configContents = function () { + var vars = [] + + if (this.server.battle_eye_password) { + vars.push('RConPassword ' + this.server.battle_eye_password) + } + + if (this.server.battle_eye_port) { + vars.push('RConPort ' + this.server.battle_eye_port) + } + + return vars.join('\n') +} + +BattlEye.prototype.configPath = function () { + if (this.config.game === 'arma3_x64') { + return path.join(this.config.path, 'battleye', 'beserver_x64.cfg') + } + + return path.join(this.config.path, 'battleye', 'beserver.cfg') +} + +BattlEye.prototype.createConfigFile = function (callback) { + var contents = this.configContents() + var filePath = this.configPath() + + fs.writeFile(filePath, contents, function (err) { + if (err) { + console.error('Failed to write BattlEye config: ' + err) + } + + callback(err) + }) +} + +module.exports = BattlEye diff --git a/lib/server.js b/lib/server.js index 7c785a0..314cdbe 100644 --- a/lib/server.js +++ b/lib/server.js @@ -5,6 +5,8 @@ var slugify = require('slugify') var ArmaServer = require('arma-server') +var BattlEye = require('./battleye') + var queryInterval = 5000 var queryTypes = { arma1: 'arma', @@ -47,6 +49,8 @@ Server.prototype.update = function (options) { this.allowed_file_patching = options.allowed_file_patching this.auto_start = options.auto_start this.battle_eye = options.battle_eye + this.battle_eye_password = options.battle_eye_password || '' + this.battle_eye_port = options.battle_eye_port || '' this.file_patching = options.file_patching this.forcedDifficulty = options.forcedDifficulty || null this.max_players = options.max_players @@ -132,6 +136,23 @@ Server.prototype.start = function () { return this } + var self = this + + if (this.battle_eye) { + var battlEye = new BattlEye(this.config, this) + battlEye.createConfigFile(function () { + self.realStart() + }) + } else { + this.realStart() + } +} + +Server.prototype.realStart = function () { + if (this.instance) { + return this + } + var parameters = this.getParameters() var server = new ArmaServer.Server({ additionalConfigurationOptions: this.getAdditionalConfigurationOptions(), @@ -261,6 +282,8 @@ Server.prototype.toJSON = function () { allowed_file_patching: this.allowed_file_patching, auto_start: this.auto_start, battle_eye: this.battle_eye, + battle_eye_password: this.battle_eye_password, + battle_eye_port: this.battle_eye_port, id: this.id, file_patching: this.file_patching, forcedDifficulty: this.forcedDifficulty, diff --git a/public/js/app/models/server.js b/public/js/app/models/server.js index 7d13dda..f2bd803 100644 --- a/public/js/app/models/server.js +++ b/public/js/app/models/server.js @@ -8,6 +8,8 @@ module.exports = Backbone.Model.extend({ allowed_file_patching: 1, auto_start: false, battle_eye: false, + battle_eye_password: '', + battle_eye_port: '', file_patching: false, forcedDifficulty: '', max_players: null, diff --git a/public/js/tpl/servers/form.html b/public/js/tpl/servers/form.html index 814fa33..04b6e5b 100644 --- a/public/js/tpl/servers/form.html +++ b/public/js/tpl/servers/form.html @@ -99,12 +99,26 @@