From 6f1c90720402415b62fb4d5e809ec7dbc1cd7f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Tue, 26 Sep 2017 00:11:20 +0200 Subject: 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 --- clientmods/preview/init.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'clientmods') diff --git a/clientmods/preview/init.lua b/clientmods/preview/init.lua index 150db1816..bf5fb3db8 100644 --- a/clientmods/preview/init.lua +++ b/clientmods/preview/init.lua @@ -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() -- cgit v1.2.3