Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
# editorconfig-tools is unable to ignore longs strings or urls
max_line_length = null
24 changes: 24 additions & 0 deletions app/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div ng-include="'app/core/header.html'" ng-show="connected"></div>

<div class="container">

<div ng-include="'app/connection/connect.html'" ng-show="!connected"></div>

<div class="col-sm-2 sidebar" ng-show="connected">

<ul class="nav nav-sidebar">
<li ng-repeat="page in pages" ng-class="{'active' : $route.current.title == page.title }">
<a href="#{{nav( page.originalPath )}}">{{page.title}}</a>
</li>
</ul>

</div>

<div class="col-sm-10" ng-show="connected">

<h1 class="page-header">{{$route.current.title}}</h1>
<div class="row" ng-view></div>

</div>

</div>
62 changes: 62 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
app.controller('appController', AppController);

function AppController($scope, $rootScope, connectionService, $timeout, $route, $location) {
$scope.$route = $route;

$scope.pages = $.map($route.routes, (route) => {
if (route.nav) {
return [route];
}
});

$scope.openLeftMenu = function () {
$mdSidenav('left').toggle();
};

$scope.isConnected = function () {
return connectionService.isConnected();
}

$rootScope.nav = function (url) {
return url.replace(':address', connectionService.address);
}

$rootScope.$on('$stateChangeStart', function (next, current) {
console.log(next);
});

connectionService.onOpen = function () {
$scope.connected = true;
$scope.$broadcast('onConnected');
$scope.$digest();
$scope.address = connectionService.address;
}

connectionService.onClose = function (ev) {
$scope.$broadcast('onDisconnected', ev);
$scope.$digest();
}

connectionService.onError = function (ev) {
$scope.$broadcast('onConnectionError', ev);
$scope.$digest();
}

connectionService.onMessage = function (data) {
$scope.$apply(function () {
$scope.$broadcast('onMessage', data);
});
}

$scope.disconnect = function () {
if (confirm('Do you really want to disconnect?')) {
connectionService.disconnect();
$scope.connected = false;

$location.path('/home');
}
}

// hide loading spinner
$('#pageloader').hide();
}
22 changes: 22 additions & 0 deletions app/chat/chat.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div ng-controller="chatController" id="ChatController">

<div style="height: 600px" class="Output scrollable">
<div ng-repeat="line in output" ng-class="line.Class">
<span class="chattime">{{(line.Time * 1000) | date:'shortTime'}}</span>
<span class="chatname" data-ng-if="line.UserId > 0">
<a href="#/{{address}}/player/{{line.UserId}}/">{{line.Username}}:</a>
</span>
<span style="display:inline-block;">{{line.Message}}</span>
</div>
</div>

<form ng-submit="submitCommand()" class="md-inline-form">
<div class="input-group">
<input class="form-control" type="text" placeholder="Message" ng-model="command">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">Submit</button>
</span>
</div>
</form>

</div>
83 changes: 83 additions & 0 deletions app/chat/chat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
app.controller('chatController', ChatController);

function ChatController($scope, connectionService, $timeout) {
$scope.output = [];

$scope.submitCommand = function () {
if (!$scope.command) {
return;
}

connectionService.command('say ' + $scope.command, 1);
$scope.command = '';
}

$scope.$on('onMessage', function (event, data) {
if (data.Type !== 'Chat') return;

$scope.onMessage(JSON.parse(data.Message));
});

$scope.onMessage = function (data) {
data.Message = stripHtml(data.Message);
$scope.output.push(data);

if ($scope.isOnBottom()) {
$scope.scrollToBottom();
}
}

$scope.scrollToBottom = function () {
var element = $('#ChatController .Output');

$timeout(function () {
element.scrollTop(element.prop('scrollHeight'));
}, 50);
}

$scope.isOnBottom = function () {
// get jquery element
var element = $('#ChatController .Output');

// height of the element
var height = element.height();

// scroll position from top position
var scrollTop = element.scrollTop();

// full height of the element
var scrollHeight = element.prop('scrollHeight');

if ((scrollTop + height) > (scrollHeight - 10)) {
return true;
}

return false;
}

//
// Calls console.tail - which returns the last 256 entries from the console.
// This is then added to the console
//
$scope.getHistory = function () {
connectionService.request('chat.tail 512', $scope, function (data) {
var messages = JSON.parse(data.Message);

messages.forEach(function (message) {
$scope.onMessage(message);
});

$scope.scrollToBottom();
});
}

connectionService.installService($scope, $scope.getHistory)
}

function stripHtml(html) {
if (!html) return '';

var tmp = document.createElement('div');
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || '';
}
54 changes: 54 additions & 0 deletions app/connection/connect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<div ng-controller="connectionController" class="row">

