From 8db1528ae5a78c2de1edfd1f848675a5898b1004 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Fri, 29 Apr 2016 15:24:12 +0100 Subject: [PATCH] Chat section --- html/chat.html | 11 +++++++++++ index.html | 1 + js/app.js | 1 + js/chat.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 html/chat.html create mode 100644 js/chat.js diff --git a/html/chat.html b/html/chat.html new file mode 100644 index 0000000..bb8e812 --- /dev/null +++ b/html/chat.html @@ -0,0 +1,11 @@ +
+ +
{{line.Message}}
+ +
+
+ +
+
+ +
\ No newline at end of file diff --git a/index.html b/index.html index 5a3f3d2..363d606 100644 --- a/index.html +++ b/index.html @@ -64,6 +64,7 @@ + \ No newline at end of file diff --git a/js/app.js b/js/app.js index 3e0f872..d23e2ea 100644 --- a/js/app.js +++ b/js/app.js @@ -8,6 +8,7 @@ app.config( function ( $routeProvider ) { $routeProvider.when( "/home", { Title: "Home" } ) $routeProvider.when( "/:address/console", { Title: "Console", templateUrl: "html/console.html", Nav: true } ) + $routeProvider.when( "/:address/chat", { Title: "Chat", templateUrl: "html/chat.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" } ) diff --git a/js/chat.js b/js/chat.js new file mode 100644 index 0000000..4cb1a89 --- /dev/null +++ b/js/chat.js @@ -0,0 +1,52 @@ + +app.controller( 'ChatController', ChatController ); + +function ChatController( $scope, rconService, $timeout ) +{ + $scope.Output = new Array(); + + $scope.SubmitCommand = function () + { + $scope.Output.push( { Message: $scope.Command, Type: 'Command' } ); + + rconService.Command( "say " + $scope.Command, 1 ); + $scope.Command = ""; + } + + $scope.$on( "OnMessage", function ( event, msg ) { $scope.OnMessage( msg ); } ); + + $scope.OnMessage = function( msg ) + { + if ( msg.Type != "Chat" ) return; + + msg.Class = msg.Type; + msg.Message = msg.Message.substr( 7 ); + $scope.Output.push( msg ); + + $timeout( $scope.ScrollToBottom, 50 ); + } + + $scope.ScrollToBottom = function() + { + // TODO - don't scroll if we're not at the bottom ! + $( "#ChatController .Output" ).scrollTop( $( "#ChatController .Output" )[0].scrollHeight ); + } + + // + // Calls console.tail - which returns the last 256 entries from the console. + // This is then added to the console + // + $scope.GetHistory = function () + { + console.log( "GetHistory" ); + + rconService.Request( "console.tail 4096", $scope, function ( msg ) + { + var messages = JSON.parse( msg.Message ); + + messages.forEach( function ( x ) { $scope.OnMessage( x ); } ); + } ); + } + + rconService.InstallService( $scope, $scope.GetHistory ) +} \ No newline at end of file