-- Chat command handler
--
-core.chatcommands = {}
+core.registered_chatcommands = {}
+core.chatcommands = core.registered_chatcommands -- BACKWARDS COMPATIBILITY
function core.register_chatcommand(cmd, def)
def = def or {}
def.params = def.params or ""
def.description = def.description or ""
def.privs = def.privs or {}
def.mod_origin = core.get_current_modname() or "??"
- core.chatcommands[cmd] = def
+ core.registered_chatcommands[cmd] = def
end
core.register_on_chat_message(function(name, message)
if not param then
param = ""
end
- local cmd_def = core.chatcommands[cmd]
+ local cmd_def = core.registered_chatcommands[cmd]
if not cmd_def then
return false
end
if param == "" then
local msg = ""
local cmds = {}
- for cmd, def in pairs(core.chatcommands) do
+ for cmd, def in pairs(core.registered_chatcommands) do
if core.check_player_privs(name, def.privs) then
cmds[#cmds + 1] = cmd
end
.. " or '/help all' to list everything."
elseif param == "all" then
local cmds = {}
- for cmd, def in pairs(core.chatcommands) do
+ for cmd, def in pairs(core.registered_chatcommands) do
if core.check_player_privs(name, def.privs) then
cmds[#cmds + 1] = format_help_line(cmd, def)
end
return true, "Available privileges:\n"..table.concat(privs, "\n")
else
local cmd = param
- local def = core.chatcommands[cmd]
+ local def = core.registered_chatcommands[cmd]
if not def then
return false, "Command not available: "..cmd
else
if not (caller_privs.privs or caller_privs.basic_privs) then
return false, "Your privileges are insufficient."
end
-
+
if not core.get_auth_handler().get_auth(grantname) then
return false, "Player " .. grantname .. " does not exist."
end
local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)")
if not grantname or not grantprivstr then
return false, "Invalid parameters (see /help grant)"
- end
+ end
return handle_grant_command(name, grantname, grantprivstr)
end,
})
func = function(name, param)
if param == "" then
return false, "Invalid parameters (see /help grantme)"
- end
+ end
return handle_grant_command(name, name, param)
end,
})