Skip to content

Commit 76f265e

Browse files
committed
Create BattlEye config file for RCON
1 parent c5d69ac commit 76f265e

File tree

5 files changed

+127
-1
lines changed

5 files changed

+127
-1
lines changed

Diff for: lib/battleye.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var fs = require('fs')
2+
var path = require('path')
3+
4+
var BattlEye = function (config, server) {
5+
this.config = config
6+
this.server = server
7+
}
8+
9+
BattlEye.prototype.configContents = function () {
10+
var vars = []
11+
12+
if (this.server.battle_eye_password) {
13+
vars.push('RConPassword ' + this.server.battle_eye_password)
14+
}
15+
16+
if (this.server.battle_eye_port) {
17+
vars.push('RConPort ' + this.server.battle_eye_port)
18+
}
19+
20+
return vars.join('\n')
21+
}
22+
23+
BattlEye.prototype.configPath = function () {
24+
if (this.config.game === 'arma3_x64') {
25+
return path.join(this.config.path, 'battleye', 'beserver_x64.cfg')
26+
}
27+
28+
return path.join(this.config.path, 'battleye', 'beserver.cfg')
29+
}
30+
31+
BattlEye.prototype.createConfigFile = function (callback) {
32+
var contents = this.configContents()
33+
var filePath = this.configPath()
34+
35+
fs.writeFile(filePath, contents, function (err) {
36+
if (err) {
37+
console.error('Failed to write BattlEye config: ' + err)
38+
}
39+
40+
callback(err)
41+
})
42+
}
43+
44+
module.exports = BattlEye

Diff for: lib/server.js

+23
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var slugify = require('slugify')
55

66
var ArmaServer = require('arma-server')
77

8+
var BattlEye = require('./battleye')
9+
810
var queryInterval = 5000
911
var queryTypes = {
1012
arma1: 'arma',
@@ -47,6 +49,8 @@ Server.prototype.update = function (options) {
4749
this.allowed_file_patching = options.allowed_file_patching
4850
this.auto_start = options.auto_start
4951
this.battle_eye = options.battle_eye
52+
this.battle_eye_password = options.battle_eye_password || ''
53+
this.battle_eye_port = options.battle_eye_port || ''
5054
this.file_patching = options.file_patching
5155
this.forcedDifficulty = options.forcedDifficulty || null
5256
this.max_players = options.max_players
@@ -132,6 +136,23 @@ Server.prototype.start = function () {
132136
return this
133137
}
134138

139+
var self = this
140+
141+
if (this.battle_eye) {
142+
var battlEye = new BattlEye(this.config, this)
143+
battlEye.createConfigFile(function () {
144+
self.realStart()
145+
})
146+
} else {
147+
this.realStart()
148+
}
149+
}
150+
151+
Server.prototype.realStart = function () {
152+
if (this.instance) {
153+
return this
154+
}
155+
135156
var parameters = this.getParameters()
136157
var server = new ArmaServer.Server({
137158
additionalConfigurationOptions: this.getAdditionalConfigurationOptions(),
@@ -261,6 +282,8 @@ Server.prototype.toJSON = function () {
261282
allowed_file_patching: this.allowed_file_patching,
262283
auto_start: this.auto_start,
263284
battle_eye: this.battle_eye,
285+
battle_eye_password: this.battle_eye_password,
286+
battle_eye_port: this.battle_eye_port,
264287
id: this.id,
265288
file_patching: this.file_patching,
266289
forcedDifficulty: this.forcedDifficulty,

Diff for: public/js/app/models/server.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module.exports = Backbone.Model.extend({
88
allowed_file_patching: 1,
99
auto_start: false,
1010
battle_eye: false,
11+
battle_eye_password: '',
12+
battle_eye_port: '',
1113
file_patching: false,
1214
forcedDifficulty: '',
1315
max_players: null,

Diff for: public/js/tpl/servers/form.html

+15-1
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,26 @@
9999
<div class="col-sm-offset-2 col-sm-10">
100100
<div class="checkbox">
101101
<label>
102-
<input type="checkbox" class="battle-eye" <% if (battle_eye) { %>checked="checked"<% } %>> BattleEye
102+
<input type="checkbox" class="battle-eye" <% if (battle_eye) { %>checked="checked"<% } %>> BattlEye
103103
</label>
104104
</div>
105105
</div>
106106
</div>
107107

108+
<div class="form-group">
109+
<label for="battle-eye-password" class="col-sm-2 control-label">BattlEye RCON Password</label>
110+
<div class="col-sm-10">
111+
<input type="text" class="form-control battle-eye-password" placeholder="BattlEye RCON Password" value="<%- battle_eye_password %>">
112+
</div>
113+
</div>
114+
115+
<div class="form-group">
116+
<label for="battle-eye-port" class="col-sm-2 control-label">BattlEye RCON Port</label>
117+
<div class="col-sm-10">
118+
<input type="text" class="form-control battle-eye-port" placeholder="BattlEye RCON Port" value="<%- battle_eye_port %>">
119+
</div>
120+
</div>
121+
108122
<div class="form-group">
109123
<div class="col-sm-offset-2 col-sm-10">
110124
<div class="checkbox">

Diff for: test/lib/battleye.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var path = require('path')
2+
require('should')
3+
4+
var BattlEye = require('../../lib/battleye.js')
5+
var Server = require('../../lib/server.js')
6+
7+
var server = new Server(null, null, {
8+
battle_eye: true,
9+
battle_eye_password: 'password',
10+
battle_eye_port: '12345',
11+
title: 'BattlEye Server'
12+
})
13+
14+
describe('BattlEye', function () {
15+
describe('configContents()', function () {
16+
it('should include password', function () {
17+
var battlEye = new BattlEye({}, server)
18+
battlEye.configContents().should.containEql('RConPassword password')
19+
})
20+
21+
it('should include port', function () {
22+
var battlEye = new BattlEye({}, server)
23+
battlEye.configContents().should.containEql('RConPort 12345')
24+
})
25+
26+
it('should generate valid config contents', function () {
27+
var battlEye = new BattlEye({}, server)
28+
battlEye.configContents().should.eql('RConPassword password\nRConPort 12345')
29+
})
30+
})
31+
32+
describe('configPath()', function () {
33+
it('should generate x64 config for arma 3 x64 server', function () {
34+
var battlEye = new BattlEye({ game: 'arma3_x64', path: '/' }, server)
35+
battlEye.configPath().should.eql(path.join('/', 'battleye', 'beserver_x64.cfg'))
36+
})
37+
38+
it('should generate regular config for arma3 server', function () {
39+
var battlEye = new BattlEye({ game: 'arma3', path: '/' }, server)
40+
battlEye.configPath().should.eql(path.join('/', 'battleye', 'beserver.cfg'))
41+
})
42+
})
43+
})

0 commit comments

Comments
 (0)