-
-
Players: {{info.Players}}
-
+
+
Players: {{info.Players}}
-
-
-
Joining: {{info.Joining}}
-
+
+
Joining: {{info.Joining}}
-
-
-
Queued: {{info.Queued}}
-
+
+
Queued: {{info.Queued}}
-
-
-
-
diff --git a/js/connection.js b/js/connection.js
index d4781f8..f11882d 100644
--- a/js/connection.js
+++ b/js/connection.js
@@ -7,11 +7,51 @@ function ConnectionController( $scope, rconService, $routeParams, $timeout, $loc
$scope.Password = "";
$scope.SaveConnection = true;
- if ( localStorage.previousConnections != null )
- $scope.PreviousConnects = angular.fromJson( localStorage.previousConnections );
+ $scope.connectionsLimit = 5;
- if ( $scope.PreviousConnects == null )
- $scope.PreviousConnects = new Array();
+ 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 ()
{
@@ -42,11 +82,19 @@ function ConnectionController( $scope, rconService, $routeParams, $timeout, $loc
{
if ( $scope.SaveConnection )
{
- $scope.PreviousConnects.push( { Address: $scope.Address, Password: $scope.Password } );
+ // 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
@@ -83,5 +131,5 @@ function ConnectionController( $scope, rconService, $routeParams, $timeout, $loc
}
}, 20 );
+
}
-
diff --git a/js/console.js b/js/console.js
index 02ce256..699bafc 100644
--- a/js/console.js
+++ b/js/console.js
@@ -3,38 +3,114 @@ app.controller( 'ConsoleController', ConsoleController );
function ConsoleController( $scope, rconService, $timeout )
{
- $scope.Output = new Array();
+ $scope.Output = [];
+ $scope.commandHistory = [];
+ $scope.commandHistoryIndex = 0;
+
+ $scope.KeyUp = function (event)
+ {
+ switch(event.keyCode) {
+
+ // Arrow Key Up
+ case 38:
+
+ // rotate through commandHistory
+ $scope.commandHistoryIndex--;
+ if($scope.commandHistoryIndex < 0) {
+ $scope.commandHistoryIndex = $scope.commandHistory.length;
+ }
+
+ // set command from history
+ if($scope.commandHistory[$scope.commandHistoryIndex]) {
+ $scope.Command = $scope.commandHistory[$scope.commandHistoryIndex];
+ }
+
+ break;
+
+ // Arrow Key Down
+ case 40:
+
+ // rotate through commandHistory
+ $scope.commandHistoryIndex++;
+ if($scope.commandHistoryIndex >= $scope.commandHistory.length) {
+ $scope.commandHistoryIndex = 0;
+ }
+
+ // set command from history
+ if($scope.commandHistory[$scope.commandHistoryIndex]) {
+ $scope.Command = $scope.commandHistory[$scope.commandHistoryIndex];
+ }
+
+ break;
+
+ default:
+ // reset command history index
+ $scope.commandHistoryIndex = $scope.commandHistory.length;
+ break;
+ }
+ }
$scope.SubmitCommand = function ()
{
- $scope.OnMessage( { Message: $scope.Command, Type: 'Command' } )
+ $scope.OnMessage( { Message: $scope.Command, Type: 'Command' } );
+
+ $scope.commandHistory.push($scope.Command);
rconService.Command( $scope.Command, 1 );
$scope.Command = "";
+ $scope.commandHistoryIndex = 0;
}
-
$scope.$on( "OnMessage", function ( event, msg ) { $scope.OnMessage( msg ); } );
$scope.OnMessage = function( msg )
{
- if ( msg.Message.startsWith( "[rcon] " ) ) return;
- if ( msg.Type != "Generic" && msg.Type != "Log" && msg.Type != "Error" && msg.Type != "Warning" )
- {
- console.log( msg );
- return;
+ if ( msg.Message.startsWith( "[rcon] " ) ) {
+ return;
}
- msg.Class = msg.Type;
- $scope.Output.push( msg );
+ switch(msg.Type) {
+ case 'Generic':
+ case 'Log':
+ case 'Error':
+ case 'Warning':
+ $scope.addOutput(msg);
+ break;
- $timeout( $scope.ScrollToBottom, 50 );
+ default:
+ console.log( msg );
+ return;
+ }
}
$scope.ScrollToBottom = function()
{
- // TODO - don't scroll if we're not at the bottom !
- $( "#ConsoleController .Output" ).scrollTop( $( "#ConsoleController .Output" )[0].scrollHeight );
+ var element = $( "#ConsoleController .Output" );
+
+ $timeout( function() {
+ element.scrollTop( element.prop('scrollHeight') );
+ }, 50 );
+ }
+
+ $scope.isOnBottom = function()
+ {
+ // get jquery element
+ var element = $( "#ConsoleController .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;
}
//
@@ -43,15 +119,27 @@ function ConsoleController( $scope, rconService, $timeout )
//
$scope.GetHistory = function ()
{
- console.log( "GetHistory" );
-
rconService.Request( "console.tail 128", $scope, function ( msg )
{
var messages = JSON.parse( msg.Message );
- messages.forEach( function ( x ) { $scope.OnMessage( x ); } );
+ messages.forEach( function ( msg ) {
+ $scope.OnMessage( msg );
+ });
+
+ $scope.ScrollToBottom();
} );
}
+ $scope.addOutput = function (msg)
+ {
+ msg.Class = msg.Type;
+ $scope.Output.push( msg );
+
+ if($scope.isOnBottom()) {
+ $scope.ScrollToBottom();
+ }
+ }
+
rconService.InstallService( $scope, $scope.GetHistory )
}
\ No newline at end of file
diff --git a/js/playerInfo.js b/js/playerInfo.js
index 92d07a2..24f594f 100644
--- a/js/playerInfo.js
+++ b/js/playerInfo.js
@@ -4,4 +4,39 @@ app.controller( 'PlayerInfoController', PlayerInfoController );
function PlayerInfoController( $scope, rconService, $routeParams )
{
$scope.userid = $routeParams.userid;
+
+ $scope.info = null;
+
+ $scope.refresh = function ()
+ {
+ rconService.getPlayers($scope, function(players) {
+
+ for(var i in players) {
+ if(players[i].SteamID === $scope.userid){
+
+ // set player data
+ $scope.info = players[i];
+
+ return;
+ }
+ }
+
+ // player not found
+ // reset data to null
+ $scope.info = null;
+ });
+ }
+
+ $scope.getUsername = function ()
+ {
+ // try to find players name in info
+ if($scope.info && $scope.info.DisplayName) {
+ return $scope.info.DisplayName;
+ }
+
+ // otherwise show the id
+ return $scope.userid;
+ }
+
+ rconService.InstallService( $scope, $scope.refresh )
}
\ No newline at end of file
diff --git a/js/playerlist.js b/js/playerlist.js
index 390ab88..820faea 100644
--- a/js/playerlist.js
+++ b/js/playerlist.js
@@ -3,14 +3,14 @@ app.controller( 'PlayerListController', PlayerListController );
function PlayerListController( $scope, rconService, $interval )
{
- $scope.Output = new Array();
+ $scope.Output = [];
$scope.OrderBy = '-ConnectedSeconds';
$scope.Refresh = function ()
{
- rconService.Request( "playerlist", $scope, function ( msg )
+ rconService.getPlayers($scope, function ( players )
{
- $scope.Players = JSON.parse( msg.Message );
+ $scope.Players = players;
});
}
diff --git a/js/rconService.js b/js/rconService.js
index 58aa456..15853fb 100644
--- a/js/rconService.js
+++ b/js/rconService.js
@@ -1,9 +1,9 @@
function RconService()
{
- var s = {};
-
- s.Callbacks = {};
+ var s = {
+ Callbacks: {}
+ };
s.Connect = function ( addr, pass )
{
@@ -102,5 +102,16 @@ function RconService()
}
}
+ s.getPlayers = function(scope, success) {
+ this.Request( "playerlist", scope, function ( response )
+ {
+ var players = JSON.parse( response.Message );
+
+ if(typeof success === 'function') {
+ success.call(scope, players);
+ }
+ });
+ }
+
return s;
}
\ No newline at end of file