Fetch the console history
This commit is contained in:
+35
-11
@@ -1,28 +1,52 @@
|
|||||||
|
|
||||||
app.controller( 'ConsoleController', ['$scope', 'rconService', ConsoleController] );
|
app.controller( 'ConsoleController', ConsoleController );
|
||||||
|
|
||||||
function ConsoleController( $scope, rconService )
|
function ConsoleController( $scope, rconService, $timeout )
|
||||||
{
|
{
|
||||||
$scope.Output = rconService.Output;
|
$scope.Output = new Array();
|
||||||
|
|
||||||
$scope.SubmitCommand = function ()
|
$scope.SubmitCommand = function ()
|
||||||
{
|
{
|
||||||
rconService.Command( $scope.Command, 0 );
|
$scope.OnMessage( { Message: $scope.Command, Type: 'Command' } )
|
||||||
|
|
||||||
|
rconService.Command( $scope.Command, 1 );
|
||||||
$scope.Command = "";
|
$scope.Command = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.$on( "OnMessage", function ( event, msg )
|
$scope.$on( "OnMessage", function ( event, msg ) { $scope.OnMessage( msg ); } );
|
||||||
|
|
||||||
|
$scope.OnMessage = function( msg )
|
||||||
{
|
{
|
||||||
if ( msg.Message.startsWith( "[CHAT] " ) )
|
// Ignore rcon entries
|
||||||
msg.Class = "Chat";
|
if ( msg.Message.startsWith( "[rcon] " ) ) return;
|
||||||
|
|
||||||
if ( msg.Identifier == 1 )
|
msg.Class = msg.Type;
|
||||||
msg.Class = "Requested";
|
$scope.Output.push( msg );
|
||||||
|
|
||||||
if ( msg.Identifier > 1 )
|
$timeout( $scope.ScrollToBottom, 50 );
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
$scope.ScrollToBottom = function()
|
||||||
|
{
|
||||||
|
// TODO - don't scroll if we're not at the bottom !
|
||||||
$( "#ConsoleController .Output" ).scrollTop( $( "#ConsoleController .Output" )[0].scrollHeight );
|
$( "#ConsoleController .Output" ).scrollTop( $( "#ConsoleController .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 256", $scope, function ( msg )
|
||||||
|
{
|
||||||
|
var messages = JSON.parse( msg.Message );
|
||||||
|
|
||||||
|
messages.forEach( function ( x ) { $scope.OnMessage( x ); } );
|
||||||
} );
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
rconService.InstallService( $scope, $scope.GetHistory )
|
||||||
}
|
}
|
||||||
+1
-6
@@ -5,10 +5,6 @@ function RconService()
|
|||||||
|
|
||||||
s.Callbacks = {};
|
s.Callbacks = {};
|
||||||
|
|
||||||
// A list of untargetted ouput from the server
|
|
||||||
// ie - the console history
|
|
||||||
s.Output = new Array();
|
|
||||||
|
|
||||||
s.Connect = function ( addr, pass )
|
s.Connect = function ( addr, pass )
|
||||||
{
|
{
|
||||||
s.Socket = new WebSocket( "ws://" + addr + "/" + pass );
|
s.Socket = new WebSocket( "ws://" + addr + "/" + pass );
|
||||||
@@ -22,7 +18,7 @@ function RconService()
|
|||||||
// This is a targetted message, it has an identifier
|
// This is a targetted message, it has an identifier
|
||||||
// So feed it back to the right callback.
|
// So feed it back to the right callback.
|
||||||
//
|
//
|
||||||
if ( data.Identifier != 0 )
|
if ( data.Identifier > 1000 )
|
||||||
{
|
{
|
||||||
var cb = s.Callbacks[data.Identifier];
|
var cb = s.Callbacks[data.Identifier];
|
||||||
if ( cb != null )
|
if ( cb != null )
|
||||||
@@ -42,7 +38,6 @@ function RconService()
|
|||||||
//
|
//
|
||||||
if ( s.OnMessage != null )
|
if ( s.OnMessage != null )
|
||||||
{
|
{
|
||||||
s.Output.push( data );
|
|
||||||
s.OnMessage( data );
|
s.OnMessage( data );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,14 +31,28 @@ H3
|
|||||||
padding: 8px;
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ConsoleController .Output .Requested
|
#ConsoleController .Output div
|
||||||
{
|
{
|
||||||
color: #2196F3;
|
padding: 2px 4px;
|
||||||
|
color: #888;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ConsoleController .Output .Chat
|
#ConsoleController .Output .Command
|
||||||
{
|
{
|
||||||
color: #4CAF50;
|
color: #009688;
|
||||||
|
background-color: rgba(137, 255, 0, 0.44);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ConsoleController .Output .Warning
|
||||||
|
{
|
||||||
|
color: #c79621;
|
||||||
|
background-color: rgba(255, 128, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ConsoleController .Output .Assert, #ConsoleController .Output .Error
|
||||||
|
{
|
||||||
|
color: #b42626;
|
||||||
|
background-color: rgba(255,0,0,.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ConsoleController .Input input
|
#ConsoleController .Input input
|
||||||
|
|||||||
Reference in New Issue
Block a user