Prevent chatcommands being executed while cloaked
Prevents chatcommands being executed while cloaked. Currently the best way of doing it is iterating over every command and modifying it. Mods may prevent this from happening by setting allow_while_cloaked in the chatcommand definition.
This commit is contained in:
parent
3df9c5cdd7
commit
b91825abd1
|
@ -7,7 +7,8 @@
|
|||
minetest.register_chatcommand("cloak", {
|
||||
params = "[victim]",
|
||||
description = "Cloak a player so they are not visible.",
|
||||
privs = {privs = true},
|
||||
allow_while_cloaked = true,
|
||||
privs = {privs = true},
|
||||
func = function(player, victim)
|
||||
if not victim or victim == '' then
|
||||
victim = player
|
||||
|
@ -30,6 +31,7 @@ minetest.register_chatcommand("cloak", {
|
|||
minetest.register_chatcommand("uncloak", {
|
||||
params = "[victim]",
|
||||
description = "Uncloak a player so they are visible.",
|
||||
allow_while_cloaked = true,
|
||||
func = function(player, victim)
|
||||
if not victim or victim == '' then
|
||||
victim = player
|
||||
|
|
20
core.lua
20
core.lua
|
@ -13,6 +13,7 @@ cloaking.get_player_by_name = minetest.get_player_by_name
|
|||
cloaking.get_server_status = minetest.get_server_status
|
||||
|
||||
local cloaked_players = {}
|
||||
local chatcommands_modified = false
|
||||
|
||||
-- Override built-in functions
|
||||
minetest.get_connected_players = function()
|
||||
|
@ -45,8 +46,27 @@ minetest.get_server_status = function()
|
|||
return status
|
||||
end
|
||||
|
||||
-- Override every chatcommand
|
||||
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."
|
||||
else
|
||||
return real_cmd(name, param)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- The cloak and uncloak functions
|
||||
cloaking.cloak = function(player)
|
||||
if not chatcommands_modified then override_chatcommands() end
|
||||
if type(player) == "string" then
|
||||
player = cloaking.get_player_by_name(player)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue