Create BattlEye config file for RCON

This commit is contained in:
Björn Dahlgren 2022-01-20 03:05:38 +01:00
parent b1b043ca4c
commit ce5e370238
5 changed files with 127 additions and 1 deletions

44
lib/battleye.js Normal file
View File

@ -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

View File

@ -5,6 +5,8 @@ var slugify = require('slugify')
var ArmaServer = require('arma-server') var ArmaServer = require('arma-server')
var BattlEye = require('./battleye')
var queryInterval = 5000 var queryInterval = 5000
var queryTypes = { var queryTypes = {
arma1: 'arma', arma1: 'arma',
@ -47,6 +49,8 @@ Server.prototype.update = function (options) {
this.allowed_file_patching = options.allowed_file_patching this.allowed_file_patching = options.allowed_file_patching
this.auto_start = options.auto_start this.auto_start = options.auto_start
this.battle_eye = options.battle_eye 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.file_patching = options.file_patching
this.forcedDifficulty = options.forcedDifficulty || null this.forcedDifficulty = options.forcedDifficulty || null
this.max_players = options.max_players this.max_players = options.max_players
@ -132,6 +136,23 @@ Server.prototype.start = function () {
return this 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 parameters = this.getParameters()
var server = new ArmaServer.Server({ var server = new ArmaServer.Server({
additionalConfigurationOptions: this.getAdditionalConfigurationOptions(), additionalConfigurationOptions: this.getAdditionalConfigurationOptions(),
@ -261,6 +282,8 @@ Server.prototype.toJSON = function () {
allowed_file_patching: this.allowed_file_patching, allowed_file_patching: this.allowed_file_patching,
auto_start: this.auto_start, auto_start: this.auto_start,
battle_eye: this.battle_eye, battle_eye: this.battle_eye,
battle_eye_password: this.battle_eye_password,
battle_eye_port: this.battle_eye_port,
id: this.id, id: this.id,
file_patching: this.file_patching, file_patching: this.file_patching,
forcedDifficulty: this.forcedDifficulty, forcedDifficulty: this.forcedDifficulty,

View File

@ -8,6 +8,8 @@ module.exports = Backbone.Model.extend({
allowed_file_patching: 1, allowed_file_patching: 1,
auto_start: false, auto_start: false,
battle_eye: false, battle_eye: false,
battle_eye_password: '',
battle_eye_port: '',
file_patching: false, file_patching: false,
forcedDifficulty: '', forcedDifficulty: '',
max_players: null, max_players: null,

View File

@ -99,12 +99,26 @@
<div class="col-sm-offset-2 col-sm-10"> <div class="col-sm-offset-2 col-sm-10">
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" class="battle-eye" <% if (battle_eye) { %>checked="checked"<% } %>> BattleEye <input type="checkbox" class="battle-eye" <% if (battle_eye) { %>checked="checked"<% } %>> BattlEye
</label> </label>
</div> </div>
</div> </div>
</div> </div>
<div class="form-group">
<label for="battle-eye-password" class="col-sm-2 control-label">BattlEye RCON Password</label>
<div class="col-sm-10">
<input type="text" class="form-control battle-eye-password" placeholder="BattlEye RCON Password" value="<%- battle_eye_password %>">
</div>
</div>
<div class="form-group">
<label for="battle-eye-port" class="col-sm-2 control-label">BattlEye RCON Port</label>
<div class="col-sm-10">
<input type="text" class="form-control battle-eye-port" placeholder="BattlEye RCON Port" value="<%- battle_eye_port %>">
</div>
</div>
<div class="form-group"> <div class="form-group">
<div class="col-sm-offset-2 col-sm-10"> <div class="col-sm-offset-2 col-sm-10">
<div class="checkbox"> <div class="checkbox">

43
test/lib/battleye.js Normal file
View File

@ -0,0 +1,43 @@
var path = require('path')
require('should')
var BattlEye = require('../../lib/battleye.js')
var Server = require('../../lib/server.js')
var server = new Server(null, null, {
battle_eye: true,
battle_eye_password: 'password',
battle_eye_port: '12345',
title: 'BattlEye Server'
})
describe('BattlEye', function () {
describe('configContents()', function () {
it('should include password', function () {
var battlEye = new BattlEye({}, server)
battlEye.configContents().should.containEql('RConPassword password')
})
it('should include port', function () {
var battlEye = new BattlEye({}, server)
battlEye.configContents().should.containEql('RConPort 12345')
})
it('should generate valid config contents', function () {
var battlEye = new BattlEye({}, server)
battlEye.configContents().should.eql('RConPassword password\nRConPort 12345')
})
})
describe('configPath()', function () {
it('should generate x64 config for arma 3 x64 server', function () {
var battlEye = new BattlEye({ game: 'arma3_x64', path: '/' }, server)
battlEye.configPath().should.eql(path.join('/', 'battleye', 'beserver_x64.cfg'))
})
it('should generate regular config for arma3 server', function () {
var battlEye = new BattlEye({ game: 'arma3', path: '/' }, server)
battlEye.configPath().should.eql(path.join('/', 'battleye', 'beserver.cfg'))
})
})
})