From fac18c00b64260405efc41ef13def6ed8bf0364b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Dahlgren?= Date: Sat, 19 Nov 2016 23:31:38 +0100 Subject: [PATCH] Set startup parameters for server instances --- README.md | 4 ++ config.js.example | 4 ++ lib/manager.js | 1 + lib/server.js | 14 ++++++ public/js/app/collections/parameters.js | 14 ++++++ public/js/app/models/parameter.js | 15 ++++++ public/js/app/models/server.js | 1 + .../js/app/views/servers/parameters/list.js | 47 +++++++++++++++++++ .../app/views/servers/parameters/list_item.js | 32 +++++++++++++ public/js/app/views/servers/view.js | 7 ++- public/js/tpl/servers/parameters/list.html | 26 ++++++++++ .../js/tpl/servers/parameters/list_item.html | 19 ++++++++ public/js/tpl/servers/view.html | 5 +- 13 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 public/js/app/collections/parameters.js create mode 100644 public/js/app/models/parameter.js create mode 100644 public/js/app/views/servers/parameters/list.js create mode 100644 public/js/app/views/servers/parameters/list_item.js create mode 100644 public/js/tpl/servers/parameters/list.html create mode 100644 public/js/tpl/servers/parameters/list_item.html diff --git a/README.md b/README.md index 412328e..c375bf7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config.js.example b/config.js.example index 5b34954..dbe2265 100644 --- a/config.js.example +++ b/config.js.example @@ -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', diff --git a/lib/manager.js b/lib/manager.js index 332a708..8b7aa38 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -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, diff --git a/lib/server.js b/lib/server.js index fc07994..7a4a163 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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, diff --git a/public/js/app/collections/parameters.js b/public/js/app/collections/parameters.js new file mode 100644 index 0000000..0027461 --- /dev/null +++ b/public/js/app/collections/parameters.js @@ -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, + }); + +}); diff --git a/public/js/app/models/parameter.js b/public/js/app/models/parameter.js new file mode 100644 index 0000000..b89e0ca --- /dev/null +++ b/public/js/app/models/parameter.js @@ -0,0 +1,15 @@ +define(function (require) { + + "use strict"; + + var $ = require('jquery'), + _ = require('underscore'), + Backbone = require('backbone'); + + return Backbone.Model.extend({ + defaults: { + parameter: '' + }, + }); + +}); diff --git a/public/js/app/models/server.js b/public/js/app/models/server.js index 23b8b48..4c84b3c 100644 --- a/public/js/app/models/server.js +++ b/public/js/app/models/server.js @@ -13,6 +13,7 @@ define(function (require) { headless: false, max_players: null, mods: [], + parameters: [], password: '', persistent: false, port: 2302, diff --git a/public/js/app/views/servers/parameters/list.js b/public/js/app/views/servers/parameters/list.js new file mode 100644 index 0000000..11b915c --- /dev/null +++ b/public/js/app/views/servers/parameters/list.js @@ -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'); + }), + }; + }, + }); + +}); diff --git a/public/js/app/views/servers/parameters/list_item.js b/public/js/app/views/servers/parameters/list_item.js new file mode 100644 index 0000000..8dad8c6 --- /dev/null +++ b/public/js/app/views/servers/parameters/list_item.js @@ -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(); + }, + }); +}); diff --git a/public/js/app/views/servers/view.js b/public/js/app/views/servers/view.js index 96f14d5..00e9e0a 100644 --- a/public/js/app/views/servers/view.js +++ b/public/js/app/views/servers/view.js @@ -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'); diff --git a/public/js/tpl/servers/parameters/list.html b/public/js/tpl/servers/parameters/list.html new file mode 100644 index 0000000..e96011e --- /dev/null +++ b/public/js/tpl/servers/parameters/list.html @@ -0,0 +1,26 @@ + + + + + + + + + +
+ + + Add new parameter + + Startup Parameters +
+ + diff --git a/public/js/tpl/servers/parameters/list_item.html b/public/js/tpl/servers/parameters/list_item.html new file mode 100644 index 0000000..a8039f5 --- /dev/null +++ b/public/js/tpl/servers/parameters/list_item.html @@ -0,0 +1,19 @@ + +
+
+ +
+ +
+
+ +
+
+ +
+
+
+ diff --git a/public/js/tpl/servers/view.html b/public/js/tpl/servers/view.html index f36a33f..661a775 100644 --- a/public/js/tpl/servers/view.html +++ b/public/js/tpl/servers/view.html @@ -22,5 +22,8 @@
-
+
+
+
+