1
0
mirror of https://github.com/minetest/minetest_game.git synced 2025-07-03 23:20:22 +02:00

default.log_player_action supports a list of message parts (thanks appgurueu)

This commit is contained in:
nixnoxus
2022-04-22 18:24:36 +02:00
parent fc6e5944a2
commit c3466dbd18
2 changed files with 21 additions and 8 deletions

View File

@ -1131,11 +1131,13 @@ These non-players are marked by the content of `is_fake_player`
(if it is a string) or a "*" in brackets after the player name in (if it is a string) or a "*" in brackets after the player name in
the log. the log.
`default.log_player_action(player, message, pos)` `default.log_player_action(player, ...)`
* `player` The player who performed the action * `player` The player who performed the action
* `message` A message describing the action in 3rd person singular present tense. * `message_parts` Any mumber of message parts describing the action
* `pos` Position of the node at which the action was performed in 3rd person singular present tense. It can also
contain a `position` / `vector` which is logged as
" at (X,Y,Z)"
`default.set_inventory_action_loggers(def, name)` `default.set_inventory_action_loggers(def, name)`

View File

@ -721,16 +721,27 @@ end
local log_non_player_actions = minetest.settings:get_bool("log_non_player_actions", false) local log_non_player_actions = minetest.settings:get_bool("log_non_player_actions", false)
function default.log_player_action(player, message, pos) -- `vector.check` is available since minetest >= 5.5.0
local who = player:get_player_name() local is_vector = vector.check or function(v)
return v and type(v) == "table" and
v.x or type(v.x) == "number" and
v.y or type(v.y) == "number" and
v.z or type(v.z) == "number"
end
function default.log_player_action(player, ...)
local msg = player:get_player_name()
if player.is_fake_player or not player:is_player() then if player.is_fake_player or not player:is_player() then
if not log_non_player_actions then if not log_non_player_actions then
return return
end end
who = who .. "(" .. (type(player.is_fake_player) == "string" msg = msg .. "(" .. (type(player.is_fake_player) == "string"
and player.is_fake_player or "*").. ")" and player.is_fake_player or "*").. ")"
end end
minetest.log("action", who .. " " .. message .. " at " .. minetest.pos_to_string(pos)) for _, v in ipairs({...}) do
msg = msg .. " " .. (is_vector(v) and ("at " .. minetest.pos_to_string(v)) or v)
end
minetest.log("action", msg)
end end
function default.set_inventory_action_loggers(def, name) function default.set_inventory_action_loggers(def, name)