From d2d65be1d9ab42d81e4050f95614c83e584bd143 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Sun, 8 Apr 2018 11:57:30 +1200 Subject: [PATCH] Fix local echo in laggy servers Instead of displaying the first buffer item, now display the whole buffer when required. --- init.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 8b98221..c90f55b 100644 --- a/init.lua +++ b/init.lua @@ -9,7 +9,7 @@ local channel = main_channel local storage = minetest.get_mod_storage() local channels = {} local messages_sent = 0 -local buffer = {} +local buffer = '' local msgprefix local localplayer = '[you]' local show_main_channel = true @@ -116,7 +116,8 @@ minetest.register_on_sending_chat_messages(function(msg) end local players = get_channel_users(c) if not players then return end - table.insert(buffer, '-' .. c .. '- <' .. localplayer .. '> ' .. msg) + if #buffer > 0 then buffer = buffer .. '\n' end + buffer = buffer .. '-' .. c .. '- <' .. localplayer .. '> ' .. msg messages_sent = messages_sent + #players for p = 1, #players do minetest.run_server_chatcommand('msg', players[p] .. ' -' .. c .. @@ -132,8 +133,8 @@ minetest.register_on_receiving_chat_messages(function(msg) if messages_sent > 0 then messages_sent = messages_sent - 1 if messages_sent == 0 and #buffer > 0 then - minetest.display_chat_message(buffer[1]) - table.remove(buffer, 1) + minetest.display_chat_message(buffer) + buffer = '' end return true end