Compare commits
1 Commits
master
...
server-wip
Author | SHA1 | Date |
---|---|---|
Kevin Mok | 9e0f41f00f |
105
init.lua
105
init.lua
|
@ -1,47 +1,98 @@
|
||||||
aliases = {}
|
aliases = {}
|
||||||
|
|
||||||
function alias(short, cmd_table)
|
-- http://lua-users.org/wiki/CopyTable
|
||||||
aliases[short] = cmd_table
|
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
|
end
|
||||||
|
|
||||||
|
-- https://github.com/Uberi/Minetest-WorldEdit/blob/master/worldedit_shortcommands/init.lua
|
||||||
|
-- function alias(short, orig, params)
|
||||||
|
-- -- params = params or ""
|
||||||
|
-- local def = minetest.chatcommands[orig]
|
||||||
|
-- -- minetest.log(params or (orig .. ": no params"))
|
||||||
|
-- minetest.log("verbose", orig)
|
||||||
|
-- -- minetest.debug(orig)
|
||||||
|
-- if params then
|
||||||
|
-- def = deepcopy(def)
|
||||||
|
-- def.params = params
|
||||||
|
-- end
|
||||||
|
-- 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
|
||||||
|
|
||||||
|
alias("gim", "giveme")
|
||||||
|
alias("grm", "grantme")
|
||||||
-- needs to be in minetest game?
|
-- needs to be in minetest game?
|
||||||
-- alias("h", "home")
|
-- alias("h", "home")
|
||||||
|
alias("sd", "shutdown")
|
||||||
|
alias("t", "teleport")
|
||||||
|
alias("t0", "teleport", "0 0 0")
|
||||||
|
|
||||||
aliases["clc"] = { { "fp", "s1 -2 1 2" }, { "fp", "s2 2 1 -2" }, { "cl" } }
|
minetest.register_on_chat_message(function(name, message)
|
||||||
aliases["day"] = { { "time", "6000" } }
|
-- minetest.chat_send_player(name, "Alias")
|
||||||
aliases["gim"] = { { "giveme" } }
|
minetest.chat_send_player(name, "Alias")
|
||||||
aliases["grm"] = { { "grantme" } }
|
|
||||||
aliases["grma"] = { { "grantme", "all" } }
|
|
||||||
aliases["sd"] = { { "shutdown" } }
|
|
||||||
aliases["t"] = { { "teleport" } }
|
|
||||||
aliases["tr"] = { { "pulverize" } }
|
|
||||||
aliases["t0"] = { { "teleport", "0 0 0" }, { "teleport", "1 1 1" } }
|
|
||||||
|
|
||||||
-- TODO: move WorldEdit aliases here --
|
|
||||||
|
|
||||||
minetest.register_on_sending_chat_message(function(message)
|
|
||||||
if message:sub(1,1) ~= "/" then
|
if message:sub(1,1) ~= "/" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
|
local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
|
||||||
if not cmd then
|
if not cmd then
|
||||||
minetest.display_chat_message("-!- Empty command")
|
-- minetest.chat_send_player(name, "-!- Empty command")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
param = param or ""
|
param = param or ""
|
||||||
|
|
||||||
-- run each cmd pair
|
local cmd_def = minetest.registered_chatcommands[cmd]
|
||||||
if (not minetest.registered_chatcommands[cmd]) and (aliases[cmd]) then
|
local alias_def = aliases[cmd]
|
||||||
for i, cmd_pair in ipairs(aliases[cmd]) do
|
if not cmd_def and alias_def then
|
||||||
-- only keep passed in param if first cmd and no given param
|
minetest.chat_send_player(name, "Alias " .. cmd .. "= " .. alias_def.orig)
|
||||||
if table.getn(cmd_pair) > 1 then
|
cmd_def = minetest.registered_chatcommands[alias_def.orig]
|
||||||
param = cmd_pair[2]
|
if not cmd_def then
|
||||||
elseif i > 1 then
|
minetest.chat_send_player(name, "-!- Invalid alias: " .. cmd)
|
||||||
param = ""
|
|
||||||
end
|
|
||||||
minetest.display_chat_message("alias for: /" .. cmd_pair[1] .. " " .. param)
|
|
||||||
minetest.run_server_chatcommand(cmd_pair[1], param)
|
|
||||||
end
|
|
||||||
return true
|
return true
|
||||||
end
|
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)
|
end)
|
||||||
|
|
13
todo.md
13
todo.md
|
@ -1,13 +0,0 @@
|
||||||
- csm_restriction_flags instructions
|
|
||||||
- in-game alias modifications
|
|
||||||
- name teleport locations
|
|
||||||
- get current pos.
|
|
||||||
- new chat cmd
|
|
||||||
- toggle showing full command after running
|
|
||||||
- setting?
|
|
||||||
- store/read from JSON table?
|
|
||||||
- series of commands
|
|
||||||
- record?
|
|
||||||
- rename to aliases
|
|
||||||
- Server Command Aliases
|
|
||||||
- tests?
|
|
Loading…
Reference in New Issue