summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Millwood <thebenmachine@gmail.com>2009-10-03 12:10:48 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:15:44 +0000
commitb3691bd7f4c27e9ac216bb96d80a09a7cb7e2349 (patch)
treecba50449a677a0612732fde38141a4e255cec85a
parentb8696658e67bf459c1e2538e8f1b6a6297143adc (diff)
* Use chat rather than print for adminchat server commands
* Fixes to ready code: supports MAX_CLIENTS slots without relying on its value * Removing references to an apparently useless escape character in chat
-rw-r--r--src/cgame/cg_main.c19
-rw-r--r--src/cgame/cg_servercmds.c31
-rw-r--r--src/game/g_cmds.c26
-rw-r--r--src/game/g_main.c19
4 files changed, 33 insertions, 62 deletions
diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c
index 9f7d26d5..fe90b629 100644
--- a/src/cgame/cg_main.c
+++ b/src/cgame/cg_main.c
@@ -1425,19 +1425,17 @@ static clientInfo_t * CG_InfoFromScoreIndex( int index, int team, int *scoreInde
static qboolean CG_ClientIsReady( int clientNum )
{
- // each character of the hex string corresponds to 4 bits, which correspond
- // to readiness for client (0, 1, 2, 3...) i.e. the highest order bit
- // corresponds to the lowest clientnum
- // so we only need one character for a given client
- int val = clientNum / 4;
+ // CS_CLIENTS_READY is a hex string, each character of which is 4 bits
+ // the highest bit of the first char is a toggle for client 0, the second
+ // highest for client 1, etc.
+ // there are exactly four bits of information in each character
+ int val;
const char *s = CG_ConfigString( CS_CLIENTS_READY );
- while( *s && val > 0 )
- s++, val--;
-
- if( !*s )
- return qfalse;
+ // select the appropriate character without passing the end of the string
+ for( val = clientNum / 4; *s && val > 0; s++, val-- );
+ // convert hex -> int
if( isdigit( *s ) )
val = *s - '0';
else if( *s >= 'a' && *s <= 'f' )
@@ -1447,6 +1445,7 @@ static qboolean CG_ClientIsReady( int clientNum )
else
return qfalse;
+ // select appropriate bit
return ( ( val & 1 << ( 3 - clientNum % 4 ) ) != 0 );
}
diff --git a/src/cgame/cg_servercmds.c b/src/cgame/cg_servercmds.c
index c21d1a52..f95d18b7 100644
--- a/src/cgame/cg_servercmds.c
+++ b/src/cgame/cg_servercmds.c
@@ -446,27 +446,6 @@ static void CG_MapRestart( void )
}
/*
-=================
-CG_RemoveChatEscapeChar
-=================
-*/
-static void CG_RemoveChatEscapeChar( char *text )
-{
- int i, l;
-
- l = 0;
- for( i = 0; text[ i ]; i++ )
- {
- if( text[ i ] == '\x19' )
- continue;
-
- text[ l++ ] = text[ i ];
- }
-
- text[ l ] = '\0';
-}
-
-/*
==============
CG_Menu
==============
@@ -943,7 +922,6 @@ static void CG_Say( int clientNum, char *text )
"%s: " S_COLOR_WHITE S_COLOR_GREEN "%s" S_COLOR_WHITE "\n",
ci->name, text );
- CG_RemoveChatEscapeChar( sayText );
if( BG_ClientListTest( &cgs.ignoreList, clientNum ) )
CG_Printf( "[skipnotify]%s", sayText );
else
@@ -959,17 +937,15 @@ static void CG_SayTeam( int clientNum, char *text )
{
clientInfo_t *ci;
char sayText[ MAX_SAY_TEXT ] = {""};
-
+
if( clientNum < 0 || clientNum >= MAX_CLIENTS )
return;
-
ci = &cgs.clientinfo[ clientNum ];
Com_sprintf( sayText, sizeof( sayText ),
- "%s: " S_COLOR_WHITE S_COLOR_CYAN "%s" S_COLOR_WHITE "\n",
+ "%s: " S_COLOR_CYAN "%s" S_COLOR_WHITE "\n",
ci->name, text );
-
- CG_RemoveChatEscapeChar( sayText );
+
if( BG_ClientListTest( &cgs.ignoreList, clientNum ) )
CG_Printf( "[skipnotify]%s", sayText );
else
@@ -1160,7 +1136,6 @@ static void CG_Chat_f( void )
trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND );
}
- CG_RemoveChatEscapeChar( text );
CG_Printf( "%s\n", text );
}
diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c
index 888e678e..1c47e77d 100644
--- a/src/game/g_cmds.c
+++ b/src/game/g_cmds.c
@@ -55,7 +55,7 @@ void G_SanitiseString( char *in, char *out, int len )
skip = qfalse;
}
- if( *in == 27 || Q_IsColorString( in ) )
+ if( Q_IsColorString( in ) )
{
in += 2; // skip color code
continue;
@@ -688,8 +688,6 @@ static void G_SayTo( gentity_t *ent, gentity_t *other, int mode, int color, cons
name, Q_COLOR_ESCAPE, color, message, S_COLOR_WHITE ) );
}
-#define EC "\x19"
-
void G_Say( gentity_t *ent, gentity_t *target, int mode, const char *chatText )
{
int j;
@@ -714,30 +712,30 @@ void G_Say( gentity_t *ent, gentity_t *target, int mode, const char *chatText )
default:
case SAY_ALL:
G_LogPrintf( "say: %s^7: %s\n", ent->client->pers.netname, chatText );
- Com_sprintf( name, sizeof( name ), "%s%s%c%c"EC": ", prefix,
- ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE );
+ Com_sprintf( name, sizeof( name ), "%s%s" S_COLOR_WHITE ": ", prefix,
+ ent->client->pers.netname );
color = COLOR_GREEN;
break;
case SAY_TEAM:
G_LogPrintf( "sayteam: %s^7: %s\n", ent->client->pers.netname, chatText );
if( Team_GetLocationMsg( ent, location, sizeof( location ) ) )
- Com_sprintf( name, sizeof( name ), EC"(%s%c%c"EC") (%s)"EC": ",
- ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE, location );
+ Com_sprintf( name, sizeof( name ), "(%s" S_COLOR_WHITE ") (%s): ",
+ ent->client->pers.netname, location );
else
- Com_sprintf( name, sizeof( name ), EC"(%s%c%c"EC")"EC": ",
- ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE );
+ Com_sprintf( name, sizeof( name ), "(%s" S_COLOR_WHITE "): ",
+ ent->client->pers.netname );
color = COLOR_CYAN;
break;
case SAY_TELL:
if( target && OnSameTeam( target, ent ) &&
Team_GetLocationMsg( ent, location, sizeof( location ) ) )
- Com_sprintf( name, sizeof( name ), EC"[%s%c%c"EC"] (%s)"EC": ",
- ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE, location );
+ Com_sprintf( name, sizeof( name ), "[%s" S_COLOR_WHITE "] (%s): ",
+ ent->client->pers.netname, location );
else
- Com_sprintf( name, sizeof( name ), EC"[%s%c%c"EC"]"EC": ",
- ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE );
+ Com_sprintf( name, sizeof( name ), "[%s" S_COLOR_WHITE "]: ",
+ ent->client->pers.netname );
color = COLOR_MAGENTA;
break;
}
@@ -3156,7 +3154,7 @@ void G_DecolorString( char *in, char *out, int len )
len--;
while( *in && len > 0 ) {
- if( *in == 27 || Q_IsColorString( in ) ) {
+ if( Q_IsColorString( in ) ) {
in++;
if( *in )
in++;
diff --git a/src/game/g_main.c b/src/game/g_main.c
index 820108dc..b46c1b2e 100644
--- a/src/game/g_main.c
+++ b/src/game/g_main.c
@@ -1654,9 +1654,9 @@ void QDECL G_AdminsPrintf( const char *prefix, const char *fmt, ... )
// Send to all appropriate clients
for( i = 0; i < level.maxclients; i++ )
{
- if( G_admin_permission( &g_entities[ i ], ADMF_ADMINCHAT) )
+ if( G_admin_permission( &g_entities[ i ], ADMF_ADMINCHAT ) )
{
- trap_SendServerCommand( i, va( "print \"%s\"", outstring ) );
+ trap_SendServerCommand( i, va( "chat \"%s\"", outstring ) );
}
}
@@ -1858,14 +1858,15 @@ wait 10 seconds before going on.
*/
void CheckIntermissionExit( void )
{
- int ready, notReady, numPlayers;
+ int ready, notReady;
int i;
gclient_t *cl;
byte readyMasks[ ( MAX_CLIENTS + 7 ) / 8 ];
- char readyString[ 2 * sizeof( readyMasks ) + 1 ]; // a byte is 00 - ff
+ // each byte in readyMasks will become two characters 00 - ff in the string
+ char readyString[ 2 * sizeof( readyMasks ) + 1 ];
//if no clients are connected, just exit
- if( !level.numConnectedClients )
+ if( level.numConnectedClients == 0 )
{
ExitLevel( );
return;
@@ -1874,11 +1875,11 @@ void CheckIntermissionExit( void )
// see which players are ready
ready = 0;
notReady = 0;
- numPlayers = 0;
Com_Memset( readyMasks, 0, sizeof( readyMasks ) );
for( i = 0; i < g_maxclients.integer; i++ )
{
cl = level.clients + i;
+
if( cl->pers.connected != CON_CONNECTED )
continue;
@@ -1893,8 +1894,6 @@ void CheckIntermissionExit( void )
}
else
notReady++;
-
- numPlayers++;
}
// this is hex because we can convert bits to a hex string in pieces,
@@ -1918,14 +1917,14 @@ void CheckIntermissionExit( void )
}
// if nobody wants to go, clear timer
- if( !ready && numPlayers )
+ if( ready == 0 && notReady > 0 )
{
level.readyToExit = qfalse;
return;
}
// if everyone wants to go, go now
- if( !notReady )
+ if( notReady == 0 )
{
ExitLevel( );
return;