Commands
The two commands a player sends: aim, the heading their
ship points, and thrust, whether they are accelerating. Each command is a folder with its
parameter schema, its writes manifest, and the server handler that applies it.
<gamehoster-config-contentRoot>/
game.gamehoster.org/
gamehoster-games/
asteroids/
gamehoster-commands/
aim/
gamehoster-command.json
gamehoster-command-schema.json
gamehoster-command-handler.js
thrust/
gamehoster-command.json
gamehoster-command-schema.json
gamehoster-command-handler.js
Contents
One folder per command; each holds a parameter schema, a writes manifest and a handler.
| Name | Type | Description |
|---|---|---|
aim/ | directory | Point the ship; writes player.angle. |
thrust/ | directory | Accelerate on or off; sets a server-only flag. |
aim/
Point the ship at the mouse. angle is a public field the owner drives.
gamehoster-command.json
{ "writes": ["player.angle"] }
gamehoster-command-schema.json
[
{
"gamehoster-command-schema-name": "angle",
"gamehoster-command-schema-type": "number"
}
]
gamehoster-command-handler.js
// Point the sending player's ship towards their mouse cursor. The client sends the
// absolute heading it wants; the server stores it on the player, and it streams back
// to every viewer as the ship's public `angle`.
const me = Gamehoster.Context.playerId
if (!Gamehoster.Player.State.Get(me, "alive")) return
Gamehoster.Player.State.Set(me, "angle", Gamehoster.Command.Get("angle"))
thrust/
Hold thrust on or off. The handler writes a thrusting flag into the ship’s server-only Player.Persistent bag, where the per-tick ship step turns it into acceleration. Because that bag is not streamed schema state, the write bypasses the command writes-firewall, so this command’s writes manifest is empty.
gamehoster-command.json
{ "writes": [] }
gamehoster-command-schema.json
[
{
"gamehoster-command-schema-name": "on",
"gamehoster-command-schema-type": "bool"
}
]
gamehoster-command-handler.js
// Hold thrust on or off. The player presses the mouse button to accelerate and
// releases it to coast; the front end sends `on: true` on press and `on: false` on
// release. `thrusting` is SERVER-ONLY (Player.Persistent), where the per-tick ship update
// turns it into acceleration up to max speed, with friction when it is off. Because it is
// persistent (not streamed schema state) the write bypasses the command writes-firewall.
const me = Gamehoster.Context.playerId
if (!Gamehoster.Player.State.Get(me, "alive")) return
Gamehoster.Player.Persistent.Get(me).thrusting = !!Gamehoster.Command.Get("on")