From 1e1eac991d14958f5e01a2ed9195435dd45b05f2 Mon Sep 17 00:00:00 2001 From: mittorn Date: Sat, 23 Feb 2019 19:20:24 +0000 Subject: [PATCH] ggm_saytext feature for chat transports --- dlls/client.cpp | 2 ++ dlls/gravgunmod.cpp | 31 +++++++++++++++++++++++++++++++ dlls/gravgunmod.h | 2 ++ 3 files changed, 35 insertions(+) diff --git a/dlls/client.cpp b/dlls/client.cpp index 2672676b..b5b72606 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -2075,6 +2075,8 @@ int ConnectionlessPacket( const struct netadr_s *net_from, const char *args, cha { // Parse stuff from args //int max_buffer_size = *response_buffer_size; + if( GGM_ConnectionlessPacket( net_from, args, response_buffer, response_buffer_size ) ) + return 1; // Zero it out since we aren't going to respond. // If we wanted to response, we'd write data into response_buffer diff --git a/dlls/gravgunmod.cpp b/dlls/gravgunmod.cpp index 0bc9623a..bb43cfe2 100644 --- a/dlls/gravgunmod.cpp +++ b/dlls/gravgunmod.cpp @@ -3062,6 +3062,36 @@ void GGM_Pause_f( void ) g_fPause ^= true; } +extern int gmsgSayText; + +void GGM_SayText( const char *line ) +{ + char text[254] = {}; + + snprintf( text, sizeof( text ), "%s\n", line ); + + MESSAGE_BEGIN( MSG_ALL, gmsgSayText, NULL ); + WRITE_BYTE( ENTINDEX(0) ); + WRITE_STRING( text ); + MESSAGE_END(); +} + +void GGM_SayText_f( void ) +{ + GGM_SayText(CMD_ARGS()); +} + +int GGM_ConnectionlessPacket( const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size ) +{ + if( !strncmp( args, "ggm_chat ", 9 ) ) + { + GGM_SayText( args + 9 ); + *response_buffer_size = 0; + return 1; + } + return 0; +} + /* ===================== GGM_RegisterCVars @@ -3115,6 +3145,7 @@ void GGM_RegisterCVars( void ) g_engfuncs.pfnAddServerCommand( "ggm_load", GGM_Load_f ); g_engfuncs.pfnAddServerCommand( "ggm_votecommand", GGM_VoteCommand_f ); g_engfuncs.pfnAddServerCommand( "ggm_pause", GGM_Pause_f ); + g_engfuncs.pfnAddServerCommand( "ggm_saytext", GGM_SayText_f ); zombietime = CVAR_GET_POINTER("zombietime"); diff --git a/dlls/gravgunmod.h b/dlls/gravgunmod.h index cd904b67..26165da8 100644 --- a/dlls/gravgunmod.h +++ b/dlls/gravgunmod.h @@ -204,5 +204,7 @@ int GGM_ChangelevelVote( CBasePlayer *pPlayer, edict_t *pTrigger, const char *ps void GGM_ClearVote( void ); void GGM_StartVoteCommand( CBasePlayer *pPlayer, const char *pszCommand, const char *pszMessage ); void GGM_ConnectSaveBot( void ); +int GGM_ConnectionlessPacket( const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size ); + #endif // GRAVGUNMOD_H