diff --git a/src/config.lua b/src/config.lua index 69174b4..da2beca 100644 --- a/src/config.lua +++ b/src/config.lua @@ -15,26 +15,26 @@ -- ************************* -- Server to connect on joinplayer (string, default "irc.freenode.net") -mt_irc.server = minetest.setting_get("mt_irc.server"); +mt_irc.server = minetest.setting_get("mt_irc.server") or "irc.freenode.net"; -- Port to connect on joinplayer (number, default 6667) -mt_irc.port = tonumber(minetest.setting_get("mt_irc.port")); +mt_irc.port = tonumber(minetest.setting_get("mt_irc.port")) or 6667; -- Channel to connect on joinplayer (string, default "##mt-irc-mod") -mt_irc.channel = minetest.setting_get("mt_irc.channel"); +mt_irc.channel = minetest.setting_get("mt_irc.channel") or "##mt-irc-mod"; -- *********************** -- ** ADVANCED SETTINGS ** -- *********************** -- Time between chat updates in seconds (number, default 0.2). -mt_irc.dtime = tonumber(minetest.setting_get("mt_irc.dtime")); +mt_irc.dtime = tonumber(minetest.setting_get("mt_irc.dtime")) or 0.2; --- Underlying socket timeout in seconds (number, default 1.0). -mt_irc.timeout = tonumber(minetest.setting_get("mt_irc.timeout")); +-- Underlying socket timeout in seconds (number, default 60.0). +mt_irc.timeout = tonumber(minetest.setting_get("mt_irc.timeout")) or 60.0; -- Nickname when using single conection (string, default "minetest-"..); --- ( is the server IP address packed as a 32 bit integer). +-- ( is a random string of 6 hexidecimal numbers). mt_irc.server_nick = minetest.setting_get("mt_irc.server_nick"); -- Password to use when using single connection (string, default "") @@ -58,3 +58,15 @@ mt_irc.auto_join = not minetest.setting_getbool("mt_irc.disable_auto_join"); -- Whether to automatically connect to the server on mod load -- (boolean, default true) mt_irc.auto_connect = not minetest.setting_getbool("mt_irc.disable_auto_connect"); + +-- Set default server nick if not specified. +if (not mt_irc.server_nick) then + local pr = PseudoRandom(os.time()); + -- Workaround for bad distribution in minetest PRNG implementation. + local fmt = "minetest-%02X%02X%02X"; + mt_irc.server_nick = fmt:format( + pr:next(0, 255), + pr:next(0, 255), + pr:next(0, 255) + ); +end diff --git a/src/init.lua b/src/init.lua index 44eea94..6bd9352 100644 --- a/src/init.lua +++ b/src/init.lua @@ -29,27 +29,6 @@ local irc = require 'irc'; irc.DEBUG = ((mt_irc.debug and true) or false); --- Set defaults if not specified. -if (not mt_irc.server_nick) then - local pr = PseudoRandom(os.time()); - -- Workaround for bad distribution in minetest PRNG implementation. - local fmt = "minetest-%02X%02X%02X"; - mt_irc.server_nick = fmt:format( - pr:next(0, 255), - pr:next(0, 255), - pr:next(0, 255) - ); -end -mt_irc.server = (mt_irc.server or "irc.freenode.net"); -mt_irc.port = (mt_irc.port or 6667); -mt_irc.channel = (mt_irc.channel or "##mt-irc-mod"); -mt_irc.dtime = (mt_irc.dtime or 0.2); -mt_irc.timeout = (mt_irc.timeout or 60.0); -mt_irc.message_format_out = (mt_irc.message_format_out or "<$(nick)> $(message)"); -mt_irc.message_format_in = (mt_irc.message_format_in or "<$(name)@IRC[$(channel)]> $(message)"); -if (mt_irc.connect_on_join == nil) then mt_irc.connect_on_join = false; end -if (mt_irc.connect_on_load == nil) then mt_irc.connect_on_load = false; end - minetest.register_privilege("irc_admin", { description = "Allow IRC administrative tasks to be performed."; give_to_singleplayer = true;