diff options
-rw-r--r-- | include/protocol.h | 28 | ||||
-rw-r--r-- | modules/botserv/bs_bot.cpp | 24 | ||||
-rw-r--r-- | modules/chanserv/cs_seen.cpp | 4 | ||||
-rw-r--r-- | modules/hostserv/hs_request.cpp | 8 | ||||
-rw-r--r-- | modules/hostserv/hs_set.cpp | 8 | ||||
-rw-r--r-- | modules/nickserv/nickserv.cpp | 2 | ||||
-rw-r--r-- | modules/operserv/os_svs.cpp | 2 | ||||
-rw-r--r-- | modules/protocol/hybrid.cpp | 2 | ||||
-rw-r--r-- | modules/protocol/inspircd.cpp | 49 | ||||
-rw-r--r-- | modules/protocol/ngircd.cpp | 12 | ||||
-rw-r--r-- | modules/protocol/unrealircd.cpp | 2 | ||||
-rw-r--r-- | src/protocol.cpp | 38 |
12 files changed, 58 insertions, 121 deletions
diff --git a/include/protocol.h b/include/protocol.h index f89df0ab1..1b067421c 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -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 diff --git a/modules/botserv/bs_bot.cpp b/modules/botserv/bs_bot.cpp index 5571a82c9..c50c94411 100644 --- a/modules/botserv/bs_bot.cpp +++ b/modules/botserv/bs_bot.cpp @@ -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; } diff --git a/modules/chanserv/cs_seen.cpp b/modules/chanserv/cs_seen.cpp index 183cd5e05..1603983f5 100644 --- a/modules/chanserv/cs_seen.cpp +++ b/modules/chanserv/cs_seen.cpp @@ -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; } diff --git a/modules/hostserv/hs_request.cpp b/modules/hostserv/hs_request.cpp index d7bc6bc34..b53cd6fa9 100644 --- a/modules/hostserv/hs_request.cpp +++ b/modules/hostserv/hs_request.cpp @@ -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; } diff --git a/modules/hostserv/hs_set.cpp b/modules/hostserv/hs_set.cpp index 261e1e51f..16e4cebf9 100644 --- a/modules/hostserv/hs_set.cpp +++ b/modules/hostserv/hs_set.cpp @@ -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; } diff --git a/modules/nickserv/nickserv.cpp b/modules/nickserv/nickserv.cpp index f1f087163..dee7a2303 100644 --- a/modules/nickserv/nickserv.cpp +++ b/modules/nickserv/nickserv.cpp @@ -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; diff --git a/modules/operserv/os_svs.cpp b/modules/operserv/os_svs.cpp index ee2131c17..854fd4af2 100644 --- a/modules/operserv/os_svs.cpp +++ b/modules/operserv/os_svs.cpp @@ -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); diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index 4d2ed2e82..b060c4f43 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -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; /* diff --git a/modules/protocol/inspircd.cpp b/modules/protocol/inspircd.cpp index e0cf20b85..8ba398038 100644 --- a/modules/protocol/inspircd.cpp +++ b/modules/protocol/inspircd.cpp @@ -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); } }; diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp index ea9d92294..fc56d1055 100644 --- a/modules/protocol/ngircd.cpp +++ b/modules/protocol/ngircd.cpp @@ -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); } } } diff --git a/modules/protocol/unrealircd.cpp b/modules/protocol/unrealircd.cpp index a49adac56..195ad617c 100644 --- a/modules/protocol/unrealircd.cpp +++ b/modules/protocol/unrealircd.cpp @@ -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) diff --git a/src/protocol.cpp b/src/protocol.cpp index 55603c8e7..c1685eb27 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -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 */ |