Disable chat while cloaked and allow some commands
Disables cloaked users sending chat messages and allows some commands to be run while cloaked. Sending chat messages will not be disabled with chat3 installed.
This commit is contained in:
parent
38552b207a
commit
46f70ce01e
38
core.lua
38
core.lua
|
@ -46,16 +46,17 @@ minetest.get_server_status = function()
|
|||
return status
|
||||
end
|
||||
|
||||
-- Override every chatcommand
|
||||
-- Don't allow chat or chatcommands in all commands that don't have the
|
||||
-- allow_while_cloaked parameter set.
|
||||
local override_chatcommands = function()
|
||||
for name, def in pairs(minetest.chatcommands) do
|
||||
if not def.allow_while_cloaked then
|
||||
local real_cmd = def.func
|
||||
minetest.chatcommands[name].func = function(name, param)
|
||||
if cloaked_players[name] then
|
||||
return false, "You may not execute chatcommands while " ..
|
||||
"cloaked. Please use /uncloak if you want to " ..
|
||||
"execute a chatcommand."
|
||||
return false, "You may not execute most chatcommands " ..
|
||||
"while cloaked. Please use /uncloak if you want " ..
|
||||
"to execute a chatcommand."
|
||||
else
|
||||
return real_cmd(name, param)
|
||||
end
|
||||
|
@ -64,6 +65,23 @@ local override_chatcommands = function()
|
|||
end
|
||||
end
|
||||
|
||||
minetest.register_on_chat_message(function(name)
|
||||
if cloaked_players[name] then
|
||||
minetest.chat_send_player(name, "You cannot use chat while cloaked." ..
|
||||
" Please use /uncloak if you want to use chat.")
|
||||
return true
|
||||
end
|
||||
end)
|
||||
|
||||
-- Allow some commands through the above restriction.
|
||||
for _, cmd in ipairs({'status', 'kick', 'ban', 'xban', 'xtempban', 'help'}) do
|
||||
if minetest.chatcommands[cmd] then
|
||||
minetest.override_chatcommand(cmd, {
|
||||
allow_while_cloaked = true
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
-- The cloak and uncloak functions
|
||||
cloaking.cloak = function(player)
|
||||
if not chatcommands_modified then override_chatcommands() end
|
||||
|
@ -115,20 +133,8 @@ cloaking.auto_uncloak = function(player)
|
|||
end
|
||||
end
|
||||
|
||||
minetest.register_on_chat_message(cloaking.auto_uncloak)
|
||||
minetest.register_on_leaveplayer(cloaking.auto_uncloak)
|
||||
|
||||
if minetest.chatcommands['me'] then
|
||||
local f = minetest.chatcommands['me'].func
|
||||
minetest.override_chatcommand('me', {
|
||||
allow_while_cloaked = true,
|
||||
func = function(name, params)
|
||||
cloaking.auto_uncloak(name)
|
||||
return f(name, params)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
-- API functions
|
||||
cloaking.get_cloaked_players = function()
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
chat3?
|
||||
irc?
|
||||
xban?
|
||||
xban2?
|
||||
|
|
Loading…
Reference in New Issue