Support headless

This commit is contained in:
Björn Dahlgren 2015-02-13 17:13:55 +01:00 committed by Björn Dahlgren
parent a9429df2bd
commit f46e6acd13
5 changed files with 51 additions and 4 deletions

View File

@ -92,6 +92,7 @@ Manager.prototype.save = (function () {
data.push({
admin_password: server.admin_password,
battle_eye: server.battle_eye,
headless: server.headless,
max_players: server.max_players,
mods: server.mods,
password: server.password,

View File

@ -18,6 +18,7 @@ Server.prototype = new events.EventEmitter();
Server.prototype.update = function (options) {
this.admin_password = options.admin_password;
this.battle_eye = options.battle_eye;
this.headless = options.headless;
this.max_players = options.max_players;
this.mods = options.mods || [];
this.password = options.password;
@ -51,11 +52,13 @@ Server.prototype.queryStatus = function() {
};
Server.prototype.start = function() {
var server = new ArmaServer({
var server = new ArmaServer.Server({
battleEye: this.battle_eye ? 1 : 0,
config: this.id,
disableVoN: this.von ? 0 : 1,
headlessClients: this.headless ? ["127.0.0.1"] : null,
hostname: this.title,
localClient: this.headless ? ["127.0.0.1"] : null,
mods: this.mods,
password: this.password,
passwordAdmin: this.admin_password,
@ -70,15 +73,15 @@ Server.prototype.start = function() {
var self = this;
instance.stdout.on('data', function (data) {
console.log('stdout: ' + data);
console.log(self.id + ': ' + data);
});
instance.stderr.on('data', function (data) {
console.log('stderr: ' + data);
console.log(self.id + ' err: ' + data);
});
instance.on('close', function (code) {
console.log('child process exited with code ' + code);
console.log(self.id + ' exited with code ' + code);
clearInterval(self.queryStatusInterval);
self.state = null;
self.pid = null;
@ -93,6 +96,33 @@ Server.prototype.start = function() {
self.queryStatus();
}, queryInterval);
if (this.headless) {
var headless = new ArmaServer.Headless({
host: "127.0.0.1",
mods: this.mods,
password: this.password,
path: this.path,
platform: this.type,
port: this.port,
});
var headlessInstance = headless.start();
headlessInstance.stdout.on('data', function (data) {
console.log(self.id + ' HC: ' + data);
});
headlessInstance.stderr.on('data', function (data) {
console.log(self.id + ' HC err: ' + data);
});
headlessInstance.on('close', function (code) {
console.log(self.id + ' HC exited with code ' + code);
self.headlessInstance = null;
});
self.headlessInstance = headlessInstance;
}
this.emit('state');
return this;
@ -113,6 +143,9 @@ Server.prototype.stop = function(cb) {
});
this.instance.kill();
if (this.headlessInstance) {
this.headlessInstance.kill();
}
setTimeout(function() {
if (!handled) {
@ -131,6 +164,7 @@ Server.prototype.toJSON = function () {
return {
admin_password: this.admin_password,
battle_eye: this.battle_eye,
headless: this.headless,
id: this.id,
max_players: this.max_players,
mods: this.mods,

View File

@ -10,6 +10,7 @@ define(function (require) {
defaults: {
admin_password: '',
battle_eye: false,
headless: false,
max_players: null,
mods: [],
password: '',

View File

@ -21,6 +21,7 @@ define(function (require) {
return {
admin_password: this.$("form .admin-password").val(),
battle_eye: this.$("form .battle-eye").prop("checked"),
headless: this.$("form .headless").prop("checked"),
max_players: this.$("form .max-players").val(),
password: this.$("form .password").val(),
persistent: this.$("form .persistent").prop("checked"),

View File

@ -45,6 +45,16 @@
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox" class="headless" <% if (headless) { %>checked="checked"<% } %>> Headless Client
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">