Compare commits

...

10 Commits

Author SHA1 Message Date
Diego Martínez
83ad5f580a Add .luacheckrc. 2019-04-10 23:56:35 -04:00
D Tim Cummings
06932a6b00 Replace deprecated use of colon notation when calling methods register_hook and register_bot_command
This change removes 8 warnings from debug.txt every time server starts.
2018-06-12 11:17:25: WARNING[Main]: Deprecated use of colon notation when calling method `register_hook` at @/minetest/mods/irc_commands/init.lua:14
2018-06-12 11:17:25: WARNING[Main]: Deprecated use of colon notation when calling method `register_hook` at @/minetest/mods/irc_commands/init.lua:23
2018-06-12 11:17:25: WARNING[Main]: Deprecated use of colon notation when calling method `register_hook` at @/minetest/mods/irc_commands/init.lua:27
2018-06-12 11:17:25: WARNING[Main]: Deprecated use of colon notation when calling method `register_hook` at @/minetest/mods/irc_commands/init.lua:31
2018-06-12 11:17:25: WARNING[Main]: Deprecated use of colon notation when calling method `register_bot_command` at @/minetest/mods/irc_commands/init.lua:35
2018-06-12 11:17:25: WARNING[Main]: Deprecated use of colon notation when calling method `register_bot_command` at @/minetest/mods/irc_commands/init.lua:77
2018-06-12 11:17:25: WARNING[Main]: Deprecated use of colon notation when calling method `register_bot_command` at @/minetest/mods/irc_commands/init.lua:91
2018-06-12 11:17:25: WARNING[Main]: Deprecated use of colon notation when calling method `register_bot_command` at @/minetest/mods/irc_commands/init.lua:118
2019-04-10 23:16:47 -04:00
ShadowNinja
0956bdea31 Add mod.conf 2019-04-10 23:09:44 -04:00
ShadowNinja
d80004c524 Accept whitespace in passwords 2018-02-18 19:40:54 +00:00
ShadowNinja
99afcc794b Update authentication API usage 2016-06-01 12:17:21 -04:00
ShadowNinja
7161160667 Minor cleanup 2016-06-01 11:57:57 -04:00
ShadowNinja
0e79e91fd2 Check that the server is in its channel 2016-06-01 11:57:24 -04:00
ShadowNinja
22e523cc7a Update to latest API version 2014-05-28 20:29:32 -04:00
ShadowNinja
e2ff55d70f Reply when you have insufficient privileges for a command 2014-02-05 19:40:25 -05:00
ShadowNinja
55ea96e88e Use the reply API to reply in-channel 2013-12-03 16:37:02 -05:00
3 changed files with 83 additions and 52 deletions

8
.luacheckrc Normal file
View File

@ -0,0 +1,8 @@
unused_args = false
allow_defined_top = true
read_globals = {
"minetest",
"irc",
}

126
init.lua
View File

