From 842306f109725a4e4800f25ae4da49277379bcbd Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sat, 20 Apr 2013 00:07:06 -0400 Subject: [PATCH] Clean up globalstep --- src/init.lua | 52 ++++++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/src/init.lua b/src/init.lua index 86e3bfa..44eea94 100644 --- a/src/init.lua +++ b/src/init.lua @@ -55,6 +55,26 @@ minetest.register_privilege("irc_admin", { give_to_singleplayer = true; }); +minetest.register_globalstep(function(dtime) + if (not mt_irc.connect_ok) then return end + mt_irc.cur_time = mt_irc.cur_time + dtime + if (mt_irc.cur_time >= mt_irc.dtime) then + if (mt_irc.buffered_messages) then + for _, msg in ipairs(mt_irc.buffered_messages) do + local t = { + name=(msg.name or ""), + message=(msg.message or "") + } + local text = mt_irc.message_format_out:expandvars(t) + irc.say(mt_irc.channel, text) + end + mt_irc.buffered_messages = nil + end + irc.poll() + mt_irc.cur_time = mt_irc.cur_time - mt_irc.dtime + end +end) + mt_irc.part = function ( name ) if (not mt_irc.connected_players[name]) then minetest.chat_send_player(name, "IRC: You are not in the channel."); @@ -91,38 +111,6 @@ mt_irc.connect = function ( ) while (not mt_irc.got_motd) do irc.poll(); end - - minetest.register_globalstep(function ( dtime ) - if (not mt_irc.connect_ok) then return; end - if (not mt_irc.players_connected) then - for _,player in ipairs(minetest.get_connected_players()) do - mt_irc.connected_players[player:get_player_name()] = mt_irc.auto_join; - end - mt_irc.players_connected = true; - end - mt_irc.cur_time = mt_irc.cur_time + dtime; - if (mt_irc.cur_time >= mt_irc.dtime) then - if (mt_irc.buffered_messages) then - for _, msg in ipairs(mt_irc.buffered_messages) do - local t = { - name=(msg.name or ""); - message=(msg.message or ""); - }; - local text = mt_irc.message_format_out:expandvars(t); - irc.say(mt_irc.channel, text); - end - mt_irc.buffered_messages = nil; - end - irc.poll(); - mt_irc.cur_time = mt_irc.cur_time - mt_irc.dtime; - --local plys = minetest.get_connected_players(); - --if ((#plys <= 0) and (minetest.is_singleplayer())) then - -- minetest.after(1.0, function ( ) - -- irc.quit("Closing."); - -- end) - --end - end - end); end mt_irc.say = function ( to, msg )