Skip to content
Permalink
Browse files

Launched servers consoles are now readable.

  • Loading branch information...
roncli committed Jul 6, 2015
1 parent 2dc0d7a commit 914943b7fc310827ce05100fbc20dce0f0b8a516
@@ -34,4 +34,4 @@ test.js

# DDSN settings
settings.json
missions.json
missions.json
@@ -4,6 +4,7 @@
var app = angular.module("ddsn", []),
data = {
serverTab: "news",
serverMenuTab: "scoreboard",
addServerMenuTab: "saved",
settingsMenuTab: "descent3",
settings: {
@@ -18,7 +19,23 @@ var app = angular.module("ddsn", []),
{difficulty: 3, name: "Ace"},
{difficulty: 4, name: "Insane"}
],
selectMissionToggle: true
selectMissionToggle: true,
servers: []
},

getServer = function(port, callback) {
"use strict";

var server = data.servers.filter(function(item) {
return item.settings.server.port === port;
});

if (server) {
callback(server[0]);
return;
}

callback();
};

(function() {
@@ -82,6 +99,41 @@ var app = angular.module("ddsn", []),
};
});

app.directive("server", function() {
return {
restrict: "E",
templateUrl: "/templates/server.htm"
};
});

app.directive("serverScoreboard", function() {
return {
restrict: "E",
templateUrl: "/templates/server-scoreboard.htm"
};
});

app.directive("serverConsole", function() {
return {
restrict: "E",
templateUrl: "/templates/server-console.htm"
};
});

app.directive("serverLog", function() {
return {
restrict: "E",
templateUrl: "/templates/server-log.htm"
};
});

app.directive("serverModifications", function() {
return {
restrict: "E",
templateUrl: "/templates/server-modifications.htm"
};
});

