X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=libs%2Fl_net%2Fl_net.c;h=7f50d054b94a1f0d10c8b6e14ea5881c011f6700;hb=a5b337c0c2fb423c8fc96a3955f7f7eba75c2f01;hp=878e6a47ade6bfeb63bf25d437934954090b6354;hpb=d40c79f30c4029daa1f92e07b728518911a98d5e;p=xonotic%2Fnetradiant.git diff --git a/libs/l_net/l_net.c b/libs/l_net/l_net.c index 878e6a47..7f50d054 100644 --- a/libs/l_net/l_net.c +++ b/libs/l_net/l_net.c @@ -1,23 +1,23 @@ /* -Copyright (C) 1999-2006 Id Software, Inc. and contributors. -For a list of contributors, see the accompanying CONTRIBUTORS file. + Copyright (C) 1999-2006 Id Software, Inc. and contributors. + For a list of contributors, see the accompanying CONTRIBUTORS file. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ //==================================================================== // @@ -39,24 +39,22 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define GetMemory malloc #define FreeMemory free -#define qtrue 1 -#define qfalse 0 +#define qtrue 1 +#define qfalse 0 #ifdef _DEBUG -void WinPrint(char *str, ...) -{ +void WinPrint( const char *str, ... ){ va_list argptr; - char text[4096]; + char text[4096]; - va_start (argptr,str); - vsprintf (text, str, argptr); - va_end (argptr); + va_start( argptr,str ); + vsprintf( text, str, argptr ); + va_end( argptr ); - printf(text); + printf( "%s", text ); } #else -void WinPrint(char *str, ...) -{ +void WinPrint( const char *str, ... ){ } #endif @@ -66,13 +64,12 @@ void WinPrint(char *str, ...) // Returns: - // Changes Globals: - //=========================================================================== -void Net_SetAddressPort(address_t *address, int port) -{ +void Net_SetAddressPort( address_t *address, int port ){ sockaddr_t addr; - WINS_StringToAddr(address->ip, &addr); - WINS_SetSocketPort(&addr, port); - strcpy(address->ip, WINS_AddrToString(&addr)); + WINS_StringToAddr( address->ip, &addr ); + WINS_SetSocketPort( &addr, port ); + strcpy( address->ip, WINS_AddrToString( &addr ) ); } //end of the function Net_SetAddressPort //=========================================================================== // @@ -80,12 +77,11 @@ void Net_SetAddressPort(address_t *address, int port) // Returns: - // Changes Globals: - //=========================================================================== -int Net_AddressCompare(address_t *addr1, address_t *addr2) -{ +int Net_AddressCompare( address_t *addr1, address_t *addr2 ){ #ifdef WIN32 - return _stricmp(addr1->ip, addr2->ip); + return _stricmp( addr1->ip, addr2->ip ); #else - return strcasecmp(addr1->ip, addr2->ip); + return strcasecmp( addr1->ip, addr2->ip ); #endif } //end of the function Net_AddressCompare //=========================================================================== @@ -94,9 +90,8 @@ int Net_AddressCompare(address_t *addr1, address_t *addr2) // Returns: - // Changes Globals: - //=========================================================================== -void Net_SocketToAddress(socket_t *sock, address_t *address) -{ - strcpy(address->ip, WINS_AddrToString(&sock->addr)); +void Net_SocketToAddress( socket_t *sock, address_t *address ){ + strcpy( address->ip, WINS_AddrToString( &sock->addr ) ); } //end of the function Net_SocketToAddress //=========================================================================== // @@ -104,16 +99,15 @@ void Net_SocketToAddress(socket_t *sock, address_t *address) // Returns: - // Changes Globals: - //=========================================================================== -int Net_Send(socket_t *sock, netmessage_t *msg) -{ +int Net_Send( socket_t *sock, netmessage_t *msg ){ int size; size = msg->size; msg->size = 0; - NMSG_WriteLong(msg, size-4); + NMSG_WriteLong( msg, size - 4 ); msg->size = size; //WinPrint("Net_Send: message of size %d\n", sendmsg.size); - return WINS_Write(sock->socket, msg->data, msg->size, NULL); + return WINS_Write( sock->socket, msg->data, msg->size, NULL ); } //end of the function Net_SendSocketReliable //=========================================================================== // returns the number of bytes recieved @@ -123,64 +117,60 @@ int Net_Send(socket_t *sock, netmessage_t *msg) // Returns: - // Changes Globals: - //=========================================================================== -int Net_Receive(socket_t *sock, netmessage_t *msg) -{ +int Net_Receive( socket_t *sock, netmessage_t *msg ){ int curread; - if (sock->remaining > 0) - { - curread = WINS_Read(sock->socket, &sock->msg.data[sock->msg.size], sock->remaining, NULL); - if (curread == -1) - { - WinPrint("Net_Receive: read error\n"); + if ( sock->remaining > 0 ) { + curread = WINS_Read( sock->socket, &sock->msg.data[sock->msg.size], sock->remaining, NULL ); + if ( curread == -1 ) { + WinPrint( "Net_Receive: read error\n" ); return -1; } //end if sock->remaining -= curread; sock->msg.size += curread; - if (sock->remaining <= 0) - { + if ( sock->remaining <= 0 ) { sock->remaining = 0; - memcpy(msg, &sock->msg, sizeof(netmessage_t)); + memcpy( msg, &sock->msg, sizeof( netmessage_t ) ); sock->msg.size = 0; return msg->size - 4; } //end if return 0; } //end if - sock->msg.size = WINS_Read(sock->socket, sock->msg.data, 4, NULL); - if (sock->msg.size == 0) return 0; - if (sock->msg.size == -1) - { - WinPrint("Net_Receive: size header read error\n"); + sock->msg.size = WINS_Read( sock->socket, sock->msg.data, 4, NULL ); + if ( sock->msg.size == 0 ) { + return 0; + } + if ( sock->msg.size == -1 ) { + WinPrint( "Net_Receive: size header read error\n" ); return -1; } //end if - //WinPrint("Net_Receive: message size header %d\n", msg->size); + //WinPrint("Net_Receive: message size header %d\n", msg->size); sock->msg.read = 0; - sock->remaining = NMSG_ReadLong(&sock->msg); - if (sock->remaining == 0) return 0; - if (sock->remaining < 0 || sock->remaining > MAX_NETMESSAGE) - { - WinPrint("Net_Receive: invalid message size %d\n", sock->remaining); + sock->remaining = NMSG_ReadLong( &sock->msg ); + if ( sock->remaining == 0 ) { + return 0; + } + if ( sock->remaining < 0 || sock->remaining > MAX_NETMESSAGE ) { + WinPrint( "Net_Receive: invalid message size %d\n", sock->remaining ); return -1; } //end if - //try to read the message - curread = WINS_Read(sock->socket, &sock->msg.data[sock->msg.size], sock->remaining, NULL); - if (curread == -1) - { - WinPrint("Net_Receive: read error\n"); + //try to read the message + curread = WINS_Read( sock->socket, &sock->msg.data[sock->msg.size], sock->remaining, NULL ); + if ( curread == -1 ) { + WinPrint( "Net_Receive: read error\n" ); return -1; } //end if sock->remaining -= curread; sock->msg.size += curread; - if (sock->remaining <= 0) - { + if ( sock->remaining <= 0 ) { sock->remaining = 0; - memcpy(msg, &sock->msg, sizeof(netmessage_t)); + memcpy( msg, &sock->msg, sizeof( netmessage_t ) ); sock->msg.size = 0; return msg->size - 4; } //end if - //the message has not been completely read yet + //the message has not been completely read yet #ifdef _DEBUG - printf("++timo TODO: debug the Net_Receive on big size messages\n"); + printf( "++timo TODO: debug the Net_Receive on big size messages\n" ); #endif return 0; } //end of the function Net_Receive @@ -190,12 +180,11 @@ int Net_Receive(socket_t *sock, netmessage_t *msg) // Returns: - // Changes Globals: - //=========================================================================== -socket_t *Net_AllocSocket(void) -{ +socket_t *Net_AllocSocket( void ){ socket_t *sock; - sock = (socket_t *) GetMemory(sizeof(socket_t)); - memset(sock, 0, sizeof(socket_t)); + sock = (socket_t *) GetMemory( sizeof( socket_t ) ); + memset( sock, 0, sizeof( socket_t ) ); return sock; } //end of the function Net_AllocSocket //=========================================================================== @@ -204,9 +193,8 @@ socket_t *Net_AllocSocket(void) // Returns: - // Changes Globals: - //=========================================================================== -void Net_FreeSocket(socket_t *sock) -{ - FreeMemory(sock); +void Net_FreeSocket( socket_t *sock ){ + FreeMemory( sock ); } //end of the function Net_FreeSocket //=========================================================================== // @@ -214,36 +202,35 @@ void Net_FreeSocket(socket_t *sock) // Returns: - // Changes Globals: - //=========================================================================== -socket_t *Net_Connect(address_t *address, int port) -{ +socket_t *Net_Connect( address_t *address, int port ){ int newsock; socket_t *sock; sockaddr_t sendaddr; // see if we can resolve the host name - WINS_StringToAddr(address->ip, &sendaddr); + WINS_StringToAddr( address->ip, &sendaddr ); - newsock = WINS_OpenReliableSocket(port); - if (newsock == -1) return NULL; + newsock = WINS_OpenReliableSocket( port ); + if ( newsock == -1 ) { + return NULL; + } sock = Net_AllocSocket(); - if (sock == NULL) - { - WINS_CloseSocket(newsock); + if ( sock == NULL ) { + WINS_CloseSocket( newsock ); return NULL; } //end if sock->socket = newsock; //connect to the host - if (WINS_Connect(newsock, &sendaddr) == -1) - { - Net_FreeSocket(sock); - WINS_CloseSocket(newsock); - WinPrint("Net_Connect: error connecting\n"); + if ( WINS_Connect( newsock, &sendaddr ) == -1 ) { + Net_FreeSocket( sock ); + WINS_CloseSocket( newsock ); + WinPrint( "Net_Connect: error connecting\n" ); return NULL; } //end if - memcpy(&sock->addr, &sendaddr, sizeof(sockaddr_t)); + memcpy( &sock->addr, &sendaddr, sizeof( sockaddr_t ) ); //now we can send messages // return sock; @@ -255,28 +242,27 @@ socket_t *Net_Connect(address_t *address, int port) // Returns: - // Changes Globals: - //=========================================================================== -socket_t *Net_ListenSocket(int port) -{ +socket_t *Net_ListenSocket( int port ){ int newsock; socket_t *sock; - newsock = WINS_OpenReliableSocket(port); - if (newsock == -1) return NULL; + newsock = WINS_OpenReliableSocket( port ); + if ( newsock == -1 ) { + return NULL; + } - if (WINS_Listen(newsock) == -1) - { - WINS_CloseSocket(newsock); + if ( WINS_Listen( newsock ) == -1 ) { + WINS_CloseSocket( newsock ); return NULL; } //end if sock = Net_AllocSocket(); - if (sock == NULL) - { - WINS_CloseSocket(newsock); + if ( sock == NULL ) { + WINS_CloseSocket( newsock ); return NULL; } //end if sock->socket = newsock; - WINS_GetSocketAddr(newsock, &sock->addr); - WinPrint("listen socket opened at %s\n", WINS_AddrToString(&sock->addr)); + WINS_GetSocketAddr( newsock, &sock->addr ); + WinPrint( "listen socket opened at %s\n", WINS_AddrToString( &sock->addr ) ); // return sock; } //end of the function Net_ListenSocket @@ -286,23 +272,23 @@ socket_t *Net_ListenSocket(int port) // Returns: - // Changes Globals: - //=========================================================================== -socket_t *Net_Accept(socket_t *sock) -{ +socket_t *Net_Accept( socket_t *sock ){ int newsocket; sockaddr_t sendaddr; socket_t *newsock; - newsocket = WINS_Accept(sock->socket, &sendaddr); - if (newsocket == -1) return NULL; + newsocket = WINS_Accept( sock->socket, &sendaddr ); + if ( newsocket == -1 ) { + return NULL; + } newsock = Net_AllocSocket(); - if (newsock == NULL) - { - WINS_CloseSocket(newsocket); + if ( newsock == NULL ) { + WINS_CloseSocket( newsocket ); return NULL; } //end if newsock->socket = newsocket; - memcpy(&newsock->addr, &sendaddr, sizeof(sockaddr_t)); + memcpy( &newsock->addr, &sendaddr, sizeof( sockaddr_t ) ); // return newsock; } //end of the function Net_Accept @@ -312,10 +298,9 @@ socket_t *Net_Accept(socket_t *sock) // Returns: - // Changes Globals: - //=========================================================================== -void Net_Disconnect(socket_t *sock) -{ - WINS_CloseSocket(sock->socket); - Net_FreeSocket(sock); +void Net_Disconnect( socket_t *sock ){ + WINS_CloseSocket( sock->socket ); + Net_FreeSocket( sock ); } //end of the function Net_Disconnect //=========================================================================== // @@ -323,9 +308,8 @@ void Net_Disconnect(socket_t *sock) // Returns: - // Changes Globals: - //=========================================================================== -void Net_StringToAddress(char *string, address_t *address) -{ - strcpy(address->ip, string); +void Net_StringToAddress( const char *string, address_t *address ){ + strcpy( address->ip, string ); } //end of the function Net_StringToAddress //=========================================================================== // @@ -333,9 +317,8 @@ void Net_StringToAddress(char *string, address_t *address) // Returns: - // Changes Globals: - //=========================================================================== -void Net_MyAddress(address_t *address) -{ - strcpy(address->ip, WINS_MyAddress()); +void Net_MyAddress( address_t *address ){ + strcpy( address->ip, WINS_MyAddress() ); } //end of the function Net_MyAddress //=========================================================================== // @@ -343,11 +326,10 @@ void Net_MyAddress(address_t *address) // Returns: - // Changes Globals: - //=========================================================================== -int Net_Setup(void) -{ +int Net_Setup( void ){ WINS_Init(); // - WinPrint("my address is %s\n", WINS_MyAddress()); + WinPrint( "my address is %s\n", WINS_MyAddress() ); // return qtrue; } //end of the function Net_Setup @@ -357,8 +339,7 @@ int Net_Setup(void) // Returns: - // Changes Globals: - //=========================================================================== -void Net_Shutdown(void) -{ +void Net_Shutdown( void ){ WINS_Shutdown(); } //end of the function Net_Shutdown //=========================================================================== @@ -367,8 +348,7 @@ void Net_Shutdown(void) // Returns: - // Changes Globals: - //=========================================================================== -void NMSG_Clear(netmessage_t *msg) -{ +void NMSG_Clear( netmessage_t *msg ){ msg->size = 4; } //end of the function NMSG_Clear //=========================================================================== @@ -377,14 +357,13 @@ void NMSG_Clear(netmessage_t *msg) // Returns: - // Changes Globals: - //=========================================================================== -void NMSG_WriteChar (netmessage_t *msg, int c) -{ - if (c < -128 || c > 127) - WinPrint("NMSG_WriteChar: range error\n"); +void NMSG_WriteChar( netmessage_t *msg, int c ){ + if ( c < -128 || c > 127 ) { + WinPrint( "NMSG_WriteChar: range error\n" ); + } - if (msg->size >= MAX_NETMESSAGE) - { - WinPrint("NMSG_WriteChar: overflow\n"); + if ( msg->size >= MAX_NETMESSAGE ) { + WinPrint( "NMSG_WriteChar: overflow\n" ); return; } //end if msg->data[msg->size] = c; @@ -396,14 +375,13 @@ void NMSG_WriteChar (netmessage_t *msg, int c) // Returns: - // Changes Globals: - //=========================================================================== -void NMSG_WriteByte(netmessage_t *msg, int c) -{ - if (c < -128 || c > 127) - WinPrint("NMSG_WriteByte: range error\n"); +void NMSG_WriteByte( netmessage_t *msg, int c ){ + if ( c < -128 || c > 127 ) { + WinPrint( "NMSG_WriteByte: range error\n" ); + } - if (msg->size + 1 >= MAX_NETMESSAGE) - { - WinPrint("NMSG_WriteByte: overflow\n"); + if ( msg->size + 1 >= MAX_NETMESSAGE ) { + WinPrint( "NMSG_WriteByte: overflow\n" ); return; } //end if msg->data[msg->size] = c; @@ -415,18 +393,17 @@ void NMSG_WriteByte(netmessage_t *msg, int c) // Returns: - // Changes Globals: - //=========================================================================== -void NMSG_WriteShort(netmessage_t *msg, int c) -{ - if (c < ((short)0x8000) || c > (short)0x7fff) - WinPrint("NMSG_WriteShort: range error"); +void NMSG_WriteShort( netmessage_t *msg, int c ){ + if ( c < ( (short)0x8000 ) || c > (short)0x7fff ) { + WinPrint( "NMSG_WriteShort: range error" ); + } - if (msg->size + 2 >= MAX_NETMESSAGE) - { - WinPrint("NMSG_WriteShort: overflow\n"); + if ( msg->size + 2 >= MAX_NETMESSAGE ) { + WinPrint( "NMSG_WriteShort: overflow\n" ); return; } //end if - msg->data[msg->size] = c&0xff; - msg->data[msg->size+1] = c>>8; + msg->data[msg->size] = c & 0xff; + msg->data[msg->size + 1] = c >> 8; msg->size += 2; } //end of the function NMSG_WriteShort //=========================================================================== @@ -435,17 +412,15 @@ void NMSG_WriteShort(netmessage_t *msg, int c) // Returns: - // Changes Globals: - //=========================================================================== -void NMSG_WriteLong(netmessage_t *msg, int c) -{ - if (msg->size + 4 >= MAX_NETMESSAGE) - { - WinPrint("NMSG_WriteLong: overflow\n"); +void NMSG_WriteLong( netmessage_t *msg, int c ){ + if ( msg->size + 4 >= MAX_NETMESSAGE ) { + WinPrint( "NMSG_WriteLong: overflow\n" ); return; } //end if - msg->data[msg->size] = c&0xff; - msg->data[msg->size+1] = (c>>8)&0xff; - msg->data[msg->size+2] = (c>>16)&0xff; - msg->data[msg->size+3] = c>>24; + msg->data[msg->size] = c & 0xff; + msg->data[msg->size + 1] = ( c >> 8 ) & 0xff; + msg->data[msg->size + 2] = ( c >> 16 ) & 0xff; + msg->data[msg->size + 3] = c >> 24; msg->size += 4; } //end of the function NMSG_WriteLong //=========================================================================== @@ -454,17 +429,15 @@ void NMSG_WriteLong(netmessage_t *msg, int c) // Returns: - // Changes Globals: - //=========================================================================== -void NMSG_WriteFloat(netmessage_t *msg, float c) -{ - if (msg->size + 4 >= MAX_NETMESSAGE) - { - WinPrint("NMSG_WriteLong: overflow\n"); +void NMSG_WriteFloat( netmessage_t *msg, float c ){ + if ( msg->size + 4 >= MAX_NETMESSAGE ) { + WinPrint( "NMSG_WriteLong: overflow\n" ); return; } //end if - msg->data[msg->size] = *((int *)&c)&0xff; - msg->data[msg->size+1] = (*((int *)&c)>>8)&0xff; - msg->data[msg->size+2] = (*((int *)&c)>>16)&0xff; - msg->data[msg->size+3] = *((int *)&c)>>24; + msg->data[msg->size] = *( (int *)&c ) & 0xff; + msg->data[msg->size + 1] = ( *( (int *)&c ) >> 8 ) & 0xff; + msg->data[msg->size + 2] = ( *( (int *)&c ) >> 16 ) & 0xff; + msg->data[msg->size + 3] = *( (int *)&c ) >> 24; msg->size += 4; } //end of the function NMSG_WriteFloat //=========================================================================== @@ -473,15 +446,13 @@ void NMSG_WriteFloat(netmessage_t *msg, float c) // Returns: - // Changes Globals: - //=========================================================================== -void NMSG_WriteString(netmessage_t *msg, char *string) -{ - if (msg->size + strlen(string) + 1 >= MAX_NETMESSAGE) - { - WinPrint("NMSG_WriteString: overflow\n"); +void NMSG_WriteString( netmessage_t *msg, char *string ){ + if ( msg->size + strlen( string ) + 1 >= MAX_NETMESSAGE ) { + WinPrint( "NMSG_WriteString: overflow\n" ); return; } //end if - memcpy(&msg->data[msg->size], string, strlen(string) + 1); - msg->size += strlen(string) + 1; + memcpy( &msg->data[msg->size], string, strlen( string ) + 1 ); + msg->size += strlen( string ) + 1; } //end of the function NMSG_WriteString //=========================================================================== // @@ -489,8 +460,7 @@ void NMSG_WriteString(netmessage_t *msg, char *string) // Returns: - // Changes Globals: - //=========================================================================== -void NMSG_ReadStart(netmessage_t *msg) -{ +void NMSG_ReadStart( netmessage_t *msg ){ msg->readoverflow = qfalse; msg->read = 4; } //end of the function NMSG_ReadStart @@ -500,16 +470,14 @@ void NMSG_ReadStart(netmessage_t *msg) // Returns: - // Changes Globals: - //=========================================================================== -int NMSG_ReadChar(netmessage_t *msg) -{ - if (msg->read + 1 > msg->size) - { +int NMSG_ReadChar( netmessage_t *msg ){ + if ( msg->read + 1 > msg->size ) { msg->readoverflow = qtrue; - WinPrint("NMSG_ReadChar: read overflow\n"); + WinPrint( "NMSG_ReadChar: read overflow\n" ); return 0; } //end if msg->read++; - return msg->data[msg->read-1]; + return msg->data[msg->read - 1]; } //end of the function NMSG_ReadChar //=========================================================================== // @@ -517,16 +485,14 @@ int NMSG_ReadChar(netmessage_t *msg) // Returns: - // Changes Globals: - //=========================================================================== -int NMSG_ReadByte(netmessage_t *msg) -{ - if (msg->read + 1 > msg->size) - { +int NMSG_ReadByte( netmessage_t *msg ){ + if ( msg->read + 1 > msg->size ) { msg->readoverflow = qtrue; - WinPrint("NMSG_ReadByte: read overflow\n"); + WinPrint( "NMSG_ReadByte: read overflow\n" ); return 0; } //end if msg->read++; - return msg->data[msg->read-1]; + return msg->data[msg->read - 1]; } //end of the function NMSG_ReadByte //=========================================================================== // @@ -534,17 +500,15 @@ int NMSG_ReadByte(netmessage_t *msg) // Returns: - // Changes Globals: - //=========================================================================== -int NMSG_ReadShort(netmessage_t *msg) -{ +int NMSG_ReadShort( netmessage_t *msg ){ int c; - if (msg->read + 2 > msg->size) - { + if ( msg->read + 2 > msg->size ) { msg->readoverflow = qtrue; - WinPrint("NMSG_ReadShort: read overflow\n"); + WinPrint( "NMSG_ReadShort: read overflow\n" ); return 0; } //end if - c = (short)(msg->data[msg->read] + (msg->data[msg->read+1]<<8)); + c = (short)( msg->data[msg->read] + ( msg->data[msg->read + 1] << 8 ) ); msg->read += 2; return c; } //end of the function NMSG_ReadShort @@ -554,20 +518,18 @@ int NMSG_ReadShort(netmessage_t *msg) // Returns: - // Changes Globals: - //=========================================================================== -int NMSG_ReadLong(netmessage_t *msg) -{ +int NMSG_ReadLong( netmessage_t *msg ){ int c; - if (msg->read + 4 > msg->size) - { + if ( msg->read + 4 > msg->size ) { msg->readoverflow = qtrue; - WinPrint("NMSG_ReadLong: read overflow\n"); + WinPrint( "NMSG_ReadLong: read overflow\n" ); return 0; } //end if c = msg->data[msg->read] - + (msg->data[msg->read+1]<<8) - + (msg->data[msg->read+2]<<16) - + (msg->data[msg->read+3]<<24); + + ( msg->data[msg->read + 1] << 8 ) + + ( msg->data[msg->read + 2] << 16 ) + + ( msg->data[msg->read + 3] << 24 ); msg->read += 4; return c; } //end of the function NMSG_ReadLong @@ -577,20 +539,18 @@ int NMSG_ReadLong(netmessage_t *msg) // Returns: - // Changes Globals: - //=========================================================================== -float NMSG_ReadFloat(netmessage_t *msg) -{ +float NMSG_ReadFloat( netmessage_t *msg ){ int c; - if (msg->read + 4 > msg->size) - { + if ( msg->read + 4 > msg->size ) { msg->readoverflow = qtrue; - WinPrint("NMSG_ReadLong: read overflow\n"); + WinPrint( "NMSG_ReadLong: read overflow\n" ); return 0; } //end if c = msg->data[msg->read] - + (msg->data[msg->read+1]<<8) - + (msg->data[msg->read+2]<<16) - + (msg->data[msg->read+3]<<24); + + ( msg->data[msg->read + 1] << 8 ) + + ( msg->data[msg->read + 2] << 16 ) + + ( msg->data[msg->read + 3] << 24 ); msg->read += 4; return *(float *)&c; } //end of the function NMSG_ReadFloat @@ -600,27 +560,27 @@ float NMSG_ReadFloat(netmessage_t *msg) // Returns: - // Changes Globals: - //=========================================================================== -char *NMSG_ReadString(netmessage_t *msg) -{ - static char string[2048]; +char *NMSG_ReadString( netmessage_t *msg ){ + static char string[2048]; int l, c; - + l = 0; do { - if (msg->read + 1 > msg->size) - { + if ( msg->read + 1 > msg->size ) { msg->readoverflow = qtrue; - WinPrint("NMSG_ReadString: read overflow\n"); + WinPrint( "NMSG_ReadString: read overflow\n" ); string[l] = 0; return string; } //end if c = msg->data[msg->read]; msg->read++; - if (c == 0) break; + if ( c == 0 ) { + break; + } string[l] = c; l++; - } while (l < sizeof(string)-1); + } while ( (size_t) l < sizeof( string ) - 1 ); string[l] = 0; return string; } //end of the function NMSG_ReadString