Skip to content

Second Instance Network Failure #2198

Description

@githubawn

Prerequisites

  • I have searched for similar issues and confirmed this is not a duplicate

Game Version

  • Command & Conquer Generals
  • Command & Conquer Generals: Zero Hour
  • Other (please specify below)

Bug Description

0127.1.mp4

Hypothesis: The current networking implementation uses fixed ports for LAN communication, which likely leads to initialization failures when multiple instances run on the same machine.

Lobby Port: Fixed at 8086 (LAN_LOBBY_PORT)
Game Port: Based on 8088 (NETWORK_BASE_PORT_NUMBER)
When attempting to run multiple game instances on the same machine (e.g., for local testing or split-screen setups), the second instance fails to bind to these ports because they are already in use by the first instance.

Reproduction Steps

Open the game executable to launch the first instance.
Navigate to Multiplayer -> LAN Lobby.
Without closing the first instance, launch a second instance of the game on the same machine.
Attempt to navigate to Multiplayer -> LAN Lobby on the second instance.
Observation: The second instance displays an error message and returns to the previous menu (or fails to initialize network capabilities).

Additional Context

Dynamic Port Allocation
File: Core/GameEngine/Include/GameNetwork/NetworkDefs.h & Transport.cpp
Action: Update Transport::init (called by LANAPI::init for Lobby and OnGameStart for Game) to attempt binding 8086/8088 first. Only if those are busy (ADDRINUSE), iterate through a range (e.g., +1 to +25). This guarantees Instance 1 remains on standard ports (Legacy Compatible).

Update Discovery/Broadcast
File: Core/GameEngine/Include/GameNetwork/LANAPI.h & LANAPIhandlers.cpp
Action: Update LANAPI::sendMessage to iterate and send discovery packets to the entire port range (e.g. 8086-8113), ensuring instances on non-standard ports receive them. Write the Host's actual listening port into the existing "Port" field of Slot 0 in the GameOptions string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething is not working right, typically is user facing⚠️ TriageIssues requiring initial review and prioritization

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions