This document defines the Binary Protocol used for Client-Server communication in the R-Type Clone. It relies on UDP for transport and MsgPack for efficient data serialization.
| Feature | Specification |
|---|---|
| Transport | UDP (via ASIO) |
| Serialization | MsgPack (Binary) |
| Architecture | Server-Authoritative |
| Update Rate | 20Hz (50ms) |
Messages travelling through the engine's internal ZeroMQ bus use a specific binary packing to avoid string parsing overhead and corruption.
[ Topic Length (4 bytes) ] [ Topic String (N bytes) ] [ MsgPack Payload (M bytes) ]
Sent whenever a key is pressed or released.
Topic: INPUT
Payload (MsgPack Map):
| Key | Type | Description |
|---|---|---|
k |
String | Key name (UP, DOWN, LEFT, RIGHT, SPACE) |
s |
Integer | State: 1 (Pressed), 0 (Released) |
Lua Example:
ECS.sendBinary("INPUT", {k="UP", s=1})Authoritative state broadcast for every moving entity.
Topic: ENTITY_POS
Payload (MsgPack Map):
| Key | Type | Description |
|---|---|---|
id |
String | Unique Entity UUID |
x, y, z |
Float | World Position |
rx, ry, rz |
Float | World Rotation (Degrees) |
vx, vy, vz |
Float | Velocity (for Client Extrapolation) |
t |
Integer | Entity Type (1:Player, 2:Bullet, 3:Enemy) |
Assigns a unique ID and entity to a newly connected client.
Topic: PLAYER_ASSIGN
Payload: String (Entity ID)
sequence_diagram
Client ->> Server: RequestNetworkConnect
Server -->> Client: NetworkStatus ("Connected")
Server ->> Server: Create Player Entity
Server -->> Client: PLAYER_ASSIGN (UUID)
Client ->> Server: CLIENT_READY
loop Gameplay
Client ->> Server: INPUT (Binary MsgPack)
Server ->> Server: Simulate Physics
Server -->> Client: ENTITY_POS (Binary MsgPack)
Client ->> Client: Interpolate & Render
end
- Zero Parsing: No
string.matchorstringstreamneeded. - Compactness: MsgPack reduces payload size by ~40% compared to JSON/Text.
- Safety: Length-prefixed topics prevent buffer overflows and injection attacks.