User:Monster Iestyn/Source Code Documentation/i_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 __I_NET__

Includes

Macros

Macro Defined as Description
DOOMCOM_ID (INT32)0x12345678l The doomcom ID number. If doomcom->id is not set to this number, it is considered invalid.
MAXPACKETLENGTH 1450 The maximum length of a packet in a LAN netgame, in bytes. This also serves as the maximum size of the packet data buffer in the doomcom struct.
INETPACKETLENGTH 1024 The maximum length of a packet in a internet netgame, in bytes.

Externs

Variables

Data name Data type Non-extern location(s) Description
hardware_MAXPACKETLENGTH INT16 d_net.c The "hardware" maximum length of a packet. This has no actual effect in a netgame: it is instead used to set a default value for software_MAXPACKETLENGTH. It also serves as an upper limit for said variable, if the user tries to modify the maximum packet length via the -packetsize command line parameter.

By default, hardware_MAXPACKETLENGTH will have a value of MAXPACKETLENGTH. However, if the the game automatically joins or starts hosting a server on game startup, a value of INETPACKETLENGTH is used. However, if the user attempts to use the -bandwidth command line parameter to increase the bandwidth to above 100000, hardware_MAXPACKETLENGTH will be set to a value of MAXPACKETLENGTH.

net_bandwidth INT32 d_net.c The network bandwidth, in bytes per second. This defaults to 30000 bytes per second, or 16000 if the the game automatically starts hosting a server on game startup, or 800000 if the user is hosting a LAN netgame on game startup.
*doomcom doomcom_t d_net.c The doomcom buffer, for handling network communication related settings. In SRB2 this is mainly used for sending or receiving packets.
*bannednode boolean d_net.c A pointer to an array storing whether each node is on the ban list or not. Similarly to the function pointers, this defaults to an array in i_tcp.c, but it may point to another array depending on port and/or libraries supported in the build. Each node's entry in this array is set when you receive a packet from them for the first time (see I_NetGet).

If you are the host of a server, any PT_CLIENTJOIN packet recieved from a banned node will make the game automatically send a PT_SERVERREFUSE packet in reply, stating they are banned from the server. This has no effect otherwise.

Function pointers

In public releases of SRB2 these normally point to a set of functions within i_tcp.c (once I_InitTcpNetwork has been called), but they may point to other set of functions depending on the port of SRB2 used and/or whether support for a networking library or driver exists in the build (e.g.: SDL builds compiled with support for SDL_net, a library not used by public releases).

Data name Return type Params Non-extern location(s) Description
I_NetGet boolean none d_net.c Receives a packet from a remote node, and modifies doomcom accordingly. If a packet was sent from an address not connected to the netgame, finds a new node for the address to use; however, if the address is also found in the banlist, this marks the new node as banned.

If a packet was received this call:

  • doomcom->remotenode is the node of the player who sent the packet.
  • doomcom->data is the buffer for the packet's data.
  • doomcom->datalength is the number of bytes received (i.e. the size of doomcom->data).

If no packet was received this call:

  • doomcom->remotenode is set to -1, indicating that no packet was received.

Returns true if a packet was received from a new node, false in all other cases.

I_NetCanGet boolean none d_net.c Returns true if there is packet data to be received, false if not. This pointer is non-NULL only if SRB2 is using the default TCP network driver code (this is always the case in current public releases); the DOS port also requires WatTCP, and the KOS Dreamcast port also requires lwIP. (Note: this function is currently unused)
I_NetSend void none d_net.c Sends a packet to a remote node using data from doomcom (which must be set beforehand):
  • doomcom->remotenode is the node of the player to send the packet to.
  • doomcom->data is the buffer for the packet's data.
  • doomcom->datalength is the number of bytes to send (i.e. the size of doomcom->data).
I_NetCanSend boolean none d_net.c Returns true if packet data can be sent, false if not. This pointer is non-NULL only if SRB2 is using the default TCP network driver code (this is always the case in current public releases); the DOS port also requires WatTCP, and the KOS Dreamcast port also requires lwIP.
I_NetFreeNodenum void INT32 nodenum d_net.c Closes a node's connection, and frees the node for future use by new players. This does not work on node 0 (the local client's node).
I_NetMakeNodewPort SINT8 const char *address,
const char *port
d_net.c Open a connection with a specified address and port. Returns the new node for the address.
I_NetOpenSocket boolean none d_net.c
I_NetCloseSocket boolean none d_net.c
I_Ban boolean INT32 node d_net.c Adds a node to the ban list. Returns true if successful, false if not.
I_ClearBans void none d_net.c Clears the ban list.
I_GetNodeAddress const char * INT32 node d_net.c Returns the address for a specified node.
I_GetBanAddress const char * size_t ban d_net.c Returns the address for a specified ban list entry.
I_GetBanMask const char * size_t ban d_net.c
I_SetBanAddress boolean const char *address,
const char *mask
d_net.c

Typedefs

Name Type Attributes Description
doomcom_t struct ATTRPACK The doomcom buffer's data struct.

doomcom_t

Data name Data type Description
id INT32 This should always have a value of DOOMCOM_ID. If it does not, the doomcom buffer is invalid.
intnum INT16 Unused
command INT16 Unused
remotenode INT16 The node of a remote player. (See I_NetSend and I_NetGet.)
datalength INT16 The packet data buffer's length, in bytes. (See I_NetSend and I_NetGet.)
numnodes INT16 The number of nodes to wait for at the start of a netgame. Note: this is always set to 1 in SRB2.
ticdup INT16 Unused.
extratics INT16 The number of backup tics the server will send to clients. By default this is set to 1.
gametype INT16 Unused
savegame INT16 Unused
map INT16 Unused
consoleplayer INT16 Unused – note that this will always have a value of zero.
numslots INT16 The highest player number in use plus one.
data[MAXPACKETLENGTH] char The packet data buffer. (See I_NetSend and I_NetGet.)

Function prototypes

Function name Return type Params Defined in Description
I_NetMakeNode SINT8 const char *address d_net.c Open a connection with a specified address. Returns the new node for the address. The port can optionally be given in the address string as well, if it is using the format address:port.
I_InitNetwork boolean none
  • android/i_net.c
  • djgppdos/i_net.c
  • dummy/i_net.c
  • nds/i_net.c
  • sdl/i_net.c
  • sdl12/i_net.c
  • sdl12/SRB2DC/i_udp.c
  • win32/win_net.c
  • win32ce/win_net.c
Initialises network drivers, for ports that support them. Returns true if network drivers were initialised, returns false if not or the port does not support this feature.

For the DOS port of SRB2, the command line parameter -net is required to start up external network drivers. For SDL builds compiled with SDL_net support (not in public releases), this function returns true if the command line -server is used or a dedicated server is being started. For all other ports of SRB2, this function will always return false; attempting to use -net on the Windows port or other SDL builds will cause the game to I_Error.