Skip to content

Commit

Permalink
Apply the same punishment logic to the v4 version of antiknocker as v3.
Browse files Browse the repository at this point in the history
This has been tested and just seems to cause the bot to spam nick
changes until it floods off which is less useful than the alternative.
  • Loading branch information
SadieCat committed Jul 10, 2023
1 parent bb7fbf4 commit 12d70b5
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions 4/m_antiknocker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
#include "extension.h"
#include "modules/shun.h"

enum
{
// From RFC 1459.
ERR_NICKNAMEINUSE = 433
};

class ModuleAntiKnocker final
: public Module
{
Expand All @@ -43,6 +37,26 @@ class ModuleAntiKnocker final
unsigned long shunduration;
std::string shunreason;

void PunishUser(LocalUser* user)
{
auto* sh = new Shun(ServerInstance->Time(), shunduration, MODNAME "@" + ServerInstance->Config->ServerName, shunreason, user->GetAddress());
if (ServerInstance->XLines->AddLine(sh, nullptr))
{
ServerInstance->XLines->ApplyLines();
return;
}

// No shunning? Annoying. Just quit em.
delete sh;

std::string message;
if (!user->IsFullyConnected())
message = "Connection timeout";
else
message = INSP_FORMAT("Ping timeout: {} seconds", user->GetClass()->pingtime);
ServerInstance->Users.QuitUser(user, message);
}

ModuleAntiKnocker()
: Module(VF_NONE, "Attempts to block a common IRC spambot.")
, seenmsg(this, "seenmsg", ExtensionType::USER)
Expand Down Expand Up @@ -89,18 +103,7 @@ class ModuleAntiKnocker final
ServerInstance->SNO.WriteToSnoMask('a', "User {} ({}) was caught in an knocker trap!",
user->nick, user->GetRealUserHost());

auto* sh = new Shun(ServerInstance->Time(), shunduration, MODNAME "@" + ServerInstance->Config->ServerName, shunreason, user->GetAddress());
if (ServerInstance->XLines->AddLine(sh, nullptr))
{
ServerInstance->XLines->ApplyLines();
return MOD_RES_DENY;
}

// No shunning? Annoying. Just quit em.
delete sh;

const std::string message = INSP_FORMAT("Ping timeout: {} seconds", user->GetClass()->pingtime);
ServerInstance->Users.QuitUser(user, message);
PunishUser(user);
return MOD_RES_DENY;
}
}
Expand All @@ -116,7 +119,8 @@ class ModuleAntiKnocker final

ServerInstance->SNO.WriteToSnoMask('a', "User {} ({}) was prevented from using a knocker nick: {}",
user->nick, user->GetRealUserHost(), newnick);
user->WriteNumeric(ERR_NICKNAMEINUSE, newnick, "Nickname is already in use.");

PunishUser(user);
return MOD_RES_DENY;
}
};
Expand Down

0 comments on commit 12d70b5

Please sign in to comment.