Skip to content
This repository has been archived by the owner on Aug 20, 2020. It is now read-only.

Commit

Permalink
add chatcommand to update IRC server ingame without update minetest.c…
Browse files Browse the repository at this point in the history
…onf and reboot
  • Loading branch information
Crabman77 committed Dec 2, 2016
1 parent cc23c43 commit 378a841
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions irc/chatcmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,19 @@ minetest.chatcommands["me"].func = function(name, param, ...)
irc:say(("* %s %s"):format(name, param))
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
})

30 changes: 30 additions & 0 deletions irc/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,33 @@ if not irc.config.nick then
)
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()

0 comments on commit 378a841

Please sign in to comment.