forked from minetest-monitoring/monitoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatcommands.lua
More file actions
72 lines (61 loc) · 1.82 KB
/
chatcommands.lua
File metadata and controls
72 lines (61 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
minetest.register_chatcommand("metric", {
params = "<metric_name>",
description = "shows the current metric value of a gauge or counter",
func = function(_, param)
if param == "" or not param then
return false, "Please specify the metric!"
end
local metric = monitoring.metrics_mapped[param]
if not metric then
return false, "No such metric: '" .. param .. "'"
end
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)
minetest.register_chatcommand("forceload", {
privs = { server = true },
description = "checks or sets the forceload property of the current mapblock",
params = "[<on|off>]",
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "Player '" .. name .. "' not found"
end
local ppos = player:get_pos()
if param == "on" then
-- enable
minetest.forceload_block(ppos, false)
return true, "Enabled forceloading in current mapblock"
elseif param == "off" then
-- disable
minetest.forceload_free_block(ppos, false)
return true, "Disabled forceloading in current mapblock"
else
-- check
local fl = monitoring.is_forceloaded(ppos)
return true, "Current mapblock is " .. (fl and "" or "not ") .. "forceloaded"
end
end
})