diff options
author | M. Kristall <mkpdev@gmail.com> | 2010-02-25 16:18:33 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:17:27 +0000 |
commit | 8a75ae8f815a7e2067a8ebf19f20b39948d748ab (patch) | |
tree | bac6fca807a8311011991ae9d261c3f3605add34 | |
parent | 69f3a7fece69a9eee18e74f43b898a333d4969c6 (diff) |
* Refactor emoticon code
* Remove some redundant code
* Make an error non-fatal
* Formatting fixes
-rw-r--r-- | src/cgame/cg_main.c | 8 | ||||
-rw-r--r-- | src/cgame/cg_servercmds.c | 2 | ||||
-rw-r--r-- | src/game/bg_misc.c | 62 | ||||
-rw-r--r-- | src/game/bg_public.h | 2 | ||||
-rw-r--r-- | src/game/g_client.c | 12 | ||||
-rw-r--r-- | src/game/g_cmds.c | 43 | ||||
-rw-r--r-- | src/game/g_local.h | 4 | ||||
-rw-r--r-- | src/game/g_main.c | 2 | ||||
-rw-r--r-- | src/game/g_team.c | 23 | ||||
-rw-r--r-- | src/game/g_utils.c | 25 | ||||
-rw-r--r-- | src/qcommon/q_shared.h | 9 | ||||
-rw-r--r-- | src/ui/ui_main.c | 9 | ||||
-rw-r--r-- | src/ui/ui_shared.c | 55 | ||||
-rw-r--r-- | src/ui/ui_shared.h | 4 |
14 files changed, 95 insertions, 165 deletions
diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c index c7b69852..dd08e324 100644 --- a/src/cgame/cg_main.c +++ b/src/cgame/cg_main.c @@ -1698,16 +1698,16 @@ void CG_AssetCache( void ) if( cg_emoticons.integer ) { cgDC.Assets.emoticonCount = BG_LoadEmoticons( cgDC.Assets.emoticons, - cgDC.Assets.emoticonWidths ); + MAX_EMOTICONS ); } else cgDC.Assets.emoticonCount = 0; for( i = 0; i < cgDC.Assets.emoticonCount; i++ ) { - cgDC.Assets.emoticonShaders[ i ] = trap_R_RegisterShaderNoMip( - va( "emoticons/%s_%dx1.tga", cgDC.Assets.emoticons[ i ], - cgDC.Assets.emoticonWidths[ i ] ) ); + cgDC.Assets.emoticons[ i ].shader = trap_R_RegisterShaderNoMip( + va( "emoticons/%s_%dx1.tga", cgDC.Assets.emoticons[ i ].name, + cgDC.Assets.emoticons[ i ].width ) ); } } diff --git a/src/cgame/cg_servercmds.c b/src/cgame/cg_servercmds.c index 7af79e9c..f0fb60a6 100644 --- a/src/cgame/cg_servercmds.c +++ b/src/cgame/cg_servercmds.c @@ -91,7 +91,7 @@ static void CG_ParseTeamInfo( void ) client = atoi( CG_Argv( i * 5 + 1 ) ); if( client < 0 || client >= MAX_CLIENTS ) { - CG_Error( "CG_ParseTeamInfo: bad client number: %d", client ); + CG_Printf( "[skipnotify]CG_ParseTeamInfo: bad client number: %d", client ); return; } diff --git a/src/game/bg_misc.c b/src/game/bg_misc.c index 0859a7af..0c23befc 100644 --- a/src/game/bg_misc.c +++ b/src/game/bg_misc.c @@ -3875,17 +3875,14 @@ weapon_t BG_PrimaryWeapon( int stats[ ] ) BG_LoadEmoticons ============ */ -int BG_LoadEmoticons( char names[ ][ MAX_EMOTICON_NAME_LEN ], int widths[ ] ) +int BG_LoadEmoticons( emoticon_t *emoticons, int num ) { int numFiles; char fileList[ MAX_EMOTICONS * ( MAX_EMOTICON_NAME_LEN + 9 ) ] = {""}; int i; char *filePtr; int fileLen; - char emoticon[ MAX_EMOTICON_NAME_LEN + 9 ] = {""}; - int loaded = 0; int count; - int width = 0; numFiles = trap_FS_GetFileList( "emoticons", "x1.tga", fileList, sizeof( fileList ) ); @@ -3896,65 +3893,38 @@ int BG_LoadEmoticons( char names[ ][ MAX_EMOTICON_NAME_LEN ], int widths[ ] ) filePtr = fileList; fileLen = 0; count = 0; - for( i = 0; i < numFiles; i++, filePtr += fileLen + 1 ) + for( i = 0; i < numFiles && count < num; i++, filePtr += fileLen + 1 ) { - if( count >= MAX_EMOTICONS ) - { - count++; - continue; - } - fileLen = strlen( filePtr ); - if( fileLen > MAX_EMOTICON_NAME_LEN + 8 ) + if( fileLen < 9 || filePtr[ fileLen - 8 ] != '_' || + filePtr[ fileLen - 7 ] < '1' || filePtr[ fileLen - 7 ] > '9' ) { - Com_Printf( S_COLOR_YELLOW "WARNING: MAX_EMOTICON_NAME_LEN is %d. " - "skipping \"%s\", filename too long", MAX_EMOTICON_NAME_LEN, filePtr ); - continue; - } - if( fileLen < 9 ) - { - Com_Printf( S_COLOR_YELLOW "WARNING: skipping \"%s\", filename too short", + Com_Printf( S_COLOR_YELLOW "skipping invalidly named emoticon \"%s\"\n", filePtr ); continue; } - if( !trap_FS_FOpenFile( va( "emoticons/%s", filePtr ), NULL, FS_READ ) ) + if( fileLen - 8 > MAX_EMOTICON_NAME_LEN ) { - Com_Printf( S_COLOR_YELLOW "WARNING: BG_LoadEmoticons(): detected " - " an unreadable .tga file name \"emoticons/%s\" in emoticon detection", - filePtr ); - break; - } - - Q_strncpyz( emoticon, filePtr, sizeof( emoticon ) ); - - if( emoticon[ fileLen - 8 ] != '_' ) - { - Com_Printf( S_COLOR_YELLOW "WARNING: skipping \"%s\", filename invalid", - filePtr ); + Com_Printf( S_COLOR_YELLOW "emoticon file name \"%s\" too long (>%d)\n", + filePtr, MAX_EMOTICON_NAME_LEN + 8 ); continue; } - - width = emoticon[ fileLen - 7 ] - '0'; - - if( width < 1 || width > 9 ) + if( !trap_FS_FOpenFile( va( "emoticons/%s", filePtr ), NULL, FS_READ ) ) { - Com_Printf( S_COLOR_YELLOW "WARNING: skipping \"%s\", invalid width", - filePtr ); + Com_Printf( S_COLOR_YELLOW "could not open \"emoticons/%s\"\n", filePtr ); continue; } - emoticon[ fileLen - 8 ] = '\0'; - - Q_strncpyz( names[ count ], emoticon, sizeof( names[ count ] ) ); - if( widths ) - widths[ count ] = width; + Q_strncpyz( emoticons[ count ].name, filePtr, fileLen - 8 + 1 ); +#ifndef GAME + emoticons[ count ].width = filePtr[ fileLen - 7 ] - '0'; +#endif count++; - loaded = count; } Com_Printf( "Loaded %d of %d emoticons (MAX_EMOTICONS is %d)\n", - loaded, count, MAX_EMOTICONS ); - return loaded; + count, numFiles, MAX_EMOTICONS ); + return count; } /* diff --git a/src/game/bg_public.h b/src/game/bg_public.h index c9c752e0..6fd949ff 100644 --- a/src/game/bg_public.h +++ b/src/game/bg_public.h @@ -1302,7 +1302,7 @@ voiceTrack_t *BG_VoiceTrackFind( voiceTrack_t *head, team_t team, class_t class, weapon_t weapon, int enthusiasm, int *trackNum ); -int BG_LoadEmoticons( char names[ ][ MAX_EMOTICON_NAME_LEN ], int widths[ ] ); +int BG_LoadEmoticons( emoticon_t *emoticons, int num ); char *BG_TeamName( team_t team ); diff --git a/src/game/g_client.c b/src/game/g_client.c index f3426d42..b6f1ab61 100644 --- a/src/game/g_client.c +++ b/src/game/g_client.c @@ -785,7 +785,7 @@ static qboolean G_IsEmoticon( const char *s, qboolean *escaped ) { for( j = 0; j < level.emoticonCount; j++ ) { - if( !Q_stricmp( emoticon, level.emoticons[ j ] ) ) + if( !Q_stricmp( emoticon, level.emoticons[ j ].name ) ) { *escaped = escape; return qtrue; @@ -1014,16 +1014,16 @@ void ClientUserinfoChanged( int clientNum ) if( strcmp( oldname, newname ) ) { if( client->pers.nameChangeTime && - ( level.time - client->pers.nameChangeTime ) - <= ( g_minNameChangePeriod.value * 1000 ) ) + level.time - client->pers.nameChangeTime <= + g_minNameChangePeriod.value * 1000 ) { trap_SendServerCommand( ent - g_entities, va( "print \"Name change spam protection (g_minNameChangePeriod = %d)\n\"", g_minNameChangePeriod.integer ) ); revertName = qtrue; } - else if( g_maxNameChanges.integer > 0 - && client->pers.nameChanges >= g_maxNameChanges.integer ) + else if( g_maxNameChanges.integer > 0 && + client->pers.nameChanges >= g_maxNameChanges.integer ) { trap_SendServerCommand( ent - g_entities, va( "print \"Maximum name changes reached (g_maxNameChanges = %d)\n\"", @@ -1154,7 +1154,7 @@ void ClientUserinfoChanged( int clientNum ) client->pers.teamInfo = qtrue; else client->pers.teamInfo = qfalse; - + s = Info_ValueForKey( userinfo, "cg_unlagged" ); if( !s[0] || atoi( s ) != 0 ) client->pers.useUnlagged = qtrue; diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c index 4c3067ed..d6774950 100644 --- a/src/game/g_cmds.c +++ b/src/game/g_cmds.c @@ -32,29 +32,10 @@ Remove color codes and non-alphanumeric characters from a string */ void G_SanitiseString( char *in, char *out, int len ) { - qboolean skip = qtrue; - int spaces = 0; - len--; while( *in && len > 0 ) { - // strip leading white space - if( *in == ' ' ) - { - if( skip ) - { - in++; - continue; - } - spaces++; - } - else - { - spaces = 0; - skip = qfalse; - } - if( Q_IsColorString( in ) ) { in += 2; // skip color code @@ -68,7 +49,6 @@ void G_SanitiseString( char *in, char *out, int len ) } in++; } - out -= spaces; *out = 0; } @@ -551,10 +531,6 @@ void Cmd_Team_f( gentity_t *ent ) int aliens = level.numAlienClients; int humans = level.numHumanClients; - // stop team join spam - if( level.time - ent->client->pers.teamChangeTime < 1000 ) - return; - if( oldteam == TEAM_ALIENS ) aliens--; else if( oldteam == TEAM_HUMANS ) @@ -571,8 +547,8 @@ void Cmd_Team_f( gentity_t *ent ) if( !s[ 0 ] ) { - trap_SendServerCommand( ent-g_entities, va( "print \"team: %i\n\"", - oldteam ) ); + trap_SendServerCommand( ent-g_entities, va( "print \"team: %s\n\"", + BG_TeamName( oldteam ) ) ); return; } @@ -782,19 +758,6 @@ static void Cmd_SayArea_f( gentity_t *ent ) vec3_t mins, maxs; char *msg; - if( ent->client->pers.teamSelection == TEAM_NONE ) - { - G_TriggerMenu( ent - g_entities, MN_CMD_TEAM ); - return; - } - - if( ent->client->ps.stats[ STAT_HEALTH ] <= 0 || - ent->client->sess.spectatorState != SPECTATOR_NOT ) - { - G_TriggerMenu( ent - g_entities, MN_CMD_LIVING ); - return; - } - if( trap_Argc( ) < 2 ) { ADMP( "usage: say_area [message]\n" ); @@ -3213,7 +3176,7 @@ void Cmd_PrivateMessage_f( gentity_t *ent ) return; } - if( !Q_stricmp( cmd, "mt" ) || !Q_stricmp( cmd, "/mt" ) ) + if( !Q_stricmp( cmd, "mt" ) ) teamonly = qtrue; trap_Argv( 1, name, sizeof( name ) ); diff --git a/src/game/g_local.h b/src/game/g_local.h index b317bba9..83e0c557 100644 --- a/src/game/g_local.h +++ b/src/game/g_local.h @@ -631,7 +631,7 @@ typedef struct voice_t *voices; - char emoticons[ MAX_EMOTICONS ][ MAX_EMOTICON_NAME_LEN ]; + emoticon_t emoticons[ MAX_EMOTICONS ]; int emoticonCount; } level_locals_t; @@ -784,7 +784,6 @@ int G_ParticleSystemIndex( char *name ); int G_ShaderIndex( char *name ); int G_ModelIndex( char *name ); int G_SoundIndex( char *name ); -void G_TeamCommand( team_t team, char *cmd ); void G_KillBox (gentity_t *ent); gentity_t *G_Find (gentity_t *from, int fieldofs, const char *match); gentity_t *G_PickTarget (char *targetname); @@ -992,6 +991,7 @@ void G_RunClient( gentity_t *ent ); // g_team.c // team_t G_TeamFromString( char *str ); +void G_TeamCommand( team_t team, char *cmd ); qboolean OnSameTeam( gentity_t *ent1, gentity_t *ent2 ); void G_LeaveTeam( gentity_t *self ); void G_ChangeTeam( gentity_t *ent, team_t newTeam ); diff --git a/src/game/g_main.c b/src/game/g_main.c index 0e1df90e..0a2a37bd 100644 --- a/src/game/g_main.c +++ b/src/game/g_main.c @@ -582,7 +582,7 @@ void G_InitGame( int levelTime, int randomSeed, int restart ) trap_LocateGameData( level.gentities, level.num_entities, sizeof( gentity_t ), &level.clients[ 0 ].ps, sizeof( level.clients[ 0 ] ) ); - level.emoticonCount = BG_LoadEmoticons( level.emoticons, NULL ); + level.emoticonCount = BG_LoadEmoticons( level.emoticons, MAX_EMOTICONS ); trap_SetConfigstring( CS_INTERMISSION, "0" ); diff --git a/src/game/g_team.c b/src/game/g_team.c index 3f95f533..dec34e9a 100644 --- a/src/game/g_team.c +++ b/src/game/g_team.c @@ -63,6 +63,29 @@ team_t G_TeamFromString( char *str ) } /* +================ +G_TeamCommand + +Broadcasts a command to only a specific team +================ +*/ +void G_TeamCommand( team_t team, char *cmd ) +{ + int i; + + for( i = 0 ; i < level.maxclients ; i++ ) + { + if( level.clients[ i ].pers.connected == CON_CONNECTED ) + { + if( level.clients[ i ].pers.teamSelection == team || + ( level.clients[ i ].pers.teamSelection == TEAM_NONE && + G_admin_permission( &g_entities[ i ], ADMF_SPEC_ALLCHAT ) ) ) + trap_SendServerCommand( i, cmd ); + } + } +} + +/* ============== OnSameTeam ============== diff --git a/src/game/g_utils.c b/src/game/g_utils.c index 00ec630a..9de86337 100644 --- a/src/game/g_utils.c +++ b/src/game/g_utils.c @@ -144,31 +144,6 @@ int G_SoundIndex( char *name ) //===================================================================== - -/* -================ -G_TeamCommand - -Broadcasts a command to only a specific team -================ -*/ -void G_TeamCommand( team_t team, char *cmd ) -{ - int i; - - for( i = 0 ; i < level.maxclients ; i++ ) - { - if( level.clients[ i ].pers.connected == CON_CONNECTED ) - { - if( level.clients[ i ].pers.teamSelection == team || - ( level.clients[ i ].pers.teamSelection == TEAM_NONE && - G_admin_permission( &g_entities[ i ], ADMF_SPEC_ALLCHAT ) ) ) - trap_SendServerCommand( i, cmd ); - } - } -} - - /* ============= G_Find diff --git a/src/qcommon/q_shared.h b/src/qcommon/q_shared.h index f11c3565..44685582 100644 --- a/src/qcommon/q_shared.h +++ b/src/qcommon/q_shared.h @@ -1394,6 +1394,15 @@ typedef enum { #define MAX_EMOTICON_NAME_LEN 16 #define MAX_EMOTICONS 64 +typedef struct +{ + char name[ MAX_EMOTICON_NAME_LEN ]; +#ifndef GAME + int width; + qhandle_t shader; +#endif +} emoticon_t; + // flags for com_downloadPrompt #define DLP_TYPE_MASK 0x0f #define DLP_IGNORE 0x01 // don't download anything diff --git a/src/ui/ui_main.c b/src/ui/ui_main.c index b4e4a82c..f9c2d7f4 100644 --- a/src/ui/ui_main.c +++ b/src/ui/ui_main.c @@ -219,17 +219,16 @@ void AssetCache( void ) if( ui_emoticons.integer ) { uiInfo.uiDC.Assets.emoticonCount = BG_LoadEmoticons( - uiInfo.uiDC.Assets.emoticons, - uiInfo.uiDC.Assets.emoticonWidths ); + uiInfo.uiDC.Assets.emoticons, MAX_EMOTICONS ); } else uiInfo.uiDC.Assets.emoticonCount = 0; for( i = 0; i < uiInfo.uiDC.Assets.emoticonCount; i++ ) { - uiInfo.uiDC.Assets.emoticonShaders[ i ] = trap_R_RegisterShaderNoMip( - va( "emoticons/%s_%dx1.tga", uiInfo.uiDC.Assets.emoticons[ i ], - uiInfo.uiDC.Assets.emoticonWidths[ i ] ) ); + uiInfo.uiDC.Assets.emoticons[ i ].shader = trap_R_RegisterShaderNoMip( + va( "emoticons/%s_%dx1.tga", uiInfo.uiDC.Assets.emoticons[ i ].name, + uiInfo.uiDC.Assets.emoticons[ i ].width ) ); } } diff --git a/src/ui/ui_shared.c b/src/ui/ui_shared.c index f24e91eb..3b3466db 100644 --- a/src/ui/ui_shared.c +++ b/src/ui/ui_shared.c @@ -1880,50 +1880,43 @@ void UI_EscapeEmoticons( char *dest, const char *src, int destsize ) qboolean UI_Text_IsEmoticon( const char *s, qboolean *escaped, int *length, qhandle_t *h, int *width ) { - char name[ MAX_EMOTICON_NAME_LEN ] = {""}; const char *p = s; - int i = 0; - int j = 0; + int i; if( *p != '[' ) return qfalse; p++; - *escaped = qfalse; if( *p == '[' ) { *escaped = qtrue; p++; } + else + *escaped = qfalse; - while( *p && i < ( MAX_EMOTICON_NAME_LEN - 1 ) ) - { - if( *p == ']' ) - { - for( j = 0; j < DC->Assets.emoticonCount; j++ ) - { - if( !Q_stricmp( DC->Assets.emoticons[ j ], name ) ) - { - if( *escaped ) - { - *length = 1; - return qtrue; - } - if( h ) - *h = DC->Assets.emoticonShaders[ j ]; - if( width ) - *width = DC->Assets.emoticonWidths[ j ]; - *length = i + 2; - return qtrue; - } - } + for( *length = 0; p[ *length ] != ']'; ( *length )++ ) + if( !p[ *length ] ) return qfalse; - } - name[ i++ ] = *p; - name[ i ] = '\0'; - p++; - } - return qfalse; + + for( i = 0; i < DC->Assets.emoticonCount; i++ ) + if( !Q_stricmpn( DC->Assets.emoticons[ i ].name, p, *length ) ) + break; + + if( i == DC->Assets.emoticonCount ) + return qfalse; + + if( h ) + *h = DC->Assets.emoticons[ i ].shader; + if( width ) + *width = DC->Assets.emoticons[ i ].width; + + ( *length ) += 2; + + if( *escaped ) + ( *length )++; + + return qtrue; } static float UI_Parse_Indent( const char **text ) diff --git a/src/ui/ui_shared.h b/src/ui/ui_shared.h index aa49a8a0..154325dd 100644 --- a/src/ui/ui_shared.h +++ b/src/ui/ui_shared.h @@ -378,9 +378,7 @@ typedef struct vec4_t shadowColor; float shadowFadeClamp; qboolean fontRegistered; - char emoticons[ MAX_EMOTICONS ][ MAX_EMOTICON_NAME_LEN ]; - qhandle_t emoticonShaders[ MAX_EMOTICONS ]; - int emoticonWidths[ MAX_EMOTICONS ]; + emoticon_t emoticons[ MAX_EMOTICONS ]; int emoticonCount; } cachedAssets_t; |