summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2024-10-02 15:00:58 +0100
committerSadie Powell <sadie@witchery.services>2024-10-02 23:54:36 +0100
commit2f745132461080b4773e878d0cafb68de99a7e67 (patch)
tree01aba256ac36c6404241370de1bb67d8b9d1cd94 /src
parent94dbb1959308116c4edf411eb5e88d7ad871286d (diff)
Change User::SetModesInternal to take a split mode change.
Diffstat (limited to 'src')
-rw-r--r--src/bots.cpp19
-rw-r--r--src/messages.cpp6
-rw-r--r--src/servers.cpp10
-rw-r--r--src/users.cpp21
4 files changed, 34 insertions, 22 deletions
diff --git a/src/bots.cpp b/src/bots.cpp
index 0fb5c682d..b109f8680 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -20,7 +20,11 @@
Serialize::Checker<botinfo_map> BotListByNick("BotInfo"), BotListByUID("BotInfo");
-BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", IRCD ? IRCD->UID_Retrieve() : "", NULL), Serializable("BotInfo"), channels("ChannelInfo"), botmodes(bmodes)
+BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes)
+ : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", {}, IRCD ? IRCD->UID_Retrieve() : "", NULL)
+ , Serializable("BotInfo")
+ , channels("ChannelInfo")
+ , botmodes(bmodes)
{
this->lastmsg = this->created = Anope::CurTime;
this->introduced = false;
@@ -35,9 +39,16 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A
// If we're synchronised with the uplink already, send the bot.
if (Me && Me->IsSynced())
{
- Anope::string tmodes = !this->botmodes.empty() ? ("+" + this->botmodes) : IRCD->DefaultPseudoclientModes;
- if (!tmodes.empty())
- this->SetModesInternal(this, tmodes);
+ spacesepstream modesep(this->botmodes.empty() ? IRCD->DefaultPseudoclientModes : "+" + this->botmodes);
+
+ Anope::string modechars;
+ modesep.GetToken(modechars);
+
+ std::vector<Anope::string> modeparams;
+ modesep.GetTokens(modeparams);
+
+ if (!modechars.empty())
+ this->SetModesInternal(this, modechars, modeparams);
XLine x(this->nick, "Reserved for services");
IRCD->SendSQLine(NULL, &x);
diff --git a/src/messages.cpp b/src/messages.cpp
index 9e6f6ebb0..b21a27f37 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -214,10 +214,6 @@ void Kill::Run(MessageSource &source, const std::vector<Anope::string> &params,
void Message::Mode::Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags)
{
- Anope::string buf;
- for (unsigned i = 1; i < params.size(); ++i)
- buf += " " + params[i];
-
if (IRCD->IsChannelValid(params[0]))
{
Channel *c = Channel::Find(params[0]);
@@ -230,7 +226,7 @@ void Message::Mode::Run(MessageSource &source, const std::vector<Anope::string>
User *u = User::Find(params[0]);
if (u)
- u->SetModesInternal(source, buf.substr(1));
+ u->SetModesInternal(source, params[1], { params.begin() + 2, params.end() });
}
}
diff --git a/src/servers.cpp b/src/servers.cpp
index 1435ee743..ca418aec0 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -50,9 +50,15 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano
/* Now do mode related stuff as we know what modes exist .. */
for (auto &[_, bi] : *BotListByNick)
{
- Anope::string modes = !bi->botmodes.empty() ? ("+" + bi->botmodes) : IRCD->DefaultPseudoclientModes;
+ spacesepstream modesep(bi->botmodes.empty() ? IRCD->DefaultPseudoclientModes : "+" + bi->botmodes);
- bi->SetModesInternal(bi, modes);
+ Anope::string modechars;
+ modesep.GetToken(modechars);
+
+ std::vector<Anope::string> modeparams;
+ modesep.GetTokens(modeparams);
+
+ bi->SetModesInternal(bi, modechars, modeparams);
for (const auto &botchannel : bi->botchannels)
{
size_t h = botchannel.find('#');
diff --git a/src/users.cpp b/src/users.cpp
index 4e01c6989..e39114654 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -31,7 +31,8 @@ time_t MaxUserTime = 0;
std::list<User *> User::quitting_users;
-User::User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &uip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *account) : ip(uip)
+User::User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &uip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const std::vector<Anope::string> &smodeparams, const Anope::string &suid, NickCore *account)
+ : ip(uip)
{
if (snick.empty() || sident.empty() || shost.empty())
throw CoreException("Bad args passed to User::User");
@@ -49,7 +50,7 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope:
this->server = sserver;
this->realname = srealname;
this->timestamp = this->signon = ts;
- this->SetModesInternal(sserver, smodes);
+ this->SetModesInternal(sserver, smodes, smodeparams);
this->uid = suid;
this->super_admin = false;
this->nc = NULL;
@@ -110,7 +111,7 @@ static void Collide(User *u, const Anope::string &id, const Anope::string &type)
CollideKill(u, type);
}
-User *User::OnIntroduce(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *nc)
+User *User::OnIntroduce(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *nc, const std::vector<Anope::string> &smodeparams)
{
// How IRCds handle collisions varies a lot, for safety well just always kill both sides
// With properly set qlines, this can almost never happen anyway
@@ -132,7 +133,7 @@ User *User::OnIntroduce(const Anope::string &snick, const Anope::string &sident,
}
}
- return new User(snick, sident, shost, svhost, sip, sserver, srealname, ts, smodes, suid, nc);
+ return new User(snick, sident, shost, svhost, sip, sserver, srealname, ts, smodes, smodeparams, suid, nc);
}
void User::ChangeNick(const Anope::string &newnick, time_t ts)
@@ -672,16 +673,14 @@ void User::SetModes(BotInfo *bi, const Anope::string &umodes)
}
}
-void User::SetModesInternal(const MessageSource &source, const Anope::string &umodes)
+void User::SetModesInternal(const MessageSource &source, const Anope::string &umodes, const std::vector<Anope::string> &umodeparams)
{
if (this->server && this->server->IsSynced() && Anope::string(umodes) != "+")
Log(this, "mode") << "changes modes to " << umodes;
int add = -1;
- Anope::string modebuf;
- spacesepstream sep(umodes);
- sep.GetToken(modebuf);
- for (auto mode : modebuf)
+ auto paramit = umodeparams.begin();
+ for (const auto mode : umodes)
{
UserMode *um;
@@ -704,8 +703,8 @@ void User::SetModesInternal(const MessageSource &source, const Anope::string &um
if (add)
{
Anope::string sbuf;
- if (um->type == MODE_PARAM && sep.GetToken(sbuf))
- this->SetModeInternal(source, um, sbuf);
+ if (um->type == MODE_PARAM && paramit != umodeparams.end())
+ this->SetModeInternal(source, um, *paramit++);
else
this->SetModeInternal(source, um);
}