app.directive("addServer", function() {
return {
restrict: "E",
@@ -202,21 +254,30 @@ var app = angular.module("ddsn", []),
data.settings.addServer.server.addTrackerPort = undefined;
};

$scope.openMenu = function(ev, screen) {
$("button.server-tab").removeClass("btn-success").addClass("btn-primary");
$(ev.currentTarget).removeClass("btn-primary").addClass("btn-success");
$scope.openMenu = function(screen) {
data.serverTab = screen;
};

$scope.openAddServer = function(ev, screen) {
$("button.add-server-menu-tab").removeClass("btn-success").addClass("btn-primary");
$(ev.currentTarget).removeClass("btn-primary").addClass("btn-success");
$scope.openServer = function(port) {
getServer(port, function(server) {
if (!server) {
return;
}

data.serverTab = "server";
data.currentServer = server;
});
};

$scope.openServerMenu = function(screen) {
data.serverMenuTab = screen;
};

$scope.openAddServer = function(screen) {
data.addServerMenuTab = screen;
};

$scope.openSettings = function(ev, screen) {
$("button.settings-menu-tab").removeClass("btn-success").addClass("btn-primary");
$(ev.currentTarget).removeClass("btn-primary").addClass("btn-success");
$scope.openSettings = function(screen) {
data.settingsMenuTab = screen;
};

@@ -355,11 +416,28 @@ var app = angular.module("ddsn", []),
};

$scope.launchServer = function() {
var server;

data.settings.addServer.server.directory = data.settings.descent3.path;
ws.send(JSON.stringify({
message: "launchserver",
settings: data.settings.addServer
}));

server = {
settings: JSON.parse(JSON.stringify(data.settings.addServer)),
console: [],
loading: true
};

data.servers.push(server);

data.servers.sort(function(a, b) {
return a.settings.server.port > b.settings.server.port ? 1 : -1;
});

data.currentServer = server;
data.serverTab = "server";
};

$scope.updateSettingsDescent3Path = function() {
@@ -395,8 +473,7 @@ var app = angular.module("ddsn", []),
};

ws.onmessage = function(ev) {
var message = JSON.parse(ev.data),
key;
var message = JSON.parse(ev.data);

switch (message.message) {
case "missions":
@@ -408,13 +485,52 @@ var app = angular.module("ddsn", []),
data.loadingMissionPercent = message.percent;
scope.$apply();
break;
case "server.close":
getServer(message.port, function(server) {
if (!server) {
return;
}

data.servers.splice(data.servers.indexOf(server), 1);

// TODO: Notification that the server was closed.

scope.$apply();
});
break;
case "server.connected":
getServer(message.port, function(server) {
if (!server) {
return;
}

server.loading = false;

scope.$apply();
});
break;
case "server.raw":
getServer(message.port, function(server) {
if (!server) {
return;
}

server.console.push(message.data);

scope.$apply();
});
break;
case "settings":
for (key in message.settings) {
if (message.settings.hasOwnProperty(key)) {
data.settings[key] = message.settings[key];
(function() {
var key;

for (key in message.settings) {
if (message.settings.hasOwnProperty(key)) {
data.settings[key] = message.settings[key];
}
}
}
scope.$apply();
scope.$apply();
}());
break;
case "settings.descent3.pathValid":
data.settings.descent3.pathValid = message.valid;
@@ -71,12 +71,6 @@
<span class="input-group-addon" style="white-space: nowrap; width: 1px;">Selected mission:</span>
<span class="input-group-addon" style="width: 100%; padding: 0; text-align: left;">{{data.settings.addServer.game.missionName}} <button class="btn btn-sm btn-info" ng-if="data.settings.addServer.game.selectedMission" ng-click="data.showMissionToggle = !data.showMissionToggle;"><span ng-class="{true: 'glyphicon glyphicon-minus-sign', false: 'glyphicon glyphicon-plus-sign'}[!!data.showMissionToggle]"></span></button></span>
</div>
<div class="input-group" ng-if="data.settings.addServer.game.missionName">
<span class="input-group-addon" style="white-space: nowrap; width: 1px;">Starting Level:</span>
<span class="input-group-addon" style="width: 100%; padding: 0;">
<select class="form-control" ng-model="data.settings.addServer.game.setLevel" ng-options="(data.settings.addServer.game.selectedMission.data.levels.indexOf(level) + 1) as ((data.settings.addServer.game.selectedMission.data.levels.indexOf(level) + 1).toString() + ') ' + (level.name || level.mine)) for level in data.settings.addServer.game.selectedMission.data.levels"></select>
</span>
</div>
<div ng-if="data.showMissionToggle">
<table class="table table-condensed" style="margin-bottom: 0">
<tr ng-repeat="level in data.settings.addServer.game.selectedMission.data.levels">
@@ -93,6 +87,12 @@
</tr>
</table>
</div>
<div class="input-group" ng-if="data.settings.addServer.game.missionName">
<span class="input-group-addon" style="white-space: nowrap; width: 1px;">Starting Level:</span>
<span class="input-group-addon" style="width: 100%; padding: 0;">
<select class="form-control" ng-model="data.settings.addServer.game.setLevel" ng-options="(data.settings.addServer.game.selectedMission.data.levels.indexOf(level) + 1) as ((data.settings.addServer.game.selectedMission.data.levels.indexOf(level) + 1).toString() + ') ' + (level.name || level.mine)) for level in data.settings.addServer.game.selectedMission.data.levels"></select>
</span>
</div>
<div ng-if="data.missionsList && data.missionsList.length > 0">
<div class="panel panel-default" style="margin-bottom: 0;">
<div class="panel-heading text-center"><b>Select a mission:</b> <button class="btn btn-sm btn-info" ng-click="data.selectMissionToggle = !data.selectMissionToggle;"><span ng-class="{true: 'glyphicon glyphicon-minus-sign', false: 'glyphicon glyphicon-plus-sign'}[!!data.selectMissionToggle]"></span></button></div>
@@ -1,21 +1,21 @@
<ul class="nav nav-pills">
<li role="presentation">
<button class="add-server-menu-tab btn btn-success saved" ng-click="openAddServer($event, 'saved')"><span class="glyphicon glyphicon-hdd"></span> Saved Servers</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.addServerMenuTab === 'saved']" ng-click="openAddServer('saved')"><span class="glyphicon glyphicon-hdd"></span> Saved Servers</button>
</li>
<li role="presentation">
<button class="add-server-menu-tab btn btn-primary server" ng-click="openAddServer($event, 'server')"><span class="glyphicon glyphicon-wrench"></span> Server Options</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.addServerMenuTab === 'server']" ng-click="openAddServer('server')"><span class="glyphicon glyphicon-wrench"></span> Server Options</button>
</li>
<li role="presentation">
<button class="add-server-menu-tab btn btn-primary game" ng-click="openAddServer($event, 'game')"><span class="glyphicon glyphicon-th-list"></span> Game Options</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.addServerMenuTab === 'game']" ng-click="openAddServer('game')"><span class="glyphicon glyphicon-th-list"></span> Game Options</button>
</li>
<li role="presentation">
<button class="add-server-menu-tab btn btn-primary allowed" ng-click="openAddServer($event, 'allowed')"><span class="glyphicon glyphicon-ok"></span> Allowed Objects</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.addServerMenuTab === 'allowed']" ng-click="openAddServer('allowed')"><span class="glyphicon glyphicon-ok"></span> Allowed Objects</button>
</li>
<li role="presentation">
<button class="add-server-menu-tab btn btn-primary modifications" ng-click="openAddServer($event, 'modifications')"><span class="glyphicon glyphicon-tasks"></span> Modifications</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.addServerMenuTab === 'modifications']" ng-click="openAddServer('modifications')"><span class="glyphicon glyphicon-tasks"></span> Modifications</button>
</li>
<li role="presentation">
<button class="add-server-menu-tab btn btn-primary launch" ng-click="openAddServer($event, 'launch')"><span class="glyphicon glyphicon-share"></span> Launch Server</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.addServerMenuTab === 'launch']" ng-click="openAddServer('launch')"><span class="glyphicon glyphicon-share"></span> Launch Server</button>
</li>
</ul><br />
<add-server-saved ng-if="data.addServerMenuTab === 'saved'"></add-server-saved>
@@ -0,0 +1,5 @@
<div class="panel panel-default" style="font-family: Consolas, Lucida Console, monospace;">
<div class="panel-body" style="max-height: 500px; overflow-y: scroll;">
<div ng-repeat="line in data.currentServer.console track by $index">{{line}}</div>
</div>
</div>
No changes.
No changes.
No changes.
@@ -1,17 +1,17 @@
<ul class="nav nav-pills">
<li role="presentation">
<button class="server-tab btn btn-success" ng-click="openMenu($event, 'news')"><span class="glyphicon glyphicon-home"></span> News</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.serverTab === 'news']" ng-click="openMenu('news')"><span class="glyphicon glyphicon-home"></span> News</button>
</li>
<li role="presentation" ng-if="data.settings.descent3.pathValid">
<button class="server-tab btn btn-primary" ng-click="openMenu($event, 'dashboard')"><span class="glyphicon glyphicon-dashboard"></span> Dashboard</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.serverTab === 'dashboard']" ng-click="openMenu('dashboard')"><span class="glyphicon glyphicon-dashboard"></span> Dashboard</button>
</li>
<li role="presentation" ng-if="data.settings.descent3.pathValid" ng-repeat="server in data.servers">
<button class="server-tab btn btn-primary server" ng-click="openServer($event, server.port)">{{server.gameName}} <span class="glyphicon glyphicon-arrow-right"></span> {{server.port}}</button>
<li role="presentation" ng-repeat="server in data.servers">
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.serverTab === 'server' && data.currentServer && data.currentServer.settings.server.port === server.settings.server.port]" ng-click="openServer(server.settings.server.port)">{{server.settings.game.gameName}} <span class="glyphicon glyphicon-arrow-right"></span> {{server.settings.server.port}}</button>
</li>
<li role="presentation" ng-if="data.settings.descent3.pathValid">
<button class="server-tab btn btn-primary" ng-click="openMenu($event, 'addServer')"><span class="glyphicon glyphicon-plus"></span> Add Server</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.serverTab === 'addServer']" ng-click="openMenu('addServer')"><span class="glyphicon glyphicon-plus"></span> Add Server</button>
</li>
<li role="presentation">
<button class="server-tab btn btn-primary" ng-click="openMenu($event, 'settings')"><span class="glyphicon glyphicon-cog"></span> Settings</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.serverTab === 'settings']" ng-click="openMenu('settings')"><span class="glyphicon glyphicon-cog"></span> Settings</button>
</li>
</ul>
@@ -1,14 +1,23 @@
<ul class="nav nav-pills">
<li role="presentation">
<button class="server-menu-tab btn btn-success"><span class="glyphicon glyphicon-dashboard"></span> Scoreboard</button>
</li>
<li role="presentation">
<button class="server-menu-tab btn btn-primary"><span class="glyphicon glyphicon-list-alt"></span> Log</button>
</li>
<li role="presentation">
<button class="server-menu-tab btn btn-primary"><span class="glyphicon glyphicon-console"></span> Console</button>
</li>
<li role="presentation">
<button class="server-menu-tab btn btn-primary"><span class="glyphicon glyphicon-cog"></span> Settings</button>
</li>
</ul>
<div ng-if="!data.currentServer.loading">
<ul class="nav nav-pills">
<li role="presentation">
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.serverMenuTab === 'scoreboard']" ng-click="openServerMenu('scoreboard')"><span class="glyphicon glyphicon-dashboard"></span> Scoreboard</button>
</li>
<li role="presentation">
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.serverMenuTab === 'console']" ng-click="openServerMenu('console')"><span class="glyphicon glyphicon-console"></span> Console</button>
</li>
<li role="presentation">
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.serverMenuTab === 'log']" ng-click="openServerMenu('log')"><span class="glyphicon glyphicon-list-alt"></span> Log</button>
</li>
<li role="presentation">
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.serverMenuTab === 'settings']" ng-click="openServerMenu('settings')"><span class="glyphicon glyphicon-cog"></span> Settings</button>
</li>
</ul><br />
<server-scoreboard ng-if="data.serverMenuTab === 'scoreboard'"></server-scoreboard>
<server-console ng-if="data.serverMenuTab === 'console'"></server-console>
<server-log ng-if="data.serverMenuTab === 'scoreboard'"></server-log>
<server-settings ng-if="data.serverMenuTab === 'settings'"></server-settings>
</div>
<div ng-if="data.currentServer.loading" class="text-center">
<h1>Loading...</h1>
</div>
@@ -1,9 +1,9 @@
<ul class="nav nav-pills">
<li role="presentation">
<button class="settings-menu-tab btn btn-success descent3" ng-click="openSettings($event, 'descent3')"><span class="glyphicon glyphicon-globe"></span> Descent 3</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.settingsMenuTab === 'descent3']" ng-click="openSettings('descent3')"><span class="glyphicon glyphicon-globe"></span> Descent 3</button>
</li>
<li role="presentation">
<button class="settings-menu-tab btn btn-primary modifications" ng-click="openSettings($event, 'modifications')"><span class="glyphicon glyphicon-tasks"></span> Modifications</button>
<button ng-class="{true: 'btn btn-success', false: 'btn btn-primary'}[data.settingsMenuTab === 'modifications']" ng-click="openSettings('modifications')"><span class="glyphicon glyphicon-tasks"></span> Modifications</button>
</li>
</ul><br />
<settings-descent3 ng-if="data.settingsMenuTab === 'descent3'"></settings-descent3>

0 comments on commit 914943b

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