Skip to content

Server Replicator


type Iterator<T...> = () -> (T...)

The masking controller. This handles player filtering, as well as excluding non-ready players.

type Server = {
masking: MaskingController
}

Initializes the server replicator. World can be provided here if it wasn’t provided when creating the replicator.

type Server = {
init: (self: Server, world: jecs.World?) -> ()
}
  • world: The world to use for the replicators. Can also be provided when initing the replicator.

Destroys the server replicator. This will disconnect jecs hooks and connections.

type Server = {
destroy: (self: Server) -> ()
}

Returns an iterator that will send batched updates.

type Server = {
collect_updates: (self: Server) -> Iterator<player: Player, buf: buffer, variants: {{any}}>
}
  • player: The player to send the updates to.
  • buf: The buffer containing the updates.
  • variants: The variants table containing non-serialized values.

Returns an iterator that will send the values of unrealible components.

type Server = {
collect_unreliable: (self: Server) -> Iterator<player: Player, buf: buffer, variants: {{any}}>
}
  • player: The player to send the updates to.
  • buf: The buffer containing the updates.
  • variants: The variants table containing non-serialized values.

Gets the full state of the world for the provided player.

type Server = {
get_full: (self: Server, player: Player) -> (buffer, {{any}})
}
  • player: The player to get the full state of the world for.
  • buf: The buffer containing the full state of the world.
  • variants: The variants table containing non-serialized values.

Encodes a component for sending through the network. This returns a number between 1 to 255.

type Server = {
encode_component: (self: Server, component: Entity) -> number
}
  • component: The component to encode.
  • number: The encoded component.

Decodes a component from a number.

type Server = {
decode_component: (self: Server, encoded: number) -> Entity
}
  • number: The number to decode, This is number from encode_component.
  • component: The decoded component.

Marks a player as ready to receive updates. Non ready players will not receive updates until this is called.

type Server = {
mark_player_ready: (self: Server, player: Player) -> ()
}
  • player: The player to mark as ready.

Checks if a player has been marked as ready to receive updates.

type Server = {
is_player_ready: (self: Server, player: Player) -> boolean
}
  • player: The player to check.
  • boolean: Whether the player is ready.

Adds an alias for a player. This can be used to use different values like entities in player filters.

type Server = {
add_player_alias: (self: Server, player: Player, alias: any) -> ()
}
  • player: The player to add the alias for.
  • alias: The alias to add.

Removes an alias for a player. This is important to do when a player leaves the server.

type Server = {
remove_player_alias: (self: Server, alias: any) -> ()
}
  • alias: The alias to remove.

Generates a handshake info. This can be used to verify that the server and client are setup correctly.

type Server = {
generate_handshake: (self: Server) -> HandshakeInfo
}
  • handshake: The handshake info. This can be passed to client:verify_handshake()

Verifies a handshake info from client:generate_handshake().

type Server = {
verify_handshake: (self: Server, handshake: HandshakeInfo) -> (success: boolean, err: string?)
}
  • handshake: The handshake info to verify.
  • success: Whether the handshake info is valid.
  • err: The error message if the handshake was not successful.

Registers a custom id handler. Custom ids can only be used if they are registered.

type Server = {
register_custom_id: (self: Server, custom_id: CustomId) -> ()
}
  • custom_id: The custom id to register.