cleanup comments, restore original style whitespace (tabs)

This commit is contained in:
Tai Kedzierski 2019-01-04 22:38:45 +00:00
parent 252cfaf614
commit 719f78a1be
3 changed files with 67 additions and 64 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.swp

View File

@ -21,7 +21,7 @@ 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, "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,13 +38,13 @@ 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) )
@ -55,35 +55,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
function channels.say_chat(sendername, message, channel)
-- message must already have '<player name>' at start if from a player
-- if channel==nil then message is sent only to players in global chat
minetest.log("action","CHAT: #"..tostring(channel or "no channel").." "..message)
local all_players = minetest.get_connected_players()
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 -- if nil then send to players in global chat
minetest.chat_send_player(playername, message)
end
end
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)

View File

@ -4,11 +4,11 @@ channels.players = {}
-- workaround for settings:get*() defaults not working
local function notnil_or(d,v)
if v == nil then
return d
end
if v == nil then
return d
end
return v
return v
end
channels.allow_global_channel = notnil_or(true, minetest.settings:get_bool("channels.allow_global_channel") )
@ -21,37 +21,35 @@ 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.register_chatcommand("msg", {
params = "",
description = "?",
privs = nil,
func = function(name, param)
return true, "(private messages disabled)"
end,
})
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,18 +57,18 @@ 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)