diff --git a/engine/common/common.h b/engine/common/common.h index 163442bf..7f126dd2 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -325,11 +325,12 @@ typedef struct typedef struct host_redirect_s { - rdtype_t target; - char *buffer; - int buffersize; - netadr_t address; - void (*flush)( netadr_t adr, rdtype_t target, char *buffer ); + rdtype_t target; + char *buffer; + size_t buffersize; + netadr_t address; + void (*flush)( netadr_t adr, rdtype_t target, char *buffer ); + int lines; } host_redirect_t; typedef struct @@ -947,6 +948,7 @@ void VID_Init( void ); void UI_SetActiveMenu( qboolean fActive ); void UI_ShowConnectionWarning( void ); void Cmd_Null_f( void ); +void Rcon_Print( const char *pMsg ); // soundlib shared exports qboolean S_Init( void ); diff --git a/engine/common/system.c b/engine/common/system.c index 7d42ded7..aaa600e4 100644 --- a/engine/common/system.c +++ b/engine/common/system.c @@ -553,5 +553,5 @@ void Sys_Print( const char *pMsg ) Sys_PrintLog( pMsg ); - // Rcon_Print( pMsg ); + Rcon_Print( pMsg ); } diff --git a/engine/server/sv_client.c b/engine/server/sv_client.c index aba38cc6..0f0b6a00 100644 --- a/engine/server/sv_client.c +++ b/engine/server/sv_client.c @@ -608,7 +608,7 @@ SVC COMMAND REDIRECT ============================================================================== */ -void SV_BeginRedirect( netadr_t adr, int target, char *buffer, int buffersize, void (*flush)) +void SV_BeginRedirect( netadr_t adr, rdtype_t target, char *buffer, size_t buffersize, void (*flush)) { if( !target || !buffer || !buffersize || !flush ) return; @@ -619,6 +619,8 @@ void SV_BeginRedirect( netadr_t adr, int target, char *buffer, int buffersize, v host.rd.flush = flush; host.rd.address = adr; host.rd.buffer[0] = 0; + if( host.rd.lines == 0 ) + host.rd.lines = -1; } void SV_FlushRedirect( netadr_t adr, int dest, char *buf ) @@ -644,6 +646,9 @@ void SV_FlushRedirect( netadr_t adr, int dest, char *buf ) void SV_EndRedirect( void ) { + if( host.rd.lines > 0 ) + return; + if( host.rd.flush ) host.rd.flush( host.rd.address, host.rd.target, host.rd.buffer ); @@ -653,6 +658,34 @@ void SV_EndRedirect( void ) host.rd.flush = NULL; } +/* +================ +Rcon_Print + +Print message to rcon buffer and send to rcon redirect target +================ +*/ +void Rcon_Print( const char *pMsg ) +{ + if( host.rd.target && host.rd.lines && host.rd.flush && host.rd.buffer ) + { + size_t len = Q_strncat( host.rd.buffer, pMsg, host.rd.buffersize ); + + if( len && host.rd.buffer[len-1] == '\n' ) + { + host.rd.flush( host.rd.address, host.rd.target, host.rd.buffer ); + + if( host.rd.lines > 0 ) + host.rd.lines--; + + host.rd.buffer[0] = 0; + + if( !host.rd.lines ) + Msg( "End of redirection!\n" ); + } + } +} + /* =============== SV_GetClientIDString diff --git a/engine/server/sv_cmds.c b/engine/server/sv_cmds.c index a1be19b3..c0ce1cf4 100644 --- a/engine/server/sv_cmds.c +++ b/engine/server/sv_cmds.c @@ -931,6 +931,30 @@ void SV_EntityInfo_f( void ) } } +/* +================ +Rcon_Redirect_f + +Force redirect N lines of console output to client +================ +*/ +void Rcon_Redirect_f( void ) +{ + int lines = 2000; + + if( !host.rd.target ) + { + Msg( "redirect is only valid from rcon\n" ); + return; + } + + if( Cmd_Argc() == 2 ) + lines = Q_atoi( Cmd_Argv( 1 ) ); + + host.rd.lines = lines; + Msg( "Redirection enabled for next %d lines\n", lines ); +} + /* ================== SV_InitHostCommands @@ -978,6 +1002,7 @@ void SV_InitOperatorCommands( void ) Cmd_AddCommand( "shutdownserver", SV_KillServer_f, "shutdown current server" ); Cmd_AddCommand( "changelevel", SV_ChangeLevel_f, "change level" ); Cmd_AddCommand( "changelevel2", SV_ChangeLevel2_f, "smooth change level" ); + Cmd_AddCommand( "redirect", Rcon_Redirect_f, "force enable rcon redirection" ); if( host.type == HOST_NORMAL ) {