2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
net_chan.c
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-10-16 21:40:45 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2001-08-29 02:12:57 +00:00
|
|
|
# include <unistd.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2001-08-29 02:12:57 +00:00
|
|
|
#include <time.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/cvar.h"
|
2003-05-08 23:24:02 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/msg.h"
|
2001-11-27 04:50:41 +00:00
|
|
|
#include "QF/sys.h"
|
2001-08-29 02:12:57 +00:00
|
|
|
|
|
|
|
#include "compat.h"
|
2003-02-11 22:48:57 +00:00
|
|
|
#include "netchan.h"
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#define PACKET_HEADER 8
|
|
|
|
|
2004-02-19 08:58:42 +00:00
|
|
|
int net_nochoke;
|
|
|
|
int net_blocksend;
|
2004-02-19 23:06:47 +00:00
|
|
|
double *net_realtime;
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
int showpackets;
|
|
|
|
static cvar_t showpackets_cvar = {
|
|
|
|
.name = "showpackets",
|
|
|
|
.description =
|
|
|
|
"Show all network packets",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &showpackets },
|
|
|
|
};
|
|
|
|
int showdrop;
|
|
|
|
static cvar_t showdrop_cvar = {
|
|
|
|
.name = "showdrop",
|
|
|
|
.description =
|
|
|
|
"Toggle the display of how many packets you are dropping",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &showdrop },
|
|
|
|
};
|
|
|
|
int qport;
|
|
|
|
static cvar_t qport_cvar = {
|
|
|
|
.name = "qport",
|
|
|
|
.description =
|
|
|
|
"The internal port number for the game networking code. Useful for "
|
|
|
|
"clients who use multiple connections through one IP address (NAT/IP-"
|
|
|
|
"MASQ) because default port is random.",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_NONE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &qport },
|
|
|
|
};
|
2021-12-27 08:54:58 +00:00
|
|
|
void (*net_log_packet) (int length, const void *data, netadr_t to);
|
2001-08-29 02:12:57 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Netchan_Init (void)
|
|
|
|
{
|
|
|
|
int port;
|
|
|
|
|
|
|
|
// pick a port value that should be nice and random
|
2001-11-27 04:50:41 +00:00
|
|
|
port = Sys_TimeID ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
qport = port;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Netchan_Init_Cvars (void)
|
|
|
|
{
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&showpackets_cvar, 0, 0);
|
|
|
|
Cvar_Register (&showdrop_cvar, 0, 0);
|
|
|
|
Cvar_Register (&qport_cvar, 0, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Netchan_OutOfBand
|
|
|
|
|
|
|
|
Sends an out-of-band datagram
|
|
|
|
*/
|
|
|
|
void
|
2021-04-04 06:53:53 +00:00
|
|
|
Netchan_OutOfBand (netadr_t adr, unsigned length, byte * data)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
byte send_buf[MAX_MSGLEN + PACKET_HEADER];
|
2001-08-29 02:12:57 +00:00
|
|
|
sizebuf_t send;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// write the packet header
|
2001-02-19 21:15:25 +00:00
|
|
|
send.data = send_buf;
|
|
|
|
send.maxsize = sizeof (send_buf);
|
|
|
|
send.cursize = 0;
|
|
|
|
|
|
|
|
MSG_WriteLong (&send, -1); // -1 sequence means out of band
|
|
|
|
SZ_Write (&send, data, length);
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// send the datagram
|
2001-02-19 21:15:25 +00:00
|
|
|
// zoid, no input in demo playback mode
|
2004-02-19 08:58:42 +00:00
|
|
|
if (!net_blocksend)
|
2003-02-10 21:41:22 +00:00
|
|
|
Netchan_SendPacket (send.cursize, send.data, adr);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Netchan_OutOfBandPrint
|
|
|
|
|
|
|
|
Sends a text message in an out-of-band datagram
|
|
|
|
*/
|
|
|
|
void
|
2001-07-15 07:04:17 +00:00
|
|
|
Netchan_OutOfBandPrint (netadr_t adr, const char *format, ...)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-05-08 23:24:02 +00:00
|
|
|
static dstring_t *string;
|
2001-08-29 02:12:57 +00:00
|
|
|
va_list argptr;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-05-08 23:24:02 +00:00
|
|
|
if (!string)
|
|
|
|
string = dstring_new ();
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
va_start (argptr, format);
|
2003-05-08 23:24:02 +00:00
|
|
|
dvsprintf (string, format, argptr);
|
2001-02-19 21:15:25 +00:00
|
|
|
va_end (argptr);
|
|
|
|
|
2003-05-08 23:24:02 +00:00
|
|
|
Netchan_OutOfBand (adr, strlen (string->str), (byte *) string->str);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Netchan_Setup
|
|
|
|
|
|
|
|
called to open a channel to a remote system
|
|
|
|
*/
|
|
|
|
void
|
2011-07-23 12:39:13 +00:00
|
|
|
Netchan_Setup (netchan_t *chan, netadr_t adr, int qport, ncqport_e flags)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
memset (chan, 0, sizeof (*chan));
|
|
|
|
|
|
|
|
chan->remote_address = adr;
|
2004-02-19 23:06:47 +00:00
|
|
|
chan->last_received = *net_realtime;
|
2005-05-02 06:31:55 +00:00
|
|
|
chan->incoming_sequence = -1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
chan->message.data = chan->message_buf;
|
|
|
|
chan->message.allowoverflow = true;
|
|
|
|
chan->message.maxsize = sizeof (chan->message_buf);
|
|
|
|
|
|
|
|
chan->qport = qport;
|
2004-02-19 08:58:42 +00:00
|
|
|
chan->flags = flags;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-06-17 16:18:34 +00:00
|
|
|
chan->rate = 1.0 / 2500.0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
#define MAX_BACKUP 200
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Netchan_CanPacket
|
|
|
|
|
|
|
|
Returns true if the bandwidth choke isn't active
|
|
|
|
*/
|
|
|
|
qboolean
|
|
|
|
Netchan_CanPacket (netchan_t *chan)
|
|
|
|
{
|
2004-02-19 23:06:47 +00:00
|
|
|
if (chan->cleartime < *net_realtime + MAX_BACKUP * chan->rate)
|
2001-02-19 21:15:25 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Netchan_CanReliable
|
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
Returns true if the bandwidth choke isn't
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
|
|
|
qboolean
|
|
|
|
Netchan_CanReliable (netchan_t *chan)
|
|
|
|
{
|
|
|
|
if (chan->reliable_length)
|
|
|
|
return false; // waiting for ack
|
|
|
|
return Netchan_CanPacket (chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-04-04 06:53:53 +00:00
|
|
|
Netchan_Transmit (netchan_t *chan, unsigned length, byte *data)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
byte send_buf[MAX_MSGLEN + PACKET_HEADER];
|
|
|
|
int i;
|
2001-08-29 02:12:57 +00:00
|
|
|
unsigned int w1, w2;
|
|
|
|
qboolean send_reliable;
|
|
|
|
sizebuf_t send;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// check for message overflow
|
2001-02-19 21:15:25 +00:00
|
|
|
if (chan->message.overflowed) {
|
|
|
|
chan->fatal_error = true;
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s:Outgoing message overflow\n",
|
2001-02-19 21:15:25 +00:00
|
|
|
NET_AdrToString (chan->remote_address));
|
|
|
|
return;
|
|
|
|
}
|
2001-08-29 02:12:57 +00:00
|
|
|
// if the remote side dropped the last reliable message, resend it
|
2001-02-19 21:15:25 +00:00
|
|
|
send_reliable = false;
|
|
|
|
|
|
|
|
if (chan->incoming_acknowledged > chan->last_reliable_sequence
|
|
|
|
&& chan->incoming_reliable_acknowledged != chan->reliable_sequence)
|
|
|
|
send_reliable = true;
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// if the reliable transmit buffer is empty, copy the current message out
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!chan->reliable_length && chan->message.cursize) {
|
|
|
|
memcpy (chan->reliable_buf, chan->message_buf, chan->message.cursize);
|
|
|
|
chan->reliable_length = chan->message.cursize;
|
|
|
|
chan->message.cursize = 0;
|
|
|
|
chan->reliable_sequence ^= 1;
|
|
|
|
send_reliable = true;
|
|
|
|
}
|
2001-08-29 02:12:57 +00:00
|
|
|
// write the packet header
|
2001-02-19 21:15:25 +00:00
|
|
|
send.data = send_buf;
|
|
|
|
send.maxsize = sizeof (send_buf);
|
|
|
|
send.cursize = 0;
|
|
|
|
|
|
|
|
w1 = chan->outgoing_sequence | (send_reliable << 31);
|
|
|
|
w2 = chan->incoming_sequence | (chan->incoming_reliable_sequence << 31);
|
|
|
|
|
|
|
|
chan->outgoing_sequence++;
|
|
|
|
|
|
|
|
MSG_WriteLong (&send, w1);
|
|
|
|
MSG_WriteLong (&send, w2);
|
|
|
|
|
2011-07-26 02:29:41 +00:00
|
|
|
/// Send the qport if appropriate (we are a client).
|
2011-07-23 08:51:07 +00:00
|
|
|
if (chan->flags & NC_QPORT_SEND)
|
2004-02-19 08:58:42 +00:00
|
|
|
MSG_WriteShort (&send, chan->qport);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2011-07-26 02:29:41 +00:00
|
|
|
/// First copy the reliable message to the packet.
|
2001-02-19 21:15:25 +00:00
|
|
|
if (send_reliable) {
|
|
|
|
SZ_Write (&send, chan->reliable_buf, chan->reliable_length);
|
|
|
|
chan->last_reliable_sequence = chan->outgoing_sequence;
|
|
|
|
}
|
2011-07-26 02:29:41 +00:00
|
|
|
/// Then add the unreliable part if space is available.
|
2001-02-19 21:15:25 +00:00
|
|
|
if (send.maxsize - send.cursize >= length)
|
|
|
|
SZ_Write (&send, data, length);
|
|
|
|
|
2011-07-26 02:29:41 +00:00
|
|
|
/// Send the datagram if not blocked (in demo playback mode)
|
2001-02-19 21:15:25 +00:00
|
|
|
i = chan->outgoing_sequence & (MAX_LATENT - 1);
|
|
|
|
chan->outgoing_size[i] = send.cursize;
|
2004-02-19 23:06:47 +00:00
|
|
|
chan->outgoing_time[i] = *net_realtime;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// zoid, no input in demo playback mode
|
2004-02-19 08:58:42 +00:00
|
|
|
if (!net_blocksend)
|
2003-02-10 21:41:22 +00:00
|
|
|
Netchan_SendPacket (send.cursize, send.data, chan->remote_address);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-19 23:06:47 +00:00
|
|
|
if (chan->cleartime < *net_realtime)
|
|
|
|
chan->cleartime = *net_realtime + send.cursize * chan->rate;
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
|
|
|
chan->cleartime += send.cursize * chan->rate;
|
2004-02-19 08:58:42 +00:00
|
|
|
if (net_nochoke)
|
2004-02-19 23:06:47 +00:00
|
|
|
chan->cleartime = *net_realtime;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (showpackets & 1) {
|
2010-01-13 06:45:43 +00:00
|
|
|
Sys_Printf ("--> s=%i(%i) a=%i(%i) %-4i %i\n",
|
|
|
|
chan->outgoing_sequence, send_reliable,
|
|
|
|
chan->incoming_sequence, chan->incoming_reliable_sequence,
|
|
|
|
send.cursize,
|
2005-05-10 02:37:34 +00:00
|
|
|
chan->outgoing_sequence - chan->incoming_sequence);
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (showpackets & 4) {
|
2020-08-17 04:08:49 +00:00
|
|
|
SZ_Dump (&send);
|
|
|
|
}
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qboolean
|
|
|
|
Netchan_Process (netchan_t *chan)
|
|
|
|
{
|
2001-08-29 02:12:57 +00:00
|
|
|
unsigned int reliable_ack, reliable_message, sequence, sequence_ack;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-19 08:58:42 +00:00
|
|
|
if (!net_blocksend)
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!NET_CompareAdr (net_from, chan->remote_address))
|
|
|
|
return false;
|
|
|
|
|
2011-07-26 02:29:41 +00:00
|
|
|
/// Get the sequence numbers.
|
2001-02-23 23:16:13 +00:00
|
|
|
MSG_BeginReading (net_message);
|
|
|
|
sequence = MSG_ReadLong (net_message);
|
|
|
|
sequence_ack = MSG_ReadLong (net_message);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2011-07-26 02:29:41 +00:00
|
|
|
/// Read the qport if appropriate (we are a server), but ignore it.
|
2011-07-23 08:51:07 +00:00
|
|
|
if (chan->flags & NC_QPORT_READ)
|
2011-06-19 01:48:02 +00:00
|
|
|
MSG_ReadShort (net_message);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
reliable_message = sequence >> 31;
|
|
|
|
reliable_ack = sequence_ack >> 31;
|
|
|
|
|
|
|
|
sequence &= ~(1 << 31);
|
|
|
|
sequence_ack &= ~(1 << 31);
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (showpackets & 2) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("<-- s=%i(%i) a=%i(%i) %i\n", sequence, reliable_message,
|
2001-02-23 23:16:13 +00:00
|
|
|
sequence_ack, reliable_ack, net_message->message->cursize);
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (showpackets & 8) {
|
2020-08-17 04:08:49 +00:00
|
|
|
SZ_Dump (net_message->message);
|
|
|
|
}
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// get a rate estimation
|
2002-07-07 02:33:00 +00:00
|
|
|
#if 0 // FIXME: Dead code
|
2001-02-19 21:15:25 +00:00
|
|
|
if (chan->outgoing_sequence - sequence_ack < MAX_LATENT) {
|
|
|
|
int i;
|
|
|
|
double time, rate;
|
|
|
|
|
|
|
|
i = sequence_ack & (MAX_LATENT - 1);
|
2004-02-19 23:06:47 +00:00
|
|
|
time = *net_realtime - chan->outgoing_time[i];
|
2001-02-19 21:15:25 +00:00
|
|
|
time -= 0.1; // subtract 100 ms
|
|
|
|
if (time <= 0) { // gotta be a digital link for <100
|
|
|
|
// ms ping
|
|
|
|
if (chan->rate > 1.0 / 5000)
|
|
|
|
chan->rate = 1.0 / 5000;
|
|
|
|
} else {
|
2010-01-13 06:42:26 +00:00
|
|
|
if (chan->outgoing_size[i] < 512) { // deal with only small
|
2001-02-19 21:15:25 +00:00
|
|
|
// messages
|
|
|
|
rate = chan->outgoing_size[i] / time;
|
|
|
|
if (rate > 5000)
|
|
|
|
rate = 5000;
|
|
|
|
rate = 1.0 / rate;
|
|
|
|
if (chan->rate > rate)
|
|
|
|
chan->rate = rate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-07-26 02:29:41 +00:00
|
|
|
/// Discard stale or duplicated packets.
|
2005-05-02 06:31:55 +00:00
|
|
|
if (sequence < (unsigned int) chan->incoming_sequence + 1) {
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (showdrop)
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s:Out of order packet %i at %i\n",
|
2001-02-19 21:15:25 +00:00
|
|
|
NET_AdrToString (chan->remote_address), sequence,
|
|
|
|
chan->incoming_sequence);
|
|
|
|
return false;
|
|
|
|
}
|
2001-08-29 02:12:57 +00:00
|
|
|
|
2011-07-26 02:29:41 +00:00
|
|
|
/// Dropped packets don't keep the message from being used.
|
2005-05-08 06:35:46 +00:00
|
|
|
chan->net_drop = sequence - (chan->incoming_sequence + 1);
|
|
|
|
if (chan->net_drop > 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
chan->drop_count += 1;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (showdrop)
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%s:Dropped %i packets at %i\n",
|
2001-02-19 21:15:25 +00:00
|
|
|
NET_AdrToString (chan->remote_address),
|
2002-07-07 02:33:00 +00:00
|
|
|
sequence - (chan->incoming_sequence + 1), sequence);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-08-29 02:12:57 +00:00
|
|
|
|
2011-07-26 02:29:41 +00:00
|
|
|
/// If the current outgoing reliable message has been acknowledged,
|
|
|
|
/// clear the buffer to make way for the next.
|
2001-02-19 21:15:25 +00:00
|
|
|
if (reliable_ack == (unsigned int) chan->reliable_sequence)
|
|
|
|
chan->reliable_length = 0; // it has been received
|
|
|
|
|
2011-07-26 02:29:41 +00:00
|
|
|
/// If this message contains a reliable message, bump
|
2012-05-21 23:23:22 +00:00
|
|
|
/// incoming_reliable_sequence
|
2001-02-19 21:15:25 +00:00
|
|
|
chan->incoming_sequence = sequence;
|
|
|
|
chan->incoming_acknowledged = sequence_ack;
|
|
|
|
chan->incoming_reliable_acknowledged = reliable_ack;
|
|
|
|
if (reliable_message)
|
|
|
|
chan->incoming_reliable_sequence ^= 1;
|
|
|
|
|
2011-07-26 02:29:41 +00:00
|
|
|
// The message can now be read from the current message pointer.
|
|
|
|
/// Update statistics counters.
|
2001-02-19 21:15:25 +00:00
|
|
|
chan->frame_latency = chan->frame_latency * OLD_AVG
|
|
|
|
+ (chan->outgoing_sequence - sequence_ack) * (1.0 - OLD_AVG);
|
|
|
|
chan->frame_rate = chan->frame_rate * OLD_AVG
|
2004-02-19 23:06:47 +00:00
|
|
|
+ (*net_realtime - chan->last_received) * (1.0 - OLD_AVG);
|
2001-02-19 21:15:25 +00:00
|
|
|
chan->good_count += 1;
|
|
|
|
|
2004-02-19 23:06:47 +00:00
|
|
|
chan->last_received = *net_realtime;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-12-19 10:54:23 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Netchan_SendPacket (int length, const void *data, netadr_t to)
|
|
|
|
{
|
2021-12-27 08:54:58 +00:00
|
|
|
if (net_log_packet) {
|
|
|
|
net_log_packet (length, data, to);
|
|
|
|
}
|
2009-12-19 10:54:23 +00:00
|
|
|
NET_SendPacket (length, data, to);
|
|
|
|
}
|