From 243061957abc5364dff87a24d7312b25d2018165 Mon Sep 17 00:00:00 2001 From: savilli <78875209+savilli@users.noreply.github.com> Date: Wed, 24 Mar 2021 17:34:02 +0300 Subject: [PATCH 1/4] Postpone map skipping until flag holder captures or loses the flag (#835) * Postpone map skipping until flag holder captures or loses the flag * Wait 5s after flag drop --- mods/ctf/ctf_match/vote.lua | 44 ++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/mods/ctf/ctf_match/vote.lua b/mods/ctf/ctf_match/vote.lua index c2738f4..eef2c6e 100644 --- a/mods/ctf/ctf_match/vote.lua +++ b/mods/ctf/ctf_match/vote.lua @@ -6,6 +6,16 @@ function ctf_match.register_on_skip_map(func) table.insert(ctf_match.registered_on_skip_map, func) end +function skip() + for i = 1, #ctf_match.registered_on_skip_map do + ctf_match.registered_on_skip_map[i]() + end + ctf_match.next() +end + +local can_vote_skip = false +local voted_skip = false +local flags_hold = 0 function ctf_match.vote_next(name) local tcolor = ctf_colors.get_color(ctf.player(name)).css or "#FFFFFFFF" minetest.chat_send_all(minetest.colorize("#FFAA11", "Vote started by ") .. @@ -22,10 +32,12 @@ function ctf_match.vote_next(name) if result == "yes" then minetest.chat_send_all("Vote to skip match passed, " .. #results.yes .. " to " .. #results.no) - for i = 1, #ctf_match.registered_on_skip_map do - ctf_match.registered_on_skip_map[i]() + + can_vote_skip = false + voted_skip = true + if flags_hold <= 0 then + skip() end - ctf_match.next() else minetest.chat_send_all("Vote to skip match failed, " .. #results.no .. " to " .. #results.yes) @@ -53,9 +65,8 @@ minetest.register_chatcommand("vote", { local matchskip_time local matchskip_timer = 0 -local can_skip = false minetest.register_globalstep(function(dtime) - if not can_skip then return end + if not can_vote_skip then return end matchskip_timer = matchskip_timer + dtime @@ -68,18 +79,25 @@ minetest.register_globalstep(function(dtime) end end) -local function prevent_autoskip() - can_skip = false -end - -ctf.register_on_new_game(prevent_autoskip) -ctf_flag.register_on_pick_up(prevent_autoskip) +ctf.register_on_new_game(function() + can_vote_skip = false + voted_skip = false + flags_hold = 0 +end) +ctf_flag.register_on_pick_up(function() + flags_hold = flags_hold + 1 +end) ctf_flag.register_on_drop(function() - can_skip = true + flags_hold = flags_hold - 1 + if voted_skip and flags_hold <= 0 then + minetest.after(5, function() + skip() + end) + end end) ctf_match.register_on_build_time_end(function() - can_skip = true + can_vote_skip = true matchskip_timer = 0 -- Set to initial vote time matchskip_time = tonumber(minetest.settings:get("ctf_match.auto_skip_delay")) or 50 * 60 From 7382db367b567cdccb27747eb212f0a2a6560080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Sat, 27 Mar 2021 15:27:22 +0100 Subject: [PATCH 2/4] Limit node placement to 5 NPS (#803) * Limit placement to 5 nodes per second * Add Readme, check pointed thing, inform player * Include team door fix * Add license --- mods/mtg/doors/init.lua | 10 ++++-- mods/pvp/place_limit/License.txt | 19 ++++++++++++ mods/pvp/place_limit/Readme.md | 8 +++++ mods/pvp/place_limit/init.lua | 53 ++++++++++++++++++++++++++++++++ mods/pvp/place_limit/mod.conf | 2 ++ 5 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 mods/pvp/place_limit/License.txt create mode 100644 mods/pvp/place_limit/Readme.md create mode 100644 mods/pvp/place_limit/init.lua create mode 100644 mods/pvp/place_limit/mod.conf diff --git a/mods/mtg/doors/init.lua b/mods/mtg/doors/init.lua index b606e80..a3792ad 100644 --- a/mods/mtg/doors/init.lua +++ b/mods/mtg/doors/init.lua @@ -362,14 +362,20 @@ function doors.register(name, def) meta:set_string("owner_team", tname) end + local copy = table.copy + local newnode = minetest.get_node(pos) + for _, on_placenode in pairs(minetest.registered_on_placenodes) do + if on_placenode(copy(pos), copy(newnode), placer, copy(node), ItemStack(itemstack), copy(pointed_thing)) then + return itemstack + end + end if not (creative and creative.is_enabled_for and creative.is_enabled_for(pn)) then itemstack:take_item() end minetest.sound_play(def.sounds.place, {pos = pos}) - on_place_node(pos, minetest.get_node(pos), - placer, node, itemstack, pointed_thing) + on_place_node(pos, newnode, placer, node, itemstack, pointed_thing) return itemstack end diff --git a/mods/pvp/place_limit/License.txt b/mods/pvp/place_limit/License.txt new file mode 100644 index 0000000..2e7c235 --- /dev/null +++ b/mods/pvp/place_limit/License.txt @@ -0,0 +1,19 @@ +Copyright (c) 2021 appgurueu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/mods/pvp/place_limit/Readme.md b/mods/pvp/place_limit/Readme.md new file mode 100644 index 0000000..8c201a7 --- /dev/null +++ b/mods/pvp/place_limit/Readme.md @@ -0,0 +1,8 @@ +# `place_limit` + +Fixes two things related to node placement: + +* Ratelimits node placement +* Disallows building to non-pointable nodes (anticheat + race condition fix) + +Licensed under the MIT license, written by appgurueu. \ No newline at end of file diff --git a/mods/pvp/place_limit/init.lua b/mods/pvp/place_limit/init.lua new file mode 100644 index 0000000..46b4683 --- /dev/null +++ b/mods/pvp/place_limit/init.lua @@ -0,0 +1,53 @@ +-- Licensed under the MIT license, written by appgurueu. +local players = {} +local blocks_per_second = 5 +local resend_chat_message_seconds = 10 + +minetest.register_on_joinplayer(function(player) + -- player has to wait after join before they can place a node + players[player:get_player_name()] = { + last_placement = minetest.get_us_time(), + last_chat_message_sent = -math.huge + } +end) + +local chat_send_player = minetest.chat_send_player +function minetest.chat_send_player(name, message) + if players[name] then + players[name].last_chat_message_sent = -math.huge + end + return chat_send_player(name, message) +end + +local chat_send_all = minetest.chat_send_all +function minetest.chat_send_all(message) + for _, playerdata in pairs(players) do + playerdata.last_chat_message_sent = -math.huge + end + return chat_send_all(message) +end + +minetest.register_on_leaveplayer(function(player) + players[player:get_player_name()] = nil +end) + +minetest.register_on_placenode(function(pos, _newnode, placer, oldnode, _itemstack, pointed_thing) + if not ItemStack(minetest.get_node(pointed_thing.under).name):get_definition().pointable then + -- this should happen rarely + minetest.chat_send_player(placer:get_player_name(), "The block you have been building to has been dug/replaced!") + minetest.set_node(pos, oldnode) + return true + end + local name = placer:get_player_name() + local playerdata = players[name] + local time = minetest.get_us_time() + if (time - playerdata.last_placement) / 1e6 < 1 / blocks_per_second then + if (time - playerdata.last_chat_message_sent) / 1e6 >= resend_chat_message_seconds then + chat_send_player(placer:get_player_name(), "You are placing blocks too fast (more than " .. blocks_per_second .. " blocks per second) !") + playerdata.last_chat_message_sent = time + end + minetest.set_node(pos, oldnode) + return true + end + playerdata.last_placement = time +end) diff --git a/mods/pvp/place_limit/mod.conf b/mods/pvp/place_limit/mod.conf new file mode 100644 index 0000000..3c6236e --- /dev/null +++ b/mods/pvp/place_limit/mod.conf @@ -0,0 +1,2 @@ +name = place_limit +description = Limits block placement From fd5b8a484e6283ffe4feafcc3fe67adaed428e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Sat, 27 Mar 2021 19:01:40 +0100 Subject: [PATCH 3/4] Fix doors disappearing when placed (#843) --- mods/mtg/doors/init.lua | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/mods/mtg/doors/init.lua b/mods/mtg/doors/init.lua index a3792ad..240134d 100644 --- a/mods/mtg/doors/init.lua +++ b/mods/mtg/doors/init.lua @@ -188,27 +188,6 @@ function _doors.door_toggle(pos, node, clicker) end -local function on_place_node(place_to, newnode, - placer, oldnode, itemstack, pointed_thing) - -- Run script hook - for _, callback in ipairs(minetest.registered_on_placenodes) do - -- Deepcopy pos, node and pointed_thing because callback can modify them - local place_to_copy = {x = place_to.x, y = place_to.y, z = place_to.z} - local newnode_copy = - {name = newnode.name, param1 = newnode.param1, param2 = newnode.param2} - local oldnode_copy = - {name = oldnode.name, param1 = oldnode.param1, param2 = oldnode.param2} - local pointed_thing_copy = { - type = pointed_thing.type, - above = vector.new(pointed_thing.above), - under = vector.new(pointed_thing.under), - ref = pointed_thing.ref, - } - callback(place_to_copy, newnode_copy, placer, - oldnode_copy, itemstack, pointed_thing_copy) - end -end - local function can_dig_door(pos, digger) replace_old_owner_information(pos) if default.can_interact_with_node(digger, pos) then @@ -364,7 +343,7 @@ function doors.register(name, def) local copy = table.copy local newnode = minetest.get_node(pos) - for _, on_placenode in pairs(minetest.registered_on_placenodes) do + for _, on_placenode in ipairs(minetest.registered_on_placenodes) do if on_placenode(copy(pos), copy(newnode), placer, copy(node), ItemStack(itemstack), copy(pointed_thing)) then return itemstack end @@ -375,8 +354,6 @@ function doors.register(name, def) minetest.sound_play(def.sounds.place, {pos = pos}) - on_place_node(pos, newnode, placer, node, itemstack, pointed_thing) - return itemstack end }) From e40d1e666a55834a83d017d8cf4c6f4cf2bc8c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Sun, 28 Mar 2021 21:45:49 +0200 Subject: [PATCH 4/4] place_limit: Use HUD notifications & quota instead of time between placements (#844) * place_limit: Use HUD notifications * Adjust warning color * Quota instead of time between placements * Bump maps submodule --- mods/pvp/place_limit/init.lua | 54 +++++++++++++++++------------------ mods/pvp/place_limit/mod.conf | 1 + 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/mods/pvp/place_limit/init.lua b/mods/pvp/place_limit/init.lua index 46b4683..51ebd8b 100644 --- a/mods/pvp/place_limit/init.lua +++ b/mods/pvp/place_limit/init.lua @@ -1,53 +1,51 @@ -- Licensed under the MIT license, written by appgurueu. local players = {} local blocks_per_second = 5 -local resend_chat_message_seconds = 10 +local resend_notification_seconds = 10 +-- Bootstrap 4 "warning" color +local warning_color = 0xFFC107 minetest.register_on_joinplayer(function(player) -- player has to wait after join before they can place a node players[player:get_player_name()] = { - last_placement = minetest.get_us_time(), - last_chat_message_sent = -math.huge + last_notification_sent = -math.huge } end) -local chat_send_player = minetest.chat_send_player -function minetest.chat_send_player(name, message) - if players[name] then - players[name].last_chat_message_sent = -math.huge - end - return chat_send_player(name, message) -end - -local chat_send_all = minetest.chat_send_all -function minetest.chat_send_all(message) - for _, playerdata in pairs(players) do - playerdata.last_chat_message_sent = -math.huge - end - return chat_send_all(message) -end - minetest.register_on_leaveplayer(function(player) players[player:get_player_name()] = nil end) minetest.register_on_placenode(function(pos, _newnode, placer, oldnode, _itemstack, pointed_thing) + local name = placer:get_player_name() if not ItemStack(minetest.get_node(pointed_thing.under).name):get_definition().pointable then - -- this should happen rarely - minetest.chat_send_player(placer:get_player_name(), "The block you have been building to has been dug/replaced!") + -- This should happen rarely + hud_event.new(name, { + name = "place_limit:unpointable", + color = warning_color, + value = "Block not pointable (dug/replaced)!", + }) minetest.set_node(pos, oldnode) return true end - local name = placer:get_player_name() - local playerdata = players[name] local time = minetest.get_us_time() - if (time - playerdata.last_placement) / 1e6 < 1 / blocks_per_second then - if (time - playerdata.last_chat_message_sent) / 1e6 >= resend_chat_message_seconds then - chat_send_player(placer:get_player_name(), "You are placing blocks too fast (more than " .. blocks_per_second .. " blocks per second) !") - playerdata.last_chat_message_sent = time + local placements = players[name] + for i = #placements, 1, -1 do + if time - placements[i] > 1e6 then + placements[i] = nil + end + end + if #placements >= blocks_per_second then + if (time - placements.last_notification_sent) / 1e6 >= resend_notification_seconds then + hud_event.new(name, { + name = "place_limit:speed", + color = warning_color, + value = "Placing too fast!", + }) + placements.last_notification_sent = time end minetest.set_node(pos, oldnode) return true end - playerdata.last_placement = time + table.insert(placements, 1, time) end) diff --git a/mods/pvp/place_limit/mod.conf b/mods/pvp/place_limit/mod.conf index 3c6236e..e29d69c 100644 --- a/mods/pvp/place_limit/mod.conf +++ b/mods/pvp/place_limit/mod.conf @@ -1,2 +1,3 @@ name = place_limit description = Limits block placement +depends = hud_events