1
0
mirror of https://github.com/anope/anope.git synced 2026-07-08 02:43:13 +02:00

Simplify limit extraction code.

This commit is contained in:
Sadie Powell
2024-03-12 12:22:57 +00:00
parent 63d682314b
commit 06add0e5fc
12 changed files with 58 additions and 121 deletions
+15 -13
View File
@@ -110,12 +110,25 @@ public:
/** Can we ask the server to unban a user? */
bool CanClearBans = false;
/* The maximum number of modes we are allowed to set with one MODE command */
unsigned MaxModes = 3;
/* The maximum length of a channel name. */
size_t MaxChannel = 0;
/* The maximum length of a hostname. */
size_t MaxHost = 0;
/* The maximum number of bytes a line may have */
unsigned MaxLine = 512;
/* The maximum number of modes we are allowed to set with one MODE command */
unsigned MaxModes = 3;
/* The maximum length of a nickname. */
size_t MaxNick = 0;
/* The maximum length of a username. */
size_t MaxUser = 0;
/* Retrieves the next free UID or SID */
virtual Anope::string UID_Retrieve();
virtual Anope::string SID_Retrieve();
@@ -313,17 +326,6 @@ public:
virtual Anope::string NormalizeMask(const Anope::string &mask);
/** Retrieves the maximum length of a channel name. */
virtual size_t GetMaxChannel();
/** Retrieves the maximum length of a hostname. */
virtual size_t GetMaxHost();
/** Retrieves the maximum length of a nickname. */
virtual size_t GetMaxNick();
/** Retrieves the maximum length of a username. */
virtual size_t GetMaxUser();
};
class CoreExport MessageSource final
+12 -12
View File
@@ -28,21 +28,21 @@ private:
return;
}
if (nick.length() > IRCD->GetMaxNick())
if (nick.length() > IRCD->MaxNick)
{
source.Reply(_("Bot nicks may only be %zu characters long."), IRCD->GetMaxNick());
source.Reply(_("Bot nicks may only be %zu characters long."), IRCD->MaxNick);
return;
}
if (user.length() > IRCD->GetMaxUser())
if (user.length() > IRCD->MaxUser)
{
source.Reply(_("Bot idents may only be %zu characters long."), IRCD->GetMaxUser());
source.Reply(_("Bot idents may only be %zu characters long."), IRCD->MaxUser);
return;
}
if (host.length() > IRCD->GetMaxHost())
if (host.length() > IRCD->MaxHost)
{
source.Reply(_("Bot hosts may only be %zu characters long."), IRCD->GetMaxHost());
source.Reply(_("Bot hosts may only be %zu characters long."), IRCD->MaxHost);
return;
}
@@ -118,21 +118,21 @@ private:
return;
}
if (nick.length() > IRCD->GetMaxNick())
if (nick.length() > IRCD->MaxNick)
{
source.Reply(_("Bot nicks may only be %zu characters long."), IRCD->GetMaxNick());
source.Reply(_("Bot nicks may only be %zu characters long."), IRCD->MaxNick);
return;
}
if (user.length() > IRCD->GetMaxUser())
if (user.length() > IRCD->MaxUser)
{
source.Reply(_("Bot idents may only be %zu characters long."), IRCD->GetMaxUser());
source.Reply(_("Bot idents may only be %zu characters long."), IRCD->MaxUser);
return;
}
if (host.length() > IRCD->GetMaxHost())
if (host.length() > IRCD->MaxHost)
{
source.Reply(_("Bot hosts may only be %zu characters long."), IRCD->GetMaxHost()
source.Reply(_("Bot hosts may only be %zu characters long."), IRCD->MaxHost
);
return;
}
+2 -2
View File
@@ -270,9 +270,9 @@ public:
if (simple)
return this->SimpleSeen(source, params);
if (target.length() > IRCD->GetMaxNick())
if (target.length() > IRCD->MaxNick)
{
source.Reply(_("Nick too long, max length is %zu characters."), IRCD->GetMaxNick());
source.Reply(_("Nick too long, max length is %zu characters."), IRCD->MaxNick);
return;
}
+4 -4
View File
@@ -122,9 +122,9 @@ public:
if (!user.empty())
{
if (user.length() > IRCD->GetMaxUser())
if (user.length() > IRCD->MaxUser)
{
source.Reply(HOST_SET_IDENTTOOLONG, IRCD->GetMaxUser());
source.Reply(HOST_SET_IDENTTOOLONG, IRCD->MaxUser);
return;
}
else if (!IRCD->CanSetVIdent)
@@ -142,9 +142,9 @@ public:
}
}
if (host.length() > IRCD->GetMaxHost())
if (host.length() > IRCD->MaxHost)
{
source.Reply(HOST_SET_TOOLONG, IRCD->GetMaxHost());
source.Reply(HOST_SET_TOOLONG, IRCD->MaxHost);
return;
}
+4 -4
View File
@@ -71,9 +71,9 @@ public:
}
}
if (host.length() > IRCD->GetMaxHost())
if (host.length() > IRCD->MaxHost)
{
source.Reply(HOST_SET_TOOLONG, IRCD->GetMaxHost());
source.Reply(HOST_SET_TOOLONG, IRCD->MaxHost);
return;
}
@@ -174,9 +174,9 @@ public:
}
}
if (host.length() > IRCD->GetMaxHost())
if (host.length() > IRCD->MaxHost)
{
source.Reply(HOST_SET_TOOLONG, IRCD->GetMaxHost());
source.Reply(HOST_SET_TOOLONG, IRCD->MaxHost);
return;
}
+1 -1
View File
@@ -238,7 +238,7 @@ public:
if (IRCD->CanSVSNick)
{
unsigned nicklen = IRCD->GetMaxNick();
unsigned nicklen = IRCD->MaxNick;
const Anope::string &guestprefix = Config->GetModule("nickserv")->Get<const Anope::string>("guestnickprefix", "Guest");
Anope::string guestnick;
+1 -1
View File
@@ -34,7 +34,7 @@ public:
}
/* Truncate long nicknames to nicklen characters */
size_t nicklen = IRCD->GetMaxNick();
size_t nicklen = IRCD->MaxNick;
if (newnick.length() > nicklen)
{
source.Reply(_("Nick \002%s\002 was truncated to %zu characters."), newnick.c_str(), nicklen);
+1 -1
View File
@@ -280,7 +280,7 @@ public:
bool IsIdentValid(const Anope::string &ident) override
{
if (ident.empty() || ident.length() > IRCD->GetMaxUser())
if (ident.empty() || ident.length() > IRCD->MaxUser)
return false;
/*
+9 -40
View File
@@ -25,18 +25,6 @@ struct SASLUser final
namespace
{
// The maximum length of a channel name.
size_t maxchannel = 0;
// The maximum length of a hostname.
size_t maxhost = 0;
// The maximum length of a nickname.
size_t maxnick = 0;
// The maximum length of a username.
size_t maxuser = 0;
// The SID of a server we are waiting to squit.
Anope::string rsquit_id;
@@ -159,16 +147,6 @@ public:
MaxLine = 4096;
}
size_t GetMaxChannel() override
{
return maxchannel ? maxchannel : IRCDProto::GetMaxChannel();
}
size_t GetMaxHost() override
{
return maxhost ? maxhost : IRCDProto::GetMaxHost();
}
size_t GetMaxListFor(Channel *c, ChannelMode *cm) override
{
ListLimits *limits = maxlist.Get(c);
@@ -183,15 +161,6 @@ public:
return IRCDProto::GetMaxListFor(c, cm);
}
size_t GetMaxNick() override
{
return maxnick ? maxnick : IRCDProto::GetMaxNick();
}
size_t GetMaxUser() override
{
return maxuser ? maxuser : IRCDProto::GetMaxUser();
}
void SendConnect() override
{
@@ -650,7 +619,7 @@ public:
bool IsIdentValid(const Anope::string &ident) override
{
if (ident.empty() || ident.length() > IRCD->GetMaxUser())
if (ident.empty() || ident.length() > IRCD->MaxUser)
return false;
for (auto c : ident)
@@ -1540,25 +1509,25 @@ struct IRCDMessageCapab final
{
auto [tokname, tokvalue] = ParseCapability(capab);
if (tokname == "MAXCHANNEL")
maxchannel = tokvalue;
IRCD->MaxChannel = tokvalue;
else if (tokname == "MAXHOST")
maxhost = tokvalue;
IRCD->MaxHost = tokvalue;
else if (tokname == "MAXMODES")
IRCD->MaxModes = tokvalue;
else if (tokname == "MAXNICK")
maxnick = tokvalue;
IRCD->MaxNick = tokvalue;
else if (tokname == "MAXUSER")
maxuser = tokvalue;
IRCD->MaxUser = tokvalue;
// Deprecated 1205 keys.
else if (tokname == "CHANMAX")
maxchannel = tokvalue;
IRCD->MaxChannel = tokvalue;
else if (tokname == "GLOBOPS" && tokvalue)
Servers::Capab.insert("GLOBOPS");
else if (tokname == "IDENTMAX")
maxuser = tokvalue;
IRCD->MaxUser = tokvalue;
else if (tokname == "NICKMAX")
maxnick = tokvalue;
IRCD->MaxNick = tokvalue;
}
}
else if (params[0].equals_cs("END"))
@@ -1995,7 +1964,7 @@ struct IRCDMessageFJoin final
users.push_back(sju);
}
auto ts = IRCD->ExtractTimestamp(params[0]);
auto ts = IRCD->ExtractTimestamp(params[1]);
Message::Join::SJoin(source, params[0], ts, modes, users);
}
};
+1 -11
View File
@@ -12,11 +12,6 @@
#include "module.h"
#include "numeric.h"
namespace
{
size_t nicklen = 0;
}
class ngIRCdProto final
: public IRCDProto
{
@@ -37,11 +32,6 @@ public:
MaxModes = 5;
}
size_t GetMaxNick() override
{
return nicklen ? nicklen : IRCDProto::GetMaxNick();
}
void SendAkill(User *u, XLine *x) override
{
// Calculate the time left before this would expire
@@ -182,7 +172,7 @@ struct IRCDMessage005 final
}
else if (parameter == "NICKLEN")
{
nicklen = Anope::Convert<size_t>(data, 0);
IRCD->MaxNick = Anope::Convert<size_t>(data, IRCD->MaxNick);
}
}
}
+1 -1
View File
@@ -423,7 +423,7 @@ private:
bool IsIdentValid(const Anope::string &ident) override
{
if (ident.empty() || ident.length() > IRCD->GetMaxUser())
if (ident.empty() || ident.length() > IRCD->MaxUser)
return false;
for (auto c : ident)
+7 -31
View File
@@ -25,6 +25,10 @@ IRCDProto *IRCD = NULL;
IRCDProto::IRCDProto(Module *creator, const Anope::string &p)
: Service(creator, "IRCDProto", creator->name)
, proto_name(p)
, MaxChannel(Config->GetBlock("networkinfo")->Get<unsigned>("chanlen", "32"))
, MaxHost(Config->GetBlock("networkinfo")->Get<unsigned>("hostlen", "64"))
, MaxNick(Config->GetBlock("networkinfo")->Get<unsigned>("nicklen", "31"))
, MaxUser(Config->GetBlock("networkinfo")->Get<unsigned>("userlen", "10"))
{
if (IRCD == NULL)
IRCD = this;
@@ -296,7 +300,7 @@ bool IRCDProto::IsNickValid(const Anope::string &nick)
bool IRCDProto::IsChannelValid(const Anope::string &chan)
{
if (chan.empty() || chan[0] != '#' || chan.length() > IRCD->GetMaxChannel())
if (chan.empty() || chan[0] != '#' || chan.length() > IRCD->MaxChannel)
return false;
if (chan.find_first_of(" ,") != Anope::string::npos)
@@ -307,7 +311,7 @@ bool IRCDProto::IsChannelValid(const Anope::string &chan)
bool IRCDProto::IsIdentValid(const Anope::string &ident)
{
if (ident.empty() || ident.length() > IRCD->GetMaxUser())
if (ident.empty() || ident.length() > IRCD->MaxUser)
return false;
for (auto c : ident)
@@ -323,7 +327,7 @@ bool IRCDProto::IsIdentValid(const Anope::string &ident)
bool IRCDProto::IsHostValid(const Anope::string &host)
{
if (host.empty() || host.length() > IRCD->GetMaxHost())
if (host.empty() || host.length() > IRCD->MaxHost)
return false;
const Anope::string &vhostdisablebe = Config->GetBlock("networkinfo")->Get<const Anope::string>("disallow_start_or_end"),
@@ -378,34 +382,6 @@ void IRCDProto::SendContextPrivmsg(BotInfo *bi, User *target, Channel *context,
});
}
size_t IRCDProto::GetMaxChannel()
{
// We can cache this as its not allowed to change on rehash.
static size_t chanlen = Config->GetBlock("networkinfo")->Get<unsigned>("chanlen", "32");
return chanlen;
}
size_t IRCDProto::GetMaxHost()
{
// We can cache this as its not allowed to change on rehash.
static size_t hostlen = Config->GetBlock("networkinfo")->Get<unsigned>("hostlen", "64");
return hostlen;
}
size_t IRCDProto::GetMaxNick()
{
// We can cache this as its not allowed to change on rehash.
static size_t nicklen = Config->GetBlock("networkinfo")->Get<unsigned>("nicklen", "31");
return nicklen;
}
size_t IRCDProto::GetMaxUser()
{
// We can cache this as its not allowed to change on rehash.
static size_t userlen = Config->GetBlock("networkinfo")->Get<unsigned>("userlen", "10");
return userlen;
}
MessageSource::MessageSource(const Anope::string &src) : source(src)
{
/* no source for incoming message is our uplink */