channels
Named byte channels between mods, and between a server mod and its client half. Local delivery works since 0.2 (messages are queued and delivered on the next poll or tick, never during send); the network targets travel as 0xBC CHANNEL packets from milestone M5 and report unsupported until then.
Package blockheads:api@0.3.1 · Lua table bh.channels · WIT source
Uses: types.{mod-id, api-error}, players.{player}
Types
channel-id type
txt
type channel-id = u32;A channel opened by the calling mod.
target variant
Where a message goes.
| Case | Payload | Description |
|---|---|---|
local | – | Every mod on this side that opened the same channel name. |
server | – | The server (from a client mod). |
player | borrow<player> | One player's client (from a server mod). |
all-players | – | Every connected client running the mod (from a server mod). |
source variant
Where a received message came from.
| Case | Payload | Description |
|---|---|---|
local | mod-id | Another mod on the same side. |
server | – | The server. |
player | borrow<player> | A player's client. |
Functions
open function
txt
open: func(name: string) -> result<channel-id, api-error>;Opens (or joins) the channel name, which must be <mod-id>:<name> of a mod the caller is or depends on. Needs the channels permission.
send function
txt
send: func(channel: channel-id, to: target, data: list<u8>) -> result<_, api-error>;Sends up to 32 KiB of bytes.
close function
txt
close: func(channel: channel-id) -> bool;Closes a channel. Returns false if it was not open.