2013-04-29 15:07:44 -07:00
|
|
|
-- This file is licensed under the terms of the BSD 2-clause license.
|
|
|
|
-- See LICENSE.txt for details.
|
|
|
|
|
|
|
|
|
2017-03-15 17:33:47 -07:00
|
|
|
function irc.player_part(name)
|
|
|
|
if not irc.joined_players[name] then
|
2016-11-20 15:53:01 -08:00
|
|
|
return false, "You are not in the channel"
|
2013-04-29 15:07:44 -07:00
|
|
|
end
|
2017-03-15 17:33:47 -07:00
|
|
|
irc.joined_players[name] = nil
|
2016-11-20 15:53:01 -08:00
|
|
|
return true, "You left the channel"
|
2013-04-29 15:07:44 -07:00
|
|
|
end
|
2017-02-15 21:36:04 -08:00
|
|
|
|
2017-03-15 17:33:47 -07:00
|
|
|
function irc.player_join(name)
|
|
|
|
if irc.joined_players[name] then
|
2016-11-20 15:53:01 -08:00
|
|
|
return false, "You are already in the channel"
|
2019-02-11 20:10:41 -08:00
|
|
|
elseif not minetest.get_player_by_name(name) then
|
|
|
|
return false, "You need to be in-game to join the channel"
|
2013-04-29 15:07:44 -07:00
|
|
|
end
|
2017-03-15 17:33:47 -07:00
|
|
|
irc.joined_players[name] = true
|
2016-11-20 15:53:01 -08:00
|
|
|
return true, "You joined the channel"
|
2013-04-29 15:07:44 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_chatcommand("join", {
|
|
|
|
description = "Join the IRC channel",
|
|
|
|
privs = {shout=true},
|
2017-03-15 17:33:47 -07:00
|
|
|
func = function(name)
|
|
|
|
return irc.player_join(name)
|
2013-04-29 15:07:44 -07:00
|
|
|
end
|
|
|
|
})
|
2017-02-15 21:36:04 -08:00
|
|
|
|
2013-04-29 15:07:44 -07:00
|
|
|
minetest.register_chatcommand("part", {
|
|
|
|
description = "Part the IRC channel",
|
|
|
|
privs = {shout=true},
|
2017-03-15 17:33:47 -07:00
|
|
|
func = function(name)
|
|
|
|
return irc.player_part(name)
|
2013-04-29 15:07:44 -07:00
|
|
|
end
|
|
|
|
})
|
2017-02-15 21:36:04 -08:00
|
|
|
|
2013-04-29 15:07:44 -07:00
|
|
|
minetest.register_chatcommand("who", {
|
|
|
|
description = "Tell who is currently on the channel",
|
|
|
|
privs = {},
|
2017-03-15 17:33:47 -07:00
|
|
|
func = function()
|
2016-11-20 15:53:01 -08:00
|
|
|
local out, n = { }, 0
|
2017-02-15 21:36:04 -08:00
|
|
|
for plname in pairs(irc.joined_players) do
|
2016-11-20 15:53:01 -08:00
|
|
|
n = n + 1
|
2017-02-15 21:36:04 -08:00
|
|
|
out[n] = plname
|
2013-04-29 15:07:44 -07:00
|
|
|
end
|
2016-11-20 15:53:01 -08:00
|
|
|
table.sort(out)
|
2020-07-18 08:57:42 -07:00
|
|
|
return true, n.." player(s) in channel: "..table.concat(out, ", ")
|
2013-04-29 15:07:44 -07:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2017-02-15 21:36:04 -08:00
|
|
|
|
2013-04-29 15:07:44 -07:00
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
2014-05-25 19:52:24 -07:00
|
|
|
irc.joined_players[name] = irc.config.auto_join
|
2013-04-29 15:07:44 -07:00
|
|
|
end)
|
2017-02-15 21:36:04 -08:00
|
|
|
|
|
|
|
|
2013-04-29 15:07:44 -07:00
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
2014-05-25 19:52:24 -07:00
|
|
|
irc.joined_players[name] = nil
|
2013-04-29 15:07:44 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-15 17:33:47 -07:00
|
|
|
function irc.sendLocal(message)
|
|
|
|
for name, _ in pairs(irc.joined_players) do
|
2018-09-09 09:08:02 -07:00
|
|
|
minetest.chat_send_player(name,
|
|
|
|
minetest.colorize(irc.config.chat_color, message))
|
2013-04-29 15:07:44 -07:00
|
|
|
end
|
2017-03-15 17:33:47 -07:00
|
|
|
irc.logChat(message)
|
2013-04-29 15:07:44 -07:00
|
|
|
end
|