diff options
author | M. Kristall <mkpdev@gmail.com> | 2011-09-25 19:12:09 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:18:14 +0000 |
commit | 37a60fa83a2e5a17ee1b3be56f98479a06b810eb (patch) | |
tree | 8ac991e2dd4619feae213354b766d119c7dde4f7 /src/cgame | |
parent | 9277c143f248a7a94c9645162217674abfcbf840 (diff) |
* Unregister commands advertised by the server when disconnecting
Now that builtin commands can't be removed, this should be safe
Diffstat (limited to 'src/cgame')
-rw-r--r-- | src/cgame/cg_local.h | 2 | ||||
-rw-r--r-- | src/cgame/cg_main.c | 3 | ||||
-rw-r--r-- | src/cgame/cg_servercmds.c | 42 |
3 files changed, 35 insertions, 12 deletions
diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h index e47a89f6..36d7a870 100644 --- a/src/cgame/cg_local.h +++ b/src/cgame/cg_local.h @@ -1770,6 +1770,7 @@ void CG_ExecuteNewServerCommands( int latestSequence ); void CG_ParseServerinfo( void ); void CG_SetConfigValues( void ); void CG_ShaderStateChanged(void); +void CG_UnregisterCommands( void ); // // cg_playerstate.c @@ -1899,6 +1900,7 @@ void trap_SendConsoleCommand( const char *text ); // register a command name so the console can perform command completion. // FIXME: replace this with a normal console command "defineCommand"? void trap_AddCommand( const char *cmdName ); +void trap_RemoveCommand( const char *cmdName ); // send a string to the server over the network void trap_SendClientCommand( const char *s ); diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c index 356f6728..3972097e 100644 --- a/src/cgame/cg_main.c +++ b/src/cgame/cg_main.c @@ -1859,8 +1859,7 @@ Called before every level change or subsystem restart */ void CG_Shutdown( void ) { - // some mods may need to do cleanup work here, - // like closing files or archiving session data + CG_UnregisterCommands( ); } /* diff --git a/src/cgame/cg_servercmds.c b/src/cgame/cg_servercmds.c index 2b02a4e3..90254a2c 100644 --- a/src/cgame/cg_servercmds.c +++ b/src/cgame/cg_servercmds.c @@ -1230,19 +1230,41 @@ static void CG_PoisonCloud_f( void ) } } +static char registeredCmds[ 8192 ]; // cmd1\0cmd2\0cmdn\0\0 static void CG_GameCmds_f( void ) { - int i; - int c = trap_Argc( ); - - /* - There is no corresponding trap_RemoveCommand because a server could send - something like - cmds quit - which would result in trap_RemoveCommand( "quit" ), which would be really bad - */ + int i; + int c = trap_Argc( ); + const char *cmd; + size_t len; + size_t offset = strlen( registeredCmds ); + for( i = 1; i < c; i++ ) - trap_AddCommand( CG_Argv( i ) ); + { + cmd = CG_Argv( i ); + len = strlen( cmd ) + 1; + if( len + offset >= sizeof( registeredCmds ) - 1 ) + { + CG_Printf( "AddCommand: too many commands (%d > %d)\n", + len + offset, sizeof( registeredCmds ) - 1 ); + return; + } + trap_AddCommand( cmd ); + strcpy( registeredCmds + offset, cmd ); + offset += len + 1; + } +} + +void CG_UnregisterCommands( void ) +{ + size_t len, offset = 0; + while( registeredCmds[ offset ] ) + { + len = strlen( registeredCmds + offset ); + trap_RemoveCommand( registeredCmds + offset ); + offset += len + 1; + } + memset( registeredCmds, 0, 2 ); } static consoleCommand_t svcommands[ ] = |