From e50a08e5d36e33cfaac1097a5690367869009301 Mon Sep 17 00:00:00 2001 From: mckayshirou Date: Mon, 17 Jul 2023 21:22:13 -0400 Subject: [PATCH] featured antispawn by appgurueu --- antispawn.lua | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ init.lua | 4 ++++ 2 files changed, 69 insertions(+) create mode 100644 antispawn.lua diff --git a/antispawn.lua b/antispawn.lua new file mode 100644 index 0000000..473c4ff --- /dev/null +++ b/antispawn.lua @@ -0,0 +1,65 @@ +local PLAYERS_MSG = {} +local PLAYERS_FREQ = {} +local SPAM_SPEED = 5 +local SPAM_SPEED_MSECS = SPAM_SPEED * 1e6 +local SPAM_WARN = 5 +-- In seconds +local SPAM_KICK = SPAM_WARN + 5 +local RESET_TIME = 30 +-- Convert to microsecs +local RESET_TIME_MSECS = RESET_TIME * 1e6 +local WARNING_COLOR = minetest.get_color_escape_sequence"#FFBB33" +minetest.register_on_leaveplayer(function(player) + PLAYERS_MSG[player:get_player_name()] = nil + PLAYERS_FREQ[player:get_player_name()] = nil +end) +minetest.register_on_joinplayer(function(player) + PLAYERS_MSG[player:get_player_name()] = {} +end) +minetest.register_on_chat_message(function(name, message) + for msg, info in pairs(PLAYERS_MSG[name]) do + if minetest.get_us_time() - info[2] >= RESET_TIME_MSECS then PLAYERS_MSG[name][msg] = nil end + end + if PLAYERS_MSG[name][message] then + local amount = PLAYERS_MSG[name][message][1] + 1 + PLAYERS_MSG[name][message][1] = amount + PLAYERS_MSG[name][message][2] = minetest.get_us_time() + if amount >= SPAM_KICK then minetest.kick_player(name, "Kicked for spamming.") + elseif amount >= SPAM_WARN then + minetest.chat_send_player(name, WARNING_COLOR .. "Warning! You've sent the message '" .. message .. "' too often. Wait at least " .. RESET_TIME .. " seconds before sending it again.") + end + else PLAYERS_MSG[name][message] = { 1, minetest.get_us_time() } end + if not PLAYERS_FREQ[name] then + PLAYERS_FREQ[name] = { + 0, + 0, + minetest.get_us_time(), + 0 + } + return + end + local warns = PLAYERS_FREQ[name][4] + local amount = PLAYERS_FREQ[name][2] + local speed = PLAYERS_FREQ[name][1] + local delay = minetest.get_us_time() - PLAYERS_FREQ[name][3] + speed = (speed * amount + delay) / (amount + 1) + if amount >= SPAM_WARN then + if warns + 1 == SPAM_KICK - SPAM_WARN then minetest.kick_player(name, "Kicked for spamming.") + elseif speed <= SPAM_SPEED_MSECS then + minetest.chat_send_player(name, WARNING_COLOR .. "Warning! You are sending messages too fast. Wait at least " .. SPAM_SPEED .. " seconds before sending another message.") + warns = warns + 1 + speed = SPAM_SPEED_MSECS + amount = SPAM_WARN + else + speed = 0 + amount = 0 + warns = 0 + end + end + PLAYERS_FREQ[name] = { + speed, + amount + 1, + minetest.get_us_time(), + warns + } +end) diff --git a/init.lua b/init.lua index dc1e98f..6fe7392 100644 --- a/init.lua +++ b/init.lua @@ -24,6 +24,7 @@ local moddefault = minetest.get_modpath("default") -- path of default mod if ava local modkillme = minetest.get_modpath("killme") -- if killme is present as mod if available, otherwise we use own local modcommand = minetest.get_modpath("game_commands") -- updated killme is present as mod if available, otherwise we use own local modcreative = minetest.get_modpath("creative") -- if creative is available, otherwise false/nil +local modantispawn = minetest.get_modpath("antispam") -- if rnd1 anticheat mod is loaded, cos only wolrs with mt4 local modanticheat = minetest.get_modpath("anticheat") -- if rnd1 anticheat mod is loaded, cos only wolrs with mt4 local modbeowulf = minetest.get_modpath("beowulf") -- if rnd1 anticheat mod is loaded, cos only wolrs with mt4 local checkapikey = minetest.settings:get("governing.checkapikey") or "" -- need for geoip improved ip information, then geoip normal will be used @@ -92,6 +93,7 @@ governing.modmail = modmail -- path of the mail mod if available for sending mes governing.moddefault = moddefault -- path of default mod if available, otherwise false/nil governing.modkillme = modkillme -- if killme is present as mod if available, otherwise we use own governing.modcommand = modcommand -- if same killme and commands is present as mod if available, otherwise we use own +governing.modantispawn = modantispawn -- autodetect if older mod antispan by appguru are present governing.modanticheat = modanticheat -- if rnd1 anticheat mod is present cos only works with mt4 governing.modbeowulf = modbeowulf -- if beowulf anticheat mod is present cos only works with mt5 governing.checkapikey = checkapikey -- need for geoip improved ip information, then geoip normal will be used @@ -179,6 +181,8 @@ dofile(governing.modpath.."/geoip.lua") -- format the geoip responses managed b dofile(governing.modpath.."/anticheats.lua") -- load anticheat mod that combined rnd + beowulf + fairplay +dofile(governing.modpath.."/antispawn.lua") -- load antispawn chat features only if mod antispan is not loaded + dofile(governing.modpath.."/commands.lua") -- must be at end. so relies on others functionalities --[[ end of include code files mod features ]]