Server intercepts non-existent commands
Before reaching mod function. No way to call chat command functions with set parameters.
This commit is contained in:
parent
eac314c1b7
commit
9e0f41f00f
100
init.lua
100
init.lua
|
@ -1,15 +1,50 @@
|
||||||
|
aliases = {}
|
||||||
|
|
||||||
|
-- http://lua-users.org/wiki/CopyTable
|
||||||
|
function deepcopy(orig)
|
||||||
|
local orig_type = type(orig)
|
||||||
|
local copy
|
||||||
|
if orig_type == 'table' then
|
||||||
|
copy = {}
|
||||||
|
for orig_key, orig_value in next, orig, nil do
|
||||||
|
copy[deepcopy(orig_key)] = deepcopy(orig_value)
|
||||||
|
end
|
||||||
|
setmetatable(copy, deepcopy(getmetatable(orig)))
|
||||||
|
else -- number, string, boolean, etc
|
||||||
|
copy = orig
|
||||||
|
end
|
||||||
|
return copy
|
||||||
|
end
|
||||||
|
|
||||||
-- https://github.com/Uberi/Minetest-WorldEdit/blob/master/worldedit_shortcommands/init.lua
|
-- https://github.com/Uberi/Minetest-WorldEdit/blob/master/worldedit_shortcommands/init.lua
|
||||||
function alias(short, orig)
|
-- function alias(short, orig, params)
|
||||||
if not minetest.chatcommands[orig] then
|
-- -- params = params or ""
|
||||||
minetest.log("error", "custom_aliases: original command " .. orig .. " does not exist")
|
-- local def = minetest.chatcommands[orig]
|
||||||
return true
|
-- -- minetest.log(params or (orig .. ": no params"))
|
||||||
end
|
-- minetest.log("verbose", orig)
|
||||||
if minetest.chatcommands[short] then
|
-- -- minetest.debug(orig)
|
||||||
minetest.log("error", "custom_aliases: alias " .. short .. " already exists")
|
-- if params then
|
||||||
return true
|
-- def = deepcopy(def)
|
||||||
end
|
-- def.params = params
|
||||||
minetest.register_chatcommand(short, minetest.chatcommands[orig])
|
-- end
|
||||||
return false
|
-- if not minetest.chatcommands[orig] then
|
||||||
|
-- minetest.log("error", "custom_aliases: original command " .. orig .. " does not exist")
|
||||||
|
-- return true
|
||||||
|
-- end
|
||||||
|
-- if minetest.chatcommands[short] then
|
||||||
|
-- minetest.log("error", "custom_aliases: alias " .. short .. " already exists")
|
||||||
|
-- return true
|
||||||
|
-- end
|
||||||
|
-- -- minetest.register_chatcommand(short, minetest.chatcommands[orig])
|
||||||
|
-- minetest.register_chatcommand(short, def)
|
||||||
|
-- return false
|
||||||
|
-- end
|
||||||
|
|
||||||
|
function alias(short, orig, param)
|
||||||
|
aliases[short] = {
|
||||||
|
orig = orig,
|
||||||
|
param = param or ""
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
alias("gim", "giveme")
|
alias("gim", "giveme")
|
||||||
|
@ -18,3 +53,46 @@ alias("grm", "grantme")
|
||||||
-- alias("h", "home")
|
-- alias("h", "home")
|
||||||
alias("sd", "shutdown")
|
alias("sd", "shutdown")
|
||||||
alias("t", "teleport")
|
alias("t", "teleport")
|
||||||
|
alias("t0", "teleport", "0 0 0")
|
||||||
|
|
||||||
|
minetest.register_on_chat_message(function(name, message)
|
||||||
|
-- minetest.chat_send_player(name, "Alias")
|
||||||
|
minetest.chat_send_player(name, "Alias")
|
||||||
|
|
||||||
|
if message:sub(1,1) ~= "/" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
|
||||||
|
if not cmd then
|
||||||
|
-- minetest.chat_send_player(name, "-!- Empty command")
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
param = param or ""
|
||||||
|
|
||||||
|
local cmd_def = minetest.registered_chatcommands[cmd]
|
||||||
|
local alias_def = aliases[cmd]
|
||||||
|
if not cmd_def and alias_def then
|
||||||
|
minetest.chat_send_player(name, "Alias " .. cmd .. "= " .. alias_def.orig)
|
||||||
|
cmd_def = minetest.registered_chatcommands[alias_def.orig]
|
||||||
|
if not cmd_def then
|
||||||
|
minetest.chat_send_player(name, "-!- Invalid alias: " .. cmd)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local has_privs, missing_privs = minetest.check_player_privs(name, cmd_def.privs)
|
||||||
|
if has_privs then
|
||||||
|
minetest.set_last_run_mod(cmd_def.mod_origin)
|
||||||
|
local success, message = cmd_def.func(name, param)
|
||||||
|
if message then
|
||||||
|
minetest.chat_send_player(name, message)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(name, "You don't have permission"
|
||||||
|
.. " to run this command (missing privileges: "
|
||||||
|
.. table.concat(missing_privs, ", ") .. ")")
|
||||||
|
end
|
||||||
|
return true -- Handled chat message
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
Loading…
Reference in New Issue