From e4452d48ab09f41e31c9522c32cd453a349541d2 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Thu, 3 Mar 2016 12:53:56 +0000 Subject: [PATCH] URLs include address, automatically connected to if password is present --- html/playerInfo.html | 2 +- html/playerXp.html | 2 +- html/playerlist.html | 6 ++-- index.html | 3 +- js/app.js | 67 +++++++++----------------------------------- js/connection.js | 64 ++++++++++++++++++++++++++++++++++++++++++ js/rconService.js | 3 +- 7 files changed, 85 insertions(+), 62 deletions(-) create mode 100644 js/connection.js diff --git a/html/playerInfo.html b/html/playerInfo.html index 626dc4a..781ddfa 100644 --- a/html/playerInfo.html +++ b/html/playerInfo.html @@ -3,7 +3,7 @@ Info about player {{userid}} -

View XP info for this player

+

View XP info for this player

Show info about this player here \ No newline at end of file diff --git a/html/playerXp.html b/html/playerXp.html index c037a16..1d599c3 100644 --- a/html/playerXp.html +++ b/html/playerXp.html @@ -3,7 +3,7 @@ -

Statistics for player {{userid}}

+

Statistics for player {{userid}}

diff --git a/html/playerlist.html b/html/playerlist.html index 3f7e4e6..3b4b404 100644 --- a/html/playerlist.html +++ b/html/playerlist.html @@ -1,10 +1,10 @@
- + @@ -21,7 +21,7 @@
- XP: {{line.UnspentXp}} + XP: {{line.UnspentXp}}
diff --git a/index.html b/index.html index 84d3ed8..a8ce0b9 100644 --- a/index.html +++ b/index.html @@ -20,7 +20,7 @@ - + {{p.Title}} @@ -68,6 +68,7 @@ + diff --git a/js/app.js b/js/app.js index da3b32c..9f6848a 100644 --- a/js/app.js +++ b/js/app.js @@ -11,11 +11,12 @@ app.config( function ( $mdThemingProvider, $routeProvider ) 'default': '700' }).accentPalette( 'blue' ); - $routeProvider.when( "/console", { Title: "Console", templateUrl: "html/console.html", Nav: true } ) - $routeProvider.when( "/playerlist", { Title: "Player List", templateUrl: "html/playerlist.html", Nav: true } ) - $routeProvider.when( "/player/:userid", { Title: "Player Info", templateUrl: "html/playerInfo.html" } ) - $routeProvider.when( "/player/:userid/xp", { Title: "Player Xp Stats", templateUrl: "html/playerXp.html" } ) - .otherwise( { redirectTo: '/console' } ); + $routeProvider.when( "/home", { Title: "Home", templateUrl: "html/home.html" } ) + $routeProvider.when( "/:address/console", { Title: "Console", templateUrl: "html/console.html", Nav: true } ) + $routeProvider.when( "/:address/playerlist", { Title: "Player List", templateUrl: "html/playerlist.html", Nav: true } ) + $routeProvider.when( "/:address/player/:userid", { Title: "Player Info", templateUrl: "html/playerInfo.html" } ) + $routeProvider.when( "/:address/player/:userid/xp", { Title: "Player Xp Stats", templateUrl: "html/playerXp.html" } ) + $routeProvider.otherwise( { redirectTo: '/home' } ); } ); @@ -24,6 +25,7 @@ app.controller( 'RconController', RconController ); function RconController( $scope, $rootScope, rconService, $mdSidenav, $timeout, $mdDialog, $route ) { $scope.$route = $route; + $scope.pages = $.map( $route.routes, function ( value, index ) { @@ -40,6 +42,11 @@ function RconController( $scope, $rootScope, rconService, $mdSidenav, $timeout, return rconService.IsConnected(); } + $rootScope.Nav = function ( url ) + { + return url.replace( ":address", rconService.Address ); + } + $rootScope.$on( '$stateChangeStart', function ( next, current ) { console.log( next ); @@ -50,6 +57,7 @@ function RconController( $scope, $rootScope, rconService, $mdSidenav, $timeout, $scope.Connected = true; $scope.$broadcast( "OnConnected" ); $scope.$digest(); + $scope.address = rconService.Address; } rconService.OnClose = function ( ev ) @@ -73,55 +81,6 @@ function RconController( $scope, $rootScope, rconService, $mdSidenav, $timeout, } } -app.controller( 'ConnectionController', ConnectionController ); - -function ConnectionController( $scope, rconService ) -{ - $scope.Address = ""; - $scope.Password = ""; - $scope.SaveConnection = true; - - if ( localStorage.previousConnections != null ) - $scope.PreviousConnects = angular.fromJson( localStorage.previousConnections ); - - if ( $scope.PreviousConnects == null ) - $scope.PreviousConnects = new Array(); - - $scope.Connect = function () - { - $scope.LastErrorMessage = null; - rconService.Connect( $scope.Address, $scope.Password ); - } - - $scope.ConnectTo = function ( c ) - { - $scope.SaveConnection = false; - $scope.LastErrorMessage = null; - rconService.Connect( c.Address, c.Password ); - } - - $scope.$on( "OnDisconnected", function ( x, ev ) - { - console.log( ev ); - $scope.LastErrorMessage = "Connection was closed - Error " + ev.code; - $scope.$digest(); - } ); - - $scope.$on( "OnConnected", function ( x, ev ) - { - if ( $scope.SaveConnection ) - { - $scope.PreviousConnects.push( { Address: $scope.Address, Password: $scope.Password } ); - localStorage.previousConnections = angular.toJson( $scope.PreviousConnects ); - } - } ); -} - - - - - - app.filter( 'SecondsToDuration', [SecondsToDuration] ); function SecondsToDuration() diff --git a/js/connection.js b/js/connection.js new file mode 100644 index 0000000..28f2db8 --- /dev/null +++ b/js/connection.js @@ -0,0 +1,64 @@ + +app.controller( 'ConnectionController', ConnectionController ); + +function ConnectionController( $scope, rconService, $routeParams, $timeout ) +{ + $scope.Address = ""; + $scope.Password = ""; + $scope.SaveConnection = true; + + if ( localStorage.previousConnections != null ) + $scope.PreviousConnects = angular.fromJson( localStorage.previousConnections ); + + if ( $scope.PreviousConnects == null ) + $scope.PreviousConnects = new Array(); + + $scope.Connect = function () + { + $scope.LastErrorMessage = null; + rconService.Connect( $scope.Address, $scope.Password ); + } + + $scope.ConnectTo = function ( c ) + { + $scope.SaveConnection = false; + $scope.LastErrorMessage = null; + rconService.Connect( c.Address, c.Password ); + } + + $scope.$on( "OnDisconnected", function ( x, ev ) + { + console.log( ev ); + $scope.LastErrorMessage = "Connection was closed - Error " + ev.code; + $scope.$digest(); + } ); + + $scope.$on( "OnConnected", function ( x, ev ) + { + if ( $scope.SaveConnection ) + { + $scope.PreviousConnects.push( { Address: $scope.Address, Password: $scope.Password } ); + localStorage.previousConnections = angular.toJson( $scope.PreviousConnects ); + } + } ); + + + // + // If a server address is passed in.. try to connect if we have a saved entry + // + $timeout( function () + { + $scope.Address = $routeParams.address; + + if ( $scope.Address != null ) + { + var foundAddress = Enumerable.From( $scope.PreviousConnects ).Where( function ( x ) { return x.Address == $scope.Address } ).First(); + if ( foundAddress != null ) + { + $scope.ConnectTo( foundAddress ); + } + } + + }, 20 ); +} + diff --git a/js/rconService.js b/js/rconService.js index 15db19e..01fed47 100644 --- a/js/rconService.js +++ b/js/rconService.js @@ -12,6 +12,7 @@ function RconService() s.Connect = function ( addr, pass ) { s.Socket = new WebSocket( "ws://" + addr + "/" + pass ); + s.Address = addr; s.Socket.onmessage = function ( e ) { @@ -49,8 +50,6 @@ function RconService() s.Socket.onopen = s.OnOpen; s.Socket.onclose = s.OnClose; s.Socket.onerror = s.OnError; - - console.log( s.Socket ); } s.Command = function ( msg, identifier )