<div class="col-md-offset-4 col-md-6 panel jumbotron" style="margin-top: 128px">

<h2>Connect</h2>

<div class="alert alert-danger" ng-show="lastErrorMessage != null">
{{lastErrorMessage}}
</div>

<p>Enter the address (including rcon port) and the rcon password below to connect.</p>

<form ng-submit="connect()">

<div class="form-group">
<label for="conncetion-adress">Address</label>
<input required minlength=5 ng-model="address" name="address" class="form-control" placeholder="xxx.xxx.xxx.xxx:28016" id="conncetion-adress">
</div>

<div class="form-group">
<label for="conncetion-password">Password</label>
<input required minlength=2 type="password" ng-model="password" name="password" class="form-control" id="conncetion-password">
</div>

<div class="checkbox pull-right">
<label>
<input type="checkbox" ng-model="saveConnection"> Save Connection
</label>
</div>

<button type="submit" class="btn btn-primary btn-block" ng-click="connect()">Connect</button>

</form>
</div>

<div class="col-md-offset-4 col-md-6 panel jumbotron">

<div ng-show="previousConnects.length > 0">
<h2>Saved Connections</h2>
<ul ng-repeat="connection in previousConnects | orderBy:array:true | limitTo:connectionsLimit">
<li>
<a ng-click="connectTo(connection)" href="#/{{connection.address}}/info">{{connection.address}}</a> - {{connection.date | date:'short'}}
</li>
</ul>
<div ng-show="previousConnects.length > connectionsLimit || connectionsLimit === undefined">
<button type="submit" class="btn btn-primary btn-block" ng-click="toggleConnectionsLimit()">
Show {{(connectionsLimit === undefined) ? 'less' : 'more'}}
</button>
</div>
</div>

</div>

</div>
129 changes: 129 additions & 0 deletions app/connection/connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
app.controller('connectionController', ConnectionController);

function ConnectionController($scope, connectionService, $routeParams, $timeout, $location) {
$scope.address = '';
$scope.password = '';
$scope.saveConnection = true;

$scope.connectionsLimit = 5;

function _loadFromLocalStorage() {
var connections = [];

// load and parse from local storage
if (localStorage && localStorage.previousConnections) {
connections = angular.fromJson(localStorage.previousConnections);
}

// double check
if (!connections) {
connections = [];
}

return connections;
}

function _addWithoutDuplicates(connections, connection) {
// prepare new array
var filteredConnections = [];

for (var i in connections) {
if (connections[i].address !== connection.address && connections[i].password !== connection.password) {
// add old connection info to our new array
filteredConnections.push(connections[i]);
}
}

// add new connection
filteredConnections.push(connection);

return filteredConnections;
}

$scope.toggleConnectionsLimit = function () {
// toggle limit between undefined and 5
// undefined sets limit to max
if ($scope.connectionsLimit === undefined) {
$scope.connectionsLimit = 5;
} else {
$scope.connectionsLimit = undefined;
}
}

$scope.connect = function () {
$scope.address = $scope.address.trim();
$scope.password = $scope.password.trim();

$scope.lastErrorMessage = null;
connectionService.connect($scope.address, $scope.password);

$location.path('/' + $scope.address + '/info');
}

$scope.connectTo = function (c) {
$scope.saveConnection = false;
$scope.lastErrorMessage = null;
connectionService.connect(c.address, c.password);
}

$scope.$on('onDisconnected', function (x, ev) {
$scope.lastErrorMessage = 'Connection was closed - Error ' + ev.code;
$scope.$digest();

$location.path('/home');
});

$scope.$on('onConnected', function (x, ev) {
if ($scope.saveConnection) {
// new connection to add
var connection = {
address: $scope.address,
password: $scope.password,
date: new Date()
};

// remove old entries and add our new connection info
var connections = _addWithoutDuplicates(_loadFromLocalStorage(), connection);

// push to scope and save data
$scope.previousConnects = connections;
localStorage.previousConnections = angular.toJson($scope.previousConnects);
}
});

$scope.previousConnects = _loadFromLocalStorage();

//
// If a server address is passed in.. try to connect if we have a saved entry
//
$timeout(function () {
$scope.address = $routeParams.address;

//
// If a password was passed as a search param, use that
//
var pw = $location.search().password;
if (pw) {
$scope.password = pw;
$location.search('password', null);
}

if ($scope.address != null) {
// If we have a password (passed as a search param) then connect using that
if ($scope.password != '') {
$scope.connect();
return;
}

var foundAddress = $scope.previousConnects.find((item) => {
return item.address === $scope.address
})
if (foundAddress != null) {
$scope.connectTo(foundAddress);
}

}

}, 20);

}
Loading