SetupHost() function handles all server initialization.
How hosting works
Configure the server address
The server binds to all available network interfaces on the specified port:
main.cpp
ENET_HOST_ANY allows the server to accept connections on any network interface.Create the ENet host
Create the server host with the following parameters:Parameters:
main.cpp
- Max clients:
1- Only one client can connect for 1v1 gameplay - Max channels:
2- Two communication channels available - Bandwidth limits:
0- No bandwidth restrictions
Verify host creation
Check if the host was created successfully:If creation fails, the function returns
main.cpp
false and the game returns to the main menu.Complete SetupHost function
main.cpp
Network variables
The following global variables manage the host connection:main.cpp
When hosting, the server uses
serverHost to manage the connection and stores the connected client in clientPeer.