diff options
author | orwell96 <orwell@bleipb.de> | 2021-02-17 19:10:40 +0100 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2021-02-17 19:15:20 +0100 |
commit | 1e4156d0a4e42b519ca2f64f4146c7a7faec49a3 (patch) | |
tree | 05e3bf4c32154fe639c9b1b59640cdb053076fca /advtrains_luaautomation/chatcmds.lua | |
parent | d13a610c2e66b4ac1e585c15022ce43317e6ea4c (diff) | |
download | advtrains-1e4156d0a4e42b519ca2f64f4146c7a7faec49a3.tar.gz advtrains-1e4156d0a4e42b519ca2f64f4146c7a7faec49a3.tar.bz2 advtrains-1e4156d0a4e42b519ca2f64f4146c7a7faec49a3.zip |
LuaATC: Improve error/print logging, log only to subscribed players
Diffstat (limited to 'advtrains_luaautomation/chatcmds.lua')
-rw-r--r-- | advtrains_luaautomation/chatcmds.lua | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/advtrains_luaautomation/chatcmds.lua b/advtrains_luaautomation/chatcmds.lua index 2d0c69d..468698b 100644 --- a/advtrains_luaautomation/chatcmds.lua +++ b/advtrains_luaautomation/chatcmds.lua @@ -43,12 +43,78 @@ core.register_chatcommand("env_create", { privs = {atlatc=true}, func = function(name, param) if not param or param=="" then return false, "Name required!" end + if string.find(param, "[^a-zA-Z0-9-_]") then return false, "Invalid name (only common characters)" end if atlatc.envs[param] then return false, "Environment already exists!" end atlatc.envs[param] = atlatc.env_new(param) + atlatc.envs[param].subscribers = {name} return true, "Created environment '"..param.."'. Use '/env_setup "..param.."' to define global initialization code, or start building LuaATC components!" end, }) - +core.register_chatcommand("env_subscribe", { + params = "<environment name>", + description = "Subscribe to the log of an Advtrains LuaATC environment", + privs = {atlatc=true}, + func = function(name, param) + local env=atlatc.envs[param] + if not env then return false,"Invalid environment name!" end + for _,pname in ipairs(env.subscribers) do + if pname==name then + return false, "Already subscribed!" + end + end + table.insert(env.subscribers, name) + return true, "Subscribed to environment '"..param.."'." + end, +}) +core.register_chatcommand("env_unsubscribe", { + params = "<environment name>", + description = "Unubscribe to the log of an Advtrains LuaATC environment", + privs = {atlatc=true}, + func = function(name, param) + local env=atlatc.envs[param] + if not env then return false,"Invalid environment name!" end + for index,pname in ipairs(env.subscribers) do + if pname==name then + table.remove(env.subscribers, index) + return true, "Successfully unsubscribed!" + end + end + return false, "Not subscribed to environment '"..param.."'." + end, +}) +core.register_chatcommand("env_subscriptions", { + params = "[environment name]", + description = "List Advtrains LuaATC environments you are subscribed to (no parameters) or subscribers of an environment (giving an env name).", + privs = {atlatc=true}, + func = function(name, param) + if not param or param=="" then + local none=true + for envname, env in pairs(atlatc.envs) do + for _,pname in ipairs(env.subscribers) do + if pname==name then + none=false + minetest.chat_send_player(name, envname) + end + end + end + if none then + return false, "Not subscribed to any!" + end + return true + end + local env=atlatc.envs[param] + if not env then return false,"Invalid environment name!" end + local none=true + for index,pname in ipairs(env.subscribers) do + none=false + minetest.chat_send_player(name, pname) + end + if none then + return false, "No subscribers!" + end + return true + end, +}) minetest.register_on_player_receive_fields(function(player, formname, fields) |