Voidrush SDK – Data Module
The “Data Module” helps you synchronize your game state (saves, progression, snapshots) via structured messages. It relies on standardized message types that the backend understands and relays to all players in the room.
1) Updating the State
Two approaches:
- Direct Patch (state object update):
Propagatesclient.updateGameState({ score: 42, level: 3 });game_state_updateserver-side → broadcasts to the room. - Batch (list of structured updates):
The server validates the entries and broadcastsclient.updateBatch([ { entityId: "p1", state: { x: 100, y: 200 } }, { entityId: "boss", state: { hp: 900 } } ]);game.state_updates.
2) Generic Storage/Merge
You can also send a generic game.data message; the server relays it as is and attempts to save the payload as the current “game state,” which is useful for complete snapshots:
client.sendCustomMessage("game.data", { inventory, map, flags });
The consumer then emits type: "game.data" for all clients in the room and calls _save_game_state().
3) Retrieving the State (Sync)
To initialize a client or catch up mid-game:
// request current state
client.requestSync();
// you will receive "room.state" messages and the current game state
client.on("message", (m) => {
if (m.type === "room.state") { /* lobby & presence */ }
if (m.type === "game.state" || m.type === "game.data") { /* re-hydrate */ }
});
The server responds with the room state and returns the saved state.
4) Player Data (Profile/Ready/Team)
Some useful shortcuts:
ready()marks the player as ready and updates presence.joinTeam(team)to assign an available team (string).- Sending player custom data (e.g., skin, elo):
The server merges into the presence and broadcasts the new room state.client.send("player.custom_data", { custom_data: { skin: "blue" } });
5) Turn-Based: State & History
With TurnBasedGameClient:
tb.on("message", (m) => {
if (m.type === "game.turn_move") { /* apply move */ }
if (m.type === "game_turn_ended") { /* next player */ }
});
tb.sendMove({ from:"A2", to:"A3" });
tb.endTurn();
The server validates, applies to the game state, and broadcasts dedicated messages.
6) Best Practices
- Limit message size (≤ 64 KB), otherwise the server will respond with an error.
- Avoid spamming: limit ~120 msg/s per connection.
- Use
priorityfor critical actions (real-time).