From e9322075a366f7d09b472194a13bdb239f7410cf Mon Sep 17 00:00:00 2001 From: orwell96 Date: Tue, 20 Feb 2018 16:22:31 +0100 Subject: Allow wagon owners to control their own trains ...even without the train_operator privilege This still doesn't allow them to control switches, but whatever... --- advtrains/wagons.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index fd01abd..81b7571 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -251,7 +251,7 @@ function wagon:on_step(dtime) --driver control for seatno, seat in ipairs(self.seats) do local driver=self.seatp[seatno] and minetest.get_player_by_name(self.seatp[seatno]) - local has_driverstand = self.seatp[seatno] and minetest.check_player_privs(self.seatp[seatno], {train_operator=true}) + local has_driverstand = self.seatp[seatno] and (minetest.check_player_privs(self.seatp[seatno], {train_operator=true}) or self.owner==self.seatp[seatno]) if self.seat_groups then has_driverstand = has_driverstand and (seat.driving_ctrl_access or self.seat_groups[seat.group].driving_ctrl_access) else -- cgit v1.2.3 From 4c512f1dc5755efc7afd55b58078ec466442f648 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Tue, 20 Feb 2018 16:39:31 +0100 Subject: Allow wagon owners to drive their trains #2 The check was missing at check_seat_group_access --- advtrains/wagons.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index 81b7571..3ddd8b0 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -1084,7 +1084,7 @@ function wagon:seating_from_key_helper(pname, fields, no) end end 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") then + 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 not self.seat_access then -- cgit v1.2.3 From 481f6218a8b377a0826b7e080046b5a890702e12 Mon Sep 17 00:00:00 2001 From: Gabriel PĂ©rez-Cerezo Date: Wed, 21 Feb 2018 19:58:45 +0100 Subject: Log certain events in a logfile in the world directory (also fix the output of /at_sync_ndb) --- advtrains/init.lua | 6 ++++-- advtrains/log.lua | 13 +++++++++++++ advtrains/nodedb.lua | 2 +- advtrains/settingtypes.txt | 6 +++++- advtrains/tracks.lua | 1 + advtrains/wagons.lua | 6 +++++- 6 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 advtrains/log.lua 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 -- cgit v1.2.3