Command

The things a player can send. Asteroids has two: aim points the ship at the cursor and thrust holds the engine on. Each is a directory with a param schema, a writes manifest, and a handler. Both write a single shared owner field, so they are predictable and take effect on the owner's screen the moment they are sent. (The player's ship never presses a fire button; firing is emitted by the instance update on a steady phase.)

aim

Points the sending player's ship at an absolute heading, the angle from the ship to the mouse cursor that the renderer computes. Its one param is angle; the handler stores it on the player after a guard that ignores input from a destroyed ship.

[
  {
    "gamehoster-command-schema-name": "angle",
    "gamehoster-command-schema-type": "number"
  }
]
asteroids/gamehoster-commands/aim/gamehoster-command-schema.json
{ "writes": ["player.angle"] }
asteroids/gamehoster-commands/aim/gamehoster-command.json
// Point the sending player's ship towards their mouse cursor. `angle` is a `shared`
// field the owner drives, so this handler runs on both sides: instantly on the
// owner's front end (the ship turns the moment the mouse moves) and on the server
// (authority). The client sends the absolute heading it wants; we just store it.

const me = Gamehoster.Context.playerId
if (!Gamehoster.Player.State.Get(me, "alive")) return
Gamehoster.Player.State.Set(me, "angle", Gamehoster.Command.Get("angle"))
asteroids/gamehoster-commands/aim/gamehoster-command-handler.js

thrust

Holds the engine on or off. The player presses the mouse button to accelerate and releases it to coast, so the front end sends on: true on press and on: false on release. The handler writes the thrusting flag; the shared ship body turns it into acceleration up to max speed, with friction when it is off.

[
  {
    "gamehoster-command-schema-name": "on",
    "gamehoster-command-schema-type": "bool"
  }
]
asteroids/gamehoster-commands/thrust/gamehoster-command-schema.json
{ "writes": ["player.thrusting"] }
asteroids/gamehoster-commands/thrust/gamehoster-command.json
// 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 a `shared` field, so the ship starts accelerating on the
// owner's own screen immediately, and the per-tick ship update (shared, both sides)
// turns that flag into acceleration up to max speed, with friction when it is off.

const me = Gamehoster.Context.playerId
if (!Gamehoster.Player.State.Get(me, "alive")) return
Gamehoster.Player.State.Set(me, "thrusting", !!Gamehoster.Command.Get("on"))
asteroids/gamehoster-commands/thrust/gamehoster-command-handler.js