Add command to throw all players out of trains, fixes #78
This commit is contained in:
parent
7431b40073
commit
a34ff7664a
|
@ -11,6 +11,23 @@ advtrains = {trains={}, wagon_save={}, player_to_train_mapping={}}
|
||||||
|
|
||||||
--pcall
|
--pcall
|
||||||
local no_action=false
|
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)
|
function advtrains.pcall(fun)
|
||||||
if no_action then return end
|
if no_action then return end
|
||||||
|
|
||||||
|
@ -26,19 +43,7 @@ function advtrains.pcall(fun)
|
||||||
atwarn(debug.traceback())
|
atwarn(debug.traceback())
|
||||||
end)
|
end)
|
||||||
if not succ then
|
if not succ then
|
||||||
atwarn("Restoring saved state in 1 second...")
|
reload_saves()
|
||||||
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)
|
|
||||||
else
|
else
|
||||||
return return1, return2, return3, return4
|
return return1, return2, return3, return4
|
||||||
end
|
end
|
||||||
|
@ -203,7 +208,7 @@ function advtrains.avt_load()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
advtrains.avt_save = function()
|
advtrains.avt_save = function(remove_players_from_wagons)
|
||||||
--atprint("saving")
|
--atprint("saving")
|
||||||
--No more invalidating.
|
--No more invalidating.
|
||||||
--Instead, remove path a.s.o from the saved table manually
|
--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.object:remove()
|
||||||
data.discouple=nil
|
data.discouple=nil
|
||||||
end
|
end
|
||||||
|
if remove_players_from_wagons then
|
||||||
|
data.seatp={}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if remove_players_from_wagons then
|
||||||
|
advtrains.player_to_train_mapping={}
|
||||||
end
|
end
|
||||||
|
|
||||||
local tmp_trains={}
|
local tmp_trains={}
|
||||||
|
@ -342,16 +353,34 @@ end
|
||||||
|
|
||||||
--## MAIN SAVE ROUTINE ##
|
--## MAIN SAVE ROUTINE ##
|
||||||
-- Causes the saving of everything
|
-- Causes the saving of everything
|
||||||
function advtrains.save()
|
function advtrains.save(remove_players_from_wagons)
|
||||||
if not init_load then
|
if not init_load then
|
||||||
--wait... we haven't loaded yet?!
|
--wait... we haven't loaded yet?!
|
||||||
atwarn("Instructed to save() but load() was never called!")
|
atwarn("Instructed to save() but load() was never called!")
|
||||||
return
|
return
|
||||||
end
|
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
|
if atlatc then
|
||||||
atlatc.save()
|
atlatc.save()
|
||||||
end
|
end
|
||||||
atprint("[save_all]Saved advtrains save files")
|
atprint("[save_all]Saved advtrains save files")
|
||||||
end
|
end
|
||||||
minetest.register_on_shutdown(advtrains.save)
|
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
|
||||||
|
})
|
||||||
|
|
|
@ -303,8 +303,5 @@ minetest.register_chatcommand("at_sync_ndb",
|
||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
privs = {train_operator=true}, -- Require the "privs" privilege to run
|
privs = {train_operator=true}, -- Require the "privs" privilege to run
|
||||||
func = function(name, param)
|
|
||||||
ndb.restore_all()
|
|
||||||
end, -- Called when command is run.
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue