From 69bc5dbb1612de21a4893dcf4b8e1d7abf1f05b2 Mon Sep 17 00:00:00 2001 From: kay27 Date: Fri, 29 Apr 2022 02:43:25 +0300 Subject: [PATCH] Fix UNIQUE constraint failed: auth.name in callback createAuth() --- mods/PLAYER/mcl_anticheat/init.lua | 3 +++ mods/PLAYER/mcl_anticheat/ratelimit.lua | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 mods/PLAYER/mcl_anticheat/ratelimit.lua diff --git a/mods/PLAYER/mcl_anticheat/init.lua b/mods/PLAYER/mcl_anticheat/init.lua index 2e3f427a6..cadad5c92 100644 --- a/mods/PLAYER/mcl_anticheat/init.lua +++ b/mods/PLAYER/mcl_anticheat/init.lua @@ -1,3 +1,6 @@ +local modpath = minetest.get_modpath(minetest.get_current_modname()) +dofile(modpath .. "/ratelimit.lua") + local enable_anticheat = true local kick_cheaters = false local kick_threshold = 10 diff --git a/mods/PLAYER/mcl_anticheat/ratelimit.lua b/mods/PLAYER/mcl_anticheat/ratelimit.lua new file mode 100644 index 000000000..4e4f5bd2d --- /dev/null +++ b/mods/PLAYER/mcl_anticheat/ratelimit.lua @@ -0,0 +1,21 @@ +-- by LoneWolfHT +-- https://github.com/minetest/minetest/issues/12220#issuecomment-1108789409 + +local ratelimit = {} +local after = minetest.after +local LIMIT = 2 + +local function remove_entry(ip) + ratelimit[ip] = nil +end + +minetest.register_on_mods_loaded(function() + table.insert(core.registered_on_prejoinplayers, 1, function(player, 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)