net/online: Online with friends for Bola na Rede, on Table Codes (roomsKit).
Rooms: six seats, three a side (SEAT_PLAYER maps a seat to the sim player
it drives), a short letter code, the host picks clubs, AI difficulty and
length (room settings) and starts. Empty seats are AI; a guest who leaves
or goes silent for a second is handed to the AI at once.
Match: the host runs the only sim (sim.match). Each guest sends its raw
input (move, sprint, held shoot and running counts of every button press)
at 30 Hz and on every change; the host turns it into the CONTRACT intent
record for that guest's player (sim.match setIntentSource). The host
publishes a snapshot 20 times a second (every player, the ball, phase,
clock, score, meters, the last input each guest had acked) with the events
of the last two seconds. Guests build the match with sim.match
startReplica, draw everyone 100 ms behind the newest snapshot
(interpolated), predict their own player from their own input (replayed
from the host's position after every snapshot, the error eased out), and
replay the host's events through the sim's own emit at the moment they
happened on the drawn timeline, so every screen shows the same goal.
The shell (ui.BolaShell) calls `tick(dt)` every frame and `setHooks` once.
teamOfSeat(i: number) → string
Rooms
| arg | type | description |
|---|
| i | number | |
slotOfSeat(i: number) → number
| arg | type | description |
|---|
| i | number | |
room( ) → any
The room this machine is in, or nil.
available( ) → boolean
Whether the Rooms entity is running (play mode with the scene's Rooms entity).
create( ) → any
Create a room (this machine hosts it and sits in seat 1, home forward).
hasHuman(room: any) → boolean
| arg | type | description |
|---|
| room | any | |
joinFailed(reason: string) → void
| arg | type | description |
|---|
| reason | string | |
join(code: string) → void
Join a room by code. Answers ok, reason (badCode, noRoom, closed, ...): "closed" when this machine saw that room close. An accepted join is watched: it ends in the room's lobby or, within JOIN_TIMEOUT seconds, in the shell's onJoinFailed(reason) hook ("closed", "full", "timeout").
| arg | type | description |
|---|
| code | string | |
joining( ) → boolean
Whether a join is on its way (asked for, not yet seated).
cancelJoin( ) → void
Give up on a join on its way; if it lands later this machine leaves the room at once.
leave( ) → void
Leave the room (mid-match too: the host hands the seat to the AI).
sit(i: number) → void
Move to seat i (picking a side) in the lobby.
| arg | type | description |
|---|
| i | number | |
settings( ) → any
The room's match settings { home, away (club indexes), difficulty, minutes }.
setSetting(key: string, value: any) → void
Host: change one match setting.
| arg | type | description |
|---|
| key | string | |
| value | any | |
stepClub(side: string, dir: number) → void
Host: step a club picker (side "home"/"away", dir -1/1), never the other side's club.
| arg | type | description |
|---|
| side | string | |
| dir | number | |
startMatch( ) → boolean
Host: start the match (empty seats become AI).
lobby( ) → any
What the lobby draws: { code, isHost, phase, mySeat, settings, seats = { [i] = { kind, name, me, host, team, slot } } }.
sampleInput(dt: number) → void
Raw input (every human machine)
| arg | type | description |
|---|
| dt | number | |
seatMap(room: any) → void
Host
| arg | type | description |
|---|
| room | any | |
hostIntent(p: any, hasBall: boolean, dt: number) → any
| arg | type | description |
|---|
| p | any | |
| hasBall | boolean | |
| dt | number | |
recordEvent(name: string, payload: any) → void
| arg | type | description |
|---|
| name | string | |
| payload | any | |
lerp(a: number, b: number, t: number) → number
Guest: interpolation, prediction, events
| arg | type | description |
|---|
| a | number | |
| b | number | |
| t | number | |
lerpAngle(a: number, b: number, t: number) → number
| arg | type | description |
|---|
| a | number | |
| b | number | |
| t | number | |
predictStep(pr: any, move: vector, sprint: boolean, dt: number, hasBall: boolean, keeper: boolean, charging: boolean) → void
| arg | type | description |
|---|
| pr | any | |
| move | vector | |
| sprint | boolean | |
| dt | number | |
| hasBall | boolean | |
| keeper | boolean | |
| charging | boolean | |
predicting(m: any, snap: any) → boolean
| arg | type | description |
|---|
| m | any | |
| snap | any | |
guestFrame(dt: number) → void
| arg | type | description |
|---|
| dt | number | |
matchOpts(setup: any) → any
Match lifecycle (called by the shell)
| arg | type | description |
|---|
| setup | any | |
match( ) → any
The match this machine plays: { host, myPid, myTeam, setup } or nil.
active( ) → boolean
Whether an online match is being played or watched on this machine.
myTeam( ) → string
This machine's team in the online match ("home"/"away"), or nil.
beginMatch( ) → any
Start the match on this machine: the host starts the sim, a guest its replica. The shell calls it after subscribing to the match's events. Answers the team definitions { home, away }.
endMatch( ) → void
Stop the match on this machine. The host also ends the round, so the room returns to its lobby.
corrections( ) → any
Correction measurements of this guest's own-player prediction: { n, mean, max, p95 } in metres.
tick(dt: number) → void
One network frame: the host publishes a snapshot when one is due; a guest sends its input and draws the match. Stepped every frame by this module's own frame driver while a match runs.
| arg | type | description |
|---|
| dt | number | |
setHooks(h: any) → void
The shell's hooks: { onMatchStart(setup), onRoomChanged(), onRoomGone(reason), onHostLeft() }.