server: implement rcon redirection, add redirect command from old engine

This commit is contained in:
Alibek Omarov 2021-03-27 23:46:57 +03:00
parent 9c9953bb60
commit c62db950f1
4 changed files with 67 additions and 7 deletions

View File

@ -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 );

View File

@ -553,5 +553,5 @@ void Sys_Print( const char *pMsg )
Sys_PrintLog( pMsg );
// Rcon_Print( pMsg );
Rcon_Print( pMsg );
}

View File

@ -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

View File

@ -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 )
{