diff --git a/include/netchan.h b/include/netchan.h index 71da80691..8384789f3 100644 --- a/include/netchan.h +++ b/include/netchan.h @@ -73,11 +73,11 @@ qboolean NET_IsClientLegal(netadr_t *adr); int Net_Log_Init (const char **sound_precache); -void Log_Incoming_Packet (const char *p, int len); -void Log_Outgoing_Packet (const char *p, int len); +void Log_Incoming_Packet (const char *p, int len, int has_sequence); +void Log_Outgoing_Packet (const char *p, int len, int has_sequence); void Net_LogStop (void); -void Analyze_Client_Packet (const byte * data, int len); -void Analyze_Server_Packet (const byte * data, int len); +void Analyze_Client_Packet (const byte * data, int len, int has_sequence); +void Analyze_Server_Packet (const byte * data, int len, int has_sequence); extern struct cvar_s *net_packetlog; @@ -147,23 +147,11 @@ void Netchan_Setup (netchan_t *chan, netadr_t adr, int qport); qboolean Netchan_CanPacket (netchan_t *chan); qboolean Netchan_CanReliable (netchan_t *chan); -static inline int -Netchan_GetPacket (void) -{ - int ret; - - ret = NET_GetPacket (); - if (ret && net_packetlog->int_val) - Log_Incoming_Packet(net_message->message->data, - net_message->message->cursize); - return ret; -} - static inline void Netchan_SendPacket (int length, void *data, netadr_t to) { if (net_packetlog->int_val) - Log_Outgoing_Packet(data, length); + Log_Outgoing_Packet(data, length, 1); NET_SendPacket (length, data, to); } diff --git a/qw/source/cl_demo.c b/qw/source/cl_demo.c index 48607d670..f8abbf242 100644 --- a/qw/source/cl_demo.c +++ b/qw/source/cl_demo.c @@ -402,9 +402,12 @@ CL_GetMessage (void) if (cls.demoplayback) return CL_GetDemoMessage (); - if (!Netchan_GetPacket ()) + if (!NET_GetPacket ()) return false; + Log_Incoming_Packet(net_message->message->data, + net_message->message->cursize, 1); + CL_WriteDemoMessage (net_message->message); return true; diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index 14e0bf445..405384810 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -1014,7 +1014,7 @@ CL_ReadPackets (void) if (cls.demoplayback && net_packetlog->int_val) Log_Incoming_Packet(net_message->message->data, - net_message->message->cursize); + net_message->message->cursize, 0); // remote command packet if (*(int *) net_message->message->data == -1) { diff --git a/qw/source/net_packetlog.c b/qw/source/net_packetlog.c index 3ddb07867..4c450f555 100644 --- a/qw/source/net_packetlog.c +++ b/qw/source/net_packetlog.c @@ -250,7 +250,7 @@ ascii_dump_buf (unsigned char *buf, int len) } */ void -Log_Incoming_Packet (const char *p, int len) +Log_Incoming_Packet (const char *p, int len, int has_sequence) { if (!net_loglevel->int_val) return; @@ -261,20 +261,20 @@ Log_Incoming_Packet (const char *p, int len) if (net_loglevel->int_val != 3) hex_dump_buf ((unsigned char *) p, len); if (net_loglevel->int_val > 1) - Analyze_Client_Packet (p, len); + Analyze_Client_Packet (p, len, has_sequence); } else { Net_LogPrintf ("\n>>>>>>>>>>>>>>>>>>>>> server to client %d bytes: " ">>>>>>>>>>>>>>>>>>>>>>>>\n", len); if (net_loglevel->int_val != 3) hex_dump_buf ((unsigned char *) p, len); if (net_loglevel->int_val > 1) - Analyze_Server_Packet (p, len); + Analyze_Server_Packet (p, len, has_sequence); } return; } void -Log_Outgoing_Packet (const char *p, int len) +Log_Outgoing_Packet (const char *p, int len, int has_sequence) { if (!net_loglevel->int_val) return; @@ -285,14 +285,14 @@ Log_Outgoing_Packet (const char *p, int len) if (net_loglevel->int_val != 3) hex_dump_buf ((unsigned char *) p, len); if (net_loglevel->int_val > 1) - Analyze_Server_Packet (p, len); + Analyze_Server_Packet (p, len, has_sequence); } else { Net_LogPrintf ("\n<<<<<<<<<<<<<<<<<<<<< client to server %d bytes: " "<<<<<<<<<<<<<<<<<<<<<<<<\n", len); if (net_loglevel->int_val != 3) hex_dump_buf ((unsigned char *) p, len); if (net_loglevel->int_val > 1) - Analyze_Client_Packet (p, len); + Analyze_Client_Packet (p, len, has_sequence); } return; } @@ -376,29 +376,33 @@ Log_Delta(int bits) static void -Parse_Server_Packet (void) +Parse_Server_Packet (int has_sequence) { const char *s; int c, i, ii, iii, mask1, mask2; - long seq1, seq2; + long seq1 = 0, seq2; - seq1 = MSG_ReadLong (&packet); - if (packet.badread) - return; + if (has_sequence) { + seq1 = MSG_ReadLong (&packet); + if (packet.badread) + return; + } if (seq1 == -1) { Net_LogPrintf ("Special Packet"); } else { - seq2 = MSG_ReadLong (&packet); - // FIXME: display seqs right when reliable - Net_LogPrintf ("\nSeq: %ld Ack: %ld ", seq1 & 0x7FFFFFFF, - seq2 & 0x7FFFFFFF); + if (has_sequence) { + seq2 = MSG_ReadLong (&packet); + // FIXME: display seqs right when reliable + Net_LogPrintf ("\nSeq: %ld Ack: %ld ", seq1 & 0x7FFFFFFF, + seq2 & 0x7FFFFFFF); - if ((seq1 >> 31) & 0x01) - Net_LogPrintf ("SV_REL "); - if ((seq2 >> 31) & 0x01) - Net_LogPrintf ("SV_RELACK"); - Net_LogPrintf ("\n"); + if ((seq1 >> 31) & 0x01) + Net_LogPrintf ("SV_REL "); + if ((seq2 >> 31) & 0x01) + Net_LogPrintf ("SV_RELACK"); + Net_LogPrintf ("\n"); + } while (1) { if (packet.badread) @@ -806,36 +810,39 @@ Parse_Server_Packet (void) } void -Analyze_Server_Packet (const byte * data, int len) +Analyze_Server_Packet (const byte * data, int len, int has_sequence) { if (!Net_PacketLog) Net_PacketLog = _stdout; packet.message->data = (byte*)data; packet.message->cursize = len; MSG_BeginReading (&packet); - Parse_Server_Packet (); + Parse_Server_Packet (has_sequence); if (Net_PacketLog == _stdout) Net_PacketLog = NULL; } static void -Parse_Client_Packet (void) +Parse_Client_Packet (int has_sequence) { int mask, i, c, ii; - long seq1, seq2; + long seq1 = 0, seq2; - seq1 = MSG_ReadLong (&packet); + if (has_sequence) + seq1 = MSG_ReadLong (&packet); if (seq1 == -1) { Net_LogPrintf ("Special: %s\n", MSG_ReadString (&packet)); return; } else { - // FIXME: display seqs right when reliable - seq2 = MSG_ReadLong (&packet); + if (has_sequence) { + // FIXME: display seqs right when reliable + seq2 = MSG_ReadLong (&packet); - Net_LogPrintf ("\nSeq: %ld Ack: %ld ", seq1 & 0x7FFFFFFF, - seq2 & 0x7FFFFFFF); + Net_LogPrintf ("\nSeq: %ld Ack: %ld ", seq1 & 0x7FFFFFFF, + seq2 & 0x7FFFFFFF); - Net_LogPrintf ("QP: %u\n", MSG_ReadShort (&packet)); + Net_LogPrintf ("QP: %u\n", MSG_ReadShort (&packet)); + } while (1) { if (packet.badread) @@ -912,14 +919,14 @@ Parse_Client_Packet (void) } void -Analyze_Client_Packet (const byte * data, int len) +Analyze_Client_Packet (const byte * data, int len, int has_sequence) { if (!Net_PacketLog) Net_PacketLog = _stdout; packet.message->data = (byte*)data; packet.message->cursize = len; MSG_BeginReading (&packet); - Parse_Client_Packet (); + Parse_Client_Packet (has_sequence); if (Net_PacketLog == _stdout) Net_PacketLog = NULL; } diff --git a/qw/source/sv_main.c b/qw/source/sv_main.c index 12b6acd5d..bca463daf 100644 --- a/qw/source/sv_main.c +++ b/qw/source/sv_main.c @@ -1750,7 +1750,9 @@ SV_ReadPackets (void) double until; good = false; - while (Netchan_GetPacket ()) { + while (NET_GetPacket ()) { + Log_Incoming_Packet(net_message->message->data, + net_message->message->cursize, 1); if (SV_FilterIP (net_from.ip, &until)) { SV_SendBan (until); // tell them we aren't listening... continue; diff --git a/qw/source/sv_send.c b/qw/source/sv_send.c index 0ff596595..cb40f0e77 100644 --- a/qw/source/sv_send.c +++ b/qw/source/sv_send.c @@ -848,17 +848,13 @@ SV_SendClientMessages (void) // if the reliable message overflowed, drop the client if (c->netchan.message.overflowed) { int i; - byte *data = Hunk_TempAlloc (MAX_MSGLEN + 8); - memset (data, 0, 8); - - memcpy (data + 8, c->netchan.message.data, - c->netchan.message.cursize); - Analyze_Server_Packet (data, c->netchan.message.cursize + 8); + Analyze_Server_Packet (c->netchan.message.data, + c->netchan.message.cursize, 0); for (i = 0; i < c->num_backbuf; i++) { - memcpy (data + 8, c->backbuf_data[i], c->backbuf_size[i]); - Analyze_Server_Packet (data, c->backbuf_size[i] + 8); + Analyze_Server_Packet (c->backbuf_data[i], + c->backbuf_size[i], 0); } SZ_Clear (&c->netchan.message);