cleanup comments, restore original style whitespace (tabs)
Style and review fixes from SmallJokermaster
parent
32f87d2578
commit
e806777a5f
|
@ -0,0 +1 @@
|
|||
*.swp
|
|
@ -1,17 +1,3 @@
|
|||
local function tablejoin(t, i, j)
|
||||
local s = ""
|
||||
local k
|
||||
|
||||
if not i then i = 1 end
|
||||
if not j then j = #t end
|
||||
|
||||
for k=i,j do
|
||||
s = s.." "..t[k]
|
||||
end
|
||||
|
||||
return s
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("channel", {
|
||||
description = "Manages chat channels",
|
||||
privs = {
|
||||
|
@ -20,9 +6,9 @@ minetest.register_chatcommand("channel", {
|
|||
},
|
||||
func = function(name, param)
|
||||
if param == "" then
|
||||
minetest.chat_send_player(name, "Online players: /channel online")
|
||||
minetest.chat_send_player(name, "Join/switch: /channel join <channel>")
|
||||
minetest.chat_send_player(name, "Leave channel: /channel leave")
|
||||
minetest.chat_send_player(name, "Online players: /channel online")
|
||||
minetest.chat_send_player(name, "Join/switch: /channel join <channel>")
|
||||
minetest.chat_send_player(name, "Leave channel: /channel leave")
|
||||
minetest.chat_send_player(name, "Invite to channel: /channel invite <playername>")
|
||||
return
|
||||
|
||||
|
@ -38,16 +24,16 @@ minetest.register_chatcommand("channel", {
|
|||
|
||||
local args = param:split(" ")
|
||||
|
||||
if args[1] == "join" and #args >= 2 then
|
||||
if args[1] == "join" and #args == 2 then
|
||||
channels.command_set(name, args[2])
|
||||
return
|
||||
|
||||
elseif args[1] == "invite" and #args == 2 then
|
||||
channels.command_invite(name, args[2])
|
||||
return
|
||||
elseif args[1] == "invite" and #args == 2 then
|
||||
channels.command_invite(name, args[2])
|
||||
return
|
||||
|
||||
elseif args[1] == "wall" and #args >= 2 then
|
||||
channels.command_wall(name, tablejoin(args,2) )
|
||||
channels.command_wall(name, table.concat(args," ",2, #args) )
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -55,35 +41,39 @@ minetest.register_chatcommand("channel", {
|
|||
end,
|
||||
})
|
||||
|
||||
function channels.say_chat(name, message, channel)
|
||||
-- message must already have '<player name>' at start if from a player
|
||||
minetest.log("action","CHAT: #"..tostring(channel or "no channel").." "..message)
|
||||
function channels.say_chat(sendername, message, channel)
|
||||
-- For chat messages: 'message' must begin with '<playername>'
|
||||
-- if channel==nil then message is sent only to players in global chat
|
||||
|
||||
local all_players = minetest.get_connected_players()
|
||||
minetest.log("action","CHAT: #" .. (channel or "no channel") .. " " .. message)
|
||||
|
||||
for _,player in ipairs(all_players) do
|
||||
local playername = player:get_player_name()
|
||||
if channels.players[playername] == channel then -- if nil then send to players in global chat
|
||||
minetest.chat_send_player(playername, message)
|
||||
end
|
||||
end
|
||||
local all_players = minetest.get_connected_players()
|
||||
|
||||
for _,player in ipairs(all_players) do
|
||||
local playername = player:get_player_name()
|
||||
if channels.players[playername] == channel then
|
||||
minetest.chat_send_player(playername, message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function channels.command_invite(hoster,guest)
|
||||
local channelname = channels.players[hoster]
|
||||
if not channelname then
|
||||
if channels.allow_global_channel then
|
||||
channelname = "the global chat"
|
||||
else
|
||||
minetest.chat_send_player(hoster, "The global channel is not usable.")
|
||||
return
|
||||
end
|
||||
else
|
||||
channelname = "the '"..channelname.."' chat channel."
|
||||
end
|
||||
local channelname = channels.players[hoster]
|
||||
if not channelname then
|
||||
if channels.allow_global_channel then
|
||||
channelname = "the global chat"
|
||||
else
|
||||
minetest.chat_send_player(hoster, "The global channel is not usable.")
|
||||
return
|
||||
end
|
||||
else
|
||||
channelname = "the '" .. channelname .. "' chat channel."
|
||||
end
|
||||
|
||||
minetest.chat_send_player(guest, hoster.." invites you to join "..channelname)
|
||||
minetest.chat_send_player(hoster, guest.." was invited to join "..channelname)
|
||||
minetest.chat_send_player(guest, hoster .. " invites you to join " .. channelname)
|
||||
|
||||
-- Let other players in channel know
|
||||
channels.say_chat(hoster, hoster .. " invites " .. guest .. " to join " .. channelname, channelname)
|
||||
end
|
||||
|
||||
function channels.command_wall(name, message)
|
||||
|
@ -93,7 +83,7 @@ function channels.command_wall(name, message)
|
|||
return
|
||||
end
|
||||
|
||||
minetest.chat_send_all("(Announcement from "..name.."): "..message)
|
||||
minetest.chat_send_all("(Announcement from " .. name .. "): " .. message)
|
||||
end
|
||||
|
||||
function channels.command_online(name)
|
||||
|
@ -102,7 +92,7 @@ function channels.command_online(name)
|
|||
if channel then
|
||||
for k,v in pairs(channels.players) do
|
||||
if v == channel and k ~= name then
|
||||
players = players..", "..k
|
||||
players = players .. ", " .. k
|
||||
end
|
||||
end
|
||||
else
|
||||
|
@ -110,13 +100,13 @@ function channels.command_online(name)
|
|||
for _,player in ipairs(oplayers) do
|
||||
local p_name = player:get_player_name()
|
||||
if not channels.players[p_name] and p_name ~= name then
|
||||
players = players..", "..p_name
|
||||
players = players .. ", " .. p_name
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
minetest.chat_send_player(name, "Online players in this channel: "..players)
|
||||
minetest.chat_send_player(name, "Online players in this channel: " .. players)
|
||||
end
|
||||
|
||||
function channels.command_set(name, param)
|
||||
|
@ -131,13 +121,13 @@ function channels.command_set(name, param)
|
|||
minetest.chat_send_player(name, "Error: You are already in this channel")
|
||||
return
|
||||
end
|
||||
channels.say_chat(name, "# "..name.." left the channel", channel_old)
|
||||
channels.say_chat(name, "# " .. name .. " left the channel", channel_old)
|
||||
else
|
||||
local oplayers = minetest.get_connected_players()
|
||||
for _,player in ipairs(oplayers) do
|
||||
local p_name = player:get_player_name()
|
||||
if not channels.players[p_name] and p_name ~= name and channels.allow_global_channel then
|
||||
minetest.chat_send_player(p_name, "# "..name.." left the global chat")
|
||||
minetest.chat_send_player(p_name, "# " .. name .. " left the global chat")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -157,11 +147,11 @@ function channels.command_set(name, param)
|
|||
name = "Channel",
|
||||
number = 0xFFFFFF,
|
||||
position = {x = 0.6, y = 0.03},
|
||||
text = "Channel: "..param,
|
||||
text = "Channel: " .. param,
|
||||
scale = {x = 200,y = 25},
|
||||
alignment = {x = 0, y = 0},
|
||||
})
|
||||
channels.say_chat("", "# "..name.." joined the channel", param)
|
||||
channels.say_chat("", "# " .. name .. " joined the channel", param)
|
||||
end
|
||||
|
||||
function channels.command_leave(name)
|
||||
|
@ -178,7 +168,7 @@ function channels.command_leave(name)
|
|||
end
|
||||
|
||||
if channels.players[name] then
|
||||
channels.say_chat("", "# "..name.." left the channel", channels.players[name])
|
||||
channels.say_chat("", "# " .. name .. " left the channel", channels.players[name])
|
||||
channels.players[name] = nil
|
||||
end
|
||||
|
||||
|
|
79
init.lua
79
init.lua
|
@ -2,56 +2,41 @@ channels = {}
|
|||
channels.huds = {}
|
||||
channels.players = {}
|
||||
|
||||
-- workaround for settings:get*() defaults not working
|
||||
local function notnil_or(d,v)
|
||||
if v == nil then
|
||||
return d
|
||||
end
|
||||
channels.allow_global_channel = minetest.settings:get_bool("channels.allow_global_channel") ~= false
|
||||
channels.disable_private_messages = minetest.settings:get_bool("channels.disable_private_messages") == true
|
||||
channels.suggested_channel = minetest.settings:get("channels.suggested_channel")
|
||||
|
||||
return v
|
||||
end
|
||||
|
||||
channels.allow_global_channel = notnil_or(true, minetest.settings:get_bool("channels.allow_global_channel") )
|
||||
channels.disable_private_messages = notnil_or(false, minetest.settings:get_bool("channels.disable_private_messages") )
|
||||
channels.suggested_channel = minetest.settings:get_bool("channels.suggested_channel")
|
||||
|
||||
dofile(minetest.get_modpath("channels").."/chatcommands.lua")
|
||||
dofile(minetest.get_modpath("channels") .. "/chatcommands.lua")
|
||||
|
||||
|
||||
|
||||
|
||||
if channels.disable_private_messages then
|
||||
minetest.register_chatcommand("msg", {
|
||||
params = "",
|
||||
description = "?",
|
||||
privs = nil,
|
||||
func = function(name, param)
|
||||
return true, "(private messages disabled)"
|
||||
end,
|
||||
})
|
||||
minetest.registered_chatcommands["msg"] = nil
|
||||
end
|
||||
|
||||
channels.remind_global_off = function()
|
||||
-- Can be called by other mods
|
||||
|
||||
if not channels.allow_global_channel and channels.suggested_channel then
|
||||
channels.say_chat("*server*", "<announcement from *server*> Out-of-channel chat is off. (try '/channel join "..channels.suggested_channel.."' ?)")
|
||||
end
|
||||
local function remind_global_off()
|
||||
if not channels.allow_global_channel and channels.suggested_channel then
|
||||
channels.say_chat("*server*",
|
||||
"<*server*> Out-of-channel chat is off." ..
|
||||
"(try '/channel join " .. channels.suggested_channel .. "' ?)"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
if not channels.allow_global_channel then
|
||||
local global_inhibition_counter = 0 -- local to the file
|
||||
local global_inhibition_counter = 0 -- local to the file
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
global_inhibition_counter = global_inhibition_counter + dtime
|
||||
if global_inhibition_counter > 5*60 then
|
||||
global_inhibition_counter = 0
|
||||
else
|
||||
return
|
||||
end
|
||||
minetest.register_globalstep(function(dtime)
|
||||
global_inhibition_counter = global_inhibition_counter + dtime
|
||||
if global_inhibition_counter > 5*60 then
|
||||
global_inhibition_counter = 0
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
channels.remind_global_off()
|
||||
end)
|
||||
remind_global_off()
|
||||
end)
|
||||
end
|
||||
|
||||
minetest.register_on_chat_message(function(name, message)
|
||||
|
@ -59,21 +44,21 @@ minetest.register_on_chat_message(function(name, message)
|
|||
|
||||
if pl_channel == "" then
|
||||
channels.players[name] = nil
|
||||
pl_channel = nil
|
||||
pl_channel = nil
|
||||
end
|
||||
|
||||
if not pl_channel then
|
||||
if not channels.allow_global_channel then
|
||||
minetest.chat_send_player(name, "No channel selected. Run '/channel' for more info")
|
||||
-- return true to prevent subsequent/global handler from kicking in
|
||||
return true
|
||||
else
|
||||
-- return false to indicate we have not handled the chat
|
||||
return false
|
||||
end
|
||||
if not channels.allow_global_channel then
|
||||
minetest.chat_send_player(name, "No channel selected. Run '/channel' for more info")
|
||||
-- return true to prevent subsequent/global handler from kicking in
|
||||
return true
|
||||
else
|
||||
-- return false to indicate we have not handled the chat
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
channels.say_chat(name, "<"..name.."> "..message, pl_channel)
|
||||
channels.say_chat(name, "<" .. name .. "> " .. message, pl_channel)
|
||||
return true
|
||||
end)
|
||||
|
||||
|
|
Loading…
Reference in New Issue