Page 1 of 1

Reset world on live server

Posted: Sun Mar 03, 2019 08:03
by ratmix
I am working on a new sub-game that requires a periodic reset of the world to it's initial/original mapgen state. I have tried minetest.delete_area, however it would take precisely 1 second less than infinity to reset an entire world. So this approach is non-viable.

I then tried to delete the world's map.sqlite file, but this crashes the server. However, on reboot, the world is indeed reset in a flash. This is what I want, but without the crash obviously. Is there any way to tell Minetest to regenerate the map.sqlite file without restarting the server?

Here is the error message produced when I delete the map.sqlite file...

Code: Select all

2019-03-03 20:43:31: ERROR[Emerge-0]: An unhandled exception occurred: Failed to prepare query 'SELECT `data` FROM `blocks` WHERE `pos` = ? LIMIT 1': no such table: blocks
2019-03-03 20:43:31: ERROR[Emerge-0]: In thread 7f206bfff700:
2019-03-03 20:43:31: ERROR[Emerge-0]: /home/realcourse/minetest5/newestMT5/compiled/minetest/src/emerge.cpp:2aa: virtual void* EmergeThread::run(): A fatal error occurred: Failed to prepare query 'SELECT `data` FROM `blocks` WHERE `pos` = ? LIMIT 1': no such table: blocks
So minetest crashes once a query to the deleted map.sqlite fails. So I'm curious if I can execute the same regeneration of the map.sqlite file that occurs on reboot whenever a database query fails - instead of throwing a fatal error.

Something like if !table then create_sqlfile() is what I need I suppose.

Or is there a better or existing solution?

Re: Reset world on live server

Posted: Sun Mar 03, 2019 17:36
by Krock
How about using the `dummy` database backend? You could then just delete the currently active mapblocks.

Re: Reset world on live server

Posted: Sun Mar 03, 2019 17:52
by ratmix
Thanks for the idea, but I think the memory required to store the necessary blocks temporarily would exceed my available RAM before it is time deleted them. (30 players on a very large map)

In addition, even for a small radius of 50, delete_blocks took over a minute to complete.

I wonder if emptying the sqlite tables would prevent a crash and force a regen.

Re: Reset world on live server

Posted: Sun Mar 03, 2019 18:44
by ratmix
This might be a solution:
  • 1. Create a new world and join it
    2. Exit after joining
    3. Save a copy of the map.sqlite file as map.sqlite.orig
    4. Call this function to regen the map os.execute('cp map.sqlite.orig map.sqlite')
This method works seamlessly and ultra fast, with two caveats. First, players should not be in an area you do not need to regen, or their client will not update it's version of the blocks. Second, I'm not sure about how the map_meta.txt file will work once caves, etc. are created. I suppose previous data will be ignored. This hasn't yet been well tested but looks promising.

Re: Reset world on live server

Posted: Wed Oct 09, 2019 17:39
by dfournier
Hey ratmix,
Did you get this to work?
I am trying to create a world that is reset when you die, but to the same world not a newly generated one.

Re: Reset world on live server

Posted: Wed Oct 23, 2019 22:42
by disconnected
As long as your seed is the same, the world should regen identically to the original. The method posted by ratmix above is the closest we could get to making this work.

Re: Reset world on live server

Posted: Thu Oct 24, 2019 04:19
by sofar
Perhaps `mtmapprune` can help. It is designed to remove blocks around a certain perimeter, but you could make that perimenter really small, and just maintain a spawn area and preserve that. It's about as efficient as you can make it. It does need to run offline (shut down the server first).

viewtopic.php?f=14&t=18579