User:Monster Iestyn/Source Code Documentation/d_net.h

From SRB2 Wiki
Jump to navigation Jump to search
This article or section is incomplete. It doesn't have all of the necessary core information on this topic. Please help the SRB2 Wiki by finishing this article.
Online link GitHub entry
File type C header file
#include guard __D_NET__

Macros

Macro Defined as Description
MAXNETNODES (MAXPLAYERS+4) (36) Maximum number of nodes/computers allowed to connect to a netgame.
BROADCASTADDR MAXNETNODES (36) A special node number used to search for local servers?
MAXSPLITSCREENPLAYERS 2 Maximum number of players allowed in splitscreen. (Unused)
STATLENGTH (TICRATE*2) Minimum amount of time, in tics, between updates of networking statistics by Net_GetNetStat.

Externs

Data name Data type Non-extern location(s) Description
Networking statistics
ticruned
ticmiss
INT32 d_net.c ticruned – The number of times the game has checked for ticcmds.

ticmiss – The number of times ticcmds were not received when checking for ticcmds.

Both are reset to zero by Net_GetNetStat every STATLENGTH tics (2 seconds).

getbps
sendbps
INT32 d_net.c Bytes of packet data received and sent per second. Updated by Net_GetNetStat every STATLENGTH tics (2 seconds).
lostpercent
duppercent
gamelostpercent
float d_net.c Percentages of sent packets lost, received packets duplicated, and ticcmds lost. Updated by Net_GetNetStat every STATLENGTH tics (2 seconds).
packetheaderlength INT32 d_net.c The length of a packet header, in bytes. This is set to a value of 20 + 8 in i_tcp.c's UDP_Socket; for the DOS port however, I_InitNetwork sets this to a value of 30+4+4 (ipx + time + 4 padding bytes)
getbytes INT32 d_net.c Number of bytes of packet data received in a set period of time. Reset to zero by Net_GetNetStat every STATLENGTH tics (2 seconds).
sendbytes INT64 d_net.c Total number of bytes of packet data sent.
Node-player arrays
nodetoplayer[MAXNETNODES] SINT8 d_clisrv.c Array storing the player number for each node. Unused nodes will have a value of -1.
nodetoplayer2[MAXNETNODES] SINT8 d_clisrv.c Array storing the second player's player number for each node, for nodes using splitscreen. Unused nodes and nodes not using splitscreen will have a value of -1. (Note: SRB2 does not currently support splitscreen in netplay)
playerpernode[MAXNETNODES] UINT8 d_clisrv.c Array storing number of players per node. This should usually be 0 or 1; if the node is using splitscreen this will be 2. (Note: SRB2 does not currently support splitscreen in netplay)
nodeingame[MAXNETNODES] boolean d_clisrv.c Array storing whether each node is in-game or not. Note that a connected player waiting to join is not considered to be in-game.

Function prototypes

Function name Return type Params Defined in Description
Net_GetNetStat boolean none d_net.c Gets the current networking statistics, if at least STATLENGTH tics (2 seconds) have passed since the last call. Returns true if the network statistics were updated this call, returns false if not.
Net_GetFreeAcks INT32 boolean urgent d_net.c Counts how many ack slots are free in the ackpak table. If urgent is true, all ack slots are counted, including those reserved for "urgent" packets (i.e.: those with a packet type lower than PT_CANFAIL); if it is false, the ack slots reserved for "urgent" packets will not be counted.
Net_AckTicker void none d_net.c Resends packets that have not been acknowledged yet by their destination nodes. If the game has not sent packets for a long time, and the game needs to acknowledge packets received from other nodes, this also sends PT_NOTHING packets containing only acks.
HSendPacket boolean INT32 node,
boolean reliable,
UINT8 acknum,
size_t packetlength
d_net.c Handler function for sending a packet to a node. Returns true if the packet was sent, false otherwise. If reliable is true, the packet will be stored in the ackpak table to be resent later if it was not acknowledged.
HGetPacket boolean none d_net.c Handler function for getting a packet. Returns true if a valid packet was found, returns false if there are no packets left. Note that invalid packets and acks (PT_NOTHING packets) are handled by this function, and will not cause the function to return; the function will continue to search for other valid packet types afterwards until one is found or no packets are left.
D_SetDoomcom void none d_net.c Initialises the doomcom struct, if not already set.
D_SaveBan void none d_clisrv.c Declared only if NONET is not defined

Saves a ban to ban.txt.

D_CheckNetGame boolean none d_net.c Checks the network game status, initialises networking-related variables and settings.
D_CloseConnection void none d_net.c If in a netgame, disconnects the local client from the netgame.
Net_UnAcknowledgePacket void INT32 node d_net.c
Net_CloseConnection void INT32 node d_net.c Closes the game's connection to the node. If the game is waiting for acks from this node, the connection is not closed immediately but will close it after the acks have been returned. If 0x8000 (aka FORCECLOSE in d_net.c) is added to the node number, the connection is forced to be closed regardless of the acks.
Net_ConnectionTimeout void INT32 node d_net.c Marks the node as having timed out. The game sends a special PT_NODETIMEOUT packet to itself to close its connection to the node later (and kick them out if they are still in-game).
Net_AbortPacketType void UINT8 packettype d_net.c Removes all acks of a given packet type.
Net_SendAcks void INT32 node d_net.c Sends a special packet with just an ack on it.
Net_WaitAllAckReceived void UINT32 timeout d_net.c Waits for all acks to be received. timeout determines the time to wait in seconds.