diff --git a/include/netchan.h b/include/netchan.h index 8384789f3..0d7e565af 100644 --- a/include/netchan.h +++ b/include/netchan.h @@ -106,6 +106,7 @@ typedef struct netadr_t remote_address; int qport; + int flags; // bandwidth estimator double cleartime; // if realtime > nc->cleartime, free to go @@ -135,6 +136,8 @@ typedef struct } netchan_t; extern int net_drop; // packets dropped before this one +extern int net_nochoke; // don't choke packets +extern int net_blocksend; // don't send packets (used by client for demos) void Netchan_Init (void); void Netchan_Init_Cvars (void); @@ -142,7 +145,10 @@ void Netchan_Transmit (netchan_t *chan, int length, byte *data); void Netchan_OutOfBand (netadr_t adr, int length, byte *data); void Netchan_OutOfBandPrint (netadr_t adr, const char *format, ...) __attribute__((format(printf,2,3))); qboolean Netchan_Process (netchan_t *chan); -void Netchan_Setup (netchan_t *chan, netadr_t adr, int qport); +void Netchan_Setup (netchan_t *chan, netadr_t adr, int qport, int flags); + +#define NC_SEND_QPORT 0x01 +#define NC_READ_QPORT 0x02 qboolean Netchan_CanPacket (netchan_t *chan); qboolean Netchan_CanReliable (netchan_t *chan); diff --git a/libs/net/net_chan.c b/libs/net/net_chan.c index 3e1ac2a52..93f736cc4 100644 --- a/libs/net/net_chan.c +++ b/libs/net/net_chan.c @@ -104,6 +104,8 @@ static __attribute__ ((unused)) const char rcsid[] = */ int net_drop; +int net_nochoke; +int net_blocksend; cvar_t *showpackets; cvar_t *showdrop; cvar_t *qport; @@ -155,10 +157,7 @@ Netchan_OutOfBand (netadr_t adr, int length, byte * data) // send the datagram // zoid, no input in demo playback mode - if (!is_server) { - if (!cls.demoplayback) - Netchan_SendPacket (send.cursize, send.data, adr); - } else + if (!net_blocksend) Netchan_SendPacket (send.cursize, send.data, adr); } @@ -189,7 +188,7 @@ Netchan_OutOfBandPrint (netadr_t adr, const char *format, ...) called to open a channel to a remote system */ void -Netchan_Setup (netchan_t *chan, netadr_t adr, int qport) +Netchan_Setup (netchan_t *chan, netadr_t adr, int qport, int flags) { memset (chan, 0, sizeof (*chan)); @@ -201,6 +200,7 @@ Netchan_Setup (netchan_t *chan, netadr_t adr, int qport) chan->message.maxsize = sizeof (chan->message_buf); chan->qport = qport; + chan->flags = flags; chan->rate = 1.0 / 2500.0; } @@ -242,7 +242,7 @@ Netchan_CanReliable (netchan_t *chan) 0 length will still generate a packet and deal with the reliable messages. */ void -Netchan_Transmit (netchan_t *chan, int length, byte * data) +Netchan_Transmit (netchan_t *chan, int length, byte *data) { byte send_buf[MAX_MSGLEN + PACKET_HEADER]; int i; @@ -286,8 +286,8 @@ Netchan_Transmit (netchan_t *chan, int length, byte * data) MSG_WriteLong (&send, w2); // send the qport if we are a client - if (!is_server) - MSG_WriteShort (&send, cls.qport); + if (chan->flags & NC_SEND_QPORT) + MSG_WriteShort (&send, chan->qport); // copy the reliable message to the packet first if (send_reliable) { @@ -304,17 +304,14 @@ Netchan_Transmit (netchan_t *chan, int length, byte * data) chan->outgoing_time[i] = realtime; // zoid, no input in demo playback mode - if (!is_server) { - if (!cls.demoplayback) - Netchan_SendPacket (send.cursize, send.data, chan->remote_address); - } else + if (!net_blocksend) Netchan_SendPacket (send.cursize, send.data, chan->remote_address); if (chan->cleartime < realtime) chan->cleartime = realtime + send.cursize * chan->rate; else chan->cleartime += send.cursize * chan->rate; - if (ServerPaused ()) + if (net_nochoke) chan->cleartime = realtime; if (showpackets->int_val) @@ -335,13 +332,9 @@ Netchan_Process (netchan_t *chan) int qport; unsigned int reliable_ack, reliable_message, sequence, sequence_ack; - if (is_server) { + if (!net_blocksend) if (!NET_CompareAdr (net_from, chan->remote_address)) return false; - } else { - if (!cls.demoplayback && - !NET_CompareAdr (net_from, chan->remote_address)) return false; - } // get sequence numbers MSG_BeginReading (net_message); @@ -349,7 +342,7 @@ Netchan_Process (netchan_t *chan) sequence_ack = MSG_ReadLong (net_message); // read the qport if we are a server - if (is_server) + if (chan->flags & NC_READ_QPORT) qport = MSG_ReadShort (net_message); reliable_message = sequence >> 31; diff --git a/qtv/source/qtv.c b/qtv/source/qtv.c index c7cf66ab7..c0249f3fb 100644 --- a/qtv/source/qtv.c +++ b/qtv/source/qtv.c @@ -50,23 +50,17 @@ static __attribute__ ((unused)) const char rcsid[] = #include "netchan.h" -#include "../../qw/include/client.h" //FIXME ick, netchan is so incestuous - SERVER_PLUGIN_PROTOS static plugin_list_t server_plugin_list[] = { SERVER_PLUGIN_LIST }; -qboolean is_server = true; double realtime; cvar_t *net_packetlog; -client_static_t cls; void Log_Outgoing_Packet (const char *p, int len, int has_sequence); void Log_Incoming_Packet (const char *p, int len, int has_sequence); -qboolean ServerPaused (void); void Log_Outgoing_Packet (const char *p, int len, int has_sequence) { } void Log_Incoming_Packet (const char *p, int len, int has_sequence) { } -qboolean ServerPaused (void) { return 0; } cbuf_t *qtv_cbuf; diff --git a/qw/source/cl_demo.c b/qw/source/cl_demo.c index 6b6ee907a..9b3cbdbbf 100644 --- a/qw/source/cl_demo.c +++ b/qw/source/cl_demo.c @@ -119,6 +119,7 @@ CL_StopPlayback (void) cls.demoplayback = 0; cls.demoplayback2 = 0; demotime_cached = 0; + net_blocksend = 0; if (cls.timedemo) CL_FinishTimeDemo (); @@ -896,6 +897,7 @@ CL_StartDemo (void) } cls.demoplayback = true; + net_blocksend = 1; if (strequal (QFS_FileExtension (name), ".mvd")) { cls.demoplayback2 = true; Con_Printf ("mvd\n"); @@ -903,7 +905,7 @@ CL_StartDemo (void) Con_Printf ("qwd\n"); } CL_SetState (ca_demostart); - Netchan_Setup (&cls.netchan, net_from, 0); + Netchan_Setup (&cls.netchan, net_from, 0, NC_SEND_QPORT); realtime = 0; cls.findtrack = true; cls.lasttype = 0; diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index 9a3ca0796..6c570e46d 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -845,7 +845,7 @@ CL_ConnectionlessPacket (void) Con_Printf ("Dup connect received. Ignored.\n"); return; } - Netchan_Setup (&cls.netchan, net_from, cls.qport); + Netchan_Setup (&cls.netchan, net_from, cls.qport, NC_SEND_QPORT); MSG_WriteByte (&cls.netchan.message, clc_stringcmd); MSG_WriteString (&cls.netchan.message, "new"); CL_SetState (ca_connected); @@ -1820,9 +1820,3 @@ Host_Shutdown (void) if (host_basepal) VID_Shutdown (); } - -qboolean -ServerPaused (void) -{ - return false; -} diff --git a/qw/source/sv_main.c b/qw/source/sv_main.c index efd644017..e383f8bda 100644 --- a/qw/source/sv_main.c +++ b/qw/source/sv_main.c @@ -83,7 +83,6 @@ static __attribute__ ((unused)) const char rcsid[] = #include "bothdefs.h" #include "buildnum.h" #include "compat.h" -#include "client.h" //FIXME needed by cls below (for netchan) #include "crudefile.h" #include "game.h" #include "netchan.h" @@ -102,7 +101,6 @@ cbuf_t *sv_cbuf; cbuf_args_t *sv_args; client_t *host_client; // current client -client_static_t cls; //FIXME needed by netchan :/ entity_state_t cl_entities[MAX_CLIENTS][UPDATE_BACKUP+1][MAX_PACKET_ENTITIES]; // client entities double sv_frametime; @@ -214,13 +212,6 @@ const char *client_info_filters[] = { // Info keys needed by client NULL }; - -qboolean -ServerPaused (void) -{ - return sv.paused; -} - /* Master_Shutdown @@ -905,7 +896,7 @@ SVC_DirectConnect (void) Netchan_OutOfBandPrint (adr, "%c", S2C_CONNECTION); - Netchan_Setup (&newcl->netchan, adr, qport); + Netchan_Setup (&newcl->netchan, adr, qport, NC_READ_QPORT); newcl->state = cs_connected; newcl->prespawned = false; diff --git a/qw/source/sv_pr_cmds.c b/qw/source/sv_pr_cmds.c index e01b7a5c0..182a5c094 100644 --- a/qw/source/sv_pr_cmds.c +++ b/qw/source/sv_pr_cmds.c @@ -1823,7 +1823,7 @@ PF_SV_AllocClient (progs_t *pr) return; } - //XXX netchan? Netchan_Setup (&newcl->netchan, adr, qport); + //XXX netchan? Netchan_Setup (&newcl->netchan, adr, qport, NC_READ_QPORT); cl->state = cs_server; cl->spectator = 0; cl->connection_started = realtime; diff --git a/qw/source/sv_user.c b/qw/source/sv_user.c index 2be7a3a36..e62ef5151 100644 --- a/qw/source/sv_user.c +++ b/qw/source/sv_user.c @@ -944,6 +944,7 @@ SV_TogglePause (const char *msg) int i; sv.paused ^= 1; + net_nochoke = sv.paused; if (msg) SV_BroadcastPrintf (PRINT_HIGH, "%s", msg);