summaryrefslogtreecommitdiff
path: root/modules/protocol
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2023-10-10 21:14:50 +0100
committerSadie Powell <sadie@witchery.services>2023-10-11 15:51:52 +0100
commita3241065c55fd2a69e8793b89a5d0b1a957b3fd0 (patch)
tree82f80ce2f3bbbdc1c1ef05fe611093cf0b34eab6 /modules/protocol
parentdc371aad6d059dbf7f30f6878c680532bedd4146 (diff)
Start migrating to range-based for loops.
Diffstat (limited to 'modules/protocol')
-rw-r--r--modules/protocol/bahamut.cpp10
-rw-r--r--modules/protocol/hybrid.cpp14
-rw-r--r--modules/protocol/inspircd.cpp22
-rw-r--r--modules/protocol/ngircd.cpp12
-rw-r--r--modules/protocol/plexus.cpp4
-rw-r--r--modules/protocol/ratbox.cpp6
-rw-r--r--modules/protocol/solanum.cpp7
-rw-r--r--modules/protocol/unrealircd.cpp70
8 files changed, 70 insertions, 75 deletions
diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp
index dec19e029..608d3d869 100644
--- a/modules/protocol/bahamut.cpp
+++ b/modules/protocol/bahamut.cpp
@@ -176,8 +176,8 @@ class BahamutIRCdProto : public IRCDProto
uc->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
+ for (auto mode : cs.Modes())
+ c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
@@ -191,9 +191,9 @@ class BahamutIRCdProto : public IRCDProto
if (!u)
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
- this->SendAkill(it->second, x);
+ for (const auto &[_, user] : UserListByNick)
+ if (x->manager->Check(user, x))
+ this->SendAkill(user, x);
return;
}
diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp
index 9ca7aed33..c554cc19d 100644
--- a/modules/protocol/hybrid.cpp
+++ b/modules/protocol/hybrid.cpp
@@ -122,8 +122,8 @@ class HybridProto : public IRCDProto
uc->status.Clear();
BotInfo *setter = BotInfo::Find(u->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), u->GetUID(), false);
+ for (auto mode : cs.Modes())
+ c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), u->GetUID(), false);
if (uc)
uc->status = cs;
@@ -140,9 +140,9 @@ class HybridProto : public IRCDProto
* No user (this akill was just added), and contains nick and/or realname.
* Find users that match and ban them.
*/
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
- this->SendAkill(it->second, x);
+ for (const auto &[_, user] : UserListByNick)
+ if (x->manager->Check(user, x))
+ this->SendAkill(user, x);
return;
}
@@ -305,10 +305,8 @@ class HybridProto : public IRCDProto
if (a == '-' || a == '_' || a == '.')
return false;
- for (i = 0; i < ident.length(); ++i)
+ for (const auto c : ident)
{
- const char &c = ident[i];
-
/* A tilde can only be used as the first character of a user name. */
if (c == '~' && i == 0)
continue;
diff --git a/modules/protocol/inspircd.cpp b/modules/protocol/inspircd.cpp
index 0e5b94f19..e91e54b57 100644
--- a/modules/protocol/inspircd.cpp
+++ b/modules/protocol/inspircd.cpp
@@ -101,8 +101,8 @@ class InspIRCdProto : public IRCDProto
void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) override
{
Anope::string mechlist;
- for (unsigned i = 0; i < mechanisms.size(); ++i)
- mechlist += "," + mechanisms[i];
+ for (const auto &mechanism : mechanisms)
+ mechlist += "," + mechanism;
UplinkSocket::Message(Me) << "METADATA * saslmechlist :" << (mechanisms.empty() ? "" : mechlist.substr(1));
}
@@ -235,9 +235,9 @@ class InspIRCdProto : public IRCDProto
if (!u)
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
- this->SendAkill(it->second, x);
+ for (const auto &[_, user] : UserListByNick)
+ if (x->manager->Check(user, x))
+ this->SendAkill(user, x);
return;
}
@@ -331,8 +331,8 @@ class InspIRCdProto : public IRCDProto
uc->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
+ for (auto mode : cs.Modes())
+ c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
@@ -498,10 +498,8 @@ class InspIRCdProto : public IRCDProto
if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
return false;
- for (unsigned i = 0; i < ident.length(); ++i)
+ for (auto c : ident)
{
- const char &c = ident[i];
-
if (c >= 'A' && c <= '}')
continue;
@@ -1639,8 +1637,8 @@ struct IRCDMessageIJoin : IRCDMessage
if (params.size() >= 4)
{
chants = params[2].is_pos_number_only() ? convertTo<unsigned>(params[2]) : 0;
- for (unsigned i = 0; i < params[3].length(); ++i)
- user.first.AddMode(params[3][i]);
+ for (auto mode : params[3])
+ user.first.AddMode(mode);
}
std::list<Message::Join::SJoinUser> users;
diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp
index 6e09ebe25..7b2fc908e 100644
--- a/modules/protocol/ngircd.cpp
+++ b/modules/protocol/ngircd.cpp
@@ -100,8 +100,8 @@ class ngIRCdProto : public IRCDProto
uc->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
+ for (auto mode : cs.Modes())
+ c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
@@ -157,13 +157,13 @@ struct IRCDMessage005 : IRCDMessage
{
size_t pos;
Anope::string parameter, data;
- for (unsigned i = 0, end = params.size(); i < end; ++i)
+ for (const auto &param : params)
{
- pos = params[i].find('=');
+ pos = param.find('=');
if (pos != Anope::string::npos)
{
- parameter = params[i].substr(0, pos);
- data = params[i].substr(pos+1, params[i].length());
+ parameter = param.substr(0, pos);
+ data = param.substr(pos+1, param.length());
if (parameter == "MODES")
{
unsigned maxmodes = convertTo<unsigned>(data);
diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp
index c93f5e39a..679915b9d 100644
--- a/modules/protocol/plexus.cpp
+++ b/modules/protocol/plexus.cpp
@@ -69,8 +69,8 @@ class PlexusProto : public IRCDProto
uc->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
+ for (auto mode : cs.Modes())
+ c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp
index 490284407..1324fa057 100644
--- a/modules/protocol/ratbox.cpp
+++ b/modules/protocol/ratbox.cpp
@@ -24,9 +24,9 @@ class RatboxProto : public IRCDProto
if (bi && bi->introduced)
return bi;
- for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
- if (it->second->introduced)
- return it->second;
+ for (const auto &[_, bi] : *BotListByNick)
+ if (bi->introduced)
+ return bi;
return NULL;
}
diff --git a/modules/protocol/solanum.cpp b/modules/protocol/solanum.cpp
index e83f231dd..1ba740d04 100644
--- a/modules/protocol/solanum.cpp
+++ b/modules/protocol/solanum.cpp
@@ -69,11 +69,8 @@ class SolanumProto : public IRCDProto
void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) override
{
Anope::string mechlist;
-
- for (unsigned i = 0; i < mechanisms.size(); ++i)
- {
- mechlist += "," + mechanisms[i];
- }
+ for (const auto &mechanism : mechanisms)
+ mechlist += "," + mechanism;
UplinkSocket::Message(Me) << "ENCAP * MECHLIST :" << (mechanisms.empty() ? "" : mechlist.substr(1));
}
diff --git a/modules/protocol/unrealircd.cpp b/modules/protocol/unrealircd.cpp
index 6f4b75541..0195f8861 100644
--- a/modules/protocol/unrealircd.cpp
+++ b/modules/protocol/unrealircd.cpp
@@ -93,9 +93,9 @@ class UnrealIRCdProto : public IRCDProto
if (!u)
{
/* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */
- for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
- if (x->manager->Check(it->second, x))
- this->SendAkill(it->second, x);
+ for (const auto &[_, user] : UserListByNick)
+ if (x->manager->Check(user, x))
+ this->SendAkill(user, x);
return;
}
@@ -174,8 +174,8 @@ class UnrealIRCdProto : public IRCDProto
uc->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
- for (size_t i = 0; i < cs.Modes().length(); ++i)
- c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false);
+ for (auto mode : cs.Modes())
+ c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
@@ -237,8 +237,8 @@ class UnrealIRCdProto : public IRCDProto
void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) override
{
Anope::string mechlist;
- for (unsigned i = 0; i < mechanisms.size(); ++i)
- mechlist += "," + mechanisms[i];
+ for (const auto &mechanism : mechanisms)
+ mechlist += "," + mechanism;
UplinkSocket::Message() << "MD client " << Me->GetName() << " saslmechlist :" << (mechanisms.empty() ? "" : mechlist.substr(1));
}
@@ -421,10 +421,8 @@ class UnrealIRCdProto : public IRCDProto
if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
return false;
- for (unsigned i = 0; i < ident.length(); ++i)
+ for (auto c : ident)
{
- const char &c = ident[i];
-
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-')
continue;
@@ -750,16 +748,14 @@ struct IRCDMessageCapab : Message::Capab
void Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags) override
{
- for (unsigned i = 0; i < params.size(); ++i)
+ for (const auto &capab : params)
{
- Anope::string capab = params[i];
-
if (capab.find("USERMODES=") != Anope::string::npos)
{
Anope::string modebuf(capab.begin() + 10, capab.end());
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
+ for (auto mode : modebuf)
{
- switch (modebuf[t])
+ switch (mode)
{
case 'B':
ModeManager::AddUserMode(new UserMode("BOT", 'B'));
@@ -825,7 +821,7 @@ struct IRCDMessageCapab : Message::Capab
ModeManager::AddUserMode(new UserMode("SSLPRIV", 'Z'));
continue;
default:
- ModeManager::AddUserMode(new UserMode("", modebuf[t]));
+ ModeManager::AddUserMode(new UserMode("", mode));
}
}
}
@@ -836,9 +832,9 @@ struct IRCDMessageCapab : Message::Capab
Anope::string modebuf;
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
+ for (auto mode : modebuf)
{
- switch (modebuf[t])
+ switch (mode)
{
case 'b':
ModeManager::AddChannelMode(new ChannelModeList("BAN", 'b'));
@@ -862,14 +858,14 @@ struct IRCDMessageCapab : Message::Capab
ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I'));
continue;
default:
- ModeManager::AddChannelMode(new ChannelModeList("", modebuf[t]));
+ ModeManager::AddChannelMode(new ChannelModeList("", mode));
}
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
+ for (auto mode : modebuf)
{
- switch (modebuf[t])
+ switch (mode)
{
case 'k':
ModeManager::AddChannelMode(new ChannelModeKey('k'));
@@ -881,14 +877,14 @@ struct IRCDMessageCapab : Message::Capab
ModeManager::AddChannelMode(new ChannelModeParam("REDIRECT", 'L'));
continue;
default:
- ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t]));
+ ModeManager::AddChannelMode(new ChannelModeParam("", mode));
}
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
+ for (auto mode : modebuf)
{
- switch (modebuf[t])
+ switch (mode)
{
case 'l':
ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true));
@@ -897,14 +893,14 @@ struct IRCDMessageCapab : Message::Capab
ModeManager::AddChannelMode(new ChannelModeHistory('H'));
continue;
default:
- ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t], true));
+ ModeManager::AddChannelMode(new ChannelModeParam("", mode, true));
}
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.length(); t < end; ++t)
+ for (auto mode : modebuf)
{
- switch (modebuf[t])
+ switch (mode)
{
case 'p':
ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p'));
@@ -979,7 +975,7 @@ struct IRCDMessageCapab : Message::Capab
ModeManager::AddChannelMode(new ChannelModeOperOnly("PERM", 'P'));
continue;
default:
- ModeManager::AddChannelMode(new ChannelMode("", modebuf[t]));
+ ModeManager::AddChannelMode(new ChannelMode("", mode));
}
}
}
@@ -1475,14 +1471,20 @@ struct IRCDMessageSJoin : IRCDMessage
*invex = ModeManager::FindChannelModeByName("INVITEOVERRIDE");
if (ban)
- for (std::list<Anope::string>::iterator it = bans.begin(), it_end = bans.end(); it != it_end; ++it)
- c->SetModeInternal(source, ban, *it);
+ {
+ for (const auto &entry : bans)
+ c->SetModeInternal(source, ban, entry);
+ }
if (except)
- for (std::list<Anope::string>::iterator it = excepts.begin(), it_end = excepts.end(); it != it_end; ++it)
- c->SetModeInternal(source, except, *it);
+ {
+ for (const auto &entry : excepts)
+ c->SetModeInternal(source, except, entry);
+ }
if (invex)
- for (std::list<Anope::string>::iterator it = invites.begin(), it_end = invites.end(); it != it_end; ++it)
- c->SetModeInternal(source, invex, *it);
+ {
+ for (const auto &entry : invites)
+ c->SetModeInternal(source, invex, entry);
+ }
}
}
};