write the saved nodedb state back to the map when restoring after a crash
also, print a complete stack trace when an error happens also, don't replace nodes in the nodedb when worldedit has been usedmaster
parent
5aaf493cef
commit
da884afbb1
BIN
advtrains.zip
BIN
advtrains.zip
Binary file not shown.
|
@ -14,9 +14,11 @@ local no_action=false
|
||||||
function advtrains.pcall(fun)
|
function advtrains.pcall(fun)
|
||||||
if no_action then return end
|
if no_action then return end
|
||||||
|
|
||||||
local succ, err, return1, return2, return3, return4=pcall(fun)
|
local succ, return1, return2, return3, return4=xpcall(fun, function(err)
|
||||||
|
atwarn("Lua Error occured: ", err)
|
||||||
|
atwarn(debug.traceback())
|
||||||
|
end)
|
||||||
if not succ then
|
if not succ then
|
||||||
atwarn("Lua Error occured: ", err)
|
|
||||||
atwarn("Restoring saved state in 1 second...")
|
atwarn("Restoring saved state in 1 second...")
|
||||||
no_action=true
|
no_action=true
|
||||||
--read last save state and continue, as if server was restarted
|
--read last save state and continue, as if server was restarted
|
||||||
|
@ -25,9 +27,13 @@ function advtrains.pcall(fun)
|
||||||
le.object:remove()
|
le.object:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
minetest.after(1, advtrains.load)
|
minetest.after(1, function()
|
||||||
|
advtrains.load()
|
||||||
|
atwarn("Reload successful!")
|
||||||
|
advtrains.ndb.restore_all()
|
||||||
|
end)
|
||||||
else
|
else
|
||||||
return err, return1, return2, return3, return4
|
return return1, return2, return3, return4
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -197,13 +197,16 @@ function advtrains.get_rail_info_at(pos, drives_on)
|
||||||
return true, conn1, conn2, rely1, rely2, railheight
|
return true, conn1, conn2, rely1, rely2, railheight
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ndb.run_lbm = function(pos, nodep)
|
||||||
minetest.register_abm({
|
|
||||||
name = "advtrains:nodedb_on_load_update",
|
|
||||||
nodenames = {"group:save_in_nodedb"},
|
|
||||||
run_at_every_load = true,
|
|
||||||
action = function(pos, node)
|
|
||||||
return advtrains.pcall(function()
|
return advtrains.pcall(function()
|
||||||
|
local node=nodep
|
||||||
|
if not node then
|
||||||
|
node=minetest.get_node_or_nil(pos)
|
||||||
|
if not node then
|
||||||
|
--this is defintely not loaded
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
local cid=ndbget(pos.x, pos.y, pos.z)
|
local cid=ndbget(pos.x, pos.y, pos.z)
|
||||||
if cid then
|
if cid then
|
||||||
--if in database, detect changes and apply.
|
--if in database, detect changes and apply.
|
||||||
|
@ -215,11 +218,17 @@ minetest.register_abm({
|
||||||
ndb.update(pos, node)
|
ndb.update(pos, node)
|
||||||
else
|
else
|
||||||
if (nodeid~=node.name or param2~=node.param2) then
|
if (nodeid~=node.name or param2~=node.param2) then
|
||||||
atprint("nodedb: lbm replaced", pos, "with nodeid", nodeid, "param2", param2, "cid is", cid)
|
local ori_ndef=minetest.registered_nodes[node.name]
|
||||||
minetest.swap_node(pos, {name=nodeid, param2 = param2})
|
if ori_ndef and ori_ndef.groups.save_in_nodedb then --check if this node has been worldedited, and don't replace then
|
||||||
local ndef=minetest.registered_nodes[nodeid]
|
atprint("nodedb: lbm replaced", pos, "with nodeid", nodeid, "param2", param2, "cid is", cid)
|
||||||
if ndef and ndef.on_updated_from_nodedb then
|
minetest.swap_node(pos, {name=nodeid, param2 = param2})
|
||||||
ndef.on_updated_from_nodedb(pos, node)
|
local ndef=minetest.registered_nodes[nodeid]
|
||||||
|
if ndef and ndef.on_updated_from_nodedb then
|
||||||
|
ndef.on_updated_from_nodedb(pos, node)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
ndb.clear(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -228,11 +237,35 @@ minetest.register_abm({
|
||||||
atprint("nodedb: ", pos, "not in database")
|
atprint("nodedb: ", pos, "not in database")
|
||||||
ndb.update(pos, node)
|
ndb.update(pos, node)
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end)
|
end)
|
||||||
end,
|
end
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_abm({
|
||||||
|
name = "advtrains:nodedb_on_load_update",
|
||||||
|
nodenames = {"group:save_in_nodedb"},
|
||||||
|
run_at_every_load = true,
|
||||||
|
action = ndb.run_lbm,
|
||||||
interval=10,
|
interval=10,
|
||||||
chance=1,
|
chance=1,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
--used when restoring stuff after a crash
|
||||||
|
ndb.restore_all = function()
|
||||||
|
atwarn("Updating the map from the nodedb, this may take a while")
|
||||||
|
local cnt=0
|
||||||
|
for y, ny in pairs(ndb_nodes) do
|
||||||
|
for x, nx in pairs(ny) do
|
||||||
|
for z, _ in pairs(nx) do
|
||||||
|
if ndb.run_lbm({x=x, y=y, z=z}) then
|
||||||
|
cnt=cnt+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
atwarn("Updated",cnt,"nodes")
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||||
return advtrains.pcall(function()
|
return advtrains.pcall(function()
|
||||||
|
|
Loading…
Reference in New Issue