diff options
-rw-r--r-- | source/cl_main.c | 2 | ||||
-rw-r--r-- | source/mvd_game.c | 42 | ||||
-rw-r--r-- | source/mvd_parse.c | 2 | ||||
-rw-r--r-- | source/q_msg.c | 18 | ||||
-rw-r--r-- | source/q_msg.h | 5 | ||||
-rw-r--r-- | source/sv_game.c | 19 | ||||
-rw-r--r-- | source/sv_send.c | 21 |
7 files changed, 52 insertions, 57 deletions
diff --git a/source/cl_main.c b/source/cl_main.c index 211c9e5..ce867d2 100644 --- a/source/cl_main.c +++ b/source/cl_main.c @@ -662,7 +662,7 @@ void CL_Disconnect( comErrorType_t type, const char *text ) { if( cls.netchan ) { // send a disconnect message to the server MSG_WriteByte( clc_stringcmd ); - MSG_WriteString( "disconnect" ); + MSG_WriteData( "disconnect", 11 ); cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data ); cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data ); diff --git a/source/mvd_game.c b/source/mvd_game.c index 8d80ae4..daf374e 100644 --- a/source/mvd_game.c +++ b/source/mvd_game.c @@ -51,12 +51,12 @@ static void MVD_LayoutClients( udpClient_t *client ) { char layout[MAX_STRING_CHARS]; char buffer[MAX_STRING_CHARS]; char status[MAX_QPATH]; - int length, totalLength; + int length, total; udpClient_t *cl; mvd_t *mvd = client->mvd; int y; - totalLength = Com_sprintf( layout, sizeof( layout ), + total = sprintf( layout, "xl 32 yb -40 string2 \""APPLICATION" "VERSION"\" " "yb -32 string http://q2pro.sf.net/ " "xv 0 yv 0 string2 Name " @@ -73,26 +73,24 @@ static void MVD_LayoutClients( udpClient_t *client ) { } else { strcpy( status, "observing" ); } - length = Com_sprintf( buffer, sizeof( buffer ), + length = sprintf( buffer, "xv 0 yv %d string \"%.15s\" " "xv 152 string %d " "xv 208 string \"%s\" ", y, cl->cl->name, cl->ping, status ); - if( totalLength + length > sizeof( layout ) - 1 ) { - length = Com_sprintf( buffer, sizeof( buffer ), - "xv 0 yv %d string <...>", y ); - if( totalLength + length > sizeof( layout ) - 1 ) { - break; - } + if( total + length >= sizeof( layout ) ) { + break; } - strcpy( layout + totalLength, buffer ); - totalLength += length; + memcpy( layout + total, buffer, length ); + total += length; y += 8; } + layout[total] = 0; + // send the layout MSG_WriteByte( svc_layout ); - MSG_WriteString( layout ); + MSG_WriteData( layout, total + 1 ); SV_ClientAddMessage( client->cl, MSG_CLEAR ); client->layouts = 1; @@ -103,14 +101,13 @@ static void MVD_LayoutChannels( udpClient_t *client ) { char layout[MAX_STRING_CHARS]; char buffer[MAX_STRING_CHARS]; mvd_t *mvd; - int length, totalLength, cursor, y; + int length, total, cursor, y; - strcpy( layout, "xv 32 yv 8 picn inventory " + total = sprintf( layout, "xv 32 yv 8 picn inventory " "xv 64 yv 32 string2 \"Channel Map CL\" " "yv 40 string \"------------- ------- --\" " "xl 32 yb -40 string2 \""APPLICATION" "VERSION"\" " "yb -32 string http://q2pro.sf.net/ " ); - totalLength = strlen( layout ); cursor = List_Count( &mvd_ready ); if( cursor ) { @@ -119,29 +116,32 @@ static void MVD_LayoutChannels( udpClient_t *client ) { y = 48; cursor = 0; LIST_FOR_EACH( mvd_t, mvd, &mvd_ready, ready ) { - length = Com_sprintf( buffer, sizeof( buffer ), + length = sprintf( buffer, "xv 56 yv %d string \"%c%-13.13s %-7.7s %d%s\" ", y, cursor == client->cursor ? 0x8d : 0x20, mvd->name, mvd->mapname, List_Count( &mvd->udpClients ), mvd == client->mvd ? "+" : "" ); - if( totalLength + length > sizeof( layout ) - 1 ) { + if( total + length >= sizeof( layout ) ) { break; } - strcpy( layout + totalLength, buffer ); - totalLength += length; + memcpy( layout + total, buffer, length ); + total += length; y += 8; cursor++; } } else { client->cursor = 0; - strcat( layout, "xv 56 yv 48 string \" <no channels>\" " ); + total += sprintf( layout + total, + "xv 56 yv 48 string \" <no channels>\" " ); } + layout[total] = 0; + // send the layout MSG_WriteByte( svc_layout ); - MSG_WriteString( layout ); + MSG_WriteData( layout, total + 1 ); SV_ClientAddMessage( client->cl, MSG_RELIABLE|MSG_CLEAR ); client->layouts = 1; diff --git a/source/mvd_parse.c b/source/mvd_parse.c index 348fca3..2b5731f 100644 --- a/source/mvd_parse.c +++ b/source/mvd_parse.c @@ -608,7 +608,7 @@ static void MVD_ParseConfigstring( mvd_t *mvd ) { MSG_WriteByte( svc_configstring ); MSG_WriteShort( index ); - MSG_WriteString( string ); + MSG_WriteData( string, length + 1 ); // broadcast configstring change LIST_FOR_EACH( udpClient_t, client, &mvd->udpClients, entry ) { diff --git a/source/q_msg.c b/source/q_msg.c index f34bec9..1611dbc 100644 --- a/source/q_msg.c +++ b/source/q_msg.c @@ -146,7 +146,6 @@ MSG_WriteString */ void MSG_WriteString( const char *string ) { int length; - int c; if( !string ) { MSG_WriteByte( 0 ); @@ -154,21 +153,13 @@ void MSG_WriteString( const char *string ) { } length = strlen( string ); - if( length > MAX_NET_STRING - 1 ) { + if( length >= MAX_NET_STRING ) { Com_WPrintf( "MSG_WriteString: overflow: %d chars", length ); MSG_WriteByte( 0 ); return; } - while( *string ) { - c = *string++; - if( c == '\xFF' ) { - c = '.'; - } - MSG_WriteByte( c ); - } - - MSG_WriteByte( 0 ); + MSG_WriteData( string, length + 1 ); } /* @@ -443,10 +434,6 @@ void MSG_WriteDir( const vec3_t dir ) { MSG_WriteByte( best ); } -void MSG_WriteData( const void *data, int length ) { - memcpy( SZ_GetSpace( &msg_write, length ), data, length ); -} - /* values transmitted over network are discrete, so * we use special macros to check for delta conditions */ @@ -1396,6 +1383,7 @@ void MSG_FlushTo( sizebuf_t *dest ) { SZ_Clear( &msg_write ); } +// NOTE: does not NUL-terminate the string void MSG_Printf( const char *fmt, ... ) { char buffer[MAX_STRING_CHARS]; va_list argptr; diff --git a/source/q_msg.h b/source/q_msg.h index 5f863e3..0b3de53 100644 --- a/source/q_msg.h +++ b/source/q_msg.h @@ -100,7 +100,6 @@ void MSG_WriteBits( int value, int bits ); int MSG_WriteDeltaUsercmd( const usercmd_t *from, const usercmd_t *cmd, int version ); int MSG_WriteDeltaUsercmd_Enhanced( const usercmd_t *from, const usercmd_t *cmd ); void MSG_WriteDir ( const vec3_t vector); -void MSG_WriteData( const void *data, int length ); void MSG_WriteDeltaEntity( const entity_state_t *from, const entity_state_t *to, msgEsFlags_t flags ); void MSG_WriteDeltaPlayerstate_Default( const player_state_t *from, const player_state_t *to ); int MSG_WriteDeltaPlayerstate_Enhanced( const player_state_t *from, player_state_t *to, msgPsFlags_t flags ); @@ -108,6 +107,10 @@ void MSG_WriteDeltaPlayerstate_Packet( const player_state_t *from, const player_ void MSG_FlushTo( sizebuf_t *dest ); void MSG_Printf( const char *fmt, ... ) q_printf( 1, 2 ); +static inline void MSG_WriteData( const void *data, int length ) { + memcpy( SZ_GetSpace( &msg_write, length ), data, length ); +} + void MSG_BeginReading( void ); int MSG_ReadChar( void ); int MSG_ReadByte( void ); diff --git a/source/sv_game.c b/source/sv_game.c index 8565846..e7a6896 100644 --- a/source/sv_game.c +++ b/source/sv_game.c @@ -147,15 +147,16 @@ static void PF_bprintf( int level, const char *fmt, ... ) { va_list argptr; char string[MAX_STRING_CHARS]; client_t *client; + int length; int i; va_start( argptr, fmt ); - Q_vsnprintf( string, sizeof( string ), fmt, argptr ); + length = Q_vsnprintf( string, sizeof( string ), fmt, argptr ); va_end( argptr ); MSG_WriteByte( svc_print ); MSG_WriteByte( level ); - MSG_WriteString( string ); + MSG_WriteData( string, length + 1 ); // echo to console if( dedicated->integer ) { @@ -210,11 +211,11 @@ Archived in MVD stream. static void PF_cprintf( edict_t *ent, int level, const char *fmt, ... ) { char msg[MAX_STRING_CHARS]; va_list argptr; - int clientNum; + int clientNum, length; client_t *client; va_start( argptr, fmt ); - Q_vsnprintf( msg, sizeof( msg ), fmt, argptr ); + length = Q_vsnprintf( msg, sizeof( msg ), fmt, argptr ); va_end( argptr ); if( !ent ) { @@ -234,7 +235,7 @@ static void PF_cprintf( edict_t *ent, int level, const char *fmt, ... ) { MSG_WriteByte( svc_print ); MSG_WriteByte( level ); - MSG_WriteString( msg ); + MSG_WriteData( msg, length + 1 ); if( level >= client->messagelevel ) { SV_ClientAddMessage( client, MSG_RELIABLE ); @@ -261,7 +262,7 @@ Archived in MVD stream. static void PF_centerprintf (edict_t *ent, const char *fmt, ...) { char msg[MAX_STRING_CHARS]; va_list argptr; - int n; + int n, length; if( !ent ) { return; @@ -274,11 +275,11 @@ static void PF_centerprintf (edict_t *ent, const char *fmt, ...) { } va_start (argptr,fmt); - Q_vsnprintf( msg, sizeof( msg ), fmt, argptr ); + length = Q_vsnprintf( msg, sizeof( msg ), fmt, argptr ); va_end (argptr); MSG_WriteByte (svc_centerprint); - MSG_WriteString (msg); + MSG_WriteData (msg, length + 1); PF_Unicast (ent, qtrue); } @@ -374,7 +375,7 @@ void PF_Configstring( int index, const char *val ) { // send the update to everyone MSG_WriteByte( svc_configstring ); MSG_WriteShort( index ); - MSG_WriteString( val ); + MSG_WriteData( val, length + 1 ); FOR_EACH_CLIENT( client ) { if( client->state < cs_primed ) { diff --git a/source/sv_send.c b/source/sv_send.c index 02369a2..1e981a3 100644 --- a/source/sv_send.c +++ b/source/sv_send.c @@ -117,17 +117,18 @@ NOT archived in MVD stream. void SV_ClientPrintf( client_t *client, int level, const char *fmt, ... ) { va_list argptr; char string[MAX_STRING_CHARS]; + int length; if( level < client->messagelevel ) return; va_start( argptr, fmt ); - Q_vsnprintf( string, sizeof( string ), fmt, argptr ); + length = Q_vsnprintf( string, sizeof( string ), fmt, argptr ); va_end( argptr ); MSG_WriteByte( svc_print ); MSG_WriteByte( level ); - MSG_WriteString( string ); + MSG_WriteData( string, length + 1 ); SV_ClientAddMessage( client, MSG_RELIABLE|MSG_CLEAR ); } @@ -144,15 +145,15 @@ void SV_BroadcastPrintf( int level, const char *fmt, ... ) { va_list argptr; char string[MAX_STRING_CHARS]; client_t *client; - int i; + int i, length; va_start( argptr, fmt ); - Q_vsnprintf( string, sizeof( string ), fmt, argptr ); + length = Q_vsnprintf( string, sizeof( string ), fmt, argptr ); va_end( argptr ); MSG_WriteByte( svc_print ); MSG_WriteByte( level ); - MSG_WriteString( string ); + MSG_WriteData( string, length + 1 ); // echo to console if( dedicated->integer ) { @@ -176,13 +177,14 @@ void SV_BroadcastPrintf( int level, const char *fmt, ... ) { void SV_ClientCommand( client_t *client, const char *fmt, ... ) { va_list argptr; char string[MAX_STRING_CHARS]; + int length; va_start( argptr, fmt ); - Q_vsnprintf( string, sizeof( string ), fmt, argptr ); + length = Q_vsnprintf( string, sizeof( string ), fmt, argptr ); va_end( argptr ); MSG_WriteByte( svc_stufftext ); - MSG_WriteString( string ); + MSG_WriteData( string, length + 1 ); SV_ClientAddMessage( client, MSG_RELIABLE|MSG_CLEAR ); } @@ -199,13 +201,14 @@ void SV_BroadcastCommand( const char *fmt, ... ) { va_list argptr; char string[MAX_STRING_CHARS]; client_t *client; + int length; va_start( argptr, fmt ); - Q_vsnprintf( string, sizeof( string ), fmt, argptr ); + length = Q_vsnprintf( string, sizeof( string ), fmt, argptr ); va_end( argptr ); MSG_WriteByte( svc_stufftext ); - MSG_WriteString( string ); + MSG_WriteData( string, length + 1 ); FOR_EACH_CLIENT( client ) { SV_ClientAddMessage( client, MSG_RELIABLE ); |