summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2018-08-31 18:33:21 -0500
committercheapie <no-email-for-you@example.com>2018-08-31 18:33:21 -0500
commitc01b63bcc291b37512b0efc44dbe545dd8587365 (patch)
tree16fda32c930430c6008c4d4cad0a691543323ff1
downloadlaggen-master.tar
laggen-master.tar.gz
laggen-master.tar.bz2
laggen-master.tar.xz
laggen-master.zip
Initial commitHEADmaster
-rw-r--r--COPYING24
-rw-r--r--depends.txt0
-rw-r--r--init.lua104
3 files changed, 128 insertions, 0 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..68a49da
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/>
diff --git a/depends.txt b/depends.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/depends.txt
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,
+})