mirror of
https://github.com/anope/anope.git
synced 2026-06-12 19:14:47 +02:00
Rework SendModeInternal to be usable with Uplink::Send.
This commit is contained in:
+13
-4
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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 << " *";
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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); }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
+23
-13
@@ -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);
|
||||
|
||||
+8
-24
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user