Merge branch 'master' of https://github.com/MT-CTF/capturetheflag
This commit is contained in:
commit
16c31aa273
6 changed files with 119 additions and 37 deletions
19
mods/pvp/place_limit/License.txt
Normal file
19
mods/pvp/place_limit/License.txt
Normal file
|
@ -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.
|
8
mods/pvp/place_limit/Readme.md
Normal file
8
mods/pvp/place_limit/Readme.md
Normal file
|
@ -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.
|
51
mods/pvp/place_limit/init.lua
Normal file
51
mods/pvp/place_limit/init.lua
Normal file
|
@ -0,0 +1,51 @@
|
|||
-- Licensed under the MIT license, written by appgurueu.
|
||||
local players = {}
|
||||
local blocks_per_second = 5
|
||||
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_notification_sent = -math.huge
|
||||
}
|
||||
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
|
||||
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 time = minetest.get_us_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
|
||||
table.insert(placements, 1, time)
|
||||
end)
|
3
mods/pvp/place_limit/mod.conf
Normal file
3
mods/pvp/place_limit/mod.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
name = place_limit
|
||||
description = Limits block placement
|
||||
depends = hud_events
|
Loading…
Add table
Add a link
Reference in a new issue