reboot.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. -- Mod API table.
  2. reboot = reboot or {}
  3. -- This function is reloadable.
  4. reboot.do_reboot = function(name, param)
  5. local message = "Server is restarting. It should be back online in a few seconds."
  6. if param ~= "" then
  7. message = param
  8. end
  9. local request_reconnect = false
  10. local sigpath = minetest.setting_get("reboot_signal_path")
  11. if sigpath then
  12. -- Signal to the control script to restart the server.
  13. local file = io.open(sigpath, "w")
  14. if not file then
  15. minetest.chat_send_player(name, "# Server: Error: could not create signal file at '" .. sigpath .. "'.")
  16. easyvend.sound_error(name)
  17. return
  18. end
  19. file:close()
  20. file = nil
  21. request_reconnect = true
  22. end
  23. -- Ask the MT server to shutdown.
  24. minetest.chat_send_all("# Server: " .. message)
  25. minetest.request_shutdown(message, request_reconnect)
  26. end
  27. if not reboot.chatcommand_registered then
  28. minetest.register_chatcommand("reboot", {
  29. params = "<kick message>",
  30. description = "Reboot the server, with an optional message to all players explaining what is going on.",
  31. -- Player must have server priviliges.
  32. privs = {server = true},
  33. func = function(...) return reboot.do_reboot(...) end,
  34. })
  35. reboot.chatcommand_registered = true
  36. end