diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /engine/sv_redirect.cpp | |
| download | archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip | |
Diffstat (limited to 'engine/sv_redirect.cpp')
| -rw-r--r-- | engine/sv_redirect.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/engine/sv_redirect.cpp b/engine/sv_redirect.cpp new file mode 100644 index 0000000..f03279d --- /dev/null +++ b/engine/sv_redirect.cpp @@ -0,0 +1,97 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// +#include "server_pch.h" +#include "net.h" +#include "sv_rcon.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +static redirect_t sv_redirected; +static netadr_t sv_redirectto; +static char sv_redirect_buffer[ 4096 ]; // can't be any bigger because then we hit other static limits in the engine print funcs + +//----------------------------------------------------------------------------- +// Purpose: Clears all remaining data from the redirection buffer. +//----------------------------------------------------------------------------- +void SV_RedirectFlush( void ) +{ + static bool bInFlush = false; // recursion guard + + Assert( bInFlush == false ); + + bInFlush = true; + if ( sv_redirected == RD_PACKET ) // Print to remote address. + { + NET_OutOfBandPrintf( sv.m_Socket, sv_redirectto, "%c%s", A2A_PRINT, sv_redirect_buffer ); + } + else if ( sv_redirected == RD_CLIENT ) // Send to client on message stream. + { + host_client->ClientPrintf( "%s", sv_redirect_buffer ); + } + else if ( sv_redirected == RD_SOCKET ) + { + RCONServer().FinishRedirect( sv_redirect_buffer, sv_redirectto ); + } + + // clear it + sv_redirect_buffer[0] = 0; + bInFlush = false; +} + +//----------------------------------------------------------------------------- +// Purpose: Sents console printfs to remote client instead of to console +// Input : rd - +// *addr - +//----------------------------------------------------------------------------- +void SV_RedirectStart (redirect_t rd, const netadr_t *addr) +{ + sv_redirected = rd; + sv_redirectto = *addr; + sv_redirect_buffer[0] = 0; +} + +//----------------------------------------------------------------------------- +// Purpose: Flushes buffers to network, and resets mode to inactive +//----------------------------------------------------------------------------- +void SV_RedirectEnd (void) +{ + SV_RedirectFlush (); + sv_redirected = RD_NONE; +} + +//----------------------------------------------------------------------------- +// Purpose: +// Input : len - +//----------------------------------------------------------------------------- +void SV_RedirectCheckFlush( int len ) +{ + if ( len + Q_strlen( sv_redirect_buffer ) > sizeof(sv_redirect_buffer) - 1) + { + SV_RedirectFlush(); + } +} + +//----------------------------------------------------------------------------- +// Purpose: +// Output : bool +//----------------------------------------------------------------------------- +bool SV_RedirectActive( void ) +{ + return ( sv_redirected != RD_NONE ) ? true : false; +} + +//----------------------------------------------------------------------------- +// Purpose: +// Input : *txt - +//----------------------------------------------------------------------------- +void SV_RedirectAddText( const char *txt ) +{ + SV_RedirectCheckFlush( strlen( txt ) ); + Q_strncat( sv_redirect_buffer, (char *)txt, sizeof( sv_redirect_buffer ), COPY_ALL_CHARACTERS ); +}
\ No newline at end of file |