diff --git a/html/console.html b/html/console.html index 373938e..1285bde 100644 --- a/html/console.html +++ b/html/console.html @@ -1,22 +1,21 @@ -
{{line.Message}}
-
- -
+ + +
- - - + + + - - - + + + -
-
- +
+
+
\ No newline at end of file diff --git a/html/playerInfo.html b/html/playerInfo.html new file mode 100644 index 0000000..626dc4a --- /dev/null +++ b/html/playerInfo.html @@ -0,0 +1,9 @@ + +
+ + Info about player {{userid}} + +

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 new file mode 100644 index 0000000..a050a8f --- /dev/null +++ b/html/playerXp.html @@ -0,0 +1,6 @@ + +
+ +Show info about this player xp here + +
\ No newline at end of file diff --git a/html/players.html b/html/playerlist.html similarity index 89% rename from html/players.html rename to html/playerlist.html index 3a09174..cba2a5b 100644 --- a/html/players.html +++ b/html/playerlist.html @@ -1,5 +1,4 @@ - -
+
@@ -7,7 +6,7 @@
-

{{line.DisplayName}}

+

{{line.DisplayName}}

diff --git a/index.html b/index.html index 1377fc5..388fba9 100644 --- a/index.html +++ b/index.html @@ -1,4 +1,4 @@ - + @@ -16,12 +16,11 @@
- - + - - + + {{p.Title}} @@ -36,13 +35,12 @@ -

Connected Server Name

+

{{$route.current.Title}}

