1
0
mirror of https://github.com/MinetestForFun/irc_modpack.git synced 2024-12-23 07:20:20 +01:00

add chatcommand to update IRC server ingame without update minetest.conf and reboot

This commit is contained in:
crabman77 2016-12-02 23:09:14 +01:00
parent cc23c43594
commit 378a841b7d
2 changed files with 46 additions and 0 deletions

View File

@ -124,3 +124,19 @@ minetest.chatcommands["me"].func = function(name, param, ...)
irc:say(("* %s %s"):format(name, param)) irc:say(("* %s %s"):format(name, param))
end end
minetest.register_chatcommand("irc_change_server", {
params = "<servername>",
description = "Change the IRC server.",
privs = {irc_admin=true},
func = function(name, param)
if param == "" then
minetest.chat_send_player(name, "Missing argument servername")
return
end
irc.config.server = param
irc.save_config()
minetest.chat_send_player(name, "New server IRC is \"".. param.."\".")
minetest.chat_send_player(name, "type \"/irc_reconnect\" to reconnect IRC.")
end
})

View File

@ -57,3 +57,33 @@ if not irc.config.nick then
) )
end end
local config_file = minetest.get_worldpath() .. "/irc.txt"
function irc.save_config()
local input, err = io.open(config_file, "w")
if input then
local conf = {server = irc.config.server}
input:write(minetest.serialize(conf))
input:close()
else
minetest.log("error", "open(" .. config_file .. ", 'w') failed: " .. err)
end
end
function irc.load_config()
local file = io.open(config_file, "r")
local settings = {}
if file then
settings = minetest.deserialize(file:read("*all"))
file:close()
if settings and type(settings) == "table" then
if settings["server"] ~= nil then
irc.config.server = settings["server"]
end
end
end
end
irc.load_config()