summaryrefslogtreecommitdiff
path: root/src/modes.cpp
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2024-02-21 20:45:38 +0000
committerSadie Powell <sadie@witchery.services>2024-02-22 00:14:08 +0000
commitaefbb4fbdab80a41c3f88566abcba4b92b2d36d5 (patch)
tree81b6ba768c99606101fbce39d54d9d521d1a1e20 /src/modes.cpp
parent9b77fdf5b680e4a084effe56345a9d01cfbf6f11 (diff)
Rework SendModeInternal to be usable with Uplink::Send.
Diffstat (limited to 'src/modes.cpp')
-rw-r--r--src/modes.cpp36
1 files changed, 23 insertions, 13 deletions
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);