-
- +
@@ -64,7 +62,12 @@ - + + + + + + \ No newline at end of file diff --git a/js/app.js b/js/app.js new file mode 100644 index 0000000..63a2d46 --- /dev/null +++ b/js/app.js @@ -0,0 +1,149 @@ + + +var app = angular.module( 'RconApp', ['ngMaterial', 'ngRoute'] ); + +app.service( 'rconService', [RconService] ); + +app.config( function ( $mdThemingProvider, $routeProvider ) +{ + $mdThemingProvider.theme( 'default' ).primaryPalette( 'blue', + { + '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' } ); + +} ); + +app.controller( 'RconController', RconController ); + +function RconController( $scope, $rootScope, rconService, $mdSidenav, $timeout, $mdDialog, $route ) +{ + $scope.$route = $route; + + $scope.pages = $.map( $route.routes, function ( value, index ) + { + return [value]; + } ); + + console.log( $scope.pages ); + + $scope.OpenLeftMenu = function () + { + $mdSidenav( 'left' ).toggle(); + }; + + $scope.IsConnected = function () + { + return rconService.IsConnected(); + } + + $rootScope.$on( '$stateChangeStart', function ( next, current ) + { + console.log( next ); + } ); + + rconService.OnOpen = function () + { + $scope.Connected = true; + $scope.$broadcast( "OnConnected" ); + $scope.$digest(); + } + + rconService.OnClose = function ( ev ) + { + $scope.$broadcast( "OnDisconnected", ev ); + $scope.$digest(); + } + + rconService.OnError = function ( ev ) + { + $scope.$broadcast( "OnConnectionError", ev ); + $scope.$digest(); + } + + rconService.OnMessage = function ( msg ) + { + $scope.$apply( function () + { + $scope.$broadcast( "OnMessage", msg ); + } ); + } +} + +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(); + + console.log( $scope.PreviousConnects ); + + $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() +{ + return function ( input ) + { + input = parseInt( input ); + + var out = ""; + var hours = Math.floor( input / 3600 ); + if ( input > 3600 ) out += hours + "h "; + + var minutes = Math.floor( input / 60 ) % 60; + if ( input > 60 ) out += minutes + "m "; + + var seconds = input % 60; + out += seconds + "s"; + + return out; + } +} diff --git a/js/console.js b/js/console.js new file mode 100644 index 0000000..0f9760b --- /dev/null +++ b/js/console.js @@ -0,0 +1,28 @@ + +app.controller( 'ConsoleController', ['$scope', 'rconService', ConsoleController] ); + +function ConsoleController( $scope, rconService ) +{ + $scope.Output = rconService.Output; + + $scope.SubmitCommand = function () + { + rconService.Command( $scope.Command, 0 ); + $scope.Command = ""; + } + + $scope.$on( "OnMessage", function ( event, msg ) + { + if ( msg.Message.startsWith( "[CHAT] " ) ) + msg.Class = "Chat"; + + if ( msg.Identifier == 1 ) + msg.Class = "Requested"; + + if ( msg.Identifier > 1 ) + return; + + $( "#ConsoleController .Output" ).scrollTop( $( "#ConsoleController .Output" )[0].scrollHeight ); + + } ); +} \ No newline at end of file diff --git a/js/playerInfo.js b/js/playerInfo.js new file mode 100644 index 0000000..92d07a2 --- /dev/null +++ b/js/playerInfo.js @@ -0,0 +1,7 @@ + +app.controller( 'PlayerInfoController', PlayerInfoController ); + +function PlayerInfoController( $scope, rconService, $routeParams ) +{ + $scope.userid = $routeParams.userid; +} \ No newline at end of file diff --git a/js/playerXp.js b/js/playerXp.js new file mode 100644 index 0000000..0033178 --- /dev/null +++ b/js/playerXp.js @@ -0,0 +1,7 @@ + +app.controller( 'PlayerXpController', PlayerXpController ); + +function PlayerXpController( $scope, rconService, $routeParams ) +{ + $scope.userid = $routeParams.userid; +} \ No newline at end of file diff --git a/js/playerlist.js b/js/playerlist.js new file mode 100644 index 0000000..20c7f45 --- /dev/null +++ b/js/playerlist.js @@ -0,0 +1,17 @@ + +app.controller( 'PlayerListController', PlayerListController ); + +function PlayerListController( $scope, rconService ) +{ + $scope.Output = new Array(); + + $scope.Refresh = function () + { + rconService.Request( "playerlist", $scope, function ( msg ) + { + $scope.Players = JSON.parse( msg.Message ); + }); + } + + rconService.InstallService( $scope, $scope.Refresh ) +} \ No newline at end of file diff --git a/js/rconService.js b/js/rconService.js new file mode 100644 index 0000000..15db19e --- /dev/null +++ b/js/rconService.js @@ -0,0 +1,112 @@ + +function RconService() +{ + var s = {}; + + s.Callbacks = {}; + + // A list of untargetted ouput from the server + // ie - the console history + s.Output = new Array(); + + s.Connect = function ( addr, pass ) + { + s.Socket = new WebSocket( "ws://" + addr + "/" + pass ); + + s.Socket.onmessage = function ( e ) + { + var data = angular.fromJson( e.data ); + + // + // This is a targetted message, it has an identifier + // So feed it back to the right callback. + // + if ( data.Identifier != 0 ) + { + var cb = s.Callbacks[data.Identifier]; + if ( cb != null ) + { + cb.scope.$apply( function () + { + cb.callback( data ); + } ); + } + s.Callbacks[data.Identifier] = null; + + return; + } + + // + // Generic console message, let OnMessage catch it + // + if ( s.OnMessage != null ) + { + s.Output.push( data ); + s.OnMessage( data ); + } + }; + + s.Socket.onopen = s.OnOpen; + s.Socket.onclose = s.OnClose; + s.Socket.onerror = s.OnError; + + console.log( s.Socket ); + } + + s.Command = function ( msg, identifier ) + { + if ( identifier == null ) + identifier = -1; + + var packet = + { + Identifier: identifier, + Message: msg, + Name: "WebRcon" + } + + s.Socket.send( JSON.stringify( packet ) ); + }; + + var LastIndex = 1001; + + // + // Make a request, call this function when it returns + // + s.Request = function ( msg, scope, callback ) + { + LastIndex++; + s.Callbacks[LastIndex] = { scope: scope, callback: callback }; + s.Command( msg, LastIndex ); + } + + // + // Returns true if websocket is connected + // + s.IsConnected = function () + { + if ( s.Socket == null ) return false; + return s.Socket.readyState == 1; + } + + // + // Helper for installing connectivity logic + // + // Basically if not connected, call this function when we are + // And if we are - then call it right now. + // + s.InstallService = function( scope, func ) + { + scope.$on( "OnConnected", function () + { + func(); + }); + + if ( s.IsConnected() ) + { + func(); + } + } + + return s; +} \ No newline at end of file diff --git a/rcon.css b/rcon.css index 939cb27..4a80b96 100644 --- a/rcon.css +++ b/rcon.css @@ -44,4 +44,43 @@ H3 #ConsoleController .Input input { color: #000; +} + +a +{ + color: #FF4081; + text-decoration: none; +} + +.menu +{ + background-color: #1976D2; +} + +.menu_button +{ + display: block; + padding: 0 16px 0 32px; + text-transform: none; + text-rendering: optimizeLegibility; + font-weight: 500; + border-radius: 0; + color: white; + cursor: pointer; + display: block; + align-items: inherit; + line-height: 40px; + margin: 0; + max-height: 40px; + overflow: hidden; + padding: 0px 16px; + text-align: left; + text-decoration: none; + white-space: normal; + width: 100%; +} + +.menu_button.selected +{ + background: #90A4AE; } \ No newline at end of file diff --git a/rcon.js b/rcon.js deleted file mode 100644 index 863d635..0000000 --- a/rcon.js +++ /dev/null @@ -1,248 +0,0 @@ - - -var app = angular.module('RconApp', ['ngMaterial', 'ngRoute']); - -app.config( function( $mdThemingProvider, $routeProvider ) -{ - $mdThemingProvider.theme('default').primaryPalette('blue').accentPalette('orange'); - - $routeProvider.when( "/console", { templateUrl: 'partials/phone-list.html'} ) - $routeProvider.when( "/players", { templateUrl: 'partials/players.html'} ) - .otherwise( {redirectTo: '/console'} ); - -}); - -app.controller('RconController', RconController); - -function RconController( $scope, rconService, $mdSidenav, $timeout, $mdDialog ) -{ - $scope.pages = - [ - { Name: "console", Title: "Console", Page: "html/console.html" }, - { Name: "players", Title: "Players", Page: "html/players.html" }, - ] - - $scope.SwitchPage = function( page ) - { - $scope.CurrentPage = page; - } - - $scope.OpenLeftMenu = function() - { - $mdSidenav('left').toggle(); - }; - - $scope.SwitchPage( $scope.pages[0] ); - - $scope.IsConnected = function() - { - return rconService.IsConnected(); - } - - rconService.OnOpen = function() - { - $scope.Connected = true; - $scope.$broadcast( "OnConnected" ); - $scope.$digest(); - } - - rconService.OnClose = function( ev ) - { - $scope.$broadcast( "OnDisconnected", ev ); - $scope.$digest(); - } - - rconService.OnError = function( ev ) - { - $scope.$broadcast( "OnConnectionError", ev ); - $scope.$digest(); - } - - rconService.OnMessage = function( msg ) - { - $scope.$broadcast( "OnMessage", msg ); - } -} - -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(); - - console.log( $scope.PreviousConnects ); - - $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.controller('ConsoleController', ['$scope', 'rconService', ConsoleController]); - -function ConsoleController( $scope, rconService ) -{ - $scope.Output = new Array(); - - $scope.SubmitCommand = function() - { - rconService.Command( $scope.Command, 1 ); - $scope.Output.push( { Class: "input", "Message": "> " + $scope.Command } ); - - $scope.Command = ""; - } - - $scope.$on( "OnMessage", function( event, msg ) - { - if ( msg.Message.startsWith( "[CHAT] " ) ) - msg.Class = "Chat"; - - if ( msg.Identifier == 1 ) - msg.Class = "Requested"; - - if ( msg.Identifier > 1 ) - return; - - $scope.Output.push( msg ); - $scope.$digest(); - - $("#ConsoleController .Output").scrollTop($("#ConsoleController .Output")[0].scrollHeight); - - }); -} - - -app.controller('PlayersController', ['$scope', 'rconService', PlayersController]); - -function PlayersController( $scope, rconService ) -{ - $scope.Output = new Array(); - - $scope.Refresh = function() - { - rconService.Command( "playerlist", 2 ); - } - - $scope.$on( "OnConnected", function( event ) - { - $scope.Refresh(); - }); - - $scope.$on( "OnMessage", function( event, msg ) - { - if ( msg.Identifier != 2 ) - return; - - $scope.Players = JSON.parse( msg.Message ); - }); - - -} - - -app.service('rconService', [RconService]); - -function RconService() -{ - var s = {}; - - s.Connect = function( addr, pass ) - { - s.Socket = new WebSocket( "ws://" + addr + "/" + pass ); - - s.Socket.onmessage = function (e) - { - if (s.OnMessage != null) - { - s.OnMessage( JSON.parse( e.data ) ); - } - }; - - s.Socket.onopen = s.OnOpen; - s.Socket.onclose = s.OnClose; - s.Socket.onerror = s.OnError; - - console.log( s.Socket ); - } - - s.Command = function( msg, identifier ) - { - if (identifier == null) - identifier = -1; - - var packet = - { - Identifier: identifier, - Message: msg, - Name: "WebRcon" - } - - s.Socket.send( JSON.stringify( packet ) ); - }; - - s.IsConnected = function() - { - if ( s.Socket == null ) return false; - console.log( s.Socket ); - - return true; - } - - return s; -} - -app.filter('SecondsToDuration', [SecondsToDuration]); - -function SecondsToDuration() -{ - return function ( input ) - { - input = parseInt( input ); - - var out = ""; - var hours = Math.floor(input / 3600); - if ( input > 3600 ) out += hours + "h "; - - var minutes = Math.floor(input / 60) % 60; - if ( input > 60 ) out += minutes + "m "; - - var seconds = input % 60; - out += seconds + "s"; - - return out; - } -} - \ No newline at end of file