mirror of
https://github.com/anope/anope.git
synced 2026-06-12 19:14:47 +02:00
Change Channel::SetModesInternal to take a split mode change.
This commit is contained in:
+1
-1
@@ -215,7 +215,7 @@ public:
|
||||
* @param mode the modes
|
||||
* @param enforce_mlock true to enforce mlock
|
||||
*/
|
||||
void SetModesInternal(MessageSource &source, const Anope::string &mode, time_t ts = 0, bool enforce_mlock = true);
|
||||
void SetModesInternal(MessageSource &source, const Anope::string &modes, const std::vector<Anope::string> ¶ms, time_t ts = 0, bool enforce_mlock = true);
|
||||
|
||||
/** Does the given user match the given list? (CMODE_BAN, CMODE_EXCEPT, etc, a list mode)
|
||||
* @param u The user
|
||||
|
||||
+3
-2
@@ -66,10 +66,11 @@ namespace Message
|
||||
* @param source The source of the SJOIN
|
||||
* @param chan The channel the users are joining to
|
||||
* @param ts The TS for the channel
|
||||
* @param modes The modes sent with the SJOIN, if any
|
||||
* @param modes The mode letters sent with the SJOIN, if any
|
||||
* @param modeparams The mode parameters sent with the SJOIN, if any
|
||||
* @param users The users and their status, if any
|
||||
*/
|
||||
static void SJoin(MessageSource &source, const Anope::string &chan, time_t ts, const Anope::string &modes, const std::list<SJoinUser> &users);
|
||||
static void SJoin(MessageSource &source, const Anope::string &chan, time_t ts, const Anope::string &modes, const std::vector<Anope::string> &modeparams, const std::list<SJoinUser> &users);
|
||||
};
|
||||
|
||||
struct CoreExport Kick
|
||||
|
||||
@@ -312,12 +312,8 @@ struct IRCDMessageMode final
|
||||
Channel *c = Channel::Find(params[0]);
|
||||
auto ts = IRCD->ExtractTimestamp(params[1]);
|
||||
|
||||
Anope::string modes = params[2];
|
||||
for (unsigned int i = 3; i < params.size(); ++i)
|
||||
modes += " " + params[i];
|
||||
|
||||
if (c)
|
||||
c->SetModesInternal(source, modes, ts);
|
||||
c->SetModesInternal(source, params[2], { params.begin() + 3, params.end() }, ts);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -400,11 +396,12 @@ struct IRCDMessageSJoin final
|
||||
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override
|
||||
{
|
||||
Anope::string modes;
|
||||
std::vector<Anope::string> modeparams;
|
||||
if (params.size() >= 4)
|
||||
for (unsigned i = 2; i < params.size(); ++i)
|
||||
modes += " " + params[i];
|
||||
if (!modes.empty())
|
||||
modes.erase(modes.begin());
|
||||
{
|
||||
modes = params[2];
|
||||
modeparams = { params.begin() + 3, params.end() };
|
||||
}
|
||||
|
||||
std::list<Message::Join::SJoinUser> users;
|
||||
|
||||
@@ -445,7 +442,7 @@ struct IRCDMessageSJoin final
|
||||
}
|
||||
|
||||
auto ts = IRCD->ExtractTimestamp(params[0]);
|
||||
Message::Join::SJoin(source, params[1], ts, modes, users);
|
||||
Message::Join::SJoin(source, params[1], ts, modes, modeparams, users);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -547,14 +547,6 @@ struct IRCDMessageSJoin final
|
||||
/* :0MC SJOIN 1654877335 #nether +nt :@0MCAAAAAB +0MCAAAAAC */
|
||||
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override
|
||||
{
|
||||
Anope::string modes;
|
||||
|
||||
for (unsigned i = 2; i < params.size() - 1; ++i)
|
||||
modes += " " + params[i];
|
||||
|
||||
if (!modes.empty())
|
||||
modes.erase(modes.begin());
|
||||
|
||||
std::list<Message::Join::SJoinUser> users;
|
||||
|
||||
spacesepstream sep(params[params.size() - 1]);
|
||||
@@ -582,7 +574,7 @@ struct IRCDMessageSJoin final
|
||||
}
|
||||
|
||||
auto ts = IRCD->ExtractTimestamp(params[0]);
|
||||
Message::Join::SJoin(source, params[1], ts, modes, users);
|
||||
Message::Join::SJoin(source, params[1], ts, params[2], { params.begin() + 3, params.end() - 1 }, users);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -637,13 +629,9 @@ struct IRCDMessageTMode final
|
||||
{
|
||||
auto ts = IRCD->ExtractTimestamp(params[0]);
|
||||
Channel *c = Channel::Find(params[1]);
|
||||
Anope::string modes = params[2];
|
||||
|
||||
for (unsigned i = 3; i < params.size(); ++i)
|
||||
modes += " " + params[i];
|
||||
|
||||
if (c)
|
||||
c->SetModesInternal(source, modes, ts);
|
||||
c->SetModesInternal(source, params[2], { params.begin() + 3, params.end() }, ts);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -2056,15 +2056,6 @@ struct IRCDMessageFJoin final
|
||||
|
||||
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override
|
||||
{
|
||||
Anope::string modes;
|
||||
if (params.size() >= 3)
|
||||
{
|
||||
for (unsigned i = 2; i < params.size() - 1; ++i)
|
||||
modes += " " + params[i];
|
||||
if (!modes.empty())
|
||||
modes.erase(modes.begin());
|
||||
}
|
||||
|
||||
std::list<Message::Join::SJoinUser> users;
|
||||
|
||||
spacesepstream sep(params[params.size() - 1]);
|
||||
@@ -2102,7 +2093,7 @@ struct IRCDMessageFJoin final
|
||||
}
|
||||
|
||||
auto ts = IRCD->ExtractTimestamp(params[1]);
|
||||
Message::Join::SJoin(source, params[0], ts, modes, users);
|
||||
Message::Join::SJoin(source, params[0], ts, params[2], { params.begin() + 3, params.end() - 1 }, users);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2114,15 +2105,10 @@ struct IRCDMessageFMode final
|
||||
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override
|
||||
{
|
||||
/* :source FMODE #test 12345678 +nto foo */
|
||||
|
||||
Anope::string modes = params[2];
|
||||
for (unsigned n = 3; n < params.size(); ++n)
|
||||
modes += " " + params[n];
|
||||
|
||||
Channel *c = Channel::Find(params[0]);
|
||||
auto ts = IRCD->ExtractTimestamp(params[1]);
|
||||
if (c)
|
||||
c->SetModesInternal(source, modes, ts);
|
||||
c->SetModesInternal(source, params[2], { params.begin() + 3, params.end() }, ts);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2198,7 +2184,7 @@ struct IRCDMessageIJoin final
|
||||
|
||||
std::list<Message::Join::SJoinUser> users;
|
||||
users.push_back(user);
|
||||
Message::Join::SJoin(source, params[0], chants, "", users);
|
||||
Message::Join::SJoin(source, params[0], chants, "", {}, users);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2250,12 +2236,8 @@ struct IRCDMessageMode final
|
||||
{
|
||||
Channel *c = Channel::Find(params[0]);
|
||||
|
||||
Anope::string modes = params[1];
|
||||
for (unsigned n = 2; n < params.size(); ++n)
|
||||
modes += " " + params[n];
|
||||
|
||||
if (c)
|
||||
c->SetModesInternal(source, modes);
|
||||
c->SetModesInternal(source, params[2], { params.begin() + 3, params.end() });
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+10
-13
@@ -224,7 +224,7 @@ struct IRCDMessageChaninfo final
|
||||
bool created;
|
||||
Channel *c = Channel::FindOrCreate(params[0], created);
|
||||
|
||||
Anope::string modes = params[1];
|
||||
std::vector<Anope::string> modeparams;
|
||||
|
||||
if (params.size() == 3)
|
||||
{
|
||||
@@ -237,17 +237,17 @@ struct IRCDMessageChaninfo final
|
||||
switch(params[1][i])
|
||||
{
|
||||
case 'k':
|
||||
modes += " " + params[2];
|
||||
modeparams.push_back(params[2]);
|
||||
continue;
|
||||
case 'l':
|
||||
modes += " " + params[3];
|
||||
modeparams.push_back(params[3]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
c->ChangeTopicInternal(NULL, source.GetName(), params[4], Anope::CurTime);
|
||||
}
|
||||
|
||||
c->SetModesInternal(source, modes);
|
||||
c->SetModesInternal(source, params[1], modeparams);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -267,11 +267,13 @@ struct IRCDMessageJoin final
|
||||
User *user = source.GetUser();
|
||||
size_t pos = params[0].find('\7');
|
||||
Anope::string channel, modes;
|
||||
std::vector<Anope::string> modeparams;
|
||||
|
||||
if (pos != Anope::string::npos)
|
||||
{
|
||||
channel = params[0].substr(0, pos);
|
||||
modes = '+' + params[0].substr(pos+1, params[0].length()) + " " + user->nick;
|
||||
modes = '+' + params[0].substr(pos+1, params[0].length());
|
||||
modeparams.push_back(user->nick);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -287,7 +289,7 @@ struct IRCDMessageJoin final
|
||||
{
|
||||
Channel *c = Channel::Find(channel);
|
||||
if (c)
|
||||
c->SetModesInternal(source, modes);
|
||||
c->SetModesInternal(source, modes, modeparams);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -367,17 +369,12 @@ struct IRCDMessageMode final
|
||||
|
||||
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override
|
||||
{
|
||||
Anope::string modes = params[1];
|
||||
|
||||
for (size_t i = 2; i < params.size(); ++i)
|
||||
modes += " " + params[i];
|
||||
|
||||
if (IRCD->IsChannelValid(params[0]))
|
||||
{
|
||||
Channel *c = Channel::Find(params[0]);
|
||||
|
||||
if (c)
|
||||
c->SetModesInternal(source, modes);
|
||||
c->SetModesInternal(source, params[1], { params.begin() + 2, params.end() });
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -485,7 +482,7 @@ struct IRCDMessageNJoin final
|
||||
users.push_back(sju);
|
||||
}
|
||||
|
||||
Message::Join::SJoin(source, params[0], 0, "", users);
|
||||
Message::Join::SJoin(source, params[0], 0, "", {}, users);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1147,10 +1147,7 @@ struct IRCDMessageMode final
|
||||
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override
|
||||
{
|
||||
auto final_is_ts = server_ts && source.GetServer() != NULL;
|
||||
|
||||
Anope::string modes = params[1];
|
||||
for (unsigned i = 2; i < params.size() - (final_is_ts ? 1 : 0); ++i)
|
||||
modes += " " + params[i];
|
||||
auto last_param = params.end() - (final_is_ts ? 1 : 0);
|
||||
|
||||
if (IRCD->IsChannelValid(params[0]))
|
||||
{
|
||||
@@ -1158,7 +1155,7 @@ struct IRCDMessageMode final
|
||||
auto ts = final_is_ts ? IRCD->ExtractTimestamp(params.back()) : 0;
|
||||
|
||||
if (c)
|
||||
c->SetModesInternal(source, modes, ts);
|
||||
c->SetModesInternal(source, params[2], { params.begin() + 3, last_param }, ts);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1420,11 +1417,12 @@ struct IRCDMessageSJoin final
|
||||
void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override
|
||||
{
|
||||
Anope::string modes;
|
||||
std::vector<Anope::string> modeparams;
|
||||
if (params.size() >= 4)
|
||||
for (unsigned i = 2; i < params.size() - 1; ++i)
|
||||
modes += " " + params[i];
|
||||
if (!modes.empty())
|
||||
modes.erase(modes.begin());
|
||||
{
|
||||
modes = params[2];
|
||||
modeparams = { params.begin() + 3, params.end() };
|
||||
}
|
||||
|
||||
std::list<Anope::string> bans, excepts, invites;
|
||||
std::list<Message::Join::SJoinUser> users;
|
||||
@@ -1474,7 +1472,7 @@ struct IRCDMessageSJoin final
|
||||
}
|
||||
|
||||
auto ts = IRCD->ExtractTimestamp(params[0]);
|
||||
Message::Join::SJoin(source, params[1], ts, modes, users);
|
||||
Message::Join::SJoin(source, params[1], ts, modes, modeparams, users);
|
||||
|
||||
if (!bans.empty() || !excepts.empty() || !invites.empty())
|
||||
{
|
||||
|
||||
+13
-15
@@ -611,13 +611,13 @@ void Channel::SetModes(BotInfo *bi, bool enforce_mlock, const Anope::string &cmo
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, time_t ts, bool enforce_mlock)
|
||||
void Channel::SetModesInternal(MessageSource &source, const Anope::string &modes, const std::vector<Anope::string> ¶ms, time_t ts, bool enforce_mlock)
|
||||
{
|
||||
if (!ts)
|
||||
;
|
||||
else if (ts > this->creation_time)
|
||||
{
|
||||
Log(LOG_DEBUG) << "Dropping mode " << mode << " on " << this->name << ", " << ts << " > " << this->creation_time;
|
||||
Log(LOG_DEBUG) << "Dropping mode " << modes << " on " << this->name << ", " << ts << " > " << this->creation_time;
|
||||
return;
|
||||
}
|
||||
else if (ts < this->creation_time)
|
||||
@@ -631,20 +631,18 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode,
|
||||
/* Removing channel modes *may* delete this channel */
|
||||
Reference<Channel> this_reference(this);
|
||||
|
||||
spacesepstream sep_modes(mode);
|
||||
Anope::string m;
|
||||
|
||||
sep_modes.GetToken(m);
|
||||
|
||||
Anope::string modestring;
|
||||
Anope::string paramstring;
|
||||
int add = -1;
|
||||
bool changed = false;
|
||||
for (unsigned int i = 0, end = m.length(); i < end && this_reference; ++i)
|
||||
auto paramit = params.begin();
|
||||
for (const auto mchar : modes)
|
||||
{
|
||||
ChannelMode *cm;
|
||||
if (!this_reference)
|
||||
break;
|
||||
|
||||
switch (m[i])
|
||||
ChannelMode *cm;
|
||||
switch (mchar)
|
||||
{
|
||||
case '+':
|
||||
modestring += '+';
|
||||
@@ -657,10 +655,10 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode,
|
||||
default:
|
||||
if (add == -1)
|
||||
continue;
|
||||
cm = ModeManager::FindChannelModeByChar(m[i]);
|
||||
cm = ModeManager::FindChannelModeByChar(mchar);
|
||||
if (!cm)
|
||||
{
|
||||
Log(LOG_DEBUG) << "Channel::SetModeInternal: Unknown mode char " << m[i];
|
||||
Log(LOG_DEBUG) << "Channel::SetModeInternal: Unknown mode char " << mchar;
|
||||
continue;
|
||||
}
|
||||
modestring += cm->mchar;
|
||||
@@ -686,9 +684,9 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode,
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Anope::string token;
|
||||
if (sep_modes.GetToken(token))
|
||||
if (paramit != params.end())
|
||||
{
|
||||
auto token = *paramit++;
|
||||
User *u = NULL;
|
||||
if (cm->type == MODE_STATUS && (u = User::Find(token)))
|
||||
paramstring += " " + u->nick;
|
||||
@@ -703,7 +701,7 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode,
|
||||
this->RemoveModeInternal(source, cm, token, enforce_mlock);
|
||||
}
|
||||
else
|
||||
Log() << "warning: Channel::SetModesInternal() received more modes requiring params than params, modes: " << mode;
|
||||
Log() << "warning: Channel::SetModesInternal() received more modes requiring params than params, modes: " << modes;
|
||||
}
|
||||
|
||||
if (!this_reference)
|
||||
|
||||
+4
-4
@@ -98,11 +98,11 @@ void Join::Run(MessageSource &source, const std::vector<Anope::string> ¶ms,
|
||||
users.emplace_back(ChannelStatus(), user);
|
||||
|
||||
Channel *chan = Channel::Find(channel);
|
||||
SJoin(source, channel, chan ? chan->creation_time : Anope::CurTime, "", users);
|
||||
SJoin(source, channel, chan ? chan->creation_time : Anope::CurTime, "", {}, users);
|
||||
}
|
||||
}
|
||||
|
||||
void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, const Anope::string &modes, const std::list<SJoinUser> &users)
|
||||
void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, const Anope::string &modes, const std::vector<Anope::string> &modeparams, const std::list<SJoinUser> &users)
|
||||
{
|
||||
bool created;
|
||||
Channel *c = Channel::FindOrCreate(chan, created, ts ? ts : Anope::CurTime);
|
||||
@@ -128,7 +128,7 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co
|
||||
/* If we are syncing, mlock is checked later in Channel::Sync. It is important to not check it here
|
||||
* so that Channel::SetCorrectModes can correctly detect the presence of channel mode +r.
|
||||
*/
|
||||
c->SetModesInternal(source, modes, ts, !c->syncing);
|
||||
c->SetModesInternal(source, modes, modeparams, ts, !c->syncing);
|
||||
|
||||
for (const auto &[status, u] : users)
|
||||
{
|
||||
@@ -223,7 +223,7 @@ void Message::Mode::Run(MessageSource &source, const std::vector<Anope::string>
|
||||
Channel *c = Channel::Find(params[0]);
|
||||
|
||||
if (c)
|
||||
c->SetModesInternal(source, buf.substr(1), 0);
|
||||
c->SetModesInternal(source, params[1], { params.begin() + 2, params.end() });
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user