From c01b63bcc291b37512b0efc44dbe545dd8587365 Mon Sep 17 00:00:00 2001 From: cheapie Date: Fri, 31 Aug 2018 18:33:21 -0500 Subject: Initial commit --- init.lua | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 init.lua (limited to 'init.lua') diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..d8e344b --- /dev/null +++ b/init.lua @@ -0,0 +1,104 @@ +local globalstepLag = 0 +local ABMLag = 0 +local ABMLastRun = 0 + +minetest.register_chatcommand("globalsteplag", + { + params = "[time per globalstep, in ms]", + description = "Add the specified amount of lag on each globalstep", + privs = {server = true}, + func = function(name,param) + if param ~= "" then + if not tonumber(param) then + return false,minetest.colorize("#FF0000","ERROR")..": Invalid value. Valid range is 0-5000." + elseif tonumber(param) > 5000 then + return false,minetest.colorize("#FF0000","ERROR")..": Invalid value. Valid range is 0-5000." + elseif tonumber(param) < 0 then + return false,minetest.colorize("#FF0000","ERROR")..": Invalid value. Only positive values are allowed." + end + else + return true,"Current globalstep lag setting: "..minetest.colorize("#00FFFF",tostring(globalstepLag)) + end + if tonumber(param) then + globalstepLag = tonumber(param) + return true,"Globalstep lag set to: "..minetest.colorize("#00FFFF",tostring(globalstepLag)) + end + end + } +) + +minetest.register_chatcommand("abmlag", + { + params = "[time per second, in ms]", + description = "Add the specified amount of lag to an ABM running (nominally) once per second", + privs = {server = true}, + func = function(name,param) + if param ~= "" then + if not tonumber(param) then + return false,minetest.colorize("#FF0000","ERROR")..": Invalid value. Valid range is 0-5000." + elseif tonumber(param) > 5000 then + return false,minetest.colorize("#FF0000","ERROR")..": Invalid value. Valid range is 0-5000." + elseif tonumber(param) < 0 then + return false,minetest.colorize("#FF0000","ERROR")..": Invalid value. Only positive values are allowed." + end + else + return true,"Current ABM lag setting: "..minetest.colorize("#00FFFF",tostring(ABMLag)) + end + if tonumber(param) then + ABMLag = tonumber(param) + return true,"ABM lag set to: "..minetest.colorize("#00FFFF",tostring(ABMLag)) + end + end + } +) + +minetest.register_chatcommand("lag", + { + params = "[time, in ms]", + description = "Freeze the server for the specified length of time", + privs = {server = true}, + func = function(name,param) + if param ~= "" then + if not tonumber(param) then + return false,minetest.colorize("#FF0000","ERROR")..": Invalid value. Valid range is 0-5000." + elseif tonumber(param) > 5000 then + return false,minetest.colorize("#FF0000","ERROR")..": Invalid value. Valid range is 0-5000." + elseif tonumber(param) < 0 then + return false,minetest.colorize("#FF0000","ERROR")..": Invalid value. Only positive values are allowed." + end + else + return false,minetest.colorize("#FF0000","ERROR")..": No value specified." + end + if tonumber(param) then + local endTime = os.clock() + (tonumber(param)/1000) + while os.clock() < endTime do + --Nothing, just busy-waiting here + end + return true,"Done!" + end + end + } +) + +minetest.register_globalstep(function() + if globalstepLag == 0 then return end + local endTime = os.clock() + (globalstepLag/1000) + while os.clock() < endTime do + --Nothing, just busy-waiting here + end +end) + +minetest.register_abm({ + label = "Generate Lag", + nodenames = {"air"}, + interval = 1, + chance = 1, + action = function() + if ABMLag == 0 or ABMLastRun < (os.time() + 1) then return end + ABMLastRun = os.time() + local endTime = os.clock() + (ABMLag/1000) + while os.clock() < endTime do + --Nothing, just busy-waiting here + end + end, +}) -- cgit v1.2.3