diff options
author | Tony J. White <tjw@tjw.org> | 2009-10-03 11:45:20 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:15:18 +0000 |
commit | 412d3c9c3479012d687139f891d14cfe18b6e6ee (patch) | |
tree | c8ca701ac8e4ef8cac3a35fbe8460b058e25bbda /src/game/g_client.c | |
parent | a60e24850d73f8d807bab40f256a3e017219f17e (diff) |
* UI_Text_* emoticon drawing support (e.g. [dretch] draws
/emoticons/dretch.tga inline with text)
* emoticons are square .tga images placed in the /emoticons dir of fs_game
* emoticons should probably be 64x64 to look nice
* g_emoticonsAllowedInNames (default ON) is an optional server setting to
prevent players from using them in names
* emoticons can be escaped by prefixing with an additional [
* cvars ui_emoticons and cg_emoticons can be set to 0 to disable drawing
of emoticons in ui or cgame contexts respectively
* fix color code continuation on wrapped lines
* prefix all wrapped lines with a space to prevent chat shenanigans
Diffstat (limited to 'src/game/g_client.c')
-rw-r--r-- | src/game/g_client.c | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/src/game/g_client.c b/src/game/g_client.c index 0e8051b8..4d674905 100644 --- a/src/game/g_client.c +++ b/src/game/g_client.c @@ -764,16 +764,54 @@ void respawn( gentity_t *ent ) } } +static qboolean G_IsEmoticon( const char *s, qboolean *escaped ) +{ + int i, j; + const char *p = s; + char emoticon[ MAX_EMOTICON_NAME_LEN ] = {""}; + qboolean escape = qfalse; + + if( *p != '[' ) + return qfalse; + p++; + if( *p == '[' ) + { + escape = qtrue; + p++; + } + i = 0; + while( *p && i < ( MAX_EMOTICON_NAME_LEN - 1 ) ) + { + if( *p == ']' ) + { + for( j = 0; j < level.emoticonCount; j++ ) + { + if( !Q_stricmp( emoticon, level.emoticons[ j ] ) ) + { + *escaped = escape; + return qtrue; + } + } + return qfalse; + } + emoticon[ i++ ] = *p; + emoticon[ i ] = '\0'; + p++; + } + return qfalse; +} + /* =========== -ClientCleanName +G_ClientCleanName ============ */ -static void ClientCleanName( const char *in, char *out, int outSize ) +static void G_ClientCleanName( const char *in, char *out, int outSize ) { int len, colorlessLen; char *p; int spaces; + qboolean escaped; //save room for trailing null byte outSize--; @@ -808,6 +846,19 @@ static void ClientCleanName( const char *in, char *out, int outSize ) len += 2; continue; } + else if( !g_emoticonsAllowedInNames.integer && G_IsEmoticon( in, &escaped ) ) + { + // make sure room in dest for both chars + if( len > outSize - 2 ) + break; + + *out++ = '['; + *out++ = '['; + len += 2; + if( escaped ) + in++; + continue; + } // don't allow too many consecutive spaces if( *in == ' ' ) @@ -942,7 +993,7 @@ void ClientUserinfoChanged( int clientNum ) // set name Q_strncpyz( oldname, client->pers.netname, sizeof( oldname ) ); s = Info_ValueForKey( userinfo, "name" ); - ClientCleanName( s, newname, sizeof( newname ) ); + G_ClientCleanName( s, newname, sizeof( newname ) ); if( strcmp( oldname, newname ) ) { |