From 7caf0dc25f701723f5e5ec47523f1b018612d024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Tue, 8 Jan 2013 13:50:47 -0200 Subject: [PATCH] Added auto-reconnect on ping timeout --- README.txt | 2 -- etc/quickinst.sh | 2 ++ src/callback.lua | 39 +++++++++++++++++++++++++++++---------- src/chatcmds.lua | 14 ++++++++++++++ src/config.lua | 17 +++++++++++++++-- src/friends.lua | 12 ++++++++++++ src/init.lua | 5 +++-- src/luairc/irc.lua | 10 +++++----- 8 files changed, 80 insertions(+), 21 deletions(-) create mode 100755 etc/quickinst.sh diff --git a/README.txt b/README.txt index 6e487fb..35f84de 100644 --- a/README.txt +++ b/README.txt @@ -183,8 +183,6 @@ I'd like to thank the users who supported this mod both on the Minetest LICENSE ------- -This license applies only to the `init.lua' and `config.lua' files. - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 diff --git a/etc/quickinst.sh b/etc/quickinst.sh new file mode 100755 index 0000000..fb6984f --- /dev/null +++ b/etc/quickinst.sh @@ -0,0 +1,2 @@ +#! /bin/sh +(cd Build && cmake . && make && make pack_mod && rm -fr ~/.minetest/games/testing/mods/irc && cp -fr irc ~/.minetest/games/testing/mods/ ) diff --git a/src/callback.lua b/src/callback.lua index 3244bdb..fddda5c 100644 --- a/src/callback.lua +++ b/src/callback.lua @@ -1,7 +1,21 @@ +-- IRC Mod for Minetest +-- By Diego Martínez +-- +-- This mod allows to tie a Minetest server to an IRC channel. +-- +-- This program is free software. It comes without any warranty, to +-- the extent permitted by applicable law. You can redistribute it +-- and/or modify it under the terms of the Do What The Fuck You Want +-- To Public License, Version 2, as published by Sam Hocevar. See +-- http://sam.zoy.org/wtfpl/COPYING for more details. +-- + +local irc = require("irc"); + minetest.register_on_joinplayer(function ( player ) - irc.say(mt_irc.channel, "*** "..player:get_player_name().." joined the game"); + mt_irc.say(mt_irc.channel, "*** "..player:get_player_name().." joined the game"); mt_irc.connected_players[player:get_player_name()] = mt_irc.auto_join; end); @@ -39,7 +53,7 @@ local function bot_command ( from, message ) end if (not mt_irc.bot_commands[cmd]) then - irc.say(from, "Unknown command `"..cmd.."'. Try `!help'."); + mt_irc.say(from, "Unknown command `"..cmd.."'. Try `!help'."); return; end @@ -80,14 +94,11 @@ irc.register_callback("private_msg", function ( from, message ) end); irc.register_callback("kick", function ( chaninfo, to, from ) - if (mt_irc.connect_ok) then - mt_irc.connect_ok = false; - minetest.chat_send_all("IRC: Bot was kicked by "..from..". Reconnecting bot in 5 seconds..."); - mt_irc.got_motd = true; - mt_irc.connect_ok = false; - irc.quit("Kicked"); - minetest.after(5, mt_irc.connect); - end + minetest.chat_send_all("IRC: Bot was kicked by "..from..". Reconnecting bot in 5 seconds..."); + mt_irc.got_motd = false; + mt_irc.connect_ok = false; + irc.quit("Kicked"); + minetest.after(5, mt_irc.connect); end); irc.register_callback("nick_change", function ( from, old_nick ) @@ -123,3 +134,11 @@ minetest.register_on_shutdown(function ( ) irc.poll(); end end); + +irc.handlers.on_error = function (from, respond_to) + minetest.chat_send_all("IRC: Ping timeout. Reconnecting bot in 5 seconds..."); + mt_irc.got_motd = false; + mt_irc.connect_ok = false; + irc.quit("Ping timeout"); + minetest.after(5, mt_irc.connect); +end diff --git a/src/chatcmds.lua b/src/chatcmds.lua index 95803fd..0cc9ece 100644 --- a/src/chatcmds.lua +++ b/src/chatcmds.lua @@ -1,4 +1,18 @@ +-- IRC Mod for Minetest +-- By Diego Martínez +-- +-- This mod allows to tie a Minetest server to an IRC channel. +-- +-- This program is free software. It comes without any warranty, to +-- the extent permitted by applicable law. You can redistribute it +-- and/or modify it under the terms of the Do What The Fuck You Want +-- To Public License, Version 2, as published by Sam Hocevar. See +-- http://sam.zoy.org/wtfpl/COPYING for more details. +-- + +local irc = require("irc"); + minetest.register_chatcommand("msg", { params = " "; description = "Send a private message to an IRC user"; diff --git a/src/config.lua b/src/config.lua index 37c7ce6..507d90c 100644 --- a/src/config.lua +++ b/src/config.lua @@ -1,3 +1,16 @@ + +-- IRC Mod for Minetest +-- By Diego Martínez +-- +-- This mod allows to tie a Minetest server to an IRC channel. +-- +-- This program is free software. It comes without any warranty, to +-- the extent permitted by applicable law. You can redistribute it +-- and/or modify it under the terms of the Do What The Fuck You Want +-- To Public License, Version 2, as published by Sam Hocevar. See +-- http://sam.zoy.org/wtfpl/COPYING for more details. +-- + -- ************************* -- ** BASIC USER SETTINGS ** -- ************************* @@ -8,7 +21,7 @@ mt_irc.server = nil; -- Port to connect on joinplayer (number, default 6667) mt_irc.port = nil; --- Channel to connect on joinplayer (string, default "#minetest-irc-testing") +-- Channel to connect on joinplayer (string, default "##mt-irc-mod") mt_irc.channel = nil; -- *********************** @@ -23,7 +36,7 @@ mt_irc.timeout = nil; -- Nickname when using single conection (string, default "minetest-"..); -- ( is the server IP address packed as a 32 bit integer). -mt_irc.server_nick = nil; +mt_irc.server_nick = "HelloIRC"; -- Password to use when using single connection (string, default "") mt_irc.password = nil; diff --git a/src/friends.lua b/src/friends.lua index 6d19e3d..6592195 100644 --- a/src/friends.lua +++ b/src/friends.lua @@ -1,4 +1,16 @@ +-- IRC Mod for Minetest +-- By Diego Martínez +-- +-- This mod allows to tie a Minetest server to an IRC channel. +-- +-- This program is free software. It comes without any warranty, to +-- the extent permitted by applicable law. You can redistribute it +-- and/or modify it under the terms of the Do What The Fuck You Want +-- To Public License, Version 2, as published by Sam Hocevar. See +-- http://sam.zoy.org/wtfpl/COPYING for more details. +-- + -- TODO --[[ diff --git a/src/init.lua b/src/init.lua index 16ef077..2673df8 100644 --- a/src/init.lua +++ b/src/init.lua @@ -1,5 +1,6 @@ + -- IRC Mod for Minetest --- (C) 2012 Diego Martínez +-- By Diego Martínez -- -- This mod allows to tie a Minetest server to an IRC channel. -- @@ -142,7 +143,7 @@ mt_irc.say = function ( to, msg ) irc.say(to, msg); end -mt_irc._irc = irc; +mt_irc.irc = irc; dofile(MODPATH.."/callback.lua"); dofile(MODPATH.."/chatcmds.lua"); diff --git a/src/luairc/irc.lua b/src/luairc/irc.lua index bf1c3af..b05a7a1 100644 --- a/src/luairc/irc.lua +++ b/src/luairc/irc.lua @@ -43,11 +43,11 @@ local icallbacks = { ctcp_version = {}, } local requestinfo = {whois = {}} -local handlers = {} -local ctcp_handlers = {} -local user_handlers = {} -local serverinfo = {} -local ip = nil +handlers = {} +ctcp_handlers = {} +user_handlers = {} +serverinfo = {} +ip = nil -- }}} -- defaults {{{