Skip to content

Create BattlEye config file for RCON #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions lib/battleye.js
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var slugify = require('slugify')

var ArmaServer = require('arma-server')

var BattlEye = require('./battleye')

var queryInterval = 5000
var queryTypes = {
arma1: 'arma',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions public/js/app/models/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 15 additions & 1 deletion public/js/tpl/servers/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,26 @@
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<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>
</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="col-sm-offset-2 col-sm-10">
<div class="checkbox">
Expand Down
43 changes: 43 additions & 0 deletions test/lib/battleye.js
Original file line number Diff line number Diff line change
@@ -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'))
})
})
})