53 System Interface (i_net)
This tour explores linuxdoom
’s networking interface (i_net
), which handles UDP
communication between game instances for multiplayer gameplay.
53.1 i_net.h
- Declares:
I_InitNetwork
: Initializes networking at startupI_NetCmd
: Handles network commands during runtime
// linuxdoom-1.10/i_net.h (lines 33–40)
53.2 i_net.c
53.2.1 Socket Setup
UDPsocket: Creates a new UDP network socket
// lines 90–99
BindToLocalPort: Configures a socket to listen for incoming data
// lines 105–120
53.2.2 Packet Transmission
PacketSend:
- Copies
netbuffer
to local structure - Converts fields to network byte order
- Sends via UDP
// lines 127–155
- Copies
PacketGet:
- Receives packets
- Returns
doomcom->remotenode = -1
if none are available
// doomstat.h lines 276–277
Validates packets:
// lines 161–178
53.2.3 Initialization
- I_InitNetwork:
- Allocates
doomcom
- Checks
-net
argument - Sets up sockets and network addresses
- Allocates
// lines 187–218
// lines 243–252: fallback to single-player if -net not present
// lines 281–290: set function pointers
// lines 293–303: local player + host parsing
// lines 303–312: socket setup
// lines 327–332: final socket setup
53.2.4 Packet Handling & Dispatch
- I_NetCmd:
- Dispatches based on
doomcom->command
:CMD_SEND
: →netsend()
CMD_GET
: →netget()
- Dispatches based on
// d_net.c lines 568–572
// i_net.c lines 335–346
// d_net.c lines 185, 209
And that’s how linuxdoom
’s i_net
interface enables multiplayer networking via sockets and command dispatch.