summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cgame/cg_local.h2
-rw-r--r--src/cgame/cg_main.c3
-rw-r--r--src/cgame/cg_servercmds.c42
-rw-r--r--src/game/g_cmds.c4
4 files changed, 39 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[ ] =
diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c
index 8461981f..b8e90239 100644
--- a/src/game/g_cmds.c
+++ b/src/game/g_cmds.c
@@ -3246,6 +3246,10 @@ void G_ListCommands( gentity_t *ent )
for( i = 0; i < numCmds; i++ )
{
+ // never advertise cheats
+ if( cmds[ i ].cmdFlags & CMD_CHEAT )
+ continue;
+
len = strlen( cmds[ i ].cmdName ) + 1;
if( len + outlen >= sizeof( out ) - 1 )
{