rebuild.lua 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. function serveressentials.check_outback_reset()
  2. local meta = serveressentials.modstorage
  3. local stime = meta:get_string("outback_reset_time")
  4. -- If timestamp is missing, then initialize it to the current time.
  5. -- Outback reset will be schedualed after the timeout.
  6. if not stime or stime == "" then
  7. stime = tostring(os.time())
  8. meta:set_string("outback_reset_time", stime)
  9. -- Note: we reach here only when a new world is first started.
  10. serveressentials.rebuild_outback()
  11. return
  12. end
  13. local time = tonumber(stime) -- Time of last reset (or initialization).
  14. local days = serveressentials.reset_timeout -- Timeout in days.
  15. local timeout = 60 * 60 * 24 * days
  16. local now = os.time() -- Current time.
  17. local later = time + timeout -- Time of next reset.
  18. if now >= later then
  19. stime = tostring(later)
  20. meta:set_string("outback_reset_time", stime)
  21. serveressentials.rebuild_outback()
  22. minetest.chat_send_all("# Server: The desert wind ceases to blow across the Outback.")
  23. minetest.chat_send_all("# Server: When it resumes, there is nothing left of what went before.")
  24. end
  25. end
  26. minetest.after(0, function() serveressentials.check_outback_reset() end)
  27. function serveressentials.check_midfeld_reset()
  28. local meta = serveressentials.modstorage
  29. local stime = meta:get_string("midfeld_reset_time")
  30. -- If timestamp is missing, then initialize it to the current time.
  31. -- Outback reset will be schedualed after the timeout.
  32. if not stime or stime == "" then
  33. stime = tostring(os.time())
  34. meta:set_string("midfeld_reset_time", stime)
  35. -- Note: we reach here only when a new world is first started.
  36. serveressentials.rebuild_gaterealm()
  37. return
  38. end
  39. local time = tonumber(stime) -- Time of last reset (or initialization).
  40. local days = serveressentials.midfeld_reset_timeout -- Timeout in days.
  41. local timeout = 60 * 60 * 24 * days
  42. local now = os.time() -- Current time.
  43. local later = time + timeout -- Time of next reset.
  44. if now >= later then
  45. stime = tostring(later)
  46. meta:set_string("midfeld_reset_time", stime)
  47. serveressentials.rebuild_gaterealm()
  48. minetest.chat_send_all("# Server: The fog of time settles on Midfeld.")
  49. minetest.chat_send_all("# Server: When it lifts, all is as it was at the beginning.")
  50. end
  51. end
  52. minetest.after(0, function() serveressentials.check_midfeld_reset() end)