diff options
author | M. Kristall <mkpdev@gmail.com> | 2009-10-03 12:05:47 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:15:40 +0000 |
commit | c9006304896cd95d989f68d5b103702d51fdf7bb (patch) | |
tree | c4d3e61c40fb7e1c72cc6858778126b3a4648cbd /src | |
parent | ae0a3343c5e6ce341896e0c0204dc385bc682e6f (diff) |
* (bug 3379) !adjustban command to change reason and duration of bans (flag b)
* (bug 3746) Lookup table for UI commands (Ben Millwood)
* and some other refactoring
* Fix a couple null dereferences introduced in 1120
Diffstat (limited to 'src')
-rw-r--r-- | src/cgame/cg_consolecmds.c | 34 | ||||
-rw-r--r-- | src/cgame/cg_local.h | 6 | ||||
-rw-r--r-- | src/cgame/cg_servercmds.c | 276 | ||||
-rw-r--r-- | src/cgame/cg_syscalls.c | 2 | ||||
-rw-r--r-- | src/game/g_admin.c | 298 | ||||
-rw-r--r-- | src/game/g_admin.h | 1 | ||||
-rw-r--r-- | src/game/g_cmds.c | 41 | ||||
-rw-r--r-- | src/game/g_local.h | 5 | ||||
-rw-r--r-- | src/game/g_main.c | 33 | ||||
-rw-r--r-- | src/ui/ui_atoms.c | 157 |
10 files changed, 442 insertions, 411 deletions
diff --git a/src/cgame/cg_consolecmds.c b/src/cgame/cg_consolecmds.c index 697b0e98..47aadece 100644 --- a/src/cgame/cg_consolecmds.c +++ b/src/cgame/cg_consolecmds.c @@ -188,14 +188,14 @@ static void CG_TellAttacker_f( void ) trap_SendClientCommand( command ); } -typedef struct +static void CG_UIMenu_f( void ) { - char *cmd; - void (*function)( void ); -} consoleCommand_t; + trap_SendConsoleCommand( va( "menu %s\n", CG_Argv( 1 ) ) ); +} static consoleCommand_t commands[ ] = { + { "ui_menu", CG_UIMenu_f }, { "testgun", CG_TestGun_f }, { "testmodel", CG_TestModel_f }, { "nextframe", CG_TestModelNextFrame_f }, @@ -233,19 +233,10 @@ Cmd_Argc() / Cmd_Argv() qboolean CG_ConsoleCommand( void ) { const char *cmd; - const char *arg1; int i; cmd = CG_Argv( 0 ); - // ugly hacky special case - if( !Q_stricmp( cmd, "ui_menu" ) ) - { - arg1 = CG_Argv( 1 ); - trap_SendConsoleCommand( va( "menu %s\n", arg1 ) ); - return qtrue; - } - for( i = 0; i < sizeof( commands ) / sizeof( commands[ 0 ] ); i++ ) { if( !Q_stricmp( cmd, commands[ i ].cmd ) ) @@ -285,6 +276,11 @@ void CG_InitConsoleCommands( void ) trap_AddCommand( "ui_messagemode4" ); trap_AddCommand( "say" ); trap_AddCommand( "say_team" ); + trap_AddCommand( "vsay" ); + trap_AddCommand( "vsay_team" ); + trap_AddCommand( "vsay_local" ); + trap_AddCommand( "m" ); + trap_AddCommand( "mt" ); trap_AddCommand( "tell" ); trap_AddCommand( "give" ); trap_AddCommand( "god" ); @@ -293,28 +289,22 @@ void CG_InitConsoleCommands( void ) trap_AddCommand( "team" ); trap_AddCommand( "follow" ); trap_AddCommand( "levelshot" ); - trap_AddCommand( "addbot" ); trap_AddCommand( "setviewpos" ); trap_AddCommand( "callvote" ); trap_AddCommand( "vote" ); trap_AddCommand( "callteamvote" ); trap_AddCommand( "teamvote" ); - trap_AddCommand( "stats" ); trap_AddCommand( "class" ); trap_AddCommand( "build" ); trap_AddCommand( "buy" ); trap_AddCommand( "sell" ); trap_AddCommand( "reload" ); + trap_AddCommand( "boost" ); trap_AddCommand( "itemact" ); trap_AddCommand( "itemdeact" ); trap_AddCommand( "itemtoggle" ); trap_AddCommand( "destroy" ); trap_AddCommand( "deconstruct" ); - trap_AddCommand( "menu" ); - trap_AddCommand( "ui_menu" ); - trap_AddCommand( "mapRotation" ); - trap_AddCommand( "stopMapRotation" ); - trap_AddCommand( "advanceMapRotation" ); - trap_AddCommand( "alienWin" ); - trap_AddCommand( "humanWin" ); + trap_AddCommand( "ignore" ); + trap_AddCommand( "unignore" ); } diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h index 764d8183..e4a19844 100644 --- a/src/cgame/cg_local.h +++ b/src/cgame/cg_local.h @@ -1422,6 +1422,12 @@ typedef struct clientList_t ignoreList; } cgs_t; +typedef struct +{ + char *cmd; + void ( *function )( void ); +} consoleCommand_t; + //============================================================================== extern cgs_t cgs; diff --git a/src/cgame/cg_servercmds.c b/src/cgame/cg_servercmds.c index e9de4646..c358133f 100644 --- a/src/cgame/cg_servercmds.c +++ b/src/cgame/cg_servercmds.c @@ -1105,172 +1105,180 @@ static void CG_ParseVoice( void ) /* ================= -CG_ServerCommand +CG_CenterPrint_f +================= +*/ +static void CG_CenterPrint_f( void ) +{ + CG_CenterPrint( CG_Argv( 1 ), SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH ); +} -The string has been tokenized and can be retrieved with -Cmd_Argc() / Cmd_Argv() +/* +================= +CG_Print_f ================= */ -static void CG_ServerCommand( void ) +static void CG_Print_f( void ) { - const char *cmd; - char text[ MAX_SAY_TEXT ]; + CG_Printf( "%s", CG_Argv( 1 ) ); +} - cmd = CG_Argv( 0 ); +/* +================= +CG_Chat_f +================= +*/ +static void CG_Chat_f( void ) +{ + char cmd[ 6 ], text[ MAX_SAY_TEXT ]; + qboolean team; - if( !cmd[ 0 ] ) - { - // server claimed the command - return; - } + trap_Argv( 0, cmd, sizeof( cmd ) ); + team = Q_stricmp( cmd, "chat" ); - if( !strcmp( cmd, "cp" ) ) - { - CG_CenterPrint( CG_Argv( 1 ), SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH ); + if( team && cg_teamChatsOnly.integer ) return; - } - if( !strcmp( cmd, "cs" ) ) - { - CG_ConfigStringModified( ); - return; - } + Q_strncpyz( text, CG_Argv( 1 ), sizeof( text ) ); - if( !strcmp( cmd, "print" ) ) + if( Q_stricmpn( text, "[skipnotify]", 12 ) ) { - CG_Printf( "%s", CG_Argv( 1 ) ); - return; + if( team && cg.snap->ps.stats[ STAT_TEAM ] == TEAM_ALIENS ) + trap_S_StartLocalSound( cgs.media.alienTalkSound, CHAN_LOCAL_SOUND ); + else if( team && cg.snap->ps.stats[ STAT_TEAM ] == TEAM_HUMANS ) + trap_S_StartLocalSound( cgs.media.humanTalkSound, CHAN_LOCAL_SOUND ); + else + trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND ); } - if( !strcmp( cmd, "chat" ) ) - { - if( !cg_teamChatsOnly.integer ) - { - Q_strncpyz( text, CG_Argv( 1 ), MAX_SAY_TEXT ); - if( Q_stricmpn( text, "[skipnotify]", 12 ) ) - trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND ); - CG_RemoveChatEscapeChar( text ); - CG_Printf( "%s\n", text ); - } - - return; - } + CG_RemoveChatEscapeChar( text ); + CG_Printf( "%s\n", text ); +} - if( !strcmp( cmd, "tchat" ) ) - { - Q_strncpyz( text, CG_Argv( 1 ), MAX_SAY_TEXT ); - if( Q_stricmpn( text, "[skipnotify]", 12 ) ) - { - if( cg.snap->ps.stats[ STAT_TEAM ] == TEAM_ALIENS ) - trap_S_StartLocalSound( cgs.media.alienTalkSound, CHAN_LOCAL_SOUND ); - else if( cg.snap->ps.stats[ STAT_TEAM ] == TEAM_HUMANS ) - trap_S_StartLocalSound( cgs.media.humanTalkSound, CHAN_LOCAL_SOUND ); - else - trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND ); - } - CG_RemoveChatEscapeChar( text ); - CG_Printf( "%s\n", text ); - return; - } - - if( !strcmp( cmd, "voice" ) ) - { - CG_ParseVoice( ); - return; - } +/* +================= +CG_ClientLevelShot_f +================= +*/ +static void CG_ClientLevelShot_f( void ) +{ + cg.levelShot = qtrue; +} - if( !strcmp( cmd, "scores" ) ) - { - CG_ParseScores( ); - return; - } +/* +================= +CG_ServerMenu_f +================= +*/ +static void CG_ServerMenu_f( void ) +{ + if( trap_Argc( ) == 2 && !cg.demoPlayback ) + CG_Menu( atoi( CG_Argv( 1 ) ), 0 ); - if( !strcmp( cmd, "tinfo" ) ) - { - CG_ParseTeamInfo( ); - return; - } + if( trap_Argc( ) == 3 && !cg.demoPlayback ) + CG_Menu( atoi( CG_Argv( 1 ) ), atoi( CG_Argv( 2 ) ) ); +} - if( !strcmp( cmd, "map_restart" ) ) - { - CG_MapRestart( ); - return; - } +/* +================= +CG_ServerCloseMenus_f +================= +*/ +static void CG_ServerCloseMenus_f( void ) +{ + trap_SendConsoleCommand( "closemenus\n" ); +} - if( Q_stricmp( cmd, "remapShader" ) == 0 ) - { - if( trap_Argc( ) == 4 ) - trap_R_RemapShader( CG_Argv( 1 ), CG_Argv( 2 ), CG_Argv( 3 ) ); - } +/* +================= +CG_PoisonCloud_f +================= +*/ +static void CG_PoisonCloud_f( void ) +{ + cg.poisonedTime = cg.time; - // clientLevelShot is sent before taking a special screenshot for - // the menu system during development - if( !strcmp( cmd, "clientLevelShot" ) ) + if( CG_IsParticleSystemValid( &cg.poisonCloudPS ) ) { - cg.levelShot = qtrue; - return; + cg.poisonCloudPS = CG_SpawnNewParticleSystem( cgs.media.poisonCloudPS ); + CG_SetAttachmentCent( &cg.poisonCloudPS->attachment, &cg.predictedPlayerEntity ); + CG_AttachToCent( &cg.poisonCloudPS->attachment ); } +} - //the server has triggered a menu - if( !strcmp( cmd, "servermenu" ) ) - { - if( trap_Argc( ) == 2 && !cg.demoPlayback ) - CG_Menu( atoi( CG_Argv( 1 ) ), 0 ); - if( trap_Argc( ) == 3 && !cg.demoPlayback ) - CG_Menu( atoi( CG_Argv( 1 ) ), atoi( CG_Argv( 2 ) ) ); - return; - } +/* +================= +CG_PTRRequest_f +================= +*/ +static void CG_PTRRequest_f( void ) +{ + trap_SendClientCommand( va( "ptrcverify %d", CG_ReadPTRCode( ) ) ); +} - //the server thinks this client should close all menus - if( !strcmp( cmd, "serverclosemenus" ) ) - { - trap_SendConsoleCommand( "closemenus\n" ); - return; - } +/* +================= +CG_PTRIssue_f +================= +*/ +static void CG_PTRIssue_f( void ) +{ + if( trap_Argc( ) == 2 ) + CG_WritePTRCode( atoi( CG_Argv( 1 ) ) ); +} - //poison cloud effect needs to be reliable - if( !strcmp( cmd, "poisoncloud" ) ) - { - cg.poisonedTime = cg.time; +/* +================= +CG_PTRConfirm_f +================= +*/ +static void CG_PTRConfirm_f( void ) +{ + trap_SendConsoleCommand( "menu ptrc_popmenu\n" ); +} - if( CG_IsParticleSystemValid( &cg.poisonCloudPS ) ) - { - cg.poisonCloudPS = CG_SpawnNewParticleSystem( cgs.media.poisonCloudPS ); - CG_SetAttachmentCent( &cg.poisonCloudPS->attachment, &cg.predictedPlayerEntity ); - CG_AttachToCent( &cg.poisonCloudPS->attachment ); - } +static consoleCommand_t svcommands[ ] = +{ + { "cp", CG_CenterPrint_f }, + { "cs", CG_ConfigStringModified }, + { "print", CG_Print_f }, + { "chat", CG_Chat_f }, + { "tchat", CG_Chat_f }, + { "scores", CG_ParseScores }, + { "tinfo", CG_ParseTeamInfo }, + { "map_restart", CG_MapRestart }, + { "clientLevelShot", CG_ClientLevelShot_f }, + { "servermenu", CG_ServerMenu_f }, + { "serverclosemenus", CG_ServerCloseMenus_f }, + { "poisoncloud", CG_PoisonCloud_f }, + { "voice", CG_ParseVoice }, + { "ptrcrequest", CG_PTRRequest_f }, + { "ptrcissue", CG_PTRIssue_f }, + { "ptrcconfirm", CG_PTRConfirm_f } +}; - return; - } +/* +================= +CG_ServerCommand - // server requests a ptrc - if( !strcmp( cmd, "ptrcrequest" ) ) - { - int code = CG_ReadPTRCode( ); +The string has been tokenized and can be retrieved with +Cmd_Argc() / Cmd_Argv() +================= +*/ +static void CG_ServerCommand( void ) +{ + const char *cmd; + int i; - trap_SendClientCommand( va( "ptrcverify %d", code ) ); - return; - } + cmd = CG_Argv( 0 ); - // server issues a ptrc - if( !strcmp( cmd, "ptrcissue" ) ) + for( i = 0; i < sizeof( svcommands ) / sizeof( svcommands[ 0 ] ); i++ ) { - if( trap_Argc( ) == 2 ) + if( !Q_stricmp( cmd, svcommands[ i ].cmd ) ) { - int code = atoi( CG_Argv( 1 ) ); - - CG_WritePTRCode( code ); + svcommands[ i ].function( ); + return; } - - return; - } - - // reply to ptrcverify - if( !strcmp( cmd, "ptrcconfirm" ) ) - { - trap_SendConsoleCommand( "menu ptrc_popmenu\n" ); - - return; } CG_Printf( "Unknown client game command: %s\n", cmd ); diff --git a/src/cgame/cg_syscalls.c b/src/cgame/cg_syscalls.c index b990ab8e..aa28d45d 100644 --- a/src/cgame/cg_syscalls.c +++ b/src/cgame/cg_syscalls.c @@ -347,7 +347,7 @@ void trap_R_AddPolyToScene( qhandle_t hShader , int numVerts, const polyVert_t * qboolean trap_R_inPVS( const vec3_t p1, const vec3_t p2 ) { - syscall( CG_R_INPVS, p1, p2 ); + return syscall( CG_R_INPVS, p1, p2 ); } void trap_R_AddPolysToScene( qhandle_t hShader , int numVerts, const polyVert_t *verts, int num ) diff --git a/src/game/g_admin.c b/src/game/g_admin.c index e712dfeb..375e560f 100644 --- a/src/game/g_admin.c +++ b/src/game/g_admin.c @@ -38,6 +38,15 @@ static char g_bfb[ 32000 ]; // note: list ordered alphabetically g_admin_cmd_t g_admin_cmds[ ] = { + {"adjustban", G_admin_adjustban, "b", + "change the duration or reason of a ban. duration is specified as " + "numbers followed by units 'w' (weeks), 'd' (days), 'h' (hours) or " + "'m' (minutes), or seconds if no units are specified. if the duration is" + " preceded by a + or -, the ban duration will be extended or shortened by" + " the specified amount", + "[^3ban#^7] (^5duration^7) (^5reason^7)" + }, + {"admintest", G_admin_admintest, "a", "display your current admin level", "" @@ -55,9 +64,10 @@ g_admin_cmd_t g_admin_cmds[ ] = {"ban", G_admin_ban, "b", "ban a player by IP and GUID with an optional expiration time and reason." - " time is seconds or suffix with 'w' - weeks, 'd' - days, 'h' - hours, " - "or 'm' - minutes", - "[^3name|slot#|IP^7] (^5time^7) (^5reason^7)" + " duration is specified as numbers followed by units 'w' (weeks), 'd' " + "(days), 'h' (hours) or 'm' (minutes), or seconds if no units are " + "specified", + "[^3name|slot#|IP^7] (^5duration^7) (^5reason^7)" }, {"cancelvote", G_admin_cancelvote, "c", @@ -165,7 +175,7 @@ g_admin_cmd_t g_admin_cmds[ ] = {"unban", G_admin_unban, "b", "unbans a player specified by the slot as seen in showbans", - "[^3ban slot#^7]" + "[^3ban#^7]" }, {"unlock", G_admin_unlock, "K", @@ -330,8 +340,7 @@ static qboolean admin_higher_guid( char *admin_guid, char *victim_guid ) { if( alevel < g_admin_admins[ i ]->level ) return qfalse; - if( strstr( g_admin_admins[ i ]->flags, va( "%c", ADMF_IMMUTABLE ) ) ) - return qfalse; + return !strstr( g_admin_admins[ i ]->flags, va( "%c", ADMF_IMMUTABLE ) ); } } return qtrue; @@ -729,8 +738,7 @@ static int admin_listadmins( gentity_t *ent, int start, char *search ) char name[ MAX_NAME_LENGTH ] = {""}; char name2[ MAX_NAME_LENGTH ] = {""}; char lname[ MAX_NAME_LENGTH ] = {""}; - char lname_fmt[ 5 ]; - int i,j; + int i, j; gentity_t *vic; int l = 0; qboolean dup = qfalse; @@ -756,17 +764,13 @@ static int admin_listadmins( gentity_t *ent, int start, char *search ) guid_stub[ j ] = '\0'; lname[ 0 ] = '\0'; - Q_strncpyz( lname_fmt, "%s", sizeof( lname_fmt ) ); for( j = 0; j < MAX_ADMIN_LEVELS && g_admin_levels[ j ]; j++ ) { if( g_admin_levels[ j ]->level == l ) { - G_DecolorString( g_admin_levels[ j ]->name, lname, sizeof( lname ) ); - Com_sprintf( lname_fmt, sizeof( lname_fmt ), "%%%is", - ( admin_level_maxname + strlen( g_admin_levels[ j ]->name ) - - strlen( lname ) ) ); - Com_sprintf( lname, sizeof( lname ), lname_fmt, - g_admin_levels[ j ]->name ); + Com_sprintf( lname, sizeof( lname ), va( "%%%is", + Q_PrintStrlen( g_admin_levels[ j ]->name ) - admin_level_maxname - + strlen( g_admin_levels[ j ]->name ) ), g_admin_levels[ j ]->name ); break; } } @@ -812,17 +816,13 @@ static int admin_listadmins( gentity_t *ent, int start, char *search ) guid_stub[ j ] = '\0'; lname[ 0 ] = '\0'; - Q_strncpyz( lname_fmt, "%s", sizeof( lname_fmt ) ); for( j = 0; j < MAX_ADMIN_LEVELS && g_admin_levels[ j ]; j++ ) { if( g_admin_levels[ j ]->level == g_admin_admins[ i ]->level ) { - G_DecolorString( g_admin_levels[ j ]->name, lname, sizeof( lname ) ); - Com_sprintf( lname_fmt, sizeof( lname_fmt ), "%%%is", - ( admin_level_maxname + strlen( g_admin_levels[ j ]->name ) - - strlen( lname ) ) ); - Com_sprintf( lname, sizeof( lname ), lname_fmt, - g_admin_levels[ j ]->name ); + Com_sprintf( lname, sizeof( lname ), va( "%%%is", + Q_PrintStrlen( g_admin_levels[ j ]->name ) - admin_level_maxname - + strlen( g_admin_levels[ j ]->name ) ), g_admin_levels[ j ]->name ); break; } } @@ -927,15 +927,15 @@ qboolean G_admin_cmd_check( gentity_t *ent, qboolean say ) command[ 0 ] = '\0'; G_SayArgv( 0, command, sizeof( command ) ); + if( !command[ 0 ] ) + return qfalse; if( !Q_stricmp( command, "say" ) || - ( G_admin_permission( ent, ADMF_TEAMCHAT_CMD ) && - ( !Q_stricmp( command, "say_team" ) ) ) ) + ( !Q_stricmp( command, "say_team" ) && + G_admin_permission( ent, ADMF_TEAMCHAT_CMD ) ) ) { skip = 1; G_SayArgv( 1, command, sizeof( command ) ); } - if( !command[ 0 ] ) - return qfalse; if( command[ 0 ] == '!' ) { @@ -954,7 +954,7 @@ qboolean G_admin_cmd_check( gentity_t *ent, qboolean say ) if( admin_command_permission( ent, cmd ) ) { // flooding say will have already been accounted for in ClientCommand - if( !say && G_FloodLimited( ent ) ) + if( ent && !say && G_FloodLimited( ent ) ) return qtrue; trap_SendConsoleCommand( EXEC_APPEND, g_admin_commands[ i ]->exec ); admin_log( ent, cmd, skip ); @@ -975,7 +975,7 @@ qboolean G_admin_cmd_check( gentity_t *ent, qboolean say ) if( G_admin_permission( ent, g_admin_cmds[ i ].flag[ 0 ] ) ) { // flooding say will have already been accounted for in ClientCommand - if( !say && G_FloodLimited( ent ) ) + if( ent && !say && G_FloodLimited( ent ) ) return qtrue; g_admin_cmds[ i ].handler( ent, skip ); admin_log( ent, cmd, skip ); @@ -1314,14 +1314,12 @@ qboolean G_admin_readconfig( gentity_t *ent, int skiparg ) admin_default_levels(); else { - char n[ MAX_NAME_LENGTH ] = {""}; - // max printable name length for formatting for( i = 0; i < MAX_ADMIN_LEVELS && g_admin_levels[ i ]; i++ ) { - G_DecolorString( l->name, n, sizeof( n ) ); - if( strlen( n ) > admin_level_maxname ) - admin_level_maxname = strlen( n ); + len = Q_PrintStrlen( l->name ); + if( len > admin_level_maxname ) + admin_level_maxname = len; } } @@ -1578,6 +1576,36 @@ static qboolean admin_create_ban( gentity_t *ent, return qtrue; } +int G_admin_parse_time( const char *time ) +{ + int seconds = 0, num = 0; + while( *time ) + { + if( !isdigit( *time ) ) + return -1; + while( isdigit( *time ) ) + { + num = num * 10 + *time++ - '0'; + continue; + } + if( !*time ) + break; + switch( *time++ ) + { + case 'w': num *= 7; + case 'd': num *= 24; + case 'h': num *= 60; + case 'm': num *= 60; + case 's': break; + default: return -1; + } + seconds += num; + num = 0; + } + if( num ) + seconds += num; + return seconds; +} qboolean G_admin_kick( gentity_t *ent, int skiparg ) { @@ -1615,16 +1643,14 @@ qboolean G_admin_kick( gentity_t *ent, int skiparg ) ADMP( "^3!kick: ^7disconnecting the host would end the game\n" ); return qfalse; } - if( g_adminTempBan.integer > 0 ) - { - admin_create_ban( ent, - vic->client->pers.netname, - vic->client->pers.guid, - vic->client->pers.ip, g_adminTempBan.integer, - "automatic temp ban created by kick" ); - if( g_admin.string[ 0 ] ) - admin_writeconfig(); - } + admin_create_ban( ent, + vic->client->pers.netname, + vic->client->pers.guid, + vic->client->pers.ip, + G_admin_parse_time( va( "1s%s", g_adminTempBan.string ) ), + ( *reason ) ? reason : "kicked by admin" ); + if( g_admin.string[ 0 ] ) + admin_writeconfig(); trap_SendServerCommand( pids[ 0 ], va( "disconnect \"You have been kicked.\n%s^7\nreason:\n%s\"", @@ -1642,11 +1668,10 @@ qboolean G_admin_ban( gentity_t *ent, int skiparg ) { int seconds; char search[ MAX_NAME_LENGTH ]; - char secs[ 7 ]; + char secs[ MAX_TOKEN_CHARS ]; char *reason; int minargc; char duration[ 32 ]; - int modifier = 1; int logmatch = -1, logmatches = 0; int i, j; qboolean exactmatch = qfalse; @@ -1670,32 +1695,14 @@ qboolean G_admin_ban( gentity_t *ent, int skiparg ) } if( G_SayArgc() < minargc ) { - ADMP( "^3!ban: ^7usage: !ban [name|slot|ip] [seconds] [reason]\n" ); + ADMP( "^3!ban: ^7usage: !ban [name|slot|ip] [duration] [reason]\n" ); return qfalse; } G_SayArgv( 1 + skiparg, search, sizeof( search ) ); G_SanitiseString( search, s2, sizeof( s2 ) ); G_SayArgv( 2 + skiparg, secs, sizeof( secs ) ); - // support "w" (weeks), "d" (days), "h" (hours), and "m" (minutes) modifiers - if( secs[ 0 ] ) - { - int lastchar = strlen( secs ) - 1; - if( secs[ lastchar ] == 'w' ) - modifier = 60 * 60 * 24 * 7; - else if( secs[ lastchar ] == 'd' ) - modifier = 60 * 60 * 24; - else if( secs[ lastchar ] == 'h' ) - modifier = 60 * 60; - else if( secs[ lastchar ] == 'm' ) - modifier = 60; - else if( !isdigit( secs[ lastchar ] ) ) - secs[ lastchar ] = '\0'; - } - seconds = atoi( secs ); - if( seconds > 0 ) - seconds *= modifier; - + seconds = G_admin_parse_time( secs ); if( seconds <= 0 ) { if( G_admin_permission( ent, ADMF_CAN_PERM_BAN ) ) @@ -1704,7 +1711,7 @@ qboolean G_admin_ban( gentity_t *ent, int skiparg ) } else { - ADMP( "^3!ban: ^7ban time must be positive\n" ); + ADMP( "^3!ban: ^7ban duration must be positive\n" ); return qfalse; } reason = G_SayConcatArgs( 2 + skiparg ); @@ -1829,7 +1836,7 @@ qboolean G_admin_ban( gentity_t *ent, int skiparg ) if( g_admin_namelog[ logmatch ]->slot == -1 ) { // client is already disconnected so stop here - AP( va( "print \"^3!ban:^7 %s^7 has been banned by %s^7 " + AP( va( "print \"^3!ban:^7 %s^7 has been banned by %s^7, " "duration: %s, reason: %s\n\"", g_admin_namelog[ logmatch ]->name[ 0 ], ( ent ) ? ent->client->pers.netname : "console", @@ -1846,7 +1853,7 @@ qboolean G_admin_ban( gentity_t *ent, int skiparg ) ( *reason ) ? reason : "kicked by admin" ) ); trap_DropClient( g_admin_namelog[ logmatch ]->slot, - va( "has been banned by %s^7 duration: %s, reason: %s", + va( "has been banned by %s^7, duration: %s, reason: %s", ( ent ) ? ent->client->pers.netname : "console", duration, ( *reason ) ? reason : "banned by admin" ) ); @@ -1856,23 +1863,18 @@ qboolean G_admin_ban( gentity_t *ent, int skiparg ) qboolean G_admin_unban( gentity_t *ent, int skiparg ) { int bnum; - char bs[ 4 ]; + char bs[ 5 ]; if( G_SayArgc() < 2 + skiparg ) { - ADMP( "^3!unban: ^7usage: !unban [ban #]\n" ); + ADMP( "^3!unban: ^7usage: !unban [ban#]\n" ); return qfalse; } G_SayArgv( 1 + skiparg, bs, sizeof( bs ) ); bnum = atoi( bs ); - if( bnum < 1 ) - { - ADMP( "^3!unban: ^7invalid ban #\n" ); - return qfalse; - } - if( !g_admin_bans[ bnum - 1 ] ) + if( bnum < 1 || bnum > MAX_ADMIN_BANS || !g_admin_bans[ bnum - 1 ] ) { - ADMP( "^3!unban: ^7invalid ban #\n" ); + ADMP( "^3!unban: ^7invalid ban#\n" ); return qfalse; } g_admin_bans[ bnum - 1 ]->expires = trap_RealTime( NULL ); @@ -1885,6 +1887,92 @@ qboolean G_admin_unban( gentity_t *ent, int skiparg ) return qtrue; } +qboolean G_admin_adjustban( gentity_t *ent, int skiparg ) +{ + int bnum; + int length; + int expires; + int time = trap_RealTime( NULL ); + char duration[ 32 ] = {""}; + char *reason; + char bs[ 5 ]; + char secs[ MAX_TOKEN_CHARS ]; + char mode = '\0'; + g_admin_ban_t *ban; + + if( G_SayArgc() < 3 + skiparg ) + { + ADMP( "^3!adjustban: ^7usage: !adjustban [ban#] [duration] [reason]\n" ); + return qfalse; + } + G_SayArgv( 1 + skiparg, bs, sizeof( bs ) ); + bnum = atoi( bs ); + if( bnum < 1 || bnum > MAX_ADMIN_BANS || !g_admin_bans[ bnum - 1 ] ) + { + ADMP( "^3!adjustban: ^7invalid ban#\n" ); + return qfalse; + } + ban = g_admin_bans[ bnum - 1 ]; + + G_SayArgv( 2 + skiparg, secs, sizeof( secs ) ); + if( secs[ 0 ] == '+' || secs[ 0 ] == '-' ) + mode = secs[ 0 ]; + length = G_admin_parse_time( &secs[ mode ? 1 : 0 ] ); + if( length < 0 ) + skiparg--; + else + { + if( length ) + { + if( ban->expires == 0 && mode ) + { + ADMP( "^3!adjustban: ^7new duration must be explicit\n" ); + return qfalse; + } + if( mode == '+' ) + expires = ban->expires + length; + else if( mode == '-' ) + expires = ban->expires - length; + else + expires = time + length; + if( expires <= time ) + { + ADMP( "^3!adjustban: ^7ban duration must be positive\n" ); + return qfalse; + } + } + else if( G_admin_permission( ent, ADMF_CAN_PERM_BAN ) ) + expires = 0; + else + { + ADMP( "^3!adjustban: ^7ban duration must be positive\n" ); + return qfalse; + } + + ban->expires = expires; + G_admin_duration( ( expires ) ? expires - time : -1, duration, + sizeof( duration ) ); + } + reason = G_SayConcatArgs( 3 + skiparg ); + if( *reason ) + Q_strncpyz( ban->reason, reason, sizeof( ban->reason ) ); + AP( va( "print \"^3!adjustban: ^7ban #%d for %s^7 has been updated by %s^7 " + "%s%s%s%s%s\n\"", + bnum, + ban->name, + ( ent ) ? ent->client->pers.netname : "console", + ( length >= 0 ) ? "duration: " : "", + duration, + ( length >= 0 && *reason ) ? ", " : "", + ( *reason ) ? "reason: " : "", + reason ) ); + if( ent ) + Q_strncpyz( ban->banner, ent->client->pers.netname, sizeof( ban->banner ) ); + if( g_admin.string[ 0 ] ) + admin_writeconfig(); + return qtrue; +} + qboolean G_admin_putteam( gentity_t *ent, int skiparg ) { int pids[ MAX_CLIENTS ], found; @@ -2354,12 +2442,11 @@ qboolean G_admin_listplayers( gentity_t *ent, int skiparg ) qboolean G_admin_showbans( gentity_t *ent, int skiparg ) { int i, found = 0; - int max = 0, count; + int max = -1, count; int t; char duration[ 32 ]; - char name_fmt[ 32 ] = { "%s" }; - char banner_fmt[ 32 ] = { "%s" }; int max_name = 1, max_banner = 1; + int len; int secs; int start = 0; char skip[ 11 ]; @@ -2402,11 +2489,16 @@ qboolean G_admin_showbans( gentity_t *ent, int skiparg ) } } - if( start >= MAX_ADMIN_BANS || start < 0 ) + if( start < 0 ) start = 0; - for( i = start, count = 0; i < MAX_ADMIN_BANS && g_admin_bans[ i ] && - count < MAX_ADMIN_SHOWBANS; i++ ) + if( start > max ) + { + ADMP( va( "^3!showbans: ^7%d is the last valid ban\n", max + 1 ) ); + return qfalse; + } + + for( i = start, count = 0; i <= max && count < MAX_ADMIN_SHOWBANS; i++ ) { if( g_admin_bans[ i ]->expires != 0 && ( g_admin_bans[ i ]->expires - t ) < 1 ) @@ -2414,24 +2506,17 @@ qboolean G_admin_showbans( gentity_t *ent, int skiparg ) count++; - G_DecolorString( g_admin_bans[ i ]->name, n1, sizeof( n1 ) ); - G_DecolorString( g_admin_bans[ i ]->banner, n2, sizeof( n2 ) ); - - if( strlen( n1 ) > max_name ) - max_name = strlen( n1 ); + len = Q_PrintStrlen( g_admin_bans[ i ]->name ); + if( len > max_name ) + max_name = len; - if( strlen( n2 ) > max_banner ) - max_banner = strlen( n2 ); + len = Q_PrintStrlen( g_admin_bans[ i ]->banner ); + if( len > max_banner ) + max_banner = len; } - if( start > max ) - { - ADMP( va( "^3!showbans: ^7%d is the last valid ban\n", max + 1 ) ); - return qfalse; - } ADMBP_begin(); - for( i = start, count = 0; i < MAX_ADMIN_BANS && g_admin_bans[ i ] && - count < MAX_ADMIN_SHOWBANS; i++ ) + for( i = start, count = 0; i <= max && count < MAX_ADMIN_SHOWBANS; i++ ) { if( g_admin_bans[ i ]->expires != 0 && ( g_admin_bans[ i ]->expires - t ) < 1 ) @@ -2456,15 +2541,12 @@ qboolean G_admin_showbans( gentity_t *ent, int skiparg ) secs = ( g_admin_bans[ i ]->expires - t ); G_admin_duration( secs, duration, sizeof( duration ) ); - G_DecolorString( g_admin_bans[ i ]->name, n1, sizeof( n1 ) ); - Com_sprintf( name_fmt, sizeof( name_fmt ), "%%%is", - ( max_name + strlen( g_admin_bans[ i ]->name ) - strlen( n1 ) ) ); - Com_sprintf( n1, sizeof( n1 ), name_fmt, g_admin_bans[ i ]->name ); - - G_DecolorString( g_admin_bans[ i ]->banner, n2, sizeof( n2 ) ); - Com_sprintf( banner_fmt, sizeof( banner_fmt ), "%%%is", - ( max_banner + strlen( g_admin_bans[ i ]->banner ) - strlen( n2 ) ) ); - Com_sprintf( n2, sizeof( n2 ), banner_fmt, g_admin_bans[ i ]->banner ); + Com_sprintf( n1, sizeof( n1 ), va( "%%%is", + Q_PrintStrlen( g_admin_bans[ i ]->name ) - max_name - + strlen( g_admin_bans[ i ]->name ) ), g_admin_bans[ i ]->name ); + Com_sprintf( n2, sizeof( n2 ), va( "%%%is", + Q_PrintStrlen( g_admin_bans[ i ]->banner ) - max_banner - + strlen( g_admin_bans[ i ]->banner ) ), g_admin_bans[ i ]->banner ); ADMBP( va( "%4i %s^7 %-15s %-8s %s^7 %-10s\n \\__ %s\n", ( i + 1 ), @@ -2481,7 +2563,7 @@ qboolean G_admin_showbans( gentity_t *ent, int skiparg ) i, max + 1, found ) ); - if( i + MAX_ADMIN_SHOWBANS < max ) + if( i <= max ) ADMBP( va( " run !showbans %d to see more", i + 1 ) ); ADMBP( "\n" ); ADMBP_end(); @@ -2840,7 +2922,7 @@ qboolean G_admin_namelog( gentity_t *ent, int skiparg ) ADMBP_begin(); for( i = 0; i < MAX_ADMIN_NAMELOGS && g_admin_namelog[ i ]; i++ ) { - if( search[0] ) + if( search[ 0 ] ) { found = qfalse; for( j = 0; j < MAX_ADMIN_NAMELOG_NAMES && diff --git a/src/game/g_admin.h b/src/game/g_admin.h index 87475b02..ee0f6ad7 100644 --- a/src/game/g_admin.h +++ b/src/game/g_admin.h @@ -145,6 +145,7 @@ int G_admin_level( gentity_t *ent ); qboolean G_admin_time( gentity_t *ent, int skiparg ); qboolean G_admin_setlevel( gentity_t *ent, int skiparg ); qboolean G_admin_kick( gentity_t *ent, int skiparg ); +qboolean G_admin_adjustban( gentity_t *ent, int skiparg ); qboolean G_admin_ban( gentity_t *ent, int skiparg ); qboolean G_admin_unban( gentity_t *ent, int skiparg ); qboolean G_admin_putteam( gentity_t *ent, int skiparg ); diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c index 86a26483..c015a210 100644 --- a/src/game/g_cmds.c +++ b/src/game/g_cmds.c @@ -1110,7 +1110,7 @@ void Cmd_CallVote_f( gentity_t *ent ) char arg1[ MAX_STRING_TOKENS ]; char arg2[ MAX_NAME_LENGTH ]; int clientNum = -1; - char name[ MAX_NETNAME ]; + char name[ MAX_NAME_LENGTH ]; if( !g_allowVote.integer ) { @@ -1207,8 +1207,8 @@ void Cmd_CallVote_f( gentity_t *ent ) // use ip in case this player disconnects before the vote ends Com_sprintf( level.voteString, sizeof( level.voteString ), - "!ban %s %d vote kick", level.clients[ clientNum ].pers.ip, - g_adminTempBan.integer + 1 ); + "!ban %s \"1s%s\" vote kick", level.clients[ clientNum ].pers.ip, + g_adminTempBan.string ); Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Kick player \'%s\'", name ); } @@ -1344,7 +1344,7 @@ void Cmd_CallTeamVote_f( gentity_t *ent ) char arg1[ MAX_STRING_TOKENS ]; char arg2[ MAX_NAME_LENGTH ]; int clientNum = -1; - char name[ MAX_NETNAME ]; + char name[ MAX_NAME_LENGTH ]; team = ent->client->pers.teamSelection; @@ -1447,8 +1447,8 @@ void Cmd_CallTeamVote_f( gentity_t *ent ) // use ip in case this player disconnects before the vote ends Com_sprintf( level.teamVoteString[ cs_offset ], sizeof( level.teamVoteString[ cs_offset ] ), - "!ban %s %d team vote kick", level.clients[ clientNum ].pers.ip, - g_adminTempBan.integer + 1 ); + "!ban %s \"1s%s\" team vote kick", level.clients[ clientNum ].pers.ip, + g_adminTempBan.string ); Com_sprintf( level.teamVoteDisplayString[ cs_offset ], sizeof( level.teamVoteDisplayString[ cs_offset ] ), "Kick player '%s'", name ); @@ -3224,8 +3224,6 @@ int G_SayArgc( void ) qboolean G_SayArgv( int n, char *buffer, int bufferLength ) { - int bc = 0; - int c = 0; char *s; if( bufferLength < 1 ) @@ -3233,47 +3231,40 @@ qboolean G_SayArgv( int n, char *buffer, int bufferLength ) if( n < 0 ) return qfalse; s = ConcatArgs( 0 ); - while( c < n ) + while( 1 ) { while( *s == ' ' ) s++; - if( !*s ) + if( !*s || n == 0 ) break; - c++; + n--; while( *s && *s != ' ' ) s++; } - if( c < n ) - return qfalse; - while( *s == ' ' ) - s++; - if( !*s ) + if( n > 0 ) return qfalse; //memccpy( buffer, s, ' ', bufferLength ); - while( bc < bufferLength - 1 && *s && *s != ' ' ) - buffer[ bc++ ] = *s++; - buffer[ bc ] = 0; + while( bufferLength > 1 && *s && *s != ' ' ) + *buffer++ = *s++; + *buffer = 0; return qtrue; } char *G_SayConcatArgs( int start ) { char *s; - int c = 0; s = ConcatArgs( 0 ); - while( c < start ) + while( 1 ) { while( *s == ' ' ) s++; - if( !*s ) + if( !*s || start == 0 ) break; - c++; + start--; while( *s && *s != ' ' ) s++; } - while( *s == ' ' ) - s++; return s; } diff --git a/src/game/g_local.h b/src/game/g_local.h index da99d44e..d94e99f9 100644 --- a/src/game/g_local.h +++ b/src/game/g_local.h @@ -277,8 +277,6 @@ typedef struct clientList_t ignoreList; } clientSession_t; -#define MAX_NETNAME 36 - // data to store details of clients that have abnormally disconnected typedef struct connectionRecord_s { @@ -299,7 +297,7 @@ typedef struct qboolean initialSpawn; // the first spawn should be at a cool location qboolean stickySpec; // don't stop spectating a player after they get killed qboolean pmoveFixed; // - char netname[ MAX_NETNAME ]; + char netname[ MAX_NAME_LENGTH ]; int maxHealth; // for handicapping int enterTime; // level.time the client entered the game int location; // player locations @@ -680,6 +678,7 @@ void G_ChangeTeam( gentity_t *ent, team_t newTeam ); void G_SanitiseString( char *in, char *out, int len ); void G_PrivateMessage( gentity_t *ent ); void Cmd_Test_f( gentity_t *ent ); +qboolean G_FloodLimited( gentity_t *ent ); // // g_physics.c diff --git a/src/game/g_main.c b/src/game/g_main.c index 37477980..fc0651ea 100644 --- a/src/game/g_main.c +++ b/src/game/g_main.c @@ -33,7 +33,6 @@ typedef struct int cvarFlags; int modificationCount; // for tracking changes qboolean trackChange; // track this variable, and announce if changed - qboolean teamShader; // track and if changed, update shader state } cvarTable_t; gentity_t g_entities[ MAX_GENTITIES ]; @@ -259,7 +258,7 @@ static cvarTable_t gameCvarTable[ ] = { &g_adminLog, "g_adminLog", "admin.log", CVAR_ARCHIVE, 0, qfalse }, { &g_adminParseSay, "g_adminParseSay", "1", CVAR_ARCHIVE, 0, qfalse }, { &g_adminNameProtect, "g_adminNameProtect", "1", CVAR_ARCHIVE, 0, qfalse }, - { &g_adminTempBan, "g_adminTempBan", "120", CVAR_ARCHIVE, 0, qfalse }, + { &g_adminTempBan, "g_adminTempBan", "2m", CVAR_ARCHIVE, 0, qfalse }, { &g_dretchPunt, "g_dretchPunt", "0", CVAR_ARCHIVE, 0, qfalse }, @@ -429,10 +428,6 @@ void G_FindTeams( void ) G_Printf( "%i teams with %i entities\n", c, c2 ); } -void G_RemapTeamShaders( void ) -{ -} - /* ================= @@ -443,7 +438,6 @@ void G_RegisterCvars( void ) { int i; cvarTable_t *cv; - qboolean remapped = qfalse; for( i = 0, cv = gameCvarTable; i < gameCvarTableSize; i++, cv++ ) { @@ -452,14 +446,8 @@ void G_RegisterCvars( void ) if( cv->vmCvar ) cv->modificationCount = cv->vmCvar->modificationCount; - - if( cv->teamShader ) - remapped = qtrue; } - if( remapped ) - G_RemapTeamShaders( ); - // check some things level.warmupModificationCount = g_warmup.modificationCount; } @@ -473,7 +461,6 @@ void G_UpdateCvars( void ) { int i; cvarTable_t *cv; - qboolean remapped = qfalse; for( i = 0, cv = gameCvarTable; i < gameCvarTableSize; i++, cv++ ) { @@ -492,15 +479,9 @@ void G_UpdateCvars( void ) // update serverinfo in case this cvar is passed to clients indirectly CalculateRanks( ); } - - if( cv->teamShader ) - remapped = qtrue; } } } - - if( remapped ) - G_RemapTeamShaders( ); } /* @@ -653,8 +634,6 @@ void G_InitGame( int levelTime, int randomSeed, int restart ) G_Printf( "-----------------------------------\n" ); - G_RemapTeamShaders( ); - // so the server counts the spawns without a client attached G_CountSpawns( ); @@ -790,20 +769,14 @@ void G_InitSpawnQueue( spawnQueue_t *sq ) ============ G_GetSpawnQueueLength -Return tha length of a spawn queue +Return the length of a spawn queue ============ */ int G_GetSpawnQueueLength( spawnQueue_t *sq ) { int length = sq->back - sq->front + 1; - while( length < 0 ) - length += MAX_CLIENTS; - - while( length >= MAX_CLIENTS ) - length -= MAX_CLIENTS; - - return length; + return length % MAX_CLIENTS; } /* diff --git a/src/ui/ui_atoms.c b/src/ui/ui_atoms.c index 822cecfd..58add010 100644 --- a/src/ui/ui_atoms.c +++ b/src/ui/ui_atoms.c @@ -103,111 +103,92 @@ static void UI_Cache_f( void ) Display_CacheAll(); } -/* -================= -UI_ConsoleCommand - -FIXME: lookup table -================= -*/ -qboolean UI_ConsoleCommand( int realTime ) +static void UI_Menu_f( void ) { - char * cmd; - char *arg1; - - uiInfo.uiDC.frameTime = realTime - uiInfo.uiDC.realTime; - uiInfo.uiDC.realTime = realTime; - - cmd = UI_Argv( 0 ); - - // ensure minimum menu data is available - //Menu_Cache(); - - if( Q_stricmp ( cmd, "ui_report" ) == 0 ) - { - UI_Report(); - return qtrue; - } - - if( Q_stricmp ( cmd, "ui_load" ) == 0 ) - { - UI_Load(); - return qtrue; - } - - if( Q_stricmp ( cmd, "remapShader" ) == 0 ) - { - if( trap_Argc() == 4 ) + if( Menu_Count( ) > 0 ) { - char shader1[MAX_QPATH]; - char shader2[MAX_QPATH]; - Q_strncpyz( shader1, UI_Argv( 1 ), sizeof( shader1 ) ); - Q_strncpyz( shader2, UI_Argv( 2 ), sizeof( shader2 ) ); - trap_R_RemapShader( shader1, shader2, UI_Argv( 3 ) ); - return qtrue; + trap_Key_SetCatcher( KEYCATCH_UI ); + Menus_ActivateByName( UI_Argv( 1 ) ); } - } +} - if( Q_stricmp ( cmd, "ui_cache" ) == 0 ) - { - UI_Cache_f(); - return qtrue; - } +static void UI_CloseMenus_f( void ) +{ + if( Menu_Count( ) > 0 ) + { + trap_Key_SetCatcher( trap_Key_GetCatcher( ) & ~KEYCATCH_UI ); + trap_Key_ClearStates( ); + trap_Cvar_Set( "cl_paused", "0" ); + Menus_CloseAll( ); + } +} - if( Q_stricmp ( cmd, "ui_teamOrders" ) == 0 ) - { - //UI_TeamOrdersMenu_f(); - return qtrue; - } +static void UI_MessageMode_f( void ) +{ + char *arg = UI_Argv( 0 ); - if( Q_stricmp( cmd, "ui_messagemode" ) == 0 ) - { - trap_Cvar_Set( "ui_sayBuffer", "" ); + trap_Cvar_Set( "ui_sayBuffer", "" ); uiInfo.chatTeam = qfalse; - trap_Key_SetCatcher( KEYCATCH_UI ); - Menus_CloseByName( "say" ); - Menus_CloseByName( "say_team" ); - Menus_ActivateByName( "say" ); - return qtrue; + switch( arg[ 11 ] ) + { + default: + case '\0': + // Global + uiInfo.chatTeam = qfalse; + uiInfo.chatTargetClientNum = -1; + break; + + case '2': + // Team + uiInfo.chatTeam = qtrue; + uiInfo.chatTargetClientNum = -1; + break; } - if( Q_stricmp( cmd, "ui_messagemode2" ) == 0 ) - { - trap_Cvar_Set( "ui_sayBuffer", "" ); - uiInfo.chatTargetClientNum = -1; - uiInfo.chatTeam = qtrue; + trap_Key_SetCatcher( KEYCATCH_UI ); + Menus_CloseByName( "say" ); + Menus_CloseByName( "say_team" ); - trap_Key_SetCatcher( KEYCATCH_UI ); - Menus_CloseByName( "say" ); - Menus_CloseByName( "say_team" ); + if( uiInfo.chatTeam ) Menus_ActivateByName( "say_team" ); - return qtrue; - } + else + Menus_ActivateByName( "say" ); +} - if( Q_stricmp ( cmd, "menu" ) == 0 ) - { - arg1 = UI_Argv( 1 ); +struct +{ + char *cmd; + void ( *function )( void ); +} commands[ ] = { + { "ui_load", UI_Load }, + { "ui_report", UI_Report }, + { "ui_cache", UI_Cache_f }, + { "messagemode", UI_MessageMode_f }, + { "messagemode2", UI_MessageMode_f }, + { "menu", UI_Menu_f }, + { "closemenus", UI_CloseMenus_f } +}; - if( Menu_Count( ) > 0 ) - { - trap_Key_SetCatcher( KEYCATCH_UI ); - Menus_ActivateByName( arg1 ); - return qtrue; - } - } +/* +================= +UI_ConsoleCommand +================= +*/ +qboolean UI_ConsoleCommand( int realTime ) +{ + char *cmd; + int i; + + uiInfo.uiDC.frameTime = realTime - uiInfo.uiDC.realTime; + uiInfo.uiDC.realTime = realTime; - if( Q_stricmp ( cmd, "closemenus" ) == 0 ) + cmd = UI_Argv( 0 ); + for( i = 0; i < sizeof( commands ) / sizeof( commands[ 0 ] ); i++ ) { - if( Menu_Count( ) > 0 ) + if( Q_stricmp( commands[ i ].cmd, cmd ) == 0 ) { - Menus_CloseAll( ); - if( Menu_Count( ) == 0 ) - { - trap_Key_SetCatcher( trap_Key_GetCatcher( ) & ~KEYCATCH_UI ); - trap_Key_ClearStates( ); - trap_Cvar_Set( "cl_paused", "0" ); - } + commands[ i ].function( ); } return qtrue; } |