diff options
author | orwell96 <mono96.mml@gmail.com> | 2017-06-12 21:13:53 +0200 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2017-06-12 21:13:53 +0200 |
commit | a34ff7664af45864151d55bd41e2031b322affe2 (patch) | |
tree | af315b961d97f7f252805bec604691e448a84a5f | |
parent | 7431b4007359f62e06dab8298d70a25c3d557c77 (diff) | |
download | advtrains-a34ff7664af45864151d55bd41e2031b322affe2.tar.gz advtrains-a34ff7664af45864151d55bd41e2031b322affe2.tar.bz2 advtrains-a34ff7664af45864151d55bd41e2031b322affe2.zip |
Add command to throw all players out of trains, fixes #78
-rw-r--r-- | advtrains/advtrains/init.lua | 61 | ||||
-rw-r--r-- | advtrains/advtrains/nodedb.lua | 3 |
2 files changed, 45 insertions, 19 deletions
diff --git a/advtrains/advtrains/init.lua b/advtrains/advtrains/init.lua index c6bb2ad..74990e7 100644 --- a/advtrains/advtrains/init.lua +++ b/advtrains/advtrains/init.lua @@ -11,6 +11,23 @@ advtrains = {trains={}, wagon_save={}, player_to_train_mapping={}} --pcall local no_action=false + +local function reload_saves() + atwarn("Restoring saved state in 1 second...") + no_action=true + --read last save state and continue, as if server was restarted + for aoi, le in pairs(minetest.luaentities) do + if le.is_wagon then + le.object:remove() + end + end + minetest.after(1, function() + advtrains.load() + atwarn("Reload successful!") + advtrains.ndb.restore_all() + end) +end + function advtrains.pcall(fun) if no_action then return end @@ -26,19 +43,7 @@ function advtrains.pcall(fun) atwarn(debug.traceback()) end) if not succ then - atwarn("Restoring saved state in 1 second...") - no_action=true - --read last save state and continue, as if server was restarted - for aoi, le in pairs(minetest.luaentities) do - if le.is_wagon then - le.object:remove() - end - end - minetest.after(1, function() - advtrains.load() - atwarn("Reload successful!") - advtrains.ndb.restore_all() - end) + reload_saves() else return return1, return2, return3, return4 end @@ -203,7 +208,7 @@ function advtrains.avt_load() end end -advtrains.avt_save = function() +advtrains.avt_save = function(remove_players_from_wagons) --atprint("saving") --No more invalidating. --Instead, remove path a.s.o from the saved table manually @@ -228,6 +233,12 @@ advtrains.avt_save = function() data.discouple.object:remove() data.discouple=nil end + if remove_players_from_wagons then + data.seatp={} + end + end + if remove_players_from_wagons then + advtrains.player_to_train_mapping={} end local tmp_trains={} @@ -342,16 +353,34 @@ end --## MAIN SAVE ROUTINE ## -- Causes the saving of everything -function advtrains.save() +function advtrains.save(remove_players_from_wagons) if not init_load then --wait... we haven't loaded yet?! atwarn("Instructed to save() but load() was never called!") return end - advtrains.avt_save() --saving advtrains. includes ndb at advtrains.ndb.save_data() + advtrains.avt_save(remove_players_from_wagons) --saving advtrains. includes ndb at advtrains.ndb.save_data() if atlatc then atlatc.save() end atprint("[save_all]Saved advtrains save files") end minetest.register_on_shutdown(advtrains.save) + +-- 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 +-- These players still occupy seats in the trains. +minetest.register_chatcommand("at_empty_seats", + { + params = "", -- Short parameter description + description = "Detach all players, especially the offline ones, from all trains. Use only when no one serious is on a train.", -- Full description + privs = {train_operator=true, server=true}, -- Require the "privs" privilege to run + func = function(name, param) + return advtrains.pcall(function() + atwarn("Data is being saved. While saving, advtrains will remove the players from trains. Save files will be reloaded afterwards!") + advtrains.save(true) + reload_saves() + end) + end, + privs = {train_operator=true}, -- Require the "privs" privilege to run + }) diff --git a/advtrains/advtrains/nodedb.lua b/advtrains/advtrains/nodedb.lua index 3986633..862fd53 100644 --- a/advtrains/advtrains/nodedb.lua +++ b/advtrains/advtrains/nodedb.lua @@ -303,8 +303,5 @@ minetest.register_chatcommand("at_sync_ndb", end) end, privs = {train_operator=true}, -- Require the "privs" privilege to run - func = function(name, param) - ndb.restore_all() - end, -- Called when command is run. }) |