make the low level network code and packet logging less incentuous

This commit is contained in:
Bill Currie 2003-02-10 21:41:22 +00:00
parent ab7c31032e
commit f4fdbeee4d
10 changed files with 63 additions and 45 deletions

View file

@ -29,6 +29,8 @@
#ifndef _NET_H
#define _NET_H
#include "QF/cvar.h"
#include "QF/msg.h"
#include "QF/qdefs.h"
#include "QF/sizebuf.h"
@ -69,6 +71,19 @@ const char *NET_BaseAdrToString (netadr_t a);
qboolean NET_StringToAdr (const char *s, netadr_t *a);
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 Net_LogStop (void);
void Analyze_Client_Packet (const byte * data, int len);
void Analyze_Server_Packet (const byte * data, int len);
extern struct cvar_s *net_packetlog;
extern qboolean is_server;
qboolean ServerPaused (void);
//============================================================================
#define OLD_AVG 0.99 // total = oldtotal*OLD_AVG + new*(1-OLD_AVG)
@ -132,16 +147,24 @@ void Netchan_Setup (netchan_t *chan, netadr_t adr, int qport);
qboolean Netchan_CanPacket (netchan_t *chan);
qboolean Netchan_CanReliable (netchan_t *chan);
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 Net_LogStop (void);
void Analyze_Client_Packet (const byte * data, int len);
void Analyze_Server_Packet (const byte * data, int len);
static inline int
Netchan_GetPacket (void)
{
int ret;
extern struct cvar_s *net_packetlog;
ret = NET_GetPacket ();
if (ret && net_packetlog->int_val)
Log_Incoming_Packet(net_message->message->data,
net_message->message->cursize);
return ret;
}
extern qboolean is_server;
qboolean ServerPaused (void);
static inline void
Netchan_SendPacket (int length, void *data, netadr_t to)
{
if (net_packetlog->int_val)
Log_Outgoing_Packet(data, length);
NET_SendPacket (length, data, to);
}
#endif // _NET_H

View file

@ -402,7 +402,7 @@ CL_GetMessage (void)
if (cls.demoplayback)
return CL_GetDemoMessage ();
if (!NET_GetPacket ())
if (!Netchan_GetPacket ())
return false;
CL_WriteDemoMessage (net_message->message);

View file

