Fix endian issues, byte & packet counts for the logging.
Info / modifications by Safety0ff & I closes ticket:1936 2.3: r11065 git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/branches/qt-trunk@11067 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
ca5814a331
commit
90bfae6480
|
@ -161,10 +161,10 @@ BOOL NETstopLogging(void)
|
|||
for (i = 0; i < NUM_GAME_PACKETS; i++)
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "%-24s:\t received %u times, %u bytes; sent %u times, %u bytes\n", packetname[i],
|
||||
packetcount[0][i], packetsize[0][i], packetcount[1][i], packetsize[1][i]);
|
||||
packetcount[1][i], packetsize[1][i], packetcount[0][i], packetsize[0][i]);
|
||||
PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
|
||||
totalBytessent += packetsize[1][i];
|
||||
totalBytesrecv += packetsize[0][i];
|
||||
totalBytessent += packetsize[0][i];
|
||||
totalBytesrecv += packetsize[1][i];
|
||||
totalPacketsent += packetcount[0][i];
|
||||
totalPacketrecv += packetcount[1][i];
|
||||
}
|
||||
|
@ -218,14 +218,20 @@ BOOL NETstopLogging(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
void NETlogPacket(NETMSG *msg, BOOL received)
|
||||
|
||||
/** log packet
|
||||
* \param type, uint8_t, the packet's type.
|
||||
* \param size, uint16_t, the packet's size
|
||||
* \param received, BOOL, true if we are receiving a packet, false if we are sending a packet.
|
||||
*/
|
||||
void NETlogPacket( uint8_t type, uint16_t size, BOOL received)
|
||||
{
|
||||
if (msg->type >= NUM_GAME_PACKETS)
|
||||
if (type >= NUM_GAME_PACKETS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
packetcount[received][msg->type]++;
|
||||
packetsize[received][msg->type] += msg->size;
|
||||
packetcount[received][type]++;
|
||||
packetsize[received][type] += size;
|
||||
}
|
||||
|
||||
BOOL NETlogEntry(const char *str,UDWORD a,UDWORD b)
|
||||
|
|
|
@ -32,7 +32,7 @@ extern "C"
|
|||
BOOL NETstartLogging(void);
|
||||
BOOL NETstopLogging(void);
|
||||
BOOL NETlogEntry( const char *str, UDWORD a, UDWORD b );
|
||||
void NETlogPacket(NETMSG *msg, BOOL received);
|
||||
void NETlogPacket( uint8_t type, uint16_t size, BOOL received);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1270,8 +1270,8 @@ BOOL NETsend(NETMSG *msg, UDWORD player)
|
|||
|
||||
size = msg->size + sizeof(msg->size) + sizeof(msg->type) + sizeof(msg->destination) + sizeof(msg->source);
|
||||
|
||||
NETlogPacket(msg, false);
|
||||
msg->size = hton16(msg->size);
|
||||
NETlogPacket(msg->type, msg->size, false); // log packet we are sending
|
||||
msg->size = htons(msg->size); // convert it to network byte order
|
||||
|
||||
if (NetPlay.isHost)
|
||||
{
|
||||
|
@ -1330,8 +1330,8 @@ BOOL NETbcast(NETMSG *msg)
|
|||
|
||||
size = msg->size + sizeof(msg->size) + sizeof(msg->type) + sizeof(msg->destination) + sizeof(msg->source);
|
||||
|
||||
NETlogPacket(msg, false);
|
||||
msg->size = hton16(msg->size);
|
||||
NETlogPacket(msg->type, msg->size, false); // log packet we are sending
|
||||
msg->size = htons(msg->size); // convert it to network byte order
|
||||
|
||||
if (NetPlay.isHost)
|
||||
{
|
||||
|
@ -1699,7 +1699,7 @@ receive_message:
|
|||
|
||||
if (received == false)
|
||||
{
|
||||
return false;
|
||||
return false; // (Host | client) didn't get any data
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1712,8 +1712,7 @@ receive_message:
|
|||
else if (pMsg->destination == NET_ALL_PLAYERS)
|
||||
{
|
||||
unsigned int j;
|
||||
|
||||
pMsg->size = ntoh16(pMsg->size);
|
||||
uint16_t Sbytes;
|
||||
|
||||
if (pMsg->source != NET_HOST_ONLY && (pMsg->type == NET_KICK || pMsg->type == NET_PLAYER_LEAVING) )
|
||||
{
|
||||
|
@ -1729,6 +1728,10 @@ receive_message:
|
|||
|
||||
}
|
||||
|
||||
NETlogPacket(pMsg->type, pMsg->size, true); // log packet that we received
|
||||
Sbytes = pMsg->size;
|
||||
pMsg->size = htons(pMsg->size); // convert back to network byte order when sending
|
||||
|
||||
// we are the host, and have received a broadcast packet; distribute it
|
||||
for (j = 0; j < MAX_CONNECTED_PLAYERS; ++j)
|
||||
{
|
||||
|
@ -1742,6 +1745,7 @@ receive_message:
|
|||
debug(LOG_ERROR, "Failed to send message (host broadcast): %s", strSockError(getSockErr()));
|
||||
NETplayerClientDisconnect(j);
|
||||
}
|
||||
NETlogPacket(pMsg->type, Sbytes, false); // and since we are sending it out again, log it.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1753,7 +1757,10 @@ receive_message:
|
|||
&& connected_bsocket[pMsg->destination]->socket != NULL)
|
||||
{
|
||||
debug(LOG_NET, "Reflecting message type %hhu to %hhu", pMsg->type, pMsg->destination);
|
||||
pMsg->size = ntoh16(pMsg->size);
|
||||
|
||||
NETlogPacket(pMsg->type, pMsg->size, true); // log packet that we received
|
||||
NETlogPacket(pMsg->type, pMsg->size, false); // log packet that we are sending out
|
||||
pMsg->size = htons(pMsg->size); // convert back to network byte order when sending
|
||||
|
||||
if (writeAll(connected_bsocket[pMsg->destination]->socket, pMsg, size) == SOCKET_ERROR)
|
||||
{
|
||||
|
@ -1776,8 +1783,6 @@ receive_message:
|
|||
|
||||
} while (NETprocessSystemMessage() == true);
|
||||
|
||||
NETlogPacket(pMsg, true);
|
||||
|
||||
*type = pMsg->type;
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue