rebuild.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. -- After all mods loaded and server running.
  27. minetest.after(0, function() serveressentials.check_outback_reset() end)
  28. function serveressentials.check_midfeld_reset()
  29. local meta = serveressentials.modstorage
  30. local stime = meta:get_string("midfeld_reset_time")
  31. -- If timestamp is missing, then initialize it to the current time.
  32. -- Outback reset will be schedualed after the timeout.
  33. if not stime or stime == "" then
  34. stime = tostring(os.time())
  35. meta:set_string("midfeld_reset_time", stime)
  36. -- Note: we reach here only when a new world is first started.
  37. serveressentials.rebuild_gaterealm()
  38. return
  39. end
  40. local time = tonumber(stime) -- Time of last reset (or initialization).
  41. local days = serveressentials.midfeld_reset_timeout -- Timeout in days.
  42. local timeout = 60 * 60 * 24 * days
  43. local now = os.time() -- Current time.
  44. local later = time + timeout -- Time of next reset.
  45. if now >= later then
  46. stime = tostring(later)
  47. meta:set_string("midfeld_reset_time", stime)
  48. serveressentials.rebuild_gaterealm()
  49. minetest.chat_send_all("# Server: The fog of time settles on Midfeld.")
  50. minetest.chat_send_all("# Server: When it lifts, all is as it was at the beginning.")
  51. end
  52. end
  53. -- After all mods loaded and server running.
  54. minetest.after(0, function() serveressentials.check_midfeld_reset() end)