Browse Source

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

pull/2/head
Alibek Omarov 4 years ago
parent
commit
c62db950f1
  1. 4
      engine/common/common.h
  2. 2
      engine/common/system.c
  3. 35
      engine/server/sv_client.c
  4. 25
      engine/server/sv_cmds.c

4
engine/common/common.h

@ -327,9 +327,10 @@ typedef struct host_redirect_s @@ -327,9 +327,10 @@ typedef struct host_redirect_s
{
rdtype_t target;
char *buffer;
int buffersize;
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 ); @@ -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 );

2
engine/common/system.c

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

35
engine/server/sv_client.c

@ -608,7 +608,7 @@ SVC COMMAND REDIRECT @@ -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 @@ -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 ) @@ -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 ) @@ -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

25
engine/server/sv_cmds.c

@ -931,6 +931,30 @@ void SV_EntityInfo_f( void ) @@ -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 ) @@ -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 )
{

Loading…
Cancel
Save