aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2021-07-07 18:10:53 +0200
committerorwell96 <orwell@bleipb.de>2021-07-07 22:42:14 +0200
commitc623a338604a0bd623309314d85e1022edc7f3af (patch)
tree54b342446d9607918f412a9cdb0a4d437f7b6edb /advtrains
parent30f4e342fdc6bd74c72bcbb649d4e1ccf974bcab (diff)
downloadadvtrains-c623a338604a0bd623309314d85e1022edc7f3af.tar.gz
advtrains-c623a338604a0bd623309314d85e1022edc7f3af.tar.bz2
advtrains-c623a338604a0bd623309314d85e1022edc7f3af.zip
Shutdown callback: don't save advtrains save files when MT crashed within advtrains's main step
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/init.lua16
1 files changed, 14 insertions, 2 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua
index 96352df..083281e 100644
--- a/advtrains/init.lua
+++ b/advtrains/init.lua
@@ -569,11 +569,13 @@ advtrains.mainloop_runcnt=0
advtrains.global_slowdown = 1
local t = 0
+local within_mainstep = false
minetest.register_globalstep(function(dtime_mt)
if no_action then
-- the advtrains globalstep is skipped by command. Return immediately
return
end
+ within_mainstep = true
advtrains.mainloop_runcnt=advtrains.mainloop_runcnt+1
--atprint("Running the main loop, runcnt",advtrains.mainloop_runcnt)
@@ -586,6 +588,7 @@ minetest.register_globalstep(function(dtime_mt)
if GENERATE_ATRICIFIAL_LAG then
dtime = HOW_MANY_LAG
if os.clock()<t then
+ within_mainstep = false
return
end
@@ -616,7 +619,7 @@ minetest.register_globalstep(function(dtime_mt)
if advtrains.lines then
advtrains.lines.step(dtime)
end
-
+
--trigger a save when necessary
save_timer=save_timer-dtime
if save_timer<=0 then
@@ -626,6 +629,9 @@ minetest.register_globalstep(function(dtime_mt)
save_timer = advtrains.SAVE_INTERVAL
atprintbm("saving", t)
end
+
+ within_mainstep = false
+
end)
--if something goes wrong in these functions, there is no help. no pcall here.
@@ -678,7 +684,13 @@ function advtrains.save(remove_players_from_wagons)
--TODO very simple yet hacky workaround for the "green signals" bug
advtrains.invalidate_all_paths()
end
-minetest.register_on_shutdown(advtrains.save)
+minetest.register_on_shutdown(function()
+ if within_mainstep then
+ atwarn("Crash during advtrains main step - skipping the shutdown save operation to not save inconsistent data!")
+ else
+ advtrains.save()
+ end
+end)
-- This chat command provides a solution to the problem known on the LinuxWorks server
-- There are many players that joined a single time, got on a train and then left forever