chatcommands.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. minetest.register_chatcommand("mesecons_hud", {
  2. description = "mesecons_hud on/off",
  3. func = function(name, params)
  4. local enable = params == "on"
  5. mesecons_debug.hud[name] = enable
  6. if enable then
  7. return true, "mesecons hud enabled"
  8. else
  9. return true, "mesecons hud disabled"
  10. end
  11. end
  12. })
  13. minetest.register_chatcommand("mesecons_stats", {
  14. description = "shows some mesecons stats for the current position",
  15. func = function(name)
  16. local player = minetest.get_player_by_name(name)
  17. if not player then
  18. return
  19. end
  20. local ctx = mesecons_debug.get_context(player:get_pos())
  21. return true, "Mapblock usage: " .. ctx.avg_micros .. " us/s " ..
  22. "(across " .. mesecons_debug.context_store_size .." mapblocks)"
  23. end
  24. })
  25. minetest.register_chatcommand("mesecons_enable", {
  26. description = "enables the mesecons globlastep",
  27. privs = {mesecons_debug=true},
  28. func = function()
  29. -- flush actions, while we are on it
  30. mesecon.queue.actions = {}
  31. mesecons_debug.enabled = true
  32. return true, "mesecons enabled"
  33. end
  34. })
  35. minetest.register_chatcommand("mesecons_disable", {
  36. description = "disables the mesecons globlastep",
  37. privs = {mesecons_debug=true},
  38. func = function()
  39. mesecons_debug.enabled = false
  40. return true, "mesecons disabled"
  41. end
  42. })
  43. minetest.register_chatcommand("mesecons_whitelist_get", {
  44. description = "shows the current mapblock whitelist",
  45. privs = {mesecons_debug=true},
  46. func = function()
  47. local whitelist = "mesecons whitelist:\n"
  48. local count = 0
  49. for hash, _ in pairs(mesecons_debug.whitelist) do
  50. whitelist = whitelist .. minetest.pos_to_string(minetest.get_position_from_hash(hash)) .. "\n"
  51. count = count + 1
  52. end
  53. whitelist = whitelist .. string.format("%d mapblocks whitelisted", count)
  54. return true, whitelist
  55. end
  56. })
  57. minetest.register_chatcommand("mesecons_whitelist_add", {
  58. description = "adds the current mapblock to the whitelist",
  59. privs = {mesecons_debug=true},
  60. func = function(name)
  61. local player = minetest.get_player_by_name(name)
  62. if not player then
  63. return
  64. end
  65. local ppos = player:get_pos()
  66. local blockpos = mesecons_debug.get_blockpos(ppos)
  67. local hash = minetest.hash_node_position(blockpos)
  68. mesecons_debug.whitelist[hash] = true
  69. mesecons_debug.save_whitelist()
  70. return true, "mapblock whitlisted"
  71. end
  72. })
  73. minetest.register_chatcommand("mesecons_whitelist_remove", {
  74. description = "removes the current mapblock from the whitelist",
  75. privs = {mesecons_debug=true},
  76. func = function(name)
  77. local player = minetest.get_player_by_name(name)
  78. if not player then
  79. return
  80. end
  81. local ppos = player:get_pos()
  82. local blockpos = mesecons_debug.get_blockpos(ppos)
  83. local hash = minetest.hash_node_position(blockpos)
  84. mesecons_debug.whitelist[hash] = nil
  85. mesecons_debug.save_whitelist()
  86. return true, "mapblock removed from whitelist"
  87. end
  88. })