aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-11-10 22:38:13 +0100
committerorwell96 <orwell@bleipb.de>2018-11-10 22:38:13 +0100
commit33baf3b05c2a8b7cffdf67528c48ecad0c79ce89 (patch)
tree3b1f6704e85b6d7190fb5f5fc15c61be78eb2bcb /advtrains
parentd761c54d3d9e6252e2088a78cd95702d14e3bb80 (diff)
downloadadvtrains-33baf3b05c2a8b7cffdf67528c48ecad0c79ce89.tar.gz
advtrains-33baf3b05c2a8b7cffdf67528c48ecad0c79ce89.tar.bz2
advtrains-33baf3b05c2a8b7cffdf67528c48ecad0c79ce89.zip
Prevent oversaving of save files from newer versions
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/init.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua
index dee48ac..d8b028a 100644
--- a/advtrains/init.lua
+++ b/advtrains/init.lua
@@ -170,6 +170,8 @@ dofile(advtrains.modpath.."/log.lua")
advtrains.fpath=minetest.get_worldpath().."/advtrains"
dofile(advtrains.modpath.."/log.lua")
+local saving_disabled
+
function advtrains.avt_load()
local file, err = io.open(advtrains.fpath, "r")
if not file then
@@ -179,6 +181,15 @@ function advtrains.avt_load()
if type(tbl) == "table" then
if tbl.version then
--congrats, we have the new save format.
+ if tbl.version > 1 then
+ -- we are going to downgrade! that's not good!
+ atwarn("The save file of this world has been saved from a newer version of advtrains.")
+ atwarn("Opening it in this version could cause significant data loss once it's saved again.")
+ atwarn("Advtrains data is therefore not saved in this session.")
+ atwarn("To downgrade permanently, locate the 'version' entry in the save file and set it to 1")
+ saving_disabled = true
+ end
+
advtrains.trains = tbl.trains
advtrains.wagon_save = tbl.wagon_save
advtrains.player_to_train_mapping = tbl.ptmap or {}
@@ -376,6 +387,9 @@ function advtrains.save(remove_players_from_wagons)
atwarn("Instructed to save() but load() was never called!")
return
end
+ if saving_disabled then
+ return
+ end
advtrains.avt_save(remove_players_from_wagons) --saving advtrains. includes ndb at advtrains.ndb.save_data()
if atlatc then
atlatc.save()