Skip to content
Permalink
Browse files

Starting work on game settings.

  • Loading branch information...
roncli committed Jul 2, 2015
1 parent 9c6306a commit c81115cbd66b9b6d688355aca80c95ed490771f5
Showing with 326 additions and 15 deletions.
  1. +15 −0 index.js
  2. +50 −1 public/js/ddsn.js
  3. +58 −0 public/templates/add-server-game.htm
  4. +1 −2 public/templates/add-server-server.htm
  5. +202 −12 websocket.js
@@ -3,6 +3,21 @@ var cluster = require("cluster"),
websocket = require("./websocket"),
webServerWorker, webSocketWorker;

// A safe regexp exec method that does not leak memory.
RegExp.prototype.safeexec = function(string) {
"use strict";

var result = this.exec(string);

if (result) {
result.forEach(function(item, index) {
result[index] = item.split("").join("");
});
}

return result;
};

// Use clustering to spawn separate processes.
if (cluster.isMaster) {
webServerWorker = cluster.fork({
@@ -10,7 +10,14 @@ var app = angular.module("ddsn", []),
descent3: {
pathValid: false
}
}
},
difficulties: [
{difficulty: 0, name: "Trainee"},
{difficulty: 1, name: "Rookie"},
{difficulty: 2, name: "Hotshot"},
{difficulty: 3, name: "Ace"},
{difficulty: 4, name: "Insane"}
]
};

