Change map ids to timestamp with random suffix

Before this patch, mcl_maps used mod storage to store a map id counter.
This made it possible to set map ids sequentially. However, mod storage
is not included in world downloads – which means that a world based on a
world download would start counting at zero and overwrite existing maps.

This patch changes map ids to be a combination of the Unix timestamp and
a random value. This makes it possible to have almost sequential map ids
without the need to store a map id counter.
This commit is contained in:
Nils Dagsson Moskopp 2022-02-08 05:04:49 +01:00
parent 738cbf4861
commit b10214e1e0
No known key found for this signature in database
GPG Key ID: A3BC671C35191080
1 changed files with 1 additions and 4 deletions

View File

@ -17,7 +17,6 @@ local get_item_group = minetest.get_item_group
local dynamic_add_media = minetest.dynamic_add_media
local get_connected_players = minetest.get_connected_players
local storage = minetest.get_mod_storage()
local worldpath = minetest.get_worldpath()
local map_textures_path = worldpath .. "/mcl_maps/"
@ -46,9 +45,7 @@ function mcl_maps.create_map(pos)
local itemstack = ItemStack("mcl_maps:filled_map")
local meta = itemstack:get_meta()
local next_id = storage:get_int("next_id")
storage:set_int("next_id", next_id + 1)
local id = tostring(next_id)
local id = tostring(os.time() + math.random())
meta:set_string("mcl_maps:id", id)
meta:set_string("mcl_maps:minp", pos_to_string(minp))
meta:set_string("mcl_maps:maxp", pos_to_string(maxp))