@ -292,7 +292,7 @@ CL_SendConnectPacket (void)
snprintf (data, sizeof (data), "%c%c%c%cconnect %i %i %i \"%s\"\n",
255, 255, 255, 255, PROTOCOL_VERSION, cls.qport, cls.challenge,
Info_MakeString (cls.userinfo, 0));
NET_SendPacket (strlen (data), data, cls.server_addr);
Netchan_SendPacket (strlen (data), data, cls.server_addr);
}
/*
@ -330,7 +330,7 @@ CL_CheckForResend (void)
Con_Printf ("Connecting to %s...\n", cls.servername);
snprintf (data, sizeof (data), "%c%c%c%cgetchallenge\n", 255, 255, 255,
255);
NET_SendPacket (strlen (data), data, cls.server_addr);
Netchan_SendPacket (strlen (data), data, cls.server_addr);
}
void
@ -386,7 +386,7 @@ CL_Rcon_f (void)
to.port = BigShort (27500);
}
NET_SendPacket (strlen (message) + 1, message, to);
Netchan_SendPacket (strlen (message) + 1, message, to);
}
void
@ -772,7 +772,7 @@ CL_Packet_f (void)
}
*out = 0;
NET_SendPacket (out - send, send, adr);
Netchan_SendPacket (out - send, send, adr);
}
/*
@ -970,7 +970,7 @@ CL_ConnectionlessPacket (void)
data[4] = A2A_ACK;
data[5] = 0;
NET_SendPacket (6, &data, net_from);
Netchan_SendPacket (6, &data, net_from);
return;
}

View file

@ -112,8 +112,8 @@ S_Refresh (server_entry_t *slrefresh)
slrefresh->pingsent = Sys_DoubleTime ();
slrefresh->pongback = 0;
NET_SendPacket (6, data_ping, addy);
NET_SendPacket (11, data_status, addy);
Netchan_SendPacket (6, data_ping, addy);
Netchan_SendPacket (11, data_status, addy);
slrefresh->waitstatus = 1;
}
@ -503,21 +503,21 @@ SL_MasterUpdate(void)
SL_Del_All(slist);
slist = NULL;
NET_StringToAdr ("194.251.249.32:27000", &addy);
NET_SendPacket (3, data, addy);
Netchan_SendPacket (3, data, addy);
NET_StringToAdr ("qwmaster.barrysworld.com:27000", &addy);
NET_SendPacket (3, data, addy);
Netchan_SendPacket (3, data, addy);
NET_StringToAdr ("192.246.40.37:27000", &addy);
NET_SendPacket (3, data, addy);
Netchan_SendPacket (3, data, addy);
NET_StringToAdr ("192.246.40.37:27002", &addy);
NET_SendPacket (3, data, addy);
Netchan_SendPacket (3, data, addy);
NET_StringToAdr ("192.246.40.37:27003", &addy);
NET_SendPacket (3, data, addy);
Netchan_SendPacket (3, data, addy);
NET_StringToAdr ("192.246.40.37:27004", &addy);
NET_SendPacket (3, data, addy);
Netchan_SendPacket (3, data, addy);
NET_StringToAdr ("192.246.40.37:27006", &addy);
NET_SendPacket (3, data, addy);
Netchan_SendPacket (3, data, addy);
NET_StringToAdr ("203.9.148.7:27000", &addy);
NET_SendPacket (3, data, addy);
Netchan_SendPacket (3, data, addy);
}
static int

View file

@ -155,9 +155,9 @@ Netchan_OutOfBand (netadr_t adr, int length, byte * data)
// zoid, no input in demo playback mode
if (!is_server) {
if (!cls.demoplayback)
NET_SendPacket (send.cursize, send.data, adr);
Netchan_SendPacket (send.cursize, send.data, adr);
} else
NET_SendPacket (send.cursize, send.data, adr);
Netchan_SendPacket (send.cursize, send.data, adr);
}
/*
@ -301,9 +301,9 @@ Netchan_Transmit (netchan_t *chan, int length, byte * data)
// zoid, no input in demo playback mode
if (!is_server) {
if (!cls.demoplayback)
NET_SendPacket (send.cursize, send.data, chan->remote_address);
Netchan_SendPacket (send.cursize, send.data, chan->remote_address);
} else
NET_SendPacket (send.cursize, send.data, chan->remote_address);
Netchan_SendPacket (send.cursize, send.data, chan->remote_address);
if (chan->cleartime < realtime)
chan->cleartime = realtime + send.cursize * chan->rate;

View file

@ -302,8 +302,6 @@ NET_GetPacket (void)
return false;
}
if (net_packetlog->int_val)
Log_Incoming_Packet(net_message_buffer,_net_message_message.cursize);
return ret;
}
@ -315,9 +313,6 @@ NET_SendPacket (int length, void *data, netadr_t to)
NetadrToSockadr (&to, &addr);
if (net_packetlog->int_val)
Log_Outgoing_Packet(data,length);
ret = sendto (net_socket, data, length, 0, (struct sockaddr *) &addr,
sizeof (addr));
if (ret == -1) {

View file

@ -182,7 +182,7 @@ SV_SetMaster_f (void)
data[0] = A2A_PING;
data[1] = 0;
NET_SendPacket (2, data, master_adr[i - 1]);
Netchan_SendPacket (2, data, master_adr[i - 1]);
}
svs.last_heartbeat = -99999;

View file

@ -241,7 +241,7 @@ Master_Shutdown (void)
if (master_adr[i].port) {
SV_Printf ("Sending heartbeat to %s\n",
NET_AdrToString (master_adr[i]));
NET_SendPacket (strlen (string), string, master_adr[i]);
Netchan_SendPacket (strlen (string), string, master_adr[i]);
}
}
@ -635,7 +635,7 @@ SVC_Log (void)
if (seq == svs.logsequence - 1 || !sv_fraglogfile) {
// they already have this data, or we aren't logging frags
data[0] = A2A_NACK;
NET_SendPacket (1, data, net_from);
Netchan_SendPacket (1, data, net_from);
return;
}
@ -649,7 +649,7 @@ SVC_Log (void)
svs.logsequence - 1,
(char *) svs.log_buf[((svs.logsequence - 1) & 1)]);
NET_SendPacket (strlen (data) + 1, data, net_from);
Netchan_SendPacket (strlen (data) + 1, data, net_from);
}
/*
@ -669,7 +669,7 @@ SVC_Ping (void)
data = A2A_ACK;
NET_SendPacket (1, &data, net_from);
Netchan_SendPacket (1, &data, net_from);
}
/*
@ -1664,13 +1664,13 @@ SV_SendBan (double till)
snprintf (data + 5, sizeof (data) - 5, "\nbanned permanently.\n");
}
NET_SendPacket (strlen (data), data, net_from);
Netchan_SendPacket (strlen (data), data, net_from);
/* data[4] = A2C_CLIENT_COMMAND;
snprintf (data + 5, sizeof (data) - 5, "disconnect\n");
data2 = data + strlen (data) + 1;
snprintf (data2, sizeof (data) - (data2 - data), "12345");
NET_SendPacket (strlen (data) + strlen (data2) + 2, data, net_from);*/
Netchan_SendPacket (strlen (data) + strlen (data2) + 2, data, net_from);*/
// FIXME: this should send a disconnect to the client!
}
@ -1760,7 +1760,7 @@ SV_ReadPackets (void)
double until;
good = false;
while (NET_GetPacket ()) {
while (Netchan_GetPacket ()) {
if (SV_FilterIP (net_from.ip, &until)) {
SV_SendBan (until); // tell them we aren't listening...
continue;
@ -2260,7 +2260,7 @@ Master_Heartbeat (void)
if (master_adr[i].port) {
SV_Printf ("Sending heartbeat to %s\n",
NET_AdrToString (master_adr[i]));
NET_SendPacket (strlen (string), string, master_adr[i]);
Netchan_SendPacket (strlen (string), string, master_adr[i]);
}
}

View file

@ -80,7 +80,7 @@ SV_FlushRedirect (void)
send[4] = A2C_PRINT;
memcpy (send + 5, outputbuf, strlen (outputbuf) + 1);
NET_SendPacket (strlen (send) + 1, send, net_from);
Netchan_SendPacket (strlen (send) + 1, send, net_from);
} else if (sv_redirected == RD_CLIENT) {
ClientReliableWrite_Begin (host_client, svc_print,
strlen (outputbuf) + 3);

View file

@ -591,7 +591,7 @@ OutofBandPrintf (netadr_t where, const char *fmt, ...)
vsnprintf (send + 5, sizeof (send - 5), fmt, argptr);
va_end (argptr);
NET_SendPacket (strlen (send) + 1, send, where);
Netchan_SendPacket (strlen (send) + 1, send, where);
}
static void