diff options
author | thilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2009-10-03 21:15:23 +0000 |
---|---|---|
committer | thilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2009-10-03 21:15:23 +0000 |
commit | e62ceb3c2672a11f6ea41adb93c1cf9e54ab1ef3 (patch) | |
tree | c487d37ef8c14724e35dff74adff6771acfbecf3 /code/game | |
parent | 712284e8ad585a4d95fd094aeb71818b64501cc7 (diff) | |
download | ioquake3-aero-e62ceb3c2672a11f6ea41adb93c1cf9e54ab1ef3.tar.gz ioquake3-aero-e62ceb3c2672a11f6ea41adb93c1cf9e54ab1ef3.zip |
- Modify color generating codes to only accept numbers and not alphabetical chars anymore
- Fix client clean name so that it cannot be tricked anymore, see https://bugzilla.icculus.org/show_bug.cgi?id=3313
git-svn-id: svn://svn.icculus.org/quake3/trunk@1638 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code/game')
-rw-r--r-- | code/game/g_client.c | 112 |
1 files changed, 43 insertions, 69 deletions
diff --git a/code/game/g_client.c b/code/game/g_client.c index 575d2e0..0d812ed 100644 --- a/code/game/g_client.c +++ b/code/game/g_client.c @@ -607,85 +607,59 @@ static void ForceClientSkin( gclient_t *client, char *model, const char *skin ) ClientCheckName ============ */ -static void ClientCleanName( const char *in, char *out, int outSize ) { - int len, colorlessLen; - char ch; - char *p; - int spaces; - - //save room for trailing null byte - outSize--; - - len = 0; - colorlessLen = 0; - p = out; - *p = 0; - spaces = 0; - - while( 1 ) { - ch = *in++; - if( !ch ) { - break; - } - - // don't allow leading spaces - if( colorlessLen == 0 && ch == ' ' ) { - continue; - } - - // check colors - if( ch == Q_COLOR_ESCAPE ) { - // solo trailing carat is not a color prefix - if( !*in ) { - break; - } +static void ClientCleanName(const char *in, char *out, int outSize) +{ + int outpos = 0, colorlessLen = 0, spaces = 0; - // don't allow black in a name, period - if( ColorIndex(*in) == 0 ) { - in++; + // discard leading spaces + for(; *in == ' '; in++); + + for(; *in && outpos < outSize - 1; in++) + { + out[outpos] = *in; + + if(*in == ' ') + { + // don't allow too many consecutive spaces + if(spaces > 2) continue; - } - - // make sure room in dest for both chars - if( len > outSize - 2 ) { - break; - } - - *out++ = ch; - *out++ = *in++; - len += 2; - continue; - } - - // don't allow too many consecutive spaces - // don't count spaces in colorlessLen - if( ch == ' ' ) { + spaces++; - if( spaces > 3 ) { - continue; + } + if(outpos > 0 && out[outpos - 1] == Q_COLOR_ESCAPE) + { + if(Q_IsColorString(&out[outpos - 1])) + { + colorlessLen--; + + if(*in == COLOR_BLACK) + { + // Disallow color black in names to prevent players + // from getting advantage playing in front of black backgrounds + outpos--; + continue; + } + } + else + { + spaces = 0; + colorlessLen++; } - *out++ = ch; - len++; - continue; } - else { + else + { spaces = 0; + colorlessLen++; } - - if( len > outSize - 1 ) { - break; - } - - *out++ = ch; - colorlessLen++; - len++; + + outpos++; } - *out = 0; + + out[outpos] = '\0'; // don't allow empty names - if( *p == 0 || colorlessLen == 0 ) { - Q_strncpyz( p, "UnnamedPlayer", outSize ); - } + if( *out == '\0' || colorlessLen == 0) + Q_strncpyz(out, "UnnamedPlayer", outSize ); } |