1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Implement mod communication channels (#6351)

Implement network communication for channels

* Implement ModChannel manager server side to route incoming messages from clients to other clients
* Add signal handler switch on client & ModChannelMgr on client to handle channels
* Add Lua API bindings + client packet sending + unittests
* Implement server message sending
* Add callback from received message handler to Lua API using registration method
This commit is contained in:
Loïc Blot 2017-09-26 00:11:20 +02:00 committed by GitHub
parent 6df312a608
commit 6f1c907204
37 changed files with 1206 additions and 39 deletions

View file

@ -1,5 +1,6 @@
local modname = core.get_current_modname() or "??"
local modstorage = core.get_mod_storage()
local mod_channel
dofile("preview:example.lua")
-- This is an example function to ensure it's working properly, should be removed before merge
@ -14,6 +15,21 @@ core.register_on_connect(function()
print("Server ip: " .. server_info.ip)
print("Server address: " .. server_info.address)
print("Server port: " .. server_info.port)
mod_channel = core.mod_channel_join("experimental_preview")
end)
core.register_on_modchannel_message(function(channel, sender, message)
print("[PREVIEW][modchannels] Received message `" .. message .. "` on channel `"
.. channel .. "` from sender `" .. sender .. "`")
core.after(1, function()
mod_channel:send_all("CSM preview received " .. message)
end)
end)
core.register_on_modchannel_signal(function(channel, signal)
print("[PREVIEW][modchannels] Received signal id `" .. signal .. "` on channel `"
.. channel)
end)
core.register_on_placenode(function(pointed_thing, node)
@ -100,6 +116,12 @@ core.after(2, function()
preview_minimap()
end)
core.after(4, function()
if mod_channel:is_writeable() then
mod_channel:send_all("preview talk to experimental")
end
end)
core.after(5, function()
if core.ui.minimap then
core.ui.minimap:show()