Compare commits
10 Commits
64e53cba45
...
83ad5f580a
Author | SHA1 | Date | |
---|---|---|---|
|
83ad5f580a | ||
|
06932a6b00 | ||
|
0956bdea31 | ||
|
d80004c524 | ||
|
99afcc794b | ||
|
7161160667 | ||
|
0e79e91fd2 | ||
|
22e523cc7a | ||
|
e2ff55d70f | ||
|
55ea96e88e |
8
.luacheckrc
Normal file
8
.luacheckrc
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
unused_args = false
|
||||
allow_defined_top = true
|
||||
|
||||
read_globals = {
|
||||
"minetest",
|
||||
"irc",
|
||||
}
|
126
init.lua
126
init.lua
@ -1,21 +1,17 @@
|
||||
|
||||
irc_users = {}
|
||||
|
||||
local function notify(nick, message)
|
||||
return mt_irc:queueMsg(mt_irc.msgs.privmsg(nick, message))
|
||||
end
|
||||
local irc_users = {}
|
||||
|
||||
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
|
||||
if name == loggedInAs and not minetest.get_player_by_name(name) then
|
||||
notify(nick, message)
|
||||
irc:say(nick, message)
|
||||
end
|
||||
end
|
||||
return old_chat_send_player(name, message)
|
||||
end
|
||||
|
||||
mt_irc:register_hook("NickChange", function(user, newNick)
|
||||
irc.register_hook("NickChange", function(user, newNick)
|
||||
for nick, player in pairs(irc_users) do
|
||||
if nick == user.nick then
|
||||
irc_users[newNick] = irc_users[user.nick]
|
||||
@ -24,61 +20,83 @@ mt_irc:register_hook("NickChange", function(user, newNick)
|
||||
end
|
||||
end)
|
||||
|
||||
mt_irc:register_hook("OnQuit", function(user, reason)
|
||||
irc.register_hook("OnPart", function(user, channel, reason)
|
||||
irc_users[user.nick] = nil
|
||||
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>",
|
||||
description = "Login as a user to run commands",
|
||||
func = function(user, args)
|
||||
if args == "" then
|
||||
notify(user.nick, "You need a username and password")
|
||||
return
|
||||
return false, "You need a username and password."
|
||||
end
|
||||
local found, _, playername, password = args:find("^([^%s]+)%s([^%s]+)$")
|
||||
if not found then
|
||||
playername = args
|
||||
password = ""
|
||||
local playerName, password = args:match("^(%S+)%s(.+)$")
|
||||
if not playerName then
|
||||
return false, "Player name and password required."
|
||||
end
|
||||
if minetest.auth_table[playername] and
|
||||
minetest.auth_table[playername].password ==
|
||||
minetest.get_password_hash(playername, password) then
|
||||
local inChannel = false
|
||||
local channel = irc.conn.channels[irc.config.channel]
|
||||
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
|
||||
.." from IRC logs in as "..playername)
|
||||
irc_users[user.nick] = playername
|
||||
notify(user.nick, "You are now logged in as "..playername)
|
||||
.." from IRC logs in as "..playerName)
|
||||
irc_users[user.nick] = playerName
|
||||
handler.record_login(playerName)
|
||||
return true, "You are now logged in as "..playerName
|
||||
else
|
||||
minetest.log("action", user.nick.."@IRC attempted to log in as "
|
||||
..playername.." unsuccessfully")
|
||||
notify(user.nick, "Incorrect password or player does not exist")
|
||||
..playerName.." unsuccessfully")
|
||||
return false, "Incorrect password or player does not exist."
|
||||
end
|
||||
end})
|
||||
end
|
||||
})
|
||||
|
||||
mt_irc:register_bot_command("logout", {
|
||||
irc.register_bot_command("logout", {
|
||||
description = "Logout",
|
||||
func = function (user, args)
|
||||
if irc_users[user.nick] then
|
||||
minetest.log("action", user.nick.."@IRC logs out from "
|
||||
..irc_users[user.nick])
|
||||
irc_users[user.nick] = nil
|
||||
notify(user.nick, "You are now logged off")
|
||||
return true, "You are now logged off."
|
||||
else
|
||||
notify(from, "You are not logged in")
|
||||
return false, "You are not logged in."
|
||||
end
|
||||
end})
|
||||
end,
|
||||
})
|
||||
|
||||
mt_irc:register_bot_command("cmd", {
|
||||
irc.register_bot_command("cmd", {
|
||||
params = "<command>",
|
||||
description = "Run a command on the server",
|
||||
func = function (user, args)
|
||||
if args == "" then
|
||||
notify(user.nick, "You need a command")
|
||||
return
|
||||
return false, "You need a command."
|
||||
end
|
||||
if not irc_users[user.nick] then
|
||||
notify(user.nick, "You are not logged in")
|
||||
return
|
||||
return false, "You are not logged in."
|
||||
end
|
||||
local found, _, commandname, params = args:find("^([^%s]+)%s(.+)$")
|
||||
if not found then
|
||||
@ -86,33 +104,37 @@ mt_irc:register_bot_command("cmd", {
|
||||
end
|
||||
local command = minetest.chatcommands[commandname]
|
||||
if not command then
|
||||
notify(user.nick, "Not a valid command")
|
||||
return
|
||||
return false, "Not a valid command."
|
||||
end
|
||||
if minetest.check_player_privs(irc_users[user.nick], command.privs) then
|
||||
minetest.log("action", user.nick.."@IRC runs "
|
||||
..args.." as "..irc_users[user.nick])
|
||||
command.func(irc_users[user.nick], (params or ""))
|
||||
if not minetest.check_player_privs(irc_users[user.nick], command.privs) then
|
||||
return false, "Your privileges are insufficient."
|
||||
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",
|
||||
description = "Say something",
|
||||
func = function (user, args)
|
||||
if args == "" then
|
||||
notify(from, "You need a message")
|
||||
return
|
||||
return false, "You need a message."
|
||||
end
|
||||
if not irc_users[user.nick] then
|
||||
notify(user.nick, "You are not logged in")
|
||||
return
|
||||
return false, "You are not logged in."
|
||||
end
|
||||
if minetest.check_player_privs(irc_users[user.nick], {shout=true}) then
|
||||
minetest.log("action", user.nick.."@IRC says "
|
||||
..args.." as "..irc_users[user.nick])
|
||||
minetest.chat_send_all("<"..irc_users[user.nick].."@IRC> "..args)
|
||||
notify(user.nick, "Message sent successfuly")
|
||||
if not minetest.check_player_privs(irc_users[user.nick], {shout=true}) then
|
||||
minetest.log("action", ("%s@IRC tried to say %q as %s"
|
||||
.." without the shout privilege.")
|
||||
:format(user.nick, args, irc_users[user.nick]))
|
||||
return false, "You can not shout."
|
||||
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
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user