@ -1,21 +1,17 @@
irc_users = {} local irc_users = {}
local function notify(nick, message)
return mt_irc:queueMsg(mt_irc.msgs.privmsg(nick, message))
end
local old_chat_send_player = minetest.chat_send_player local old_chat_send_player = minetest.chat_send_player
minetest.chat_send_player = function(name, message) minetest.chat_send_player = function(name, message) -- luacheck: ignore
for nick, loggedInAs in pairs(irc_users) do for nick, loggedInAs in pairs(irc_users) do
if name == loggedInAs and not minetest.get_player_by_name(name) then if name == loggedInAs and not minetest.get_player_by_name(name) then
notify(nick, message) irc:say(nick, message)
end end
end end
return old_chat_send_player(name, message) return old_chat_send_player(name, message)
end end
mt_irc:register_hook("NickChange", function(user, newNick) irc.register_hook("NickChange", function(user, newNick)
for nick, player in pairs(irc_users) do for nick, player in pairs(irc_users) do
if nick == user.nick then if nick == user.nick then
irc_users[newNick] = irc_users[user.nick] irc_users[newNick] = irc_users[user.nick]
@ -24,61 +20,83 @@ mt_irc:register_hook("NickChange", function(user, newNick)
end end
end) end)
mt_irc:register_hook("OnQuit", function(user, reason) irc.register_hook("OnPart", function(user, channel, reason)
irc_users[user.nick] = nil irc_users[user.nick] = nil
end) end)
mt_irc:register_bot_command("login", { irc.register_hook("OnKick", function(user, channel, target, reason)
irc_users[target] = nil
end)
irc.register_hook("OnQuit", function(user, reason)
irc_users[user.nick] = nil
end)
irc.register_bot_command("login", {
params = "<username> <password>", params = "<username> <password>",
description = "Login as a user to run commands", description = "Login as a user to run commands",
func = function(user, args) func = function(user, args)
if args == "" then if args == "" then
notify(user.nick, "You need a username and password") return false, "You need a username and password."
return
end end
local found, _, playername, password = args:find("^([^%s]+)%s([^%s]+)$") local playerName, password = args:match("^(%S+)%s(.+)$")
if not found then if not playerName then
playername = args return false, "Player name and password required."
password = ""
end end
if minetest.auth_table[playername] and local inChannel = false
minetest.auth_table[playername].password == local channel = irc.conn.channels[irc.config.channel]
minetest.get_password_hash(playername, password) then if not channel then
return false, "The server needs to be in its "..
"channel for anyone to log in."
end
for cnick, cuser in pairs(channel.users) do
if user.nick == cnick then
inChannel = true
break
end
end
if not inChannel then
return false, "You need to be in the server's channel to log in."
end
local handler = minetest.get_auth_handler()
local auth = handler.get_auth(playerName)
if auth and minetest.check_password_entry(playerName, auth.password, password) then
minetest.log("action", "User "..user.nick minetest.log("action", "User "..user.nick
.." from IRC logs in as "..playername) .." from IRC logs in as "..playerName)
irc_users[user.nick] = playername irc_users[user.nick] = playerName
notify(user.nick, "You are now logged in as "..playername) handler.record_login(playerName)
return true, "You are now logged in as "..playerName
else else
minetest.log("action", user.nick.."@IRC attempted to log in as " minetest.log("action", user.nick.."@IRC attempted to log in as "
..playername.." unsuccessfully") ..playerName.." unsuccessfully")
notify(user.nick, "Incorrect password or player does not exist") return false, "Incorrect password or player does not exist."
end end
end}) end
})
mt_irc:register_bot_command("logout", { irc.register_bot_command("logout", {
description = "Logout", description = "Logout",
func = function (user, args) func = function (user, args)
if irc_users[user.nick] then if irc_users[user.nick] then
minetest.log("action", user.nick.."@IRC logs out from " minetest.log("action", user.nick.."@IRC logs out from "
..irc_users[user.nick]) ..irc_users[user.nick])
irc_users[user.nick] = nil irc_users[user.nick] = nil
notify(user.nick, "You are now logged off") return true, "You are now logged off."
else else
notify(from, "You are not logged in") return false, "You are not logged in."
end end
end}) end,
})
mt_irc:register_bot_command("cmd", { irc.register_bot_command("cmd", {
params = "<command>", params = "<command>",
description = "Run a command on the server", description = "Run a command on the server",
func = function (user, args) func = function (user, args)
if args == "" then if args == "" then
notify(user.nick, "You need a command") return false, "You need a command."
return
end end
if not irc_users[user.nick] then if not irc_users[user.nick] then
notify(user.nick, "You are not logged in") return false, "You are not logged in."
return
end end
local found, _, commandname, params = args:find("^([^%s]+)%s(.+)$") local found, _, commandname, params = args:find("^([^%s]+)%s(.+)$")
if not found then if not found then
@ -86,33 +104,37 @@ mt_irc:register_bot_command("cmd", {
end end
local command = minetest.chatcommands[commandname] local command = minetest.chatcommands[commandname]
if not command then if not command then
notify(user.nick, "Not a valid command") return false, "Not a valid command."
return
end end
if minetest.check_player_privs(irc_users[user.nick], command.privs) then if not minetest.check_player_privs(irc_users[user.nick], command.privs) then
minetest.log("action", user.nick.."@IRC runs " return false, "Your privileges are insufficient."
..args.." as "..irc_users[user.nick])
command.func(irc_users[user.nick], (params or ""))
end end
end}) minetest.log("action", user.nick.."@IRC runs "
..args.." as "..irc_users[user.nick])
return command.func(irc_users[user.nick], (params or ""))
end
})
mt_irc:register_bot_command("say", { irc.register_bot_command("say", {
params = "message", params = "message",
description = "Say something", description = "Say something",
func = function (user, args) func = function (user, args)
if args == "" then if args == "" then
notify(from, "You need a message") return false, "You need a message."
return
end end
if not irc_users[user.nick] then if not irc_users[user.nick] then
notify(user.nick, "You are not logged in") return false, "You are not logged in."
return
end end
if minetest.check_player_privs(irc_users[user.nick], {shout=true}) then if not minetest.check_player_privs(irc_users[user.nick], {shout=true}) then
minetest.log("action", user.nick.."@IRC says " minetest.log("action", ("%s@IRC tried to say %q as %s"
..args.." as "..irc_users[user.nick]) .." without the shout privilege.")
minetest.chat_send_all("<"..irc_users[user.nick].."@IRC> "..args) :format(user.nick, args, irc_users[user.nick]))
notify(user.nick, "Message sent successfuly") return false, "You can not shout."
end end
end}) minetest.log("action", ("%s@IRC says %q as %s.")
:format(user.nick, args, irc_users[user.nick]))
minetest.chat_send_all("<"..irc_users[user.nick].."@IRC> "..args)
return true, "Message sent successfuly."
end
})

1
mod.conf Normal file
View File

@ -0,0 +1 @@
name = irc_commands