Skip to content

Commit

Permalink
add lag simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Sep 1, 2020
1 parent 1a1bda6 commit 32ef6e6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions chatcommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,31 @@ minetest.register_chatcommand("metric", {
return true, "" .. metric.value or "<unknown>"
end
})

-- lag simulation

local lag = 0

minetest.register_chatcommand("lag", {
privs = { server = true },
description = "simulate server lag",
params = "<seconds>",
func = function(_, param)
lag = tonumber(param or "0") or 0
return true, "lag = " .. lag .. " s"
end
})

minetest.register_globalstep(function()
if lag < 0.01 then
-- ignore value
return
end

local start = minetest.get_us_time()
local stop = start + (lag * 1000 * 1000)

while minetest.get_us_time() < stop do
-- no-op
end
end)

0 comments on commit 32ef6e6

Please sign in to comment.