mirror of
https://github.com/rollerozxa/voxelmanip-wiki
synced 2024-05-05 08:01:02 -07:00
99 lines
3.1 KiB
Markdown
99 lines
3.1 KiB
Markdown
Allows server side mods (SSMs) communication to client side mods (CSMs) and vice versa.
|
|
|
|
[toc]
|
|
|
|
## Server Side API
|
|
|
|
### Functions
|
|
|
|
#### `minetest.mod_channel_join(channel_name)`
|
|
|
|
* `channel_name`: string, modchannel name
|
|
|
|
Returns an object for use with [Methods](#Methods). Creates the channel if it does not exist and joins the channel.
|
|
|
|
#### `minetest.register_on_modchannel_message(function(channel_name, sender, message))`
|
|
|
|
* `channel_name`: string, modchannel name (already joined)
|
|
* `sender`: string, empty if from a SSM, player name if from a client
|
|
* `message`: string, message
|
|
|
|
Used for handling messages received from the client.
|
|
|
|
### Methods
|
|
|
|
NOTE: `channel` here means the object returned by `minetest.mod_channel_join`.
|
|
|
|
#### `channel:leave()`
|
|
|
|
The server will leave the channel, meaning no more messages from this channel on `minetest.register_on_modchannel_message`
|
|
|
|
TIP: Set the channel to `nil` afterwords to free resources
|
|
|
|
#### `channel:is_writeable()`
|
|
|
|
* Returns `bool`: `true` true if the channel is writeable, `false` if it's not.
|
|
|
|
#### `channel:send_all(message)`
|
|
|
|
* `message`: string, limited to 65535 bytes
|
|
|
|
Sends to all SSMs and CSMs on the channel.
|
|
|
|
CAUTION: The message will not if channel is not writable or invalid.
|
|
|
|
## Client Side API
|
|
|
|
### Functions
|
|
|
|
#### `minetest.mod_channel_join(channel_name)`
|
|
|
|
* `channel_name`: string, modchannel name
|
|
|
|
Returns an object for use with [Methods](#Methods). Creates the channel if it does not exist and joins the channel. Is equivalent to the the server side function.
|
|
|
|
#### `minetest.register_on_modchannel_message(function(channel_name, sender, message))`
|
|
|
|
* `channel_name`: string, modchannel name (already joined and recieved acknowledgement)
|
|
* `sender`: string, empty if from a SSM, player name if from a client
|
|
* `message`: string, message
|
|
|
|
Used for handling messages received from the client. Is equivalent to the the server side function.
|
|
|
|
#### `minetest.register_on_modchannel_signal(function(channel_name, signal))`
|
|
* `channel_name`: string, channel name that the signal has come in on
|
|
* `signal`: integer, 0 - 5
|
|
|
|
0. join_ok
|
|
1. join_failed
|
|
2. leave_ok
|
|
3. leave_failed
|
|
4. event_on_not_joined_channel
|
|
5. state_changed
|
|
|
|
Used to handle signals generated by the mod channel system.
|
|
|
|
### Methods
|
|
|
|
NOTE: `channel` here means the object returned by `minetest.mod_channel_join`.
|
|
|
|
#### `channel:leave()`
|
|
|
|
The client will leave the channel, meaning no more messages from this channel on `minetest.register_on_modchannel_message`
|
|
|
|
TIP: Set the channel to `nil` afterwords to free resources
|
|
|
|
#### `channel:is_writeable()`
|
|
|
|
* Returns `bool`: `true` true if the channel is writeable, `false` if it's not.
|
|
|
|
#### `channel:send_all(message)`
|
|
|
|
* `message`: string, limited to 65535 bytes
|
|
|
|
Sends to all SSMs and CSMs on the channel.
|
|
|
|
CAUTION: The message will not if channel is not writable or invalid.
|
|
|
|
---
|
|
*This article is originally based on an article from the minetest_docs project: [modchannels.adoc](https://github.com/minetest/minetest_docs/blob/master/doc/modchannels.adoc) by wsor4035, licensed under CC-BY 4.0* |