(function() {
@@ -238,6 +245,39 @@ var app = angular.module("ddsn", []),
data.settings.addServer.server.addTrackerPortValid = typeof data.settings.addServer.server.addTrackerPort === "number" && data.settings.addServer.server.addTrackerPort >= 1 && data.settings.addServer.server.addTrackerPort <= 65535 && data.settings.addServer.server.addTrackerPort % 1 === 0;
};

$scope.updateAddServerGameNetworkModel = function() {
switch (data.settings.addServer.game.networkModel) {
case "p2p":
data.settings.addServer.game.peer2peer = true;
data.settings.addServer.game.permissible = false;
break;
case "pcs":
data.settings.addServer.game.peer2peer = false;
data.settings.addServer.game.permissible = true;
break;
default:
data.settings.addServer.game.peer2peer = false;
data.settings.addServer.game.permissible = false;
break;
}
};

$scope.updateAddServerGameMaxPlayers = function() {
data.settings.addServer.game.maxPlayersValid = typeof data.settings.addServer.game.maxPlayers === "number" && data.settings.addServer.game.maxPlayers >= 1 && data.settings.addServer.game.maxPlayers <= 31 && data.settings.addServer.game.maxPlayers % 1 === 0;
};

$scope.updateAddServerGamePps = function() {
data.settings.addServer.game.ppsValid = typeof data.settings.addServer.game.pps === "number" && data.settings.addServer.game.pps >= 1 && data.settings.addServer.game.pps <= 20 && data.settings.addServer.game.pps % 1 === 0;
};

$scope.updateAddServerGameKillGoal = function() {
data.settings.addServer.game.killGoalValid = data.settings.addServer.game.killGoal === null || (typeof data.settings.addServer.game.killGoal === "number" && data.settings.addServer.game.killGoal >= 1 && data.settings.addServer.game.killGoal % 1 === 0);
};

$scope.updateAddServerGameTimeLimit = function() {
data.settings.addServer.game.timeLimitValid = data.settings.addServer.game.timeLimit === null || (typeof data.settings.addServer.game.timeLimit === "number" && data.settings.addServer.game.timeLimit >= 1 && data.settings.addServer.game.timeLimit % 1 === 0);
};

$scope.updateSettingsDescent3Path = function() {
ws.send(JSON.stringify({
message: "settings.descent3.path",
@@ -275,6 +315,12 @@ var app = angular.module("ddsn", []),
key;

switch (message.message) {
case "missions":
// TODO: Handle missions
break;
case "missions.progress":
// TODO: Handle missinos progress
break;
case "settings":
for (key in message.settings) {
if (message.settings.hasOwnProperty(key)) {
@@ -287,6 +333,9 @@ var app = angular.module("ddsn", []),
data.settings.descent3.pathValid = message.valid;
scope.$apply();
break;
case "warning":
// TODO: Handle warning
break;
}
};
};
@@ -0,0 +1,58 @@
<div class="row">
<div class="col-xs-6">
<div ng-class="{true: 'input-group', false: 'input-group has-error'}[data.settings.addServer.game.gameName.length > 0]">
<span class="input-group-addon">Game name:</span>
<input type="text" class="form-control" placeholder="Displayed game name" ng-model="data.settings.addServer.game.gameName" />
</div>
<div class="input-group">
<span class="input-group-addon" style="white-space: nowrap; width: 1px;">Connection type:</span>
<span class="input-group-addon" style="width: 100%; padding: 0;">
<select class="form-control" ng-model="data.settings.addServer.game.connectionName" ng-options="connectionType.name as connectionType.titleName for connectionType in data.settings.connectionTypes"></select>
</span>
</div>
<div class="input-group">
<span class="input-group-addon" style="white-space: nowrap; width: 1px;">Game type:</span>
<span class="input-group-addon" style="width: 100%; padding: 0;">
<select class="form-control" ng-model="data.settings.addServer.game.scriptName" ng-options="gameType.name as gameType.titleName for gameType in data.settings.gameTypes"></select>
</span>
</div>
<div class="input-group">
<span class="input-group-addon" style="white-space: nowrap; width: 1px;">Server network model:</span>
<span class="input-group-addon" style="width: 100%; padding: 0;">
<select class="form-control" ng-model="data.settings.addServer.game.networkModel" ng-change="updateAddServerGameNetworkModel()">
<option value="cs">Client/Server</option>
<option value="p2p">Peer to Peer</option>
<option value="pcs">Permissible Client Server</option>
</select>
</span>
</div>
<div class="input-group">
<span class="input-group-addon">Message of the day:</span>
<input type="text" class="form-control" placeholder="Message displayed to players when they connect" ng-model="data.settings.addServer.game.motd" />
</div>
</div>
<div class="col-xs-6">
<div ng-class="{true: 'input-group', false: 'input-group has-error'}[data.settings.addServer.game.maxPlayersValid]">
<span class="input-group-addon">Max players:</span>
<input type="number" min="1" max="31" class="form-control" placeholder="Maximum players between 1 and 31" ng-model="data.settings.addServer.game.maxPlayers" ng-blur="updateAddServerGameMaxPlayers()" />
</div>
<div ng-class="{true: 'input-group', false: 'input-group has-error'}[data.settings.addServer.game.ppsValid]">
<span class="input-group-addon">Max packets per second:</span>
<input type="number" min="1" max="20" class="form-control" placeholder="Maximum packets per second between 1 and 20" ng-model="data.settings.addServer.game.pps" ng-blur="updateAddServerGamePps()"/>
</div>
<div ng-class="{true: 'input-group', false: 'input-group has-error'}[data.settings.addServer.game.killGoalValid]">
<span class="input-group-addon">Score goal:</span>
<input type="number" min="1" class="form-control" placeholder="Score goal, optional" ng-model="data.settings.addServer.game.killGoal" ng-blur="updateAddServerGameKillGoal()"/>
</div>
<div ng-class="{true: 'input-group', false: 'input-group has-error'}[data.settings.addServer.game.timeLimitValid]">
<span class="input-group-addon">Time limit in minutes:</span>
<input type="number" min="1" class="form-control" placeholder="Time limit in minutes, optional" ng-model="data.settings.addServer.game.timeLimit" ng-blur="updateAddServerGameTimeLimit()"/>
</div>
<div class="input-group">
<span class="input-group-addon" style="white-space: nowrap; width: 1px;">Difficulty:</span>
<span class="input-group-addon" style="width: 100%; padding: 0;">
<select class="form-control" ng-model="data.settings.addServer.game.setDifficulty" ng-options="difficulty.difficulty as difficulty.name for difficulty in data.difficulties"></select>
</span>
</div>
</div>
</div>
@@ -3,9 +3,8 @@
<div class="input-group">
<span class="input-group-addon" style="white-space: nowrap; width: 1px;">IP address:</span>
<span class="input-group-addon" style="width: 100%; padding: 0;">
<select class="form-control" ng-model="data.settings.addServer.server.ip">
<select class="form-control" ng-model="data.settings.addServer.server.ip" ng-options="network.ip as (network.ip + ' - ' + network.name) for network in data.settings.interfaces">
<option value="">Default</option>
<option ng-repeat="network in data.settings.interfaces" value="{{network.ip}}">{{network.ip}} - {{network.name}}</option>
</select>
</span>
</div>

0 comments on commit c81115c

Please sign in to comment.
You can’t perform that action at this time.