SessionHost beta
Class of @v12-engine/engine
export declare class SessionHostRuns a world for players connected to it over transports: the server's job, done anywhere. It steps the world by the clock (start) or by hand (update), and at most sendRate times a second sends every player what changed in what they may know (Delta), as their LocalSession seat sees it: against the last tick they said they got, with the events they have not. Their commands come in as they arrive, and go in at the next tick
Members
constructor
constructor(
world: World, options?: SessionHostOptions);Constructs a new instance of the SessionHost class
advance
advance(ticks?: number): void;Moves the game on by ticks at the next update, however fast it goes: a step of a held game (speed 0)
connect
connect(player: PlayerId, transport: Transport, options?: {
readOnly?: boolean;
observer?: boolean;
allow?: () => boolean | MessageRef;
name?: string;
inOrder?: boolean;
}): void;Seats a player at the world, on the host's end of a transport. The welcome goes out at once: everything the player may know, also to one who comes back. readOnly for who only watches: their commands go nowhere but their lines of chat and their pings, which go to who watches alone (observers, said by name); and with observer they see everything, from player's side. allow decides on each command before it goes in: a limit of how many, a game paused. One it lets go is answered, refused (the command event of its seq): with what it gives for why, or cannotDoThat for false. inOrder for a transport that loses nothing and keeps the order (a worker's messages): each frame is the base of the next once it went, with no answer waited for, so the player always gets what changed since the frame it has, and takes it in without looking over the rest
dispose
dispose(options?: {
closeTransports?: boolean;
}): void;Stops, and lets every player go: their connections closed, unless closeTransports is false (a server that keeps them for its lobby, after the game)
players
get players(): number;How many players are connected
publish
publish(dt: number): void;Sends everyone what changed, when it is time to, for a world something else steps: the page's own game, shared with those who watch it (shareGame). dt is the seconds since the last call. Nothing goes while the world stands still
running
get running(): boolean;Whether it runs by the clock
speed
speed: number;Simulation speed multiplier, 0 pauses
start
start(rate?: number): void;Runs the world by the clock, rate updates a second, until stop or dispose
stop
stop(): void;Stops stepping the world by the clock; does nothing if it was not started
takeTiming
takeTiming(): HostTiming & {
seconds: number;
};Where the time went since the last call, and starts counting anew: for a server to print
totals
readonly totals: {
ticks: number;
tickTime: number;
lastTick: number;
sends: number;
sendTime: number;
};Where the host's time went since it started, never counted anew: ticks and rounds of sending, with the milliseconds they took, and how long the last tick took. What a server's numbers are made of (/metrics)
update
update(dt: number): void;Lets dt seconds pass: the ticks that fit into it, then what changed to everyone, when it is time to send
world
readonly world: World;The world the host steps and sends its players views of