The gamestate is handled completly by the server. The gamestate consists of an array of players which consist of a ID and an array of units.
The clients send commands to the server and receive the current gamestate.
This is the state machine on the Server:
┏━━━━━━━┓ ┏━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃*start*┠──►┃ClientHello┠──►┃ServerHello(ClientId, World)┠─╮
┗━━━━━━━┛ ┗━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ │
│
┏━━━━━━━━━━━┓ │
┃*connected*┃◄─────────────────────────────────┴──┬─╮
┗┯┯━━━━━━━━━┛ │ │
││ │ │
││ ┏━━━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━━━━┓ │ │
│╰─►┃Command(Command)┠──►┃UpdateGamestate(Game)┠─╯ │
│ ┗━━━━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━┛ │
│ │
│ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┓ │
╰──►┃ClientReconnect(ClientId)┠────────────────────╯
┗━━━━━━━━━━━━━━━━━━━━━━━━━┛
- Initially, the server waits for a
ClientHello
message. - It responds with a
ServerHello
message that contains the client ID that can be used by the client for reconnecting with aClientReconnect
message when the connection was lost. - Then the server enters a loop and waits for a
Command
from the client. When such a command results in a world change, the world is sent back to the client as anUpdateGamestate
message.
Hello from client! Server responds with an ID that was assigned to the client.
After that only Update Gamestate commands follow.
The server sends the current gamestate to the client.
Client sends a move command to the server.
Here are some interesting links about networking in games:
- Lobby
- Players are allowd to connect
- Settings may be changed
- Running
- Players are only allowed to reconnect
- World shape, size
- Unit size, speed, HP