different execution count limit for different levels of authorization
parent
5cf4119120
commit
b85ac575ba
22
init.lua
22
init.lua
|
@ -3,7 +3,7 @@
|
|||
|
||||
basic_robot = {};
|
||||
------ SETTINGS --------
|
||||
basic_robot.call_limit = 48; -- how many execution calls per script run allowed
|
||||
basic_robot.call_limit = {50,200,1500,10^9}; -- how many execution calls per script run allowed, for auth levels 0,1,2 (normal, robot, puzzle, admin)
|
||||
basic_robot.entry_count = 2 -- how many robots ordinary player can have
|
||||
basic_robot.advanced_count = 16 -- how many robots player with robot privs can have
|
||||
basic_robot.radius = 32; -- divide whole world into blocks of this size - used for managing events like keyboard punches
|
||||
|
@ -25,7 +25,7 @@ basic_robot.bad_inventory_blocks = { -- disallow taking from these nodes invento
|
|||
|
||||
basic_robot.http_api = minetest.request_http_api();
|
||||
|
||||
basic_robot.version = "2018/12/11a";
|
||||
basic_robot.version = "2018/12/24a";
|
||||
|
||||
basic_robot.gui = {}; local robogui = basic_robot.gui -- gui management
|
||||
basic_robot.data = {}; -- stores all robot related data
|
||||
|
@ -490,7 +490,7 @@ function getSandboxEnv (name)
|
|||
env.code.run = function(script)
|
||||
if basic_robot.data[name].authlevel < 3 then
|
||||
local err = check_code(script);
|
||||
script = preprocess_code(script);
|
||||
script = preprocess_code(script, basic_robot.call_limit[basic_robot.data[name].authlevel+1]);
|
||||
if err then
|
||||
minetest.chat_send_player(name,"#ROBOT CODE CHECK ERROR : " .. err)
|
||||
return
|
||||
|
@ -658,7 +658,7 @@ end
|
|||
|
||||
--todo: 2018/12 this suddenly stopped working, wtf??
|
||||
|
||||
preprocess_code = function(script) -- version 07/24/2018
|
||||
preprocess_code = function(script, call_limit) -- version 07/24/2018
|
||||
|
||||
--[[ idea: in each local a = function (args) ... end insert counter like:
|
||||
local a = function (args) counter_check_code ... end
|
||||
|
@ -669,8 +669,8 @@ preprocess_code = function(script) -- version 07/24/2018
|
|||
script="_c_ = 0; " .. script;
|
||||
|
||||
-- process script to insert call counter in every function
|
||||
local _increase_ccounter = " _c_ = _c_ + 1; if _c_ > " .. basic_robot.call_limit ..
|
||||
" then error(\"Execution count \".. _c_ .. \" exceeded ".. basic_robot.call_limit .. "\") end; "
|
||||
local _increase_ccounter = " _c_ = _c_ + 1; if _c_ > " .. call_limit ..
|
||||
" then _G.error(\"Execution count \".. _c_ .. \" exceeded ".. call_limit .. "\") end; "
|
||||
|
||||
local i1=0; local i2 = 0;
|
||||
local found = true;
|
||||
|
@ -747,11 +747,13 @@ local function setCode( name, script ) -- to run script: 1. initSandbox 2. setCo
|
|||
local cor = false;
|
||||
if string.sub(script,1,11) == "--coroutine" then cor = true end
|
||||
|
||||
if basic_robot.data[name].authlevel<3 then -- not admin
|
||||
local authlevel = basic_robot.data[name].authlevel;
|
||||
|
||||
if authlevel<3 then -- not admin
|
||||
err = check_code(script);
|
||||
script = preprocess_code(script);
|
||||
script = preprocess_code(script,basic_robot.call_limit[authlevel+1]);
|
||||
elseif cor then
|
||||
script = preprocess_code(script); -- coroutines need ccounter reset or 'infinite loops' fail after limit
|
||||
script = preprocess_code(script, basic_robot.call_limit[authlevel+1]); -- coroutines need ccounter reset or 'infinite loops' fail after limit
|
||||
end
|
||||
if err then return err end
|
||||
|
||||
|
@ -1104,7 +1106,7 @@ local spawn_robot = function(pos,node,ttl)
|
|||
|
||||
if data.authlevel<3 then -- not admin
|
||||
err = check_code(script);
|
||||
script = preprocess_code(script);
|
||||
script = preprocess_code(script, basic_robot.call_limit[data.authlevel+1]);
|
||||
end
|
||||
if err then
|
||||
meta:set_string("infotext","#CODE CHECK ERROR : " .. err);
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
if not init then
|
||||
init = true; self.listen(1);
|
||||
self.spam(1); self.label("help bot")
|
||||
|
||||
talk = function(msg) minetest.chat_send_all("<help bot> " .. msg) end
|
||||
keywords = {
|
||||
{"tp", 14},
|
||||
{"help",
|
||||
{"robot",6},{"",1}
|
||||
},
|
||||
|
@ -22,6 +25,8 @@ if not init then
|
|||
{"rnd",{"",11}},
|
||||
{"bye",{"",12}},
|
||||
{"!!",{"",9}},
|
||||
|
||||
{"calc", 13},
|
||||
}
|
||||
answers = {
|
||||
"%s open inventory, click 'Quests' and do them to get more stuff", --1
|
||||
|
@ -36,20 +41,31 @@ if not init then
|
|||
"to get dirt craft composter and use it with leaves", -- 10
|
||||
"rnd is afk. in the meantime i can answer your questions",
|
||||
"bye %s",
|
||||
function(speaker,msg) -- 13, calc
|
||||
local expr = string.sub(msg,5); if string.find(expr,"%a") then return end
|
||||
local res = _G.loadstring("return " .. expr)(); say(expr .. " = " .. res)
|
||||
end,
|
||||
function(speaker,msg) -- 14,tp
|
||||
local p1 = minetest.get_player_by_name(speaker);
|
||||
local p2 = minetest.get_player_by_name(string.sub(msg,4));
|
||||
if p1 and p2 then
|
||||
p1:setpos(p2:getpos())
|
||||
end
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
speaker,msg = self.listen_msg();
|
||||
if msg then
|
||||
msg = string.lower(msg);
|
||||
--msg = string.lower(msg);
|
||||
sel = 0;
|
||||
for i = 1, #keywords do
|
||||
local k = string.find(msg,keywords[i][1])
|
||||
if k then
|
||||
if type(keywords[i][2])~="table" then
|
||||
if type(keywords[i][2])~="table" then -- one topic only
|
||||
if k == 1 then sel = keywords[i][2] break end
|
||||
else
|
||||
for j=2,#keywords[i] do
|
||||
for j=2,#keywords[i] do -- category of several topics
|
||||
if string.find(msg,keywords[i][j][1]) then
|
||||
sel = keywords[i][j][2]; break;
|
||||
end
|
||||
|
@ -61,10 +77,12 @@ if msg then
|
|||
|
||||
if sel>0 then
|
||||
local response = answers[sel];
|
||||
if string.find(response,"%%s") then
|
||||
say(string.format(response,speaker))
|
||||
if type(response) == "function" then
|
||||
response(speaker,msg)
|
||||
elseif string.find(response,"%%s") then
|
||||
talk(string.format(response,speaker))
|
||||
else
|
||||
say(response)
|
||||
talk(response)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue