aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--advtrains/advtrains/init.lua61
-rw-r--r--advtrains/advtrains/nodedb.lua3
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.
})
l com">Minetest Copyright (C) 2010-2014 kwolekr, Ryan Kwolek <kwolekr@minetest.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "test.h" #include "mg_schematic.h" #include "gamedef.h" #include "nodedef.h" class TestSchematic : public TestBase { public: TestSchematic() { TestManager::registerTestModule(this); } const char *getName() { return "TestSchematic"; } void runTests(IGameDef *gamedef); void testMtsSerializeDeserialize(INodeDefManager *ndef); void testLuaTableSerialize(INodeDefManager *ndef); void testFileSerializeDeserialize(INodeDefManager *ndef); static const content_t test_schem1_data[7 * 6 * 4]; static const content_t test_schem2_data[3 * 3 * 3]; static const u8 test_schem2_prob[3 * 3 * 3]; static const char *expected_lua_output; }; static TestSchematic g_test_instance; void TestSchematic::runTests(IGameDef *gamedef) { IWritableNodeDefManager *ndef = (IWritableNodeDefManager *)gamedef->getNodeDefManager(); ndef->setNodeRegistrationStatus(true); TEST(testMtsSerializeDeserialize, ndef); TEST(testLuaTableSerialize, ndef); TEST(testFileSerializeDeserialize, ndef); ndef->resetNodeResolveState(); } //////////////////////////////////////////////////////////////////////////////// void TestSchematic::testMtsSerializeDeserialize(INodeDefManager *ndef) { static const v3s16 size(7, 6, 4); static const u32 volume = size.X * size.Y * size.Z; std::stringstream ss(std::ios_base::binary | std::ios_base::in | std::ios_base::out); std::vector<std::string> names; names.push_back("foo"); names.push_back("bar"); names.push_back("baz"); names.push_back("qux"); Schematic schem, schem2; schem.flags = 0; schem.size = size; schem.schemdata = new MapNode[volume]; schem.slice_probs = new u8[size.Y]; for (size_t i = 0; i != volume; i++) schem.schemdata[i] = MapNode(test_schem1_data[i], MTSCHEM_PROB_ALWAYS, 0); for (s16 y = 0; y != size.Y; y++) schem.slice_probs[y] = MTSCHEM_PROB_ALWAYS; UASSERT(schem.serializeToMts(&ss, names)); ss.seekg(0); names.clear(); UASSERT(schem2.deserializeFromMts(&ss, &names)); UASSERTEQ(size_t, names.size(), 4); UASSERTEQ(std::string, names[0], "foo"); UASSERTEQ(std::string, names[1], "bar"); UASSERTEQ(std::string, names[2], "baz"); UASSERTEQ(std::string, names[3], "qux"); UASSERT(schem2.size == size);