aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel PĂ©rez-Cerezo <gabriel@gpcf.eu>2018-02-21 19:58:45 +0100
committerorwell96 <orwell@bleipb.de>2018-02-21 20:03:34 +0100
commit481f6218a8b377a0826b7e080046b5a890702e12 (patch)
tree3baa24616afb8790eb16f882863241b9f7d91523
parent4c512f1dc5755efc7afd55b58078ec466442f648 (diff)
downloadadvtrains-481f6218a8b377a0826b7e080046b5a890702e12.tar.gz
advtrains-481f6218a8b377a0826b7e080046b5a890702e12.tar.bz2
advtrains-481f6218a8b377a0826b7e080046b5a890702e12.zip
Log certain events in a logfile in the world directory
(also fix the output of /at_sync_ndb)
-rw-r--r--advtrains/init.lua6
-rw-r--r--advtrains/log.lua13
-rw-r--r--advtrains/nodedb.lua2
-rw-r--r--advtrains/settingtypes.txt6
-rw-r--r--advtrains/tracks.lua1
-rw-r--r--advtrains/wagons.lua6
6 files changed, 29 insertions, 5 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua
index c1940ad..38252ae 100644
--- a/advtrains/init.lua
+++ b/advtrains/init.lua
@@ -141,7 +141,8 @@ advtrains.meseconrules =
{x=0, y=1, z=-1},
{x=0, y=-1, z=-1},
{x=0, y=-2, z=0}}
-
+
+advtrains.fpath=minetest.get_worldpath().."/advtrains"
dofile(advtrains.modpath.."/path.lua")
dofile(advtrains.modpath.."/trainlogic.lua")
@@ -160,13 +161,14 @@ dofile(advtrains.modpath.."/misc_nodes.lua")
dofile(advtrains.modpath.."/crafting.lua")
dofile(advtrains.modpath.."/craft_items.lua")
+dofile(advtrains.modpath.."/log.lua")
+
if minetest.global_exists("digtron") then
dofile(advtrains.modpath.."/digtron.lua")
end
--load/save
-advtrains.fpath=minetest.get_worldpath().."/advtrains"
function advtrains.avt_load()
local file, err = io.open(advtrains.fpath, "r")
diff --git a/advtrains/log.lua b/advtrains/log.lua
new file mode 100644
index 0000000..d2b71d3
--- /dev/null
+++ b/advtrains/log.lua
@@ -0,0 +1,13 @@
+-- Log accesses to driver stands and changes to switches
+
+advtrains.log = function() end
+
+if minetest.settings:get_bool("advtrains_enable_logging") then
+ advtrains.logfile = advtrains.fpath .. "_log"
+
+ function advtrains.log (event, player, pos, data)
+ local log = io.open(advtrains.logfile, "a+")
+ log:write(os.date()..": "..event.." by "..player.." at "..minetest.pos_to_string(pos).." -- "..(data or "").."\n")
+ log:close()
+ end
+end
diff --git a/advtrains/nodedb.lua b/advtrains/nodedb.lua
index f735b79..592e730 100644
--- a/advtrains/nodedb.lua
+++ b/advtrains/nodedb.lua
@@ -256,7 +256,7 @@ ndb.restore_all = function()
end
end
end
- local text="Restore node database: Replaced",cnt,"nodes, removed",dcnt,"ghost nodes"
+ local text="Restore node database: Replaced"..cnt.."nodes, removed"..dcnt.."ghost nodes."
atlog(text)
return text
end
diff --git a/advtrains/settingtypes.txt b/advtrains/settingtypes.txt
index 60f8477..d0c27ec 100644
--- a/advtrains/settingtypes.txt
+++ b/advtrains/settingtypes.txt
@@ -5,4 +5,8 @@ advtrains_disable_collisions (Disable train collisions) bool false
# Enable the debug ring buffer
# This has no effect on the user experience, except decreased performance. Debug outputs are saved in a ring buffer to be printed when an error occurs.
# You probably want to leave this setting set to false.
-advtrains_enable_debugging (Enable debugging) bool false \ No newline at end of file
+advtrains_enable_debugging (Enable debugging) bool false
+# Enable the logging of certain events related to advtrains
+# Logs are saved in the world directory as advtrains.log
+# This setting is useful for multiplayer servers
+advtrains_enable_logging (Enable logging) bool false
diff --git a/advtrains/tracks.lua b/advtrains/tracks.lua
index 6d218b1..4b2b17c 100644
--- a/advtrains/tracks.lua
+++ b/advtrains/tracks.lua
@@ -311,6 +311,7 @@ function advtrains.register_tracks(tracktype, def, preset)
ndef.on_rightclick = function(pos, node, player)
if minetest.check_player_privs(player:get_player_name(), {train_operator=true}) then
switchfunc(pos, node)
+ advtrains.log("Switch", player:get_player_name(), pos)
end
end
if var.switchmc then
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index 3ddd8b0..2dce41b 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -1087,6 +1087,9 @@ function wagon:check_seat_group_access(pname, sgr)
if self.seat_groups[sgr].driving_ctrl_access and not (minetest.check_player_privs(pname, "train_operator") or self.owner==pname) then
return false, "Missing train_operator privilege."
end
+ if self.seat_groups[sgr].driving_ctrl_access then
+ advtrains.log("Drive", pname, self.object:getpos(), self:train().text_outside)
+ end
if not self.seat_access then
return true
end
@@ -1120,7 +1123,8 @@ function wagon:safe_decouple(pname)
minetest.chat_send_player(pname, "Couple is locked (ask owner or admin to unlock it)")
return false
end
- atprint("wagon:discouple() Splitting train", selftrain_id)
+ atprint("wagon:discouple() Splitting train", self.train_id)
+ advtrains.log("Discouple", pname, self.object:getpos(), self:train().text_outside)
advtrains.split_train_at_wagon(self)--found in trainlogic.lua
return true
end