Merge pull request #26 from Dahlgren/feature/startup-parameters

Startup Parameters
This commit is contained in:
Björn Dahlgren 2017-02-18 19:41:50 +01:00 committed by GitHub
commit cac9a7f15c
13 changed files with 187 additions and 2 deletions

View File

@ -44,7 +44,11 @@ path | Folder path to game server
port | Web port to use
host | IP or Hostname to listen on
type | Which kind of server to use, can be 'linux', 'windows' or 'wine'
parameters | Extra startup parameters added to servers and headless clients
serverMods | Mods that always and only will be used by the game servers
auth | If both username and password is set, HTTP Basic Auth will be used
prefix | Text prepended to all game servers name
suffix | Text appended to all game servers name
## How to Use

View File

@ -4,6 +4,10 @@ module.exports = {
port: 3000,
host: '0.0.0.0', // Can be either an IP or a Hostname
type: 'linux', // Can be either linux, windows or wine
parameters: [ // Additional startup parameters used by all servers
'-noSound',
'-world=empty'
],
serverMods: [ // Mods used exclusively by server and not shared with clients
'@mod1',
'@mod2',

View File

@ -101,6 +101,7 @@ Manager.prototype.save = (function () {
max_players: server.max_players,
missions: server.missions,
mods: server.mods,
parameters: server.parameters,
password: server.password,
persistent: server.persistent,
port: server.port,

View File

@ -47,6 +47,7 @@ Server.prototype.update = function (options) {
this.missions = options.missions;
this.mods = options.mods || [];
this.password = options.password;
this.parameters = options.parameters;
this.persistent = options.persistent;
this.port = options.port || 2302;
this.title = options.title;
@ -85,6 +86,16 @@ Server.prototype.queryStatus = function() {
};
Server.prototype.start = function() {
var parameters = [];
if (config.parameters && Array.isArray(config.parameters)) {
parameters = parameters.concat(config.parameters);
}
if (this.parameters && Array.isArray(this.parameters)) {
parameters = parameters.concat(this.parameters);
}
var server = new ArmaServer.Server({
battleEye: this.battle_eye ? 1 : 0,
config: this.id,
@ -95,6 +106,7 @@ Server.prototype.start = function() {
localClient: this.headless ? ["127.0.0.1"] : null,
missions: this.missions,
mods: this.mods,
parameters: parameters,
password: this.password,
passwordAdmin: this.admin_password,
path: this.config.path,
@ -151,6 +163,7 @@ Server.prototype.start = function() {
game: config.game,
host: "127.0.0.1",
mods: this.mods,
parameters: parameters,
password: this.password,
path: this.config.path,
platform: this.config.type,
@ -220,6 +233,7 @@ Server.prototype.toJSON = function () {
max_players: this.max_players,
missions: this.missions,
mods: this.mods,
parameters: this.parameters,
password: this.password,
persistent: this.persistent,
pid: this.pid,

View File

@ -0,0 +1,14 @@
define(function (require) {
"use strict";
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone'),
Parameter = require('app/models/parameter');
return Backbone.Collection.extend({
model: Parameter,
});
});

View File

@ -0,0 +1,15 @@
define(function (require) {
"use strict";
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');
return Backbone.Model.extend({
defaults: {
parameter: ''
},
});
});

View File

@ -13,6 +13,7 @@ define(function (require) {
headless: false,
max_players: null,
mods: [],
parameters: [],
password: '',
persistent: false,
port: 2302,

View File

@ -0,0 +1,47 @@
define(function (require) {
"use strict";
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
Parameter = require('app/models/parameter'),
Parameters = require('app/collections/parameters'),
ListItemView = require('app/views/servers/parameters/list_item'),
tpl = require('text!tpl/servers/parameters/list.html');
return Marionette.CompositeView.extend({
itemView: ListItemView,
itemViewContainer: "tbody",
template: _.template(tpl),
events: {
"click .add-parameter": "addParameter",
},
initialize: function (options) {
this.model = options.server;
this.collection = new Parameters(this.model.get('parameters').map(function (parameter) {
return new Parameter({
parameter: parameter,
});
}));
},
addParameter: function (e) {
e.preventDefault();
this.collection.add(new Parameter());
},
serialize : function() {
return {
parameters: this.collection.map(function (parameter) {
return parameter.get('parameter');
}),
};
},
});
});

View File

@ -0,0 +1,32 @@
define(function (require) {
"use strict";
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/servers/parameters/list_item.html'),
template = _.template(tpl);
return Marionette.ItemView.extend({
tagName: "tr",
template: template,
events: {
"click button.delete": "delete",
"change input#parameter": "changed",
},
changed: function (e) {
var val = $(e.target).val();
this.model.set(e.target.id, val);
},
delete: function (e) {
e.preventDefault();
this.model.destroy();
},
});
});

View File

@ -11,6 +11,7 @@ define(function (require) {
InfoView = require('app/views/servers/info'),
MissionsView = require('app/views/servers/missions/index'),
ModsListView = require('app/views/servers/mods/list'),
ParametersListView = require('app/views/servers/parameters/list'),
PlayersView = require('app/views/servers/players'),
tpl = require('text!tpl/servers/view.html');
@ -21,8 +22,9 @@ define(function (require) {
infoView: "#tab-info",
missionsView: "#tab-missions",
modsView: "#tab-mods",
parametersView: "#parameters",
playersView: "#tab-players",
settingsView: "#tab-settings",
settingsView: "#settings",
},
events: {
@ -43,6 +45,7 @@ define(function (require) {
this.infoView.show(new InfoView({model: this.model}));
this.missionsView.show(new MissionsView({missions: this.missions, server: this.model}));
this.modsView.show(new ModsListView({collection: this.mods, server: this.model}));
this.parametersView.show(new ParametersListView({server: this.model}));
this.playersView.show(new PlayersView({model: this.model}));
this.settingsView.show(new FormView({model: this.model}));
},
@ -50,6 +53,7 @@ define(function (require) {
serverUpdated: function() {
this.infoView.currentView.render();
this.modsView.currentView.render();
this.parametersView.currentView.render();
this.playersView.currentView.render();
this.settingsView.currentView.render();
},
@ -61,6 +65,7 @@ define(function (require) {
var data = this.settingsView.currentView.serialize();
_.extend(data, this.missionsView.currentView.serialize());
_.extend(data, this.modsView.currentView.serialize());
_.extend(data, this.parametersView.currentView.serialize());
this.model.save(data, {
success: function() {
var newId = self.model.get('id');

View File

@ -0,0 +1,26 @@
<table class="table table-striped">
<thead>
<tr>
<th>
<a class="btn btn-primary btn-xs add-parameter pull-right" href="#">
<span class="glyphicon glyphicon-plus"></span>
Add new parameter
</a>
<span>Startup Parameters</span>
</th>
</tr>
</thead>
<!-- want to insert collection items, here -->
<tbody></tbody>
</table>
<div class="alert alert-warning" role="alert">
<p>The following startup parameters are used by the Web UI:</p>
<ul>
<li>-config (Required to set title among others)</li>
<li>-mod</li>
<li>-port</li>
<li>-serverMod</li>
</ul>
</div>

View File

@ -0,0 +1,19 @@
<td>
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Parameter</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="parameter" placeholder="Parameter" value="<%- parameter %>">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-xs btn-danger delete">
<span class="glyphicon glyphicon-minus"></span>
Remove
</button>
</div>
</div>
</form>
</td>

View File

@ -22,5 +22,8 @@
<div class="tab-pane" id="tab-mods"></div>
<div class="tab-pane" id="tab-missions"></div>
<div class="tab-pane" id="tab-players"></div>
<div class="tab-pane" id="tab-settings"></div>
<div class="tab-pane" id="tab-settings">
<div id="settings"></div>
<div id="parameters"></div>
</div>
</div>