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
The gamehoster-commands/ folder: one folder per command, each with its schema, manifest and handler.

Contents

One folder per command; each holds a parameter schema, a writes manifest and a handler.

NameTypeDescription
aim/directoryPoint the ship; writes player.angle.
thrust/directoryAccelerate 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"] }
asteroids/gamehoster-commands/aim/gamehoster-command.json

gamehoster-command-schema.json

[
  {
    "gamehoster-command-schema-name": "angle",
    "gamehoster-command-schema-type": "number"
  }
]
asteroids/gamehoster-commands/aim/gamehoster-command-schema.json

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"))
asteroids/gamehoster-commands/aim/gamehoster-command-handler.js

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": [] }
asteroids/gamehoster-commands/thrust/gamehoster-command.json

gamehoster-command-schema.json

[
  {
    "gamehoster-command-schema-name": "on",
    "gamehoster-command-schema-type": "bool"
  }
]
asteroids/gamehoster-commands/thrust/gamehoster-command-schema.json

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")
asteroids/gamehoster-commands/thrust/gamehoster-command-handler.js