Data Structures | |
struct | netchan_s |
Macros | |
#define | MAX_LATENT 32 |
#define | OLD_AVG 0.99 |
Typedefs | |
typedef struct netchan_s | netchan_t |
Enumerations | |
enum | ncqport_e { NC_QPORT_SEND = 0x01, NC_QPORT_READ = 0x02 } |
Functions | |
qboolean | Netchan_CanPacket (netchan_t *chan) |
Check if a packet can be sent to the connection. More... | |
qboolean | Netchan_CanReliable (netchan_t *chan) |
Check if a reliable packet can be sent to the connection. More... | |
void | Netchan_Init (void) |
Initialize the netchan system. More... | |
void | Netchan_Init_Cvars (void) |
Initialize the netchan cvars. More... | |
void | Netchan_OutOfBand (netadr_t adr, int length, byte *data) |
Send an out-of-band packet. More... | |
void | Netchan_OutOfBandPrint (netadr_t adr, const char *format,...) |
Send a formatted string as an out-of-band packet. More... | |
qboolean | Netchan_Process (netchan_t *chan) |
Process a packet for the specifiied connection. More... | |
void | Netchan_SendPacket (int length, const void *data, netadr_t to) |
Send a packet. More... | |
void | Netchan_Setup (netchan_t *chan, netadr_t adr, int qport, ncqport_e flags) |
Initialize a new connection. More... | |
void | Netchan_Transmit (netchan_t *chan, int length, byte *data) |
Try to send an unreliable packet to a connection. More... | |
Variables | |
int | net_blocksend |
Disable packet sending. More... | |
int | net_nochoke |
Disable packet choking. More... | |
double * | net_realtime |
Pointer to variable holding the current time in seconds. More... | |
Packet Header | |
Bits | Meaning |
31 | sequence |
1 | this message contains a reliable payload |
31 | acknowledge sequence |
1 | acknowledge receipt of even/odd message |
16 | qport |
The remote connection never knows if it missed a reliable message, the local side detects that it has been dropped by seeing a sequence acknowledge higher than the last reliable sequence, but without the correct even/odd bit for the reliable set.
If the sender notices that a reliable message has been dropped, it will be retransmitted. It will not be retransmitted again until a message after the retransmit has been acknowledged and the reliable still failed to get there.
If the sequence number and reliable payload bits are all 1 (32bit -1), the packet is an out-of-band packet and should be handled without a netcon.
The reliable message can be added to at any time by doing MSG_Write* (&netchan->message, data).
If the message buffer is overflowed, either by a single message, or by multiple frames worth piling up while the last reliable transmit goes unacknowledged, the netchan signals a fatal error.
Reliable messages are always placed first in a packet, then the unreliable message is included if there is sufficient room.
To the receiver, there is no distinction between the reliable and unreliable parts of the message, they are just processed out as a single larger message.
Illogical packet sequence numbers cause the packet to be dropped, but do not kill the connection. This, combined with the tight window of valid reliable acknowledgement numbers provides protection against malicious address spoofing.
The qport field is a workaround for bad address translating routers that sometimes remap the client's source port on a packet during gameplay.
If the base part of the net address matches and the qport matches, then the channel matches even if the IP port differs. The IP port should be updated to the new value before sending out any replies.
#define MAX_LATENT 32 |
#define OLD_AVG 0.99 |
enum ncqport_e |
Check if a packet can be sent to the connection.
chan | The netchan representing the connection. |
Check if a reliable packet can be sent to the connection.
chan | The netchan representing the connection. |
void Netchan_Init | ( | void | ) |
Initialize the netchan system.
Currently only sets the qport cvar default to a random value.
void Netchan_Init_Cvars | ( | void | ) |
Initialize the netchan cvars.
Send an out-of-band packet.
adr | The address to which the data will be sent. |
length | The length of the data to be sent. |
data | The data to be sent. |
Send a formatted string as an out-of-band packet.
adr | The address to which the data will be sent. |
format | The printf style format string. |
Process a packet for the specifiied connection.
Called when the current net_message is from remote_address. Modifies net_message so that it points to the packet payload.
chan | The netchan representing the connection. |
Get the sequence numbers.
Read the qport if appropriate (we are a server), but ignore it.
Discard stale or duplicated packets.
Dropped packets don't keep the message from being used.
If the current outgoing reliable message has been acknowledged, clear the buffer to make way for the next.
If this message contains a reliable message, bump incoming_reliable_sequence
Update statistics counters.
Send a packet.
Very raw. Just calls NET_SendPacket().
length | The length of the data to be sent. |
data | The data to be sent. |
to | The address to which the data will be sent. |
Initialize a new connection.
chan | The netchan representing the connection. |
adr | The address of the remote end of the connection. |
qport | The qport associated with the connection. |
flags | Control of the sending/reading of the qport on this connection. |
Try to send an unreliable packet to a connection.
Handles transmission or retransmission of the reliable packet.
0 length will still generate a packet and deal with the reliable messages.
chan | The netchan representing the connection. |
length | The size of the unreliable packet. |
data | The data of the unreliable packet. |
Send the qport if appropriate (we are a client).
First copy the reliable message to the packet.
Then add the unreliable part if space is available.
Send the datagram if not blocked (in demo playback mode)
int net_blocksend |
Disable packet sending.
Used by clients in demo playback mode.
int net_nochoke |
Disable packet choking.
double* net_realtime |
Pointer to variable holding the current time in seconds.