aboutsummaryrefslogtreecommitdiff
path: root/chatcommands.lua
blob: 2b4a1cc41ea074c1c75dd5a81b7aac520bec398b (plain) (blame)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88


minetest.register_chatcommand("mesecons_hud", {
  description = "mesecons_hud on/off",
  func = function(name, params)
    local enable = params == "on"
    mesecons_debug.hud[name] = enable
    if enable then
      return true, "mesecons hud enabled"
    else
      return true, "mesecons hud disabled"
    end
  end
})

minetest.register_chatcommand("mesecons_stats", {
  description = "shows some mesecons stats for the current position",
  func = function(name)
    local player = minetest.get_player_by_name(name)
    if not player then
      return
    end

    local ctx = mesecons_debug.get_context(player:get_pos())
    return true, "Mapblock usage: " .. ctx.avg_micros .. " us/s " ..
      "(across " .. mesecons_debug.context_store_size .." mapblocks)"
  end
})

minetest.register_chatcommand("mesecons_enable", {
  description = "enables the mesecons globlastep",
  privs = {mesecons_debug=true},
  func = function()
    -- flush actions, while we are on it
    mesecon.queue.actions = {}
    mesecons_debug.enabled = true
    return true, "mesecons enabled"
  end
})

minetest.register_chatcommand("mesecons_disable", {
  description = "disables the mesecons globlastep",
  privs = {mesecons_debug=true},
  func = function()
    mesecons_debug.enabled = false
    return true, "mesecons disabled"
  end
})

minetest.register_chatcommand("mesecons_whitelist_add", {
  description = "adds the current mapblock to the whitelist",
  privs = {mesecons_debug=true},
  func = function(name)
    local player = minetest.get_player_by_name(name)
    if not player then
      return
    end

    local ppos = player:get_pos()
    local blockpos = mesecons_debug.get_blockpos(ppos)
    local hash = minetest.hash_node_position(blockpos)

    mesecons_debug.whitelist[hash] = true
    mesecons_debug.save_whitelist()

    return true, "mapblock whitlisted"
  end
})

minetest.register_chatcommand("mesecons_whitelist_remove", {
  description = "removes the current mapblock from the whitelist",
  privs = {mesecons_debug=true},
  func = function(name)
    local player = minetest.get_player_by_name(name)
    if not player then
      return
    end

    local ppos = player:get_pos()
    local blockpos = mesecons_debug.get_blockpos(ppos)
    local hash = minetest.hash_node_position(blockpos)

    mesecons_debug.whitelist[hash] = nil
    mesecons_debug.save_whitelist()

    return true, "mapblock removed from whitelist"
  end
})