Allows admins to run code snippets without crashing the server as often.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nodes.lua 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --
  2. -- Buttons that run snippets
  3. --
  4. minetest.register_node('snippets:button', {
  5. description = 'Snippets button',
  6. tiles = {'default_steel_block.png', 'default_steel_block.png',
  7. 'default_steel_block.png^snippets_button.png'},
  8. groups = {cracky = 2},
  9. on_construct = function(pos)
  10. local meta = minetest.get_meta(pos)
  11. meta:set_string('infotext', 'Unconfigured snippets button')
  12. meta:set_string('formspec', 'field[snippet;Snippet to run:;]')
  13. end,
  14. on_receive_fields = function(pos, formname, fields, sender)
  15. if not fields.snippet or fields.snippet == '' then return end
  16. local name = sender:get_player_name()
  17. if not minetest.check_player_privs(name, {server=true}) then
  18. minetest.chat_send_player(name, 'Insufficient privileges!')
  19. return
  20. end
  21. local snippet = fields.snippet
  22. if not snippets.registered_snippets[snippet] or
  23. snippet:sub(1, 9) == 'snippets:' then
  24. minetest.chat_send_player(name, 'Unknown snippet!')
  25. else
  26. local meta = minetest.get_meta(pos)
  27. meta:set_string('snippet', snippet)
  28. meta:set_string('infotext', 'Snippet: ' .. fields.snippet)
  29. meta:set_string('formspec', '')
  30. end
  31. end,
  32. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  33. local meta, name = minetest.get_meta(pos), clicker:get_player_name()
  34. local snippet = meta:get_string('snippet')
  35. if not snippet or snippet == '' then return end
  36. if snippets.registered_snippets[snippet] then
  37. snippets.run(snippet, name)
  38. else
  39. minetest.chat_send_player(name, 'Invalid snippet: "' .. snippet ..
  40. '"')
  41. end
  42. end,
  43. })