From 25a3336a56ddeef07be639b6cdc8e98ea0e203db Mon Sep 17 00:00:00 2001 From: luk3yx Date: Tue, 5 Mar 2019 13:43:35 +1300 Subject: [PATCH] =?UTF-8?q?Fix=20the=20workaround=20=20=E2=80=A2=20The=20w?= =?UTF-8?q?orkaround=20works=20correctly,=20however=20uses=20hacks.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- init.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 5661465..e13b963 100644 --- a/init.lua +++ b/init.lua @@ -46,7 +46,28 @@ depluralify_register = nil -- Add register_on_connect in 5.0.0 if not minetest.register_on_connect then - function minetest.register_on_connect(func) return func() end + local connected = false + local on_connects = {} + + -- A very hacky workaround + local function check_for_connection() + if minetest.localplayer then + connected = true + while #on_connects > 0 do + on_connects[#on_connects]() + on_connects[#on_connects] = nil + end + else + minetest.after(0, check_for_connection) + end + end + check_for_connection() + + -- Let other CSMs take advantage of these hacks + function minetest.register_on_connect(func) + if connected then return func() end + on_connects[#on_connects + 1] = func + end minetest.display_chat_message('WARNING: Chat channels may not work with '.. 'Minetest 5.0.0 if the server disallows CSMs!') end