Skip to content

Commit

Permalink
join_ratelimit: Account for auth from mods other than builtin (#11)
Browse files Browse the repository at this point in the history
* join_ratelimit: Account for auth from mods other than builtin

* Fix luacheck warnings
  • Loading branch information
LoneWolfHT committed Apr 25, 2022
1 parent 79aa43a commit a204f48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ read_globals = {
"vector", "ItemStack",
"dump", "screwdriver",
"minetest",
"core",

-- mods
"beerchat"
Expand Down
20 changes: 12 additions & 8 deletions join_ratelimit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
-- mitigates https://github.com/minetest/minetest/issues/11877 and https://github.com/minetest/minetest/issues/9498

local ratelimit = {}
local after = minetest.after
local LIMIT = 1

local function remove_entry(ip)
ratelimit[ip] = nil
ratelimit[ip] = nil
end

table.insert(minetest.registered_on_prejoinplayers, 1, function(_, ip)
if ratelimit[ip] then
return "You are joining too fast, please try again"
else
ratelimit[ip] = true
minetest.after(1, remove_entry, ip)
end
minetest.register_on_mods_loaded(function()
table.insert(core.registered_on_prejoinplayers, 1, function(_, ip)
if ratelimit[ip] then
return "You are joining too fast, please try again"
else
ratelimit[ip] = true
after(LIMIT, remove_entry, ip)
end
end)
end)

0 comments on commit a204f48

Please sign in to comment.