diff options
author | Sadie Powell <sadie@witchery.services> | 2024-02-21 20:45:38 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-02-22 00:14:08 +0000 |
commit | aefbb4fbdab80a41c3f88566abcba4b92b2d36d5 (patch) | |
tree | 81b6ba768c99606101fbce39d54d9d521d1a1e20 | |
parent | 9b77fdf5b680e4a084effe56345a9d01cfbf6f11 (diff) |
Rework SendModeInternal to be usable with Uplink::Send.
-rw-r--r-- | include/protocol.h | 17 | ||||
-rw-r--r-- | modules/protocol/bahamut.cpp | 18 | ||||
-rw-r--r-- | modules/protocol/hybrid.cpp | 10 | ||||
-rw-r--r-- | modules/protocol/inspircd.cpp | 8 | ||||
-rw-r--r-- | modules/protocol/plexus.cpp | 6 | ||||
-rw-r--r-- | modules/protocol/ratbox.cpp | 2 | ||||
-rw-r--r-- | modules/protocol/unrealircd.cpp | 14 | ||||
-rw-r--r-- | src/modes.cpp | 36 | ||||
-rw-r--r-- | src/protocol.cpp | 32 |
9 files changed, 79 insertions, 64 deletions
diff --git a/include/protocol.h b/include/protocol.h index f2b510d96..bb0577332 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -31,8 +31,6 @@ public: virtual ~IRCDProto(); virtual void SendSVSKillInternal(const MessageSource &, User *, const Anope::string &); - virtual void SendModeInternal(const MessageSource &, const Channel *, const Anope::string &); - virtual void SendModeInternal(const MessageSource &, User *, const Anope::string &); virtual void SendKickInternal(const MessageSource &, const Channel *, User *, const Anope::string &); virtual void SendNoticeInternal(const MessageSource &, const Anope::string &dest, const Anope::string &msg); virtual void SendPrivmsgInternal(const MessageSource &, const Anope::string &dest, const Anope::string &buf); @@ -167,8 +165,19 @@ public: */ virtual void SendSVSKill(const MessageSource &source, User *user, const char *fmt, ...) ATTR_FORMAT(4, 5); - virtual void SendMode(const MessageSource &source, const Channel *dest, const char *fmt, ...) ATTR_FORMAT(4, 5); - virtual void SendMode(const MessageSource &source, User *u, const char *fmt, ...) ATTR_FORMAT(4, 5); + virtual void SendModeInternal(const MessageSource &source, Channel *chan, const Anope::string &modes, const std::vector<Anope::string> &values); + template <typename... Args> + void SendMode(const MessageSource &source, Channel *chan, const Anope::string &modes, Args &&...args) + { + SendModeInternal(source, chan, modes, { stringify(args)... }); + } + + virtual void SendModeInternal(const MessageSource &source, User *u, const Anope::string &modes, const std::vector<Anope::string> &values); + template <typename... Args> + void SendMode(const MessageSource &source, User *u, const Anope::string &modes, Args &&...args) + { + SendModeInternal(source, u, modes, { stringify(args)... }); + } /** Introduces a client to the rest of the network * @param u The client to introduce diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index 56efb5ce4..a82f63bd8 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -47,19 +47,23 @@ public: MaxModes = 60; } - void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) override + void SendModeInternal(const MessageSource &source, Channel *chan, const Anope::string &modes, const std::vector<Anope::string> &values) override { if (Servers::Capab.count("TSMODE") > 0) { - UplinkSocket::Message(source) << "MODE " << dest->name << " " << dest->creation_time << " " << buf; + auto params = values; + params.insert(params.begin(), { chan->name, stringify(chan->creation_time), modes }); + Uplink::SendInternal({}, source, "MODE", params); } else - IRCDProto::SendModeInternal(source, dest, buf); + IRCDProto::SendModeInternal(source, chan, modes, values); } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override + void SendModeInternal(const MessageSource &source, User* u, const Anope::string &modes, const std::vector<Anope::string> &values) override { - UplinkSocket::Message(source) << "SVSMODE " << u->nick << " " << u->timestamp << " " << buf; + auto params = values; + params.insert(params.begin(), { u->nick, stringify(u->timestamp), modes }); + Uplink::SendInternal({}, source, "SVSMODE", params); } void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) override @@ -283,12 +287,12 @@ public: void SendLogin(User *u, NickAlias *) override { - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %ld", (unsigned long)u->signon); + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", u->signon); } void SendLogout(User *u) override { - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d 1"); + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", 1); } }; diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index f67f72d24..cbb4270b4 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -205,15 +205,17 @@ public: UplinkSocket::Message(Me) << "EOB"; } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override + void SendModeInternal(const MessageSource &source, User* u, const Anope::string &modes, const std::vector<Anope::string> &values) override { - UplinkSocket::Message(source) << "SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf; + auto params = values; + params.insert(params.begin(), { u->GetUID(), stringify(u->timestamp), modes }); + Uplink::SendInternal({}, source, "SVSMODE", params); } void SendLogin(User *u, NickAlias *na) override { if (UseSVSAccount == false) - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->nc->display.c_str()); + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", na->nc->display); else UplinkSocket::Message(Me) << "SVSACCOUNT " << u->GetUID() << " " << u->timestamp << " " << na->nc->display; } @@ -221,7 +223,7 @@ public: void SendLogout(User *u) override { if (UseSVSAccount == false) - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d *"); + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", '*'); else UplinkSocket::Message(Me) << "SVSACCOUNT " << u->GetUID() << " " << u->timestamp << " *"; } diff --git a/modules/protocol/inspircd.cpp b/modules/protocol/inspircd.cpp index cef005f83..fd4771a7d 100644 --- a/modules/protocol/inspircd.cpp +++ b/modules/protocol/inspircd.cpp @@ -299,13 +299,15 @@ public: void SendNumericInternal(int numeric, const Anope::string &dest, const std::vector<Anope::string> ¶ms) override { auto newparams = params; - newparams.insert(newparams.begin(), { Me->GetSID(), dest, numeric }); + newparams.insert(newparams.begin(), { Me->GetSID(), dest, stringify(numeric) }); Uplink::SendInternal({}, Me, numeric, newparams); } - void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) override + void SendModeInternal(const MessageSource &source, Channel *chan, const Anope::string &modes, const std::vector<Anope::string> &values) override { - UplinkSocket::Message(source) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf; + auto params = values; + params.insert(params.begin(), { chan->name, stringify(chan->creation_time), modes }); + Uplink::SendInternal({}, source, "FMODE", params); } void SendClientIntroduction(User *u) override diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index f68cb8072..bcf31155c 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -139,9 +139,11 @@ public: UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 255.255.255.255 " << u->GetUID() << " 0 " << u->host << " :" << u->realname; } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override + void SendModeInternal(const MessageSource &source, User* u, const Anope::string &modes, const std::vector<Anope::string> &values) override { - UplinkSocket::Message(source) << "ENCAP * SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf; + auto params = values; + params.insert(params.begin(), { "*", "SVSMODE", u->GetUID(), stringify(u->timestamp), modes }); + Uplink::SendInternal({}, source, "ENCAP", params); } void SendLogin(User *u, NickAlias *na) override diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index 361acb007..d76ad9c15 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -53,7 +53,7 @@ public: void SendAkillDel(const XLine *x) override { hybrid->SendAkillDel(x); } void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { hybrid->SendJoin(user, c, status); } void SendServer(const Server *server) override { hybrid->SendServer(server); } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override { hybrid->SendModeInternal(source, u, buf); } + void SendModeInternal(const MessageSource &source, User *u, const Anope::string &modes, const std::vector<Anope::string> &values) override { hybrid->SendModeInternal(source, u, modes, values); } void SendChannel(Channel *c) override { hybrid->SendChannel(c); } bool IsIdentValid(const Anope::string &ident) override { return hybrid->IsIdentValid(ident); } diff --git a/modules/protocol/unrealircd.cpp b/modules/protocol/unrealircd.cpp index 0da73d441..0a3d2d094 100644 --- a/modules/protocol/unrealircd.cpp +++ b/modules/protocol/unrealircd.cpp @@ -134,10 +134,12 @@ private: user->KillInternal(source, buf); } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override + void SendModeInternal(const MessageSource &source, User *u, const Anope::string &modes, const std::vector<Anope::string> &values) override { - UplinkSocket::Message(source) << "SVS2MODE " << u->GetUID() <<" " << buf; - } + auto params = values; + params.insert(params.begin(), { u->GetUID(), modes }); + Uplink::SendInternal({}, source, "SVS2MODE", params); +} void SendClientIntroduction(User *u) override { @@ -350,14 +352,14 @@ private: { /* 3.2.10.4+ treats users logged in with accounts as fully registered, even if -r, so we can not set this here. Just use the timestamp. */ if (Servers::Capab.count("ESVID") > 0 && !na->nc->HasExt("UNCONFIRMED")) - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->nc->display.c_str()); + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", na->nc->display); else - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %ld", (unsigned long)u->signon); + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", u->signon); } void SendLogout(User *u) override { - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d 0"); + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", 0); } void SendChannel(Channel *c) override diff --git a/src/modes.cpp b/src/modes.cpp index 870081860..6cf99f61e 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -330,27 +330,33 @@ static StackerInfo *GetInfo(List &l, Object *o) * @param info The stacker info for a channel or user * @return a list of strings */ -static std::list<Anope::string> BuildModeStrings(StackerInfo *info) +static auto BuildModeStrings(StackerInfo *info) { - std::list<Anope::string> ret; + std::list<std::pair<Anope::string, std::vector<Anope::string>>> ret; std::list<std::pair<Mode *, Anope::string> >::iterator it, it_end; - Anope::string buf = "+", parambuf; + Anope::string buf = "+"; + std::vector<Anope::string> parambuf; unsigned NModes = 0; + size_t paramlen = 0; for (it = info->AddModes.begin(), it_end = info->AddModes.end(); it != it_end; ++it) { - if (++NModes > IRCD->MaxModes || (buf.length() + parambuf.length() > IRCD->MaxLine - 100)) // Leave room for command, channel, etc + if (++NModes > IRCD->MaxModes || (buf.length() + paramlen > IRCD->MaxLine - 100)) // Leave room for command, channel, etc { - ret.push_back(buf + parambuf); + ret.push_back({buf, parambuf}); buf = "+"; parambuf.clear(); + paramlen = 0; NModes = 1; } buf += it->first->mchar; if (!it->second.empty()) - parambuf += " " + it->second; + { + parambuf.push_back(it->second); + paramlen += it->second.length() + 1; + } } if (buf[buf.length() - 1] == '+') @@ -359,25 +365,29 @@ static std::list<Anope::string> BuildModeStrings(StackerInfo *info) buf += "-"; for (it = info->DelModes.begin(), it_end = info->DelModes.end(); it != it_end; ++it) { - if (++NModes > IRCD->MaxModes || (buf.length() + parambuf.length() > IRCD->MaxLine - 100)) // Leave room for command, channel, etc + if (++NModes > IRCD->MaxModes || (buf.length() + paramlen > IRCD->MaxLine - 100)) // Leave room for command, channel, etc { - ret.push_back(buf + parambuf); + ret.push_back({buf, parambuf}); buf = "-"; parambuf.clear(); + paramlen = 0; NModes = 1; } buf += it->first->mchar; if (!it->second.empty()) - parambuf += " " + it->second; + { + parambuf.push_back(it->second); + paramlen += it->second.length() + 1; + } } if (buf[buf.length() - 1] == '-') buf.erase(buf.length() - 1); if (!buf.empty()) - ret.push_back(buf + parambuf); + ret.push_back({buf, parambuf}); return ret; } @@ -632,7 +642,7 @@ void ModeManager::ProcessModes() for (const auto &[u, s] : UserStackerObjects) { for (const auto &modestr : BuildModeStrings(s)) - IRCD->SendMode(s->bi, u, "%s", modestr.c_str()); + IRCD->SendModeInternal(s->bi, u, modestr.first, modestr.second); delete s; } UserStackerObjects.clear(); @@ -643,7 +653,7 @@ void ModeManager::ProcessModes() for (const auto &[c, s] : ChannelStackerObjects) { for (const auto &modestr : BuildModeStrings(s)) - IRCD->SendMode(s->bi, c, "%s", modestr.c_str()); + IRCD->SendModeInternal(s->bi, c, modestr.first, modestr.second); delete s; } ChannelStackerObjects.clear(); @@ -658,7 +668,7 @@ static void StackerDel(std::map<T *, StackerInfo *> &map, T *obj) { StackerInfo *si = it->second; for (const auto &modestr : BuildModeStrings(si)) - IRCD->SendMode(si->bi, obj, "%s", modestr.c_str()); + IRCD->SendModeInternal(si->bi, obj, modestr.first, modestr.second); delete si; map.erase(it); diff --git a/src/protocol.cpp b/src/protocol.cpp index 41df1dadc..cfa03d3d8 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -95,14 +95,18 @@ void IRCDProto::SendSVSKillInternal(const MessageSource &source, User *user, con Uplink::Send(source, "KILL", user->GetUID(), buf); } -void IRCDProto::SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) +void IRCDProto::SendModeInternal(const MessageSource &source, Channel *chan, const Anope::string &modes, const std::vector<Anope::string> &values) { - UplinkSocket::Message(source) << "MODE " << dest->name << " " << buf; + auto params = values; + params.insert(params.begin(), { chan->name, modes }); + Uplink::SendInternal({}, source, "MODE", params); } -void IRCDProto::SendModeInternal(const MessageSource &source, User *dest, const Anope::string &buf) +void IRCDProto::SendModeInternal(const MessageSource &source, User *dest, const Anope::string &modes, const std::vector<Anope::string> &values) { - UplinkSocket::Message(source) << "MODE " << dest->GetUID() << " " << buf; + auto params = values; + params.insert(params.begin(), { dest->GetUID(), modes }); + Uplink::SendInternal({}, source, "MODE", params); } void IRCDProto::SendKickInternal(const MessageSource &source, const Channel *c, User *u, const Anope::string &r) @@ -181,26 +185,6 @@ void IRCDProto::SendSVSKill(const MessageSource &source, User *user, const char SendSVSKillInternal(source, user, buf); } -void IRCDProto::SendMode(const MessageSource &source, const Channel *dest, const char *fmt, ...) -{ - va_list args; - char buf[BUFSIZE] = ""; - va_start(args, fmt); - vsnprintf(buf, BUFSIZE - 1, fmt, args); - va_end(args); - SendModeInternal(source, dest, buf); -} - -void IRCDProto::SendMode(const MessageSource &source, User *u, const char *fmt, ...) -{ - va_list args; - char buf[BUFSIZE] = ""; - va_start(args, fmt); - vsnprintf(buf, BUFSIZE - 1, fmt, args); - va_end(args); - SendModeInternal(source, u, buf); -} - void IRCDProto::SendKick(const MessageSource &source, const Channel *chan, User *user, const char *fmt, ...) { if (!chan || !user) |