diff options
author | ShadowNinja <shadowninja@minetest.net> | 2013-11-12 16:13:00 -0500 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2013-11-27 18:13:06 -0500 |
commit | 7433d65d3e383cd3d2f5ced38d9109e9fd7c72c0 (patch) | |
tree | 61b6fa4fcd8b5b00b84e5464afde07d122d4f7ca /builtin | |
parent | 1fd9a11e302566d207c046bd5145e4e05a3c58ea (diff) | |
download | minetest-7433d65d3e383cd3d2f5ced38d9109e9fd7c72c0.tar.gz minetest-7433d65d3e383cd3d2f5ced38d9109e9fd7c72c0.tar.bz2 minetest-7433d65d3e383cd3d2f5ced38d9109e9fd7c72c0.zip |
Rollback fixes and get_node_actions
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/chatcommands.lua | 53 | ||||
-rw-r--r-- | builtin/deprecated.lua | 5 |
2 files changed, 37 insertions, 21 deletions
diff --git a/builtin/chatcommands.lua b/builtin/chatcommands.lua index 831d3a7b4..b9661a888 100644 --- a/builtin/chatcommands.lua +++ b/builtin/chatcommands.lua @@ -515,34 +515,45 @@ minetest.register_on_punchnode(function(pos, node, puncher) end) minetest.register_chatcommand("rollback_check", { - params = "[<range>] [<seconds>]", + params = "[<range>] [<seconds>] [limit]", description = "check who has last touched a node or near it, ".. - "max. <seconds> ago (default range=0, seconds=86400=24h)", + "max. <seconds> ago (default range=0, seconds=86400=24h, limit=5)", privs = {rollback=true}, func = function(name, param) - local range, seconds = string.match(param, "(%d+) *(%d*)") + local range, seconds, limit = + param:match("(%d+) *(%d*) *(%d*)") range = tonumber(range) or 0 seconds = tonumber(seconds) or 86400 - minetest.chat_send_player(name, "Punch a node (limits set: range=".. - dump(range).." seconds="..dump(seconds).."s)") + limit = tonumber(limit) or 5 + if limit > 100 then + minetest.chat_send_player(name, "That limit is too high!") + return + end + minetest.chat_send_player(name, "Punch a node (range=".. + range..", seconds="..seconds.."s, limit="..limit..")") + minetest.rollback_punch_callbacks[name] = function(pos, node, puncher) local name = puncher:get_player_name() - minetest.chat_send_player(name, "Checking...") - local actor, act_p, act_seconds = - minetest.rollback_get_last_node_actor(pos, range, seconds) - if actor == "" then + minetest.chat_send_player(name, "Checking "..minetest.pos_to_string(pos).."...") + local actions = minetest.rollback_get_node_actions(pos, range, seconds, limit) + local num_actions = #actions + if num_actions == 0 then minetest.chat_send_player(name, "Nobody has touched the ".. - "specified location in "..dump(seconds).." seconds") + "specified location in "..seconds.." seconds") return end - local nodedesc = "this node" - if act_p.x ~= pos.x or act_p.y ~= pos.y or act_p.z ~= pos.z then - nodedesc = minetest.pos_to_string(act_p) + local time = os.time() + for i = num_actions, 1, -1 do + local action = actions[i] + minetest.chat_send_player(name, + ("%s %s %s -> %s %d seconds ago.") + :format( + minetest.pos_to_string(action.pos), + action.actor, + action.oldnode.name, + action.newnode.name, + time - action.time)) end - local nodename = minetest.get_node(act_p).name - minetest.chat_send_player(name, "Last actor on "..nodedesc.. - " was "..actor..", "..dump(act_seconds).. - "s ago (node is now "..nodename..")") end end, }) @@ -554,7 +565,7 @@ minetest.register_chatcommand("rollback", { func = function(name, param) local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)") if not target_name then - local player_name = nil; + local player_name = nil player_name, seconds = string.match(param, "([^ ]+) *(%d*)") if not player_name then minetest.chat_send_player(name, "Invalid parameters. See /help rollback and /help rollback_check") @@ -564,13 +575,13 @@ minetest.register_chatcommand("rollback", { end seconds = tonumber(seconds) or 60 minetest.chat_send_player(name, "Reverting actions of ".. - dump(target_name).." since "..dump(seconds).." seconds.") + target_name.." since "..seconds.." seconds.") local success, log = minetest.rollback_revert_actions_by( target_name, seconds) - if #log > 10 then + if #log > 100 then minetest.chat_send_player(name, "(log is too long to show)") else - for _,line in ipairs(log) do + for _, line in pairs(log) do minetest.chat_send_player(name, line) end end diff --git a/builtin/deprecated.lua b/builtin/deprecated.lua index 333f64cdc..d8b578d48 100644 --- a/builtin/deprecated.lua +++ b/builtin/deprecated.lua @@ -46,3 +46,8 @@ setmetatable(minetest.env, { return rawget(table, key) end }) + +function minetest.rollback_get_last_node_actor(pos, range, seconds) + return minetest.rollback_get_node_actions(pos, range, seconds, 1)[1] +end + |