Skip to content
Permalink
Browse files

Handle new colors in the game code

  • Loading branch information...
mbasaglia committed Aug 4, 2015
1 parent e644680 commit b91a743a0d133abe1bb29b795cbf7dcf15812117
@@ -319,11 +319,11 @@ extern vec4_t colorMdBlue;
#define S_COLOR_MDPURPLE "^C"
#define S_COLOR_NULL "^*"

inline bool Q_IsColorString( const char *p )
template<class String>
inline bool Q_IsColorString( String&& p )
{
return ( p[0] == Q_COLOR_ESCAPE &&
( p[1] == COLOR_NULL || ( p[1] >= '0' && p[1] != Q_COLOR_ESCAPE && p[1] < 'p' ) )
) ? true : false;
return p[0] == Q_COLOR_ESCAPE &&
( p[1] == COLOR_NULL || ( p[1] >= '0' && p[1] != Q_COLOR_ESCAPE && p[1] < 'p' ) );
}

/*
@@ -333,7 +333,8 @@ Q_IsHexColorString
Checks that a string is in the form ^xHHH (where H is a hex digit)
================
*/
inline bool Q_IsHexColorString( const char *p )
template<class String>
inline bool Q_IsHexColorString( String&& p )
{
return p[0] == Q_COLOR_ESCAPE && p[1] == Q_COLOR_HEX
&& ishex(p[2]) && ishex(p[3]) && ishex(p[4]);
@@ -299,11 +299,7 @@ int CG_DrawStrlen( const char *str )

while ( *s )
{
if ( Q_IsColorString( s ) )
{
s += 2;
}
else
if ( !Q_SkipColorString( s ) )
{
if ( *s == Q_COLOR_ESCAPE && s[1] == Q_COLOR_ESCAPE )
{
@@ -539,7 +539,7 @@ Rocket::Core::String Rocket_QuakeToRML( const char *in, int parseFlags = 0 )
span = false;
spanHasContent = false;
}
else if ( Q_IsColorString( p ) )
else if ( Q_IsColorString( p ) || Q_IsHexColorString( p ) )
{
if ( span && spanHasContent )
{
@@ -549,12 +549,21 @@ Rocket::Core::String Rocket_QuakeToRML( const char *in, int parseFlags = 0 )
}

char rgb[32];
int code = ColorIndex( *++p );
color_s color;
if ( p[1] == 'x' )
{
color = ColorFromHexString(p);
p += 4;
}
else
{
color = color_s( *++p );
}

Com_sprintf( rgb, sizeof( rgb ), "<span style='color: #%02X%02X%02X;'>",
(int)( g_color_table[ code ].r ),
(int)( g_color_table[ code ].g ),
(int)( g_color_table[ code ].b ) );
(int)( color.r ),
(int)( color.g ),
(int)( color.b ) );

// don't add the span yet, because it might be empty
spanstr = rgb;
@@ -344,7 +344,7 @@ class RocketChatField : public Rocket::Core::Element, Rocket::Core::EventListene
if ( position + 1 < str.Length() )
{
return ( str[position] == Q_COLOR_ESCAPE &&
( str[position + 1] == COLOR_NULL || ( str[position + 1] >= '0' && str[position + 1] != Q_COLOR_ESCAPE && str[position + 1] < 'p' ) )
( str[position + 1] == COLOR_NULL || Q_IsColorString( str ) || Q_IsHexColorString( str ) )
) ? true : false;
}
else
@@ -1209,9 +1209,9 @@ static int admin_out( void *admin, char *str )

for ( i = 0; l && l->name[ i ]; i++ )
{
if ( Q_IsColorString( l->name + i ) )
if ( Q_SkipColorString( l->name + i, lncol ) )
{
lncol += 2;
continue;
}
else if ( l->name[ i ] == Q_COLOR_ESCAPE && l->name[ i + 1 ] == Q_COLOR_ESCAPE )
{
@@ -3756,9 +3756,9 @@ bool G_admin_listplayers( gentity_t *ent )

for ( colorlen = j = 0; lname[ j ]; j++ )
{
if ( Q_IsColorString( &lname[ j ] ) )
if ( Q_SkipColorString( &lname[ j ], colorlen ) )
{
colorlen += 2;
continue;
}
else if ( lname[ j ] == Q_COLOR_ESCAPE && lname[ j + 1 ] == Q_COLOR_ESCAPE )
{
@@ -3823,9 +3823,9 @@ static int ban_out( void *ban, char *str )

for ( i = 0; b->name[ i ]; i++ )
{
if ( Q_IsColorString( &b->name[ i ] ) )
if ( Q_SkipColorString( &b->name[ i ], colorlen1 ) )
{
colorlen1 += 2;
continue;
}
else if ( b->name[ i ] == Q_COLOR_ESCAPE && b->name[ i + 1 ] == Q_COLOR_ESCAPE )
{
@@ -774,6 +774,23 @@ static void G_ClientCleanName( const char *in, char *out, int outSize, gclient_t
len += 2;
continue;
}
else if ( Q_IsHexColorString(in) )
{
// make sure room in dest for both chars
if ( len > outSize - 5 )
{
break;
}

for ( int i = 0; i < 5; i++ )
{
*out++ = *in++;
}
in--;

len += 5;
continue;
}
else if ( in[ 0 ] == '^' && !in[ 1 ] )
{
// single trailing ^ will mess up some things
@@ -49,9 +49,8 @@ void G_SanitiseString( const char *in, char *out, int len )
int cp = Q_UTF8_CodePoint( in );
int w;

if ( Q_IsColorString( in ) )
if ( Q_SkipColorString( in ) )
{
in += 2; // skip color code
continue;
}

@@ -1048,6 +1047,19 @@ void G_CensorString( char *out, const char *in, int len, gentity_t *ent )
len -= 2;
continue;
}
else if ( Q_IsHexColorString( in ) )
{
if ( len < 5 )
{
break;
}

for ( int i = 0; i < 5; i++ )
*out++ = *in++;

len -= 5;
continue;
}

ch = Q_UTF8_CodePoint( in );

@@ -1074,9 +1086,8 @@ void G_CensorString( char *out, const char *in, int len, gentity_t *ent )

while ( *s && *m )
{
if ( Q_IsColorString( s ) )
if ( Q_SkipColorString( s ) )
{
s += 2;
continue;
}

@@ -4672,9 +4683,8 @@ void G_DecolorString( const char *in, char *out, int len )

if ( decolor )
{
if ( Q_IsColorString( in ) )
if ( Q_SkipColorString( in ) )
{
in += 2;
continue;
}

0 comments on commit b91a743

Please sign in to comment.
You can’t perform that action at this time.