get packet logging working with mvds

This commit is contained in:
Bill Currie 2003-03-16 03:17:50 +00:00
parent dc74519205
commit 2173151560
6 changed files with 56 additions and 60 deletions

View file

@ -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);
}

View file

@ -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;

View file

@ -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) {

View file

@ -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,19 +376,22 @@ 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;
if (has_sequence) {
seq1 = MSG_ReadLong (&packet);
if (packet.badread)
return;
}
if (seq1 == -1) {
Net_LogPrintf ("Special Packet");
} else {
if (has_sequence) {
seq2 = MSG_ReadLong (&packet);
// FIXME: display seqs right when reliable
Net_LogPrintf ("\nSeq: %ld Ack: %ld ", seq1 & 0x7FFFFFFF,
@ -399,6 +402,7 @@ Parse_Server_Packet (void)
if ((seq2 >> 31) & 0x01)
Net_LogPrintf ("SV_RELACK");
Net_LogPrintf ("\n");
}
while (1) {
if (packet.badread)
@ -806,29 +810,31 @@ 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;
if (has_sequence)
seq1 = MSG_ReadLong (&packet);
if (seq1 == -1) {
Net_LogPrintf ("Special: %s\n", MSG_ReadString (&packet));
return;
} else {
if (has_sequence) {
// FIXME: display seqs right when reliable
seq2 = MSG_ReadLong (&packet);
@ -836,6 +842,7 @@ Parse_Client_Packet (void)
seq2 & 0x7FFFFFFF);
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;
}

View file

@ -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;

View file

@ -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);