Network System

🚨
Multiplayer is currently broken
Network synchronization (src/decnet.cpp) is incomplete. DirectPlay support through Free Direct / Free API is unverified. This page documents the intended architecture from the source code and README.

Overview

Free Eggbert supports up to 4 simultaneous network players via DirectPlay (DirectX 3). The implementation spans two files:

  • src/network.cppCNetwork class: DirectPlay session management, lobby browsing, transport selection
  • src/decnet.cppCDecor network methods: in-game tick-by-tick synchronization, packet send/receive, event replay

Session Lifecycle

The multiplayer flow is driven by WM_PHASE_* messages dispatched by CEvent:

  1. WM_PHASE_SERVICE — Player selects the DirectPlay transport (IPX, TCP/IP, modem)
  2. WM_PHASE_SESSION — Browse existing sessions (up to MAXSESSION=100 shown) or create a new one
  3. WM_PHASE_MULTI — Pre-game lobby; players wait until the host starts the game
  4. WM_PHASE_PLAY — Synchronized gameplay; each player sends a NetPacket every game tick

Packet Flow (Per Tick)

Every game tick during WM_PHASE_PLAY:

  1. Each player constructs a NetPacket from their current input (KEY_* bitmask), position (blupiPosX/Y), animation state (blupiIcon, blupiChannel), and vehicle (blupiTransport)
  2. Up to 5 NetMessage game events are embedded in the packet
  3. The packet is broadcast via CNetwork::Send() to all other players
  4. Each client receives packets, replays the events in decnet.cpp

Packet Types (PK_*)

ConstantValueDescription
PK_LEAVE8Player left the session gracefully
PK_LOST9Player connection lost (dropped)
PK_DIE10Player character died
PK_PAUSE12Game pause toggled by a player

Game Events (MESS_*)

Up to MAXMESSAGEPERPACKET (5) game events can be piggy-backed in each NetPacket. They use NetMessage structs with a type field set to one of these constants:

ConstantValueDescription
MESS_RESUME0Resume game after pause
MESS_PAUSE1Pause the game
MESS_LOBBY4Return to lobby
MESS_START10Start game from lobby
MESS_OBJECTSTART20Spawn a new moving object
MESS_OBJECTDELETE21Remove a moving object
MESS_MODIFDECOR30Modify a world decor cell
MESS_PLAYSOUND40Play a sound effect
MESS_STOPSOUND41Stop a sound effect
MESS_ASCENSEURSTART50Start an elevator
MESS_ASCENSEUREND51Stop an elevator
MESS_STOPCLOUD60Stop cloud invisibility effect

Personal Bombs

In multiplayer mode, each player has their own colored personal bomb type. These are fired and tracked independently per player, allowing bombs to be attributed to their owner:

PlayerConstantColor
Player 1TYPE_BOMBEPERSO1Yellow
Player 2TYPE_BOMBEPERSO2Orange
Player 3TYPE_BOMBEPERSO3Blue
Player 4TYPE_BOMBEPERSO4Green

Data Structures

See Data Structures — NetPacket for the full NetPacket and NetMessage struct field tables.

Network Limits

ConstantValueDescription
MAXNETPLAYER4Maximum simultaneous players
MAXTEAM4Maximum teams
MAXSESSION100Max sessions listed in browser
MAXNETMESSAGE20Max pending queued messages
MAXMESSAGEPERPACKET5Max game events per packet