Documentation
¶
Overview ¶
Package gameserver hosts authoritative game simulations and relays their command stream to connected clients over a transport. The simulation logic is the same engine the browser runs as wasm; this package only owns the authority loop (one fixed 40 Hz tick) and the fan-out of orders, command frames, snapshots and hashes. The transport is abstracted behind Conn so the orchestration is testable with an in-memory loopback and the real websocket adapter is a thin layer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DemoSpawnFunc ¶
DemoSpawnFunc returns a spawn provider that needs no game assets: it resolves the single synthetic unit type "scout" used by the standalone browser demo. `kbot host` falls back to this when no --root is given, so the multiplayer path can be exercised end-to-end without a TA install.
func FBISpawnFunc ¶
FBISpawnFunc returns a sim.SpawnFunc backed by the flattened game-asset tree at root (units/*.fbi, weapons/*.tdf). It is the asset bridge the native host uses to turn Spawn orders into real TA units.
Types ¶
type CobSource ¶
CobSource returns a unit type's raw COB bytecode, with ok=false for a script-less type. A match uses it to drive the authority's units through the same COB animation + scripted weapon-aim/death threads the browser clients run, so the authoritative simulation stays bit-identical to every client's prediction during combat — without it, the script-less server diverges from the COB-running clients the moment a fight starts.
func FBICobSource ¶
FBICobSource returns a CobSource backed by the flattened asset tree's scripts/*.cob files, so the native host's authority runs each unit's COB in lockstep with the browser clients (which fetch the identical bytes).
type Match ¶
type Match struct {
// contains filtered or unexported fields
}
Match is one authoritative game running its own tick loop.
func NewMatch ¶
NewMatch creates a match with a fresh world and the given spawn provider. The cob source (optional) backs each spawned unit with its COB script, run by a per-match script runtime so the authority animates and fights identically to the clients; pass nil for a script-less authority.
func (*Match) AddConn ¶
AddConn registers a connection with the match and starts its read loop. The caller (the websocket handler) provides an already-handshaken Conn.
func (*Match) Run ¶
func (m *Match) Run()
Run drives the authority loop until Stop. It must run on its own goroutine; it is the sole owner of the session, so no locking is needed.
func (*Match) ServeWS ¶
func (m *Match) ServeWS(w http.ResponseWriter, r *http.Request)
ServeWS upgrades an HTTP request to a websocket and hands the resulting connection to the match. It blocks until the request context is closed so the underlying transport stays open for the duration of the read loop.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server hosts one or more matches and routes websocket upgrades to them. It owns the lifecycle of each match's authority goroutine.
func NewServer ¶
NewServer creates an empty server that builds matches with the given spawn provider, COB source, seed and input delay. The cob source (optional, may be nil) backs each match's units with their scripts so the authority stays bit-identical to the COB-running clients. It starts a background reaper that retires matches left empty past the idle grace.
func (*Server) Match ¶
Match returns the match with the given id, creating and starting it on first use so a client can connect to a fresh game by naming it.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP upgrades websocket connections and binds them to the match named by the "match" query parameter (defaulting to "default"). A connection that creates a new match may name and classify it via the "name" and "kind" parameters, which feed the session listing.
func (*Server) Sessions ¶
func (s *Server) Sessions() []SessionInfo
Sessions returns a snapshot of every active match for discovery/listing, oldest first.
type SessionInfo ¶
type SessionInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Kind string `json:"kind"`
Players int `json:"players"`
Units int `json:"units"`
CreatedAt time.Time `json:"createdAt"`
}
SessionInfo is a thread-safe snapshot of a match's descriptive state, used by the host's session-listing endpoint.