From a3241065c55fd2a69e8793b89a5d0b1a957b3fd0 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 10 Oct 2023 21:14:50 +0100 Subject: Start migrating to range-based for loops. --- include/anope.h | 8 +-- include/modules/httpd.h | 18 +++-- include/modules/ldap.h | 4 +- include/modules/redis.h | 4 +- include/modules/sql.h | 20 +++--- include/version.cpp | 4 +- modules/commands/bs_badwords.cpp | 4 +- modules/commands/bs_botlist.cpp | 8 +-- modules/commands/bs_info.cpp | 16 ++--- modules/commands/bs_kick.cpp | 29 ++++---- modules/commands/bs_set.cpp | 6 +- modules/commands/cs_access.cpp | 35 +++++----- modules/commands/cs_akick.cpp | 17 ++--- modules/commands/cs_clone.cpp | 10 ++- modules/commands/cs_enforce.cpp | 37 +++------- modules/commands/cs_entrymsg.cpp | 8 +-- modules/commands/cs_flags.cpp | 36 +++++----- modules/commands/cs_info.cpp | 4 +- modules/commands/cs_list.cpp | 12 ++-- modules/commands/cs_log.cpp | 24 +++---- modules/commands/cs_mode.cpp | 87 +++++++++++------------ modules/commands/cs_seen.cpp | 19 +++-- modules/commands/cs_set.cpp | 18 +++-- modules/commands/cs_set_misc.cpp | 7 +- modules/commands/cs_status.cpp | 6 +- modules/commands/cs_suspend.cpp | 7 +- modules/commands/cs_sync.cpp | 4 +- modules/commands/cs_unban.cpp | 12 ++-- modules/commands/cs_updown.cpp | 3 +- modules/commands/cs_xop.cpp | 35 +++++----- modules/commands/help.cpp | 18 ++--- modules/commands/hs_del.cpp | 4 +- modules/commands/hs_group.cpp | 3 +- modules/commands/hs_list.cpp | 8 +-- modules/commands/hs_request.cpp | 23 +++---- modules/commands/hs_set.cpp | 3 +- modules/commands/ms_ignore.cpp | 8 +-- modules/commands/ms_list.cpp | 4 +- modules/commands/ms_sendall.cpp | 4 +- modules/commands/ms_staff.cpp | 4 +- modules/commands/ns_ajoin.cpp | 11 ++- modules/commands/ns_alist.cpp | 11 ++- modules/commands/ns_cert.cpp | 8 +-- modules/commands/ns_getemail.cpp | 4 +- modules/commands/ns_group.cpp | 14 ++-- modules/commands/ns_info.cpp | 4 +- modules/commands/ns_list.cpp | 12 ++-- modules/commands/ns_recover.cpp | 8 +-- modules/commands/ns_register.cpp | 4 +- modules/commands/ns_set.cpp | 37 ++++------ modules/commands/ns_set_misc.cpp | 7 +- modules/commands/ns_suspend.cpp | 4 +- modules/commands/os_akill.cpp | 8 +-- modules/commands/os_chankill.cpp | 4 +- modules/commands/os_config.cpp | 20 +++--- modules/commands/os_defcon.cpp | 21 +++--- modules/commands/os_dns.cpp | 103 +++++++++++++--------------- modules/commands/os_forbid.cpp | 35 +++++----- modules/commands/os_ignore.cpp | 4 +- modules/commands/os_info.cpp | 7 +- modules/commands/os_list.cpp | 60 +++++++++------- modules/commands/os_logsearch.cpp | 4 +- modules/commands/os_mode.cpp | 9 +-- modules/commands/os_modinfo.cpp | 16 ++--- modules/commands/os_news.cpp | 18 ++--- modules/commands/os_noop.cpp | 4 +- modules/commands/os_oper.cpp | 38 +++++----- modules/commands/os_session.cpp | 21 +++--- modules/commands/os_stats.cpp | 10 +-- modules/commands/os_sxline.cpp | 31 ++++----- modules/cs_statusupdate.cpp | 20 +++--- modules/database/db_flatfile.cpp | 59 +++++++--------- modules/database/db_old.cpp | 26 +++---- modules/database/db_redis.cpp | 53 +++++--------- modules/database/db_sql.cpp | 22 +++--- modules/database/db_sql_live.cpp | 12 ++-- modules/encryption/enc_bcrypt.cpp | 4 +- modules/encryption/enc_sha256.cpp | 4 +- modules/extra/m_ldap.cpp | 14 ++-- modules/extra/m_ldap_oper.cpp | 4 +- modules/extra/m_mysql.cpp | 56 +++++++-------- modules/extra/m_regex_pcre.cpp | 9 +-- modules/extra/m_regex_pcre2.cpp | 9 +-- modules/extra/m_regex_posix.cpp | 9 +-- modules/extra/m_regex_tre.cpp | 9 +-- modules/extra/m_sql_log.cpp | 3 +- modules/extra/m_sql_oper.cpp | 4 +- modules/extra/m_sqlite.cpp | 47 +++++++------ modules/extra/stats/irc2sql/irc2sql.cpp | 11 ++- modules/m_dns.cpp | 29 +++----- modules/m_dnsbl.cpp | 14 ++-- modules/m_httpd.cpp | 25 +++---- modules/m_proxyscan.cpp | 14 ++-- modules/m_redis.cpp | 53 ++++++-------- modules/m_rewrite.cpp | 8 +-- modules/m_sasl.cpp | 8 +-- modules/m_xmlrpc.cpp | 8 +-- modules/m_xmlrpc_main.cpp | 34 ++++----- modules/ns_maxemail.cpp | 4 +- modules/protocol/bahamut.cpp | 10 +-- modules/protocol/hybrid.cpp | 14 ++-- modules/protocol/inspircd.cpp | 22 +++--- modules/protocol/ngircd.cpp | 12 ++-- modules/protocol/plexus.cpp | 4 +- modules/protocol/ratbox.cpp | 6 +- modules/protocol/solanum.cpp | 7 +- modules/protocol/unrealircd.cpp | 70 ++++++++++--------- modules/pseudoclients/botserv.cpp | 10 ++- modules/pseudoclients/chanserv.cpp | 15 ++-- modules/pseudoclients/global.cpp | 4 +- modules/pseudoclients/memoserv.cpp | 7 +- modules/pseudoclients/nickserv.cpp | 24 +++---- modules/pseudoclients/operserv.cpp | 4 +- modules/webcpanel/pages/chanserv/drop.cpp | 3 +- modules/webcpanel/pages/chanserv/modes.cpp | 9 +-- modules/webcpanel/pages/chanserv/utils.cpp | 4 +- modules/webcpanel/pages/memoserv/memos.cpp | 4 +- modules/webcpanel/pages/nickserv/access.cpp | 4 +- modules/webcpanel/pages/nickserv/alist.cpp | 4 +- modules/webcpanel/template_fileserver.cpp | 18 ++--- modules/webcpanel/webcpanel.h | 14 ++-- src/access.cpp | 33 ++++----- src/base.cpp | 4 +- src/bots.cpp | 4 +- src/channels.cpp | 45 ++++++------ src/command.cpp | 9 +-- src/config.cpp | 97 ++++++++++++++------------ src/extensible.cpp | 5 +- src/init.cpp | 26 +++---- src/logger.cpp | 46 ++++++------- src/mail.cpp | 16 +++-- src/memos.cpp | 6 +- src/messages.cpp | 14 ++-- src/misc.cpp | 53 +++++++------- src/modes.cpp | 45 +++++------- src/module.cpp | 4 +- src/modulemanager.cpp | 24 +++---- src/nickcore.cpp | 26 +++---- src/opertype.cpp | 48 +++++-------- src/protocol.cpp | 10 ++- src/regchannel.cpp | 20 +++--- src/serialize.cpp | 9 ++- src/servers.cpp | 67 +++++++++--------- src/uplink.cpp | 4 +- src/users.cpp | 27 ++++---- src/xline.cpp | 11 +-- 146 files changed, 1155 insertions(+), 1457 deletions(-) diff --git a/include/anope.h b/include/anope.h index 121ea716c..22094cf1d 100644 --- a/include/anope.h +++ b/include/anope.h @@ -254,8 +254,8 @@ namespace Anope inline string lower() const { Anope::string new_string = *this; - for (size_type i = 0; i < new_string.length(); ++i) - new_string[i] = Anope::tolower(new_string[i]); + for (auto &chr : new_string) + chr = Anope::tolower(chr); return new_string; } @@ -265,8 +265,8 @@ namespace Anope inline string upper() const { Anope::string new_string = *this; - for (size_type i = 0; i < new_string.length(); ++i) - new_string[i] = Anope::toupper(new_string[i]); + for (auto &chr : new_string) + chr = Anope::toupper(chr); return new_string; } diff --git a/include/modules/httpd.h b/include/modules/httpd.h index 544ba5ccd..207499d3b 100644 --- a/include/modules/httpd.h +++ b/include/modules/httpd.h @@ -35,14 +35,14 @@ struct HTTPReply headers = other.headers; cookies = other.cookies; - for (unsigned i = 0; i < other.out.size(); ++i) - out.push_back(new Data(other.out[i]->buf, other.out[i]->len)); + for (const auto &datum : other.out) + out.push_back(new Data(datum->buf, datum->len)); } ~HTTPReply() { - for (unsigned i = 0; i < out.size(); ++i) - delete out[i]; + for (const auto *datum : out) + delete datum; out.clear(); } @@ -196,10 +196,8 @@ namespace HTTPUtils { Anope::string encoded; - for (unsigned i = 0; i < url.length(); ++i) + for (const auto c : url) { - const char& c = url[i]; - if (isalnum(c) || c == '.' || c == '-' || c == '*' || c == '_') encoded += c; else if (c == ' ') @@ -215,9 +213,9 @@ namespace HTTPUtils { Anope::string dst; - for (unsigned i = 0; i < src.length(); ++i) + for (const auto c : src) { - switch (src[i]) + switch (c) { case '<': dst += "<"; @@ -232,7 +230,7 @@ namespace HTTPUtils dst += "&"; break; default: - dst += src[i]; + dst += c; } } diff --git a/include/modules/ldap.h b/include/modules/ldap.h index 8c448668e..34f73f65b 100644 --- a/include/modules/ldap.h +++ b/include/modules/ldap.h @@ -42,8 +42,8 @@ struct LDAPAttributes : public std::map keys() const { std::vector k; - for (const_iterator it = this->begin(), it_end = this->end(); it != it_end; ++it) - k.push_back(it->first); + for (const auto &[key, _] : *this) + k.push_back(key); return k; } diff --git a/include/modules/redis.h b/include/modules/redis.h index d953757f0..f30311f34 100644 --- a/include/modules/redis.h +++ b/include/modules/redis.h @@ -32,8 +32,8 @@ namespace Redis i = 0; bulk.clear(); multi_bulk_size = 0; - for (unsigned j = 0; j < multi_bulk.size(); ++j) - delete multi_bulk[j]; + for (const auto *reply : multi_bulk) + delete reply; multi_bulk.clear(); } diff --git a/include/modules/sql.h b/include/modules/sql.h index ff441302b..607f8bcd9 100644 --- a/include/modules/sql.h +++ b/include/modules/sql.h @@ -34,32 +34,34 @@ namespace SQL std::set KeySet() const override { std::set keys; - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - keys.insert(it->first); + for (const auto &[key, _] : this->data) + keys.insert(key); return keys; } size_t Hash() const override { size_t hash = 0; - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - if (!it->second->str().empty()) - hash ^= Anope::hash_cs()(it->second->str()); + for (const auto &[_, value] : this->data) + { + if (!value->str().empty()) + hash ^= Anope::hash_cs()(value->str()); + } return hash; } std::map GetData() const { std::map d; - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - d[it->first] = it->second; + for (const auto &[key, value] : this->data) + d[key] = value; return d; } void Clear() { - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - delete it->second; + for (const auto &[_, value] : this->data) + delete value; this->data.clear(); } diff --git a/include/version.cpp b/include/version.cpp index 164e07756..9cb16d78e 100644 --- a/include/version.cpp +++ b/include/version.cpp @@ -146,9 +146,9 @@ static bool write_version_h(const std::string &versionh, const std::map::const_iterator it = versions.begin(); it != versions.end(); ++it) + for (const auto &[key, value] : versions) { - fd << "#define " << it->first << " " << it->second << std::endl; + fd << "#define " << key << " " << value << std::endl; } fd.close(); diff --git a/modules/commands/bs_badwords.cpp b/modules/commands/bs_badwords.cpp index 5f14a2eb6..72e8c60f3 100644 --- a/modules/commands/bs_badwords.cpp +++ b/modules/commands/bs_badwords.cpp @@ -251,8 +251,8 @@ class CommandBSBadwords : public Command source.Reply(_("Bad words list for %s:"), ci->name.c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of bad words list.")); } diff --git a/modules/commands/bs_botlist.cpp b/modules/commands/bs_botlist.cpp index d47a98f4d..b124aa2ce 100644 --- a/modules/commands/bs_botlist.cpp +++ b/modules/commands/bs_botlist.cpp @@ -26,10 +26,8 @@ class CommandBSBotList : public Command list.AddColumn(_("Nick")).AddColumn(_("Mask")); - for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (const auto &[_, bi] : *BotListByNick) { - BotInfo *bi = it->second; - if (source.HasPriv("botserv/administration") || !bi->oper_only) { ++count; @@ -50,8 +48,8 @@ class CommandBSBotList : public Command { source.Reply(_("Bot list:")); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("%d bots available."), count); } diff --git a/modules/commands/bs_info.cpp b/modules/commands/bs_info.cpp index d75390dfc..d9b3afe1d 100644 --- a/modules/commands/bs_info.cpp +++ b/modules/commands/bs_info.cpp @@ -17,10 +17,8 @@ class CommandBSInfo : public Command void send_bot_channels(std::vector &buffers, const BotInfo *bi) { Anope::string buf; - for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) + for (const auto &[_, ci] : *RegisteredChannelList) { - const ChannelInfo *ci = it->second; - if (ci->bi == bi) { buf += " " + ci->name + " "; @@ -63,15 +61,15 @@ class CommandBSInfo : public Command std::vector replies; info.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); if (source.HasPriv("botserv/administration")) { std::vector buf; this->send_bot_channels(buf, bi); - for (unsigned i = 0; i < buf.size(); ++i) - source.Reply(buf[i]); + for (const auto &line : buf) + source.Reply(line); } } @@ -94,8 +92,8 @@ class CommandBSInfo : public Command std::vector replies; info.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } else source.Reply(_("\002%s\002 is not a valid bot or registered channel."), query.c_str()); diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp index f3a3ef7cd..051400d16 100644 --- a/modules/commands/bs_kick.cpp +++ b/modules/commands/bs_kick.cpp @@ -20,8 +20,8 @@ struct KickerDataImpl : KickerData KickerDataImpl(Extensible *obj) { amsgs = badwords = bolds = caps = colors = flood = italics = repeat = reverses = underlines = false; - for (int16_t i = 0; i < TTB_SIZE; ++i) - ttb[i] = 0; + for (auto &ttbtype : ttb) + ttbtype = 0; capsmin = capspercent = 0; floodlines = floodsecs = 0; repeattimes = 0; @@ -69,8 +69,8 @@ struct KickerDataImpl : KickerData data.SetType("repeattimes", Serialize::Data::DT_INT); data["repeattimes"] << kd->repeattimes; data.SetType("dontkickops", Serialize::Data::DT_INT); data["dontkickops"] << kd->dontkickops; data.SetType("dontkickvoices", Serialize::Data::DT_INT); data["dontkickvoices"] << kd->dontkickvoices; - for (int16_t i = 0; i < TTB_SIZE; ++i) - data["ttb"] << kd->ttb[i] << " "; + for (auto ttbtype : kd->ttb) + data["ttb"] << ttbtype << " "; } void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override @@ -136,11 +136,8 @@ class CommandBSKick : public Command source.Reply(_("Configures bot kickers. \037option\037 can be one of:")); Anope::string this_name = source.command; - for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it) + for (const auto &[c_name, info] : source.service->commands) { - const Anope::string &c_name = it->first; - const CommandInfo &info = it->second; - if (c_name.find_ci(this_name + " ") == 0) { ServiceReference command("Command", info.name); @@ -928,8 +925,8 @@ struct BanData Data() { last_use = 0; - for (int i = 0; i < TTB_SIZE; ++i) - this->ttb[i] = 0; + for (auto &ttbtype : this->ttb) + ttbtype = 0; } }; @@ -997,10 +994,8 @@ class BanDataPurger : public Timer { Log(LOG_DEBUG) << "bs_main: Running bandata purger"; - for (channel_map::iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) + for (auto &[_, c] : ChannelList) { - Channel *c = it->second; - BanData *bd = c->GetExt("bandata"); if (bd != NULL) { @@ -1049,7 +1044,7 @@ class BSKick : public Module UserData *ud = userdata.Require(uc); return ud; - } + } void check_ban(ChannelInfo *ci, User *u, KickerData *kd, int ttbtype) { @@ -1308,11 +1303,11 @@ class BSKick : public Module { int i = 0, l = 0; - for (unsigned j = 0, end = realbuf.length(); j < end; ++j) + for (auto chr : realbuf) { - if (isupper(realbuf[j])) + if (isupper(chr)) ++i; - else if (islower(realbuf[j])) + else if (islower(chr)) ++l; } diff --git a/modules/commands/bs_set.cpp b/modules/commands/bs_set.cpp index 8f9e8a894..0670b537f 100644 --- a/modules/commands/bs_set.cpp +++ b/modules/commands/bs_set.cpp @@ -35,10 +35,8 @@ class CommandBSSet : public Command bool hide_privileged_commands = Config->GetBlock("options")->Get("hideprivilegedcommands"), hide_registered_commands = Config->GetBlock("options")->Get("hideregisteredcommands"); Anope::string this_name = source.command; - for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it) + for (const auto &[c_name, info] : source.service->commands) { - const Anope::string &c_name = it->first; - const CommandInfo &info = it->second; if (c_name.find_ci(this_name + " ") == 0) { if (info.hide) @@ -54,7 +52,7 @@ class CommandBSSet : public Command if (hide_privileged_commands && !info.permission.empty() && !source.HasCommand(info.permission)) continue; - source.command = it->first; + source.command = c_name; command->OnServHelp(source); } } diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp index 52dbdef20..f1d132963 100644 --- a/modules/commands/cs_access.cpp +++ b/modules/commands/cs_access.cpp @@ -16,8 +16,8 @@ static std::map defaultLevels; static inline void reset_levels(ChannelInfo *ci) { ci->ClearLevels(); - for (std::map::iterator it = defaultLevels.begin(), it_end = defaultLevels.end(); it != it_end; ++it) - ci->SetLevel(it->first, it->second); + for (auto &[priv, level] : defaultLevels) + ci->SetLevel(priv, level); } class AccessChanAccess : public ChanAccess @@ -369,12 +369,14 @@ class CommandCSAccess : public Command Anope::string timebuf; if (ci->c) - for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit) + { + for (const auto &[_, cuc] : ci->c->users) { ChannelInfo *p; - if (access->Matches(cit->second->user, cit->second->user->Account(), p)) + if (access->Matches(cuc->user, cuc->user->Account(), p)) timebuf = "Now"; } + } if (timebuf.empty()) { if (access->last_seen == 0) @@ -407,12 +409,14 @@ class CommandCSAccess : public Command Anope::string timebuf; if (ci->c) - for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit) + { + for (auto &[_, cuc] : ci->c->users) { ChannelInfo *p; - if (access->Matches(cit->second->user, cit->second->user->Account(), p)) + if (access->Matches(cuc->user, cuc->user->Account(), p)) timebuf = "Now"; } + } if (timebuf.empty()) { if (access->last_seen == 0) @@ -441,8 +445,8 @@ class CommandCSAccess : public Command source.Reply(_("Access list for %s:"), ci->name.c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of access list")); } @@ -701,9 +705,8 @@ class CommandCSLevels : public Command const std::vector &privs = PrivilegeManager::GetPrivileges(); - for (unsigned i = 0; i < privs.size(); ++i) + for (const auto &p : privs) { - const Privilege &p = privs[i]; int16_t j = ci->GetLevel(p.name); ListFormatter::ListEntry entry; @@ -722,8 +725,8 @@ class CommandCSLevels : public Command std::vector replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } void DoReset(CommandSource &source, ChannelInfo *ci) @@ -801,10 +804,8 @@ class CommandCSLevels : public Command ListFormatter list(source.GetAccount()); list.AddColumn(_("Name")).AddColumn(_("Description")); - const std::vector &privs = PrivilegeManager::GetPrivileges(); - for (unsigned i = 0; i < privs.size(); ++i) + for (const auto &p : PrivilegeManager::GetPrivileges()) { - const Privilege &p = privs[i]; ListFormatter::ListEntry entry; entry["Name"] = p.name; entry["Description"] = Language::Translate(source.nc, p.desc.c_str()); @@ -814,8 +815,8 @@ class CommandCSLevels : public Command std::vector replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } else { diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp index 04ee17da3..78215dacd 100644 --- a/modules/commands/cs_akick.cpp +++ b/modules/commands/cs_akick.cpp @@ -96,10 +96,9 @@ class CommandCSAKick : public Command /* Check excepts BEFORE we get this far */ if (ci->c) { - std::vector modes = ci->c->GetModeList("EXCEPT"); - for (unsigned int i = 0; i < modes.size(); ++i) + for (const auto &mode : ci->c->GetModeList("EXCEPT")) { - if (Anope::Match(modes[i], mask)) + if (Anope::Match(mode, mask)) { source.Reply(CHAN_EXCEPTED, mask.c_str(), ci->name.c_str()); return; @@ -129,10 +128,8 @@ class CommandCSAKick : public Command { /* Match against all currently online users with equal or * higher access. - Viper */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, u2] : UserListByNick) { - User *u2 = it->second; - AccessGroup nc_access = ci->AccessFor(nc), u_access = source.AccessFor(ci); Entry entry_mask("", mask); @@ -145,9 +142,9 @@ class CommandCSAKick : public Command /* Match against the lastusermask of all nickalias's with equal * or higher access. - Viper */ - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) + for (const auto &[_, na2] : *NickAliasList) { - na = it->second; + na = na2; AccessGroup nc_access = ci->AccessFor(na->nc), u_access = source.AccessFor(ci); if (na->nc && (na->nc == ci->GetFounder() || nc_access >= u_access)) @@ -373,8 +370,8 @@ class CommandCSAKick : public Command source.Reply(_("Autokick list for %s:"), ci->name.c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of autokick list")); } diff --git a/modules/commands/cs_clone.cpp b/modules/commands/cs_clone.cpp index 84c7d91cb..c287f6a0b 100644 --- a/modules/commands/cs_clone.cpp +++ b/modules/commands/cs_clone.cpp @@ -99,11 +99,9 @@ class CommandCSClone : public Command void CopyLevels(CommandSource &source, ChannelInfo *ci, ChannelInfo *target_ci) { - const Anope::map &cilevels = ci->GetLevelEntries(); - - for (Anope::map::const_iterator it = cilevels.begin(); it != cilevels.end(); ++it) + for (const auto &[priv, level] : ci->GetLevelEntries()) { - target_ci->SetLevel(it->first, it->second); + target_ci->SetLevel(priv, level); } source.Reply(_("All level entries from \002%s\002 have been cloned into \002%s\002."), ci->name.c_str(), target_ci->name.c_str()); @@ -199,8 +197,8 @@ public: const Anope::string settings[] = { "NOAUTOOP", "CS_KEEP_MODES", "PEACE", "PERSIST", "RESTRICTED", "CS_SECURE", "SECUREFOUNDER", "SECUREOPS", "SIGNKICK", "SIGNKICK_LEVEL", "CS_NO_EXPIRE" }; - for (unsigned int i = 0; i < sizeof(settings) / sizeof(Anope::string); ++i) - CopySetting(ci, target_ci, settings[i]); + for (const auto &setting : settings) + CopySetting(ci, target_ci, setting); CopyAccess(source, ci, target_ci); CopyAkick(source, ci, target_ci); diff --git a/modules/commands/cs_enforce.cpp b/modules/commands/cs_enforce.cpp index 801191293..eca2d0651 100644 --- a/modules/commands/cs_enforce.cpp +++ b/modules/commands/cs_enforce.cpp @@ -29,10 +29,8 @@ class CommandCSEnforce : public Command bool hadsecureops = ci->HasExt("SECUREOPS"); ci->Extend("SECUREOPS"); - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : ci->c->users) { - ChanUserContainer *uc = it->second; - ci->c->SetCorrectModes(uc->user, false); } @@ -48,9 +46,9 @@ class CommandCSEnforce : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce restricted"; std::vector users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + + for (const auto &[_, uc] : ci->c->users) { - ChanUserContainer *uc = it->second; User *user = uc->user; if (user->IsProtected()) @@ -60,10 +58,8 @@ class CommandCSEnforce : public Command users.push_back(user); } - for (unsigned i = 0; i < users.size(); ++i) + for (auto *user : users) { - User *user = users[i]; - Anope::string mask = ci->GetIdealBan(user); Anope::string reason = Language::Translate(user, _("RESTRICTED enforced by ")) + source.GetNick(); ci->c->SetMode(NULL, "BAN", mask); @@ -79,9 +75,8 @@ class CommandCSEnforce : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce registered only"; std::vector users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : ci->c->users) { - ChanUserContainer *uc = it->second; User *user = uc->user; if (user->IsProtected()) @@ -91,10 +86,8 @@ class CommandCSEnforce : public Command users.push_back(user); } - for (unsigned i = 0; i < users.size(); ++i) + for (auto *user : users) { - User *user = users[i]; - Anope::string mask = ci->GetIdealBan(user); Anope::string reason = Language::Translate(user, _("REGONLY enforced by ")) + source.GetNick(); if (!ci->c->HasMode("REGISTEREDONLY")) @@ -111,9 +104,8 @@ class CommandCSEnforce : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce SSL only"; std::vector users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (auto &[_, uc] : ci->c->users) { - ChanUserContainer *uc = it->second; User *user = uc->user; if (user->IsProtected()) @@ -123,10 +115,8 @@ class CommandCSEnforce : public Command users.push_back(user); } - for (unsigned i = 0; i < users.size(); ++i) + for (auto *user : users) { - User *user = users[i]; - Anope::string mask = ci->GetIdealBan(user); Anope::string reason = Language::Translate(user, _("SSLONLY enforced by ")) + source.GetNick(); if (!ci->c->HasMode("SSL")) @@ -143,9 +133,8 @@ class CommandCSEnforce : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce bans"; std::vector users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : ci->c->users) { - ChanUserContainer *uc = it->second; User *user = uc->user; if (user->IsProtected()) @@ -155,10 +144,8 @@ class CommandCSEnforce : public Command users.push_back(user); } - for (unsigned i = 0; i < users.size(); ++i) + for (auto *user : users) { - User *user = users[i]; - Anope::string reason = Language::Translate(user, _("BANS enforced by ")) + source.GetNick(); ci->c->Kick(NULL, user, "%s", reason.c_str()); } @@ -210,10 +197,8 @@ class CommandCSEnforce : public Command users.push_back(user); } - for (unsigned i = 0; i < users.size(); ++i) + for (auto *user : users) { - User *user = users[i]; - Anope::string reason = Language::Translate(user, _("LIMIT enforced by ")) + source.GetNick(); ci->c->Kick(NULL, user, "%s", reason.c_str()); } diff --git a/modules/commands/cs_entrymsg.cpp b/modules/commands/cs_entrymsg.cpp index 84b33423d..0b6fdcbfe 100644 --- a/modules/commands/cs_entrymsg.cpp +++ b/modules/commands/cs_entrymsg.cpp @@ -128,8 +128,8 @@ class CommandEntryMessage : public Command std::vector replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of entry message list.")); } @@ -280,8 +280,8 @@ class CSEntryMessage : public Module EntryMessageList *messages = c->ci->GetExt("entrymsg"); if (messages != NULL) - for (unsigned i = 0; i < (*messages)->size(); ++i) - u->SendMessage(c->ci->WhoSends(), "[%s] %s", c->ci->name.c_str(), (*messages)->at(i)->message.c_str()); + for (const auto &message : *(*messages)) + u->SendMessage(c->ci->WhoSends(), "[%s] %s", c->ci->name.c_str(), message->message.c_str()); } } }; diff --git a/modules/commands/cs_flags.cpp b/modules/commands/cs_flags.cpp index 6edb736fc..54a99d7b6 100644 --- a/modules/commands/cs_flags.cpp +++ b/modules/commands/cs_flags.cpp @@ -48,9 +48,9 @@ class FlagsChanAccess : public ChanAccess std::set buffer; - for (std::map::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it) - if (access->HasPriv(it->first)) - buffer.insert(it->second); + for (auto &[priv, flag] : defaultFlags) + if (access->HasPriv(priv)) + buffer.insert(flag); if (buffer.empty()) return "(none)"; @@ -189,14 +189,14 @@ class CommandCSFlags : public Command add = false; break; case '*': - for (std::map::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it) + for (const auto &[priv, flag] : defaultFlags) { - bool has = current_flags.count(it->second); + bool has = current_flags.count(flag); // If we are adding a flag they already have or removing one they don't have, don't bother if (add == has) continue; - if (!u_access.HasPriv(it->first) && !u_access.founder) + if (!u_access.HasPriv(priv) && !u_access.founder) { if (source.HasPriv("chanserv/access/modify")) override = true; @@ -205,9 +205,9 @@ class CommandCSFlags : public Command } if (add) - current_flags.insert(it->second); + current_flags.insert(flag); else - current_flags.erase(it->second); + current_flags.erase(flag); } break; default: @@ -218,11 +218,11 @@ class CommandCSFlags : public Command i = flags.length(); } - for (std::map::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it) + for (const auto &[priv, flag] : defaultFlags) { - if (f != it->second) + if (f != flag) continue; - else if (!u_access.HasPriv(it->first) && !u_access.founder) + else if (!u_access.HasPriv(priv) && !u_access.founder) { if (source.HasPriv("chanserv/access/modify")) override = true; @@ -341,8 +341,8 @@ class CommandCSFlags : public Command list.Process(replies); source.Reply(_("Flags list for %s"), ci->name.c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); if (count == ci->GetAccessCount()) source.Reply(_("End of access list.")); else @@ -454,15 +454,15 @@ class CommandCSFlags : public Command typedef std::multimap reverse_map; reverse_map reverse; - for (std::map::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it) - reverse.emplace(it->second, it->first); + for (auto &[priv, flag] : defaultFlags) + reverse.emplace(flag, priv); - for (reverse_map::iterator it = reverse.begin(), it_end = reverse.end(); it != it_end; ++it) + for (auto &[flag, priv] : reverse) { - Privilege *p = PrivilegeManager::FindPrivilege(it->second); + Privilege *p = PrivilegeManager::FindPrivilege(priv); if (p == NULL) continue; - source.Reply(" %c - %s", it->first, Language::Translate(source.nc, p->desc.c_str())); + source.Reply(" %c - %s", flag, Language::Translate(source.nc, p->desc.c_str())); } return true; diff --git a/modules/commands/cs_info.cpp b/modules/commands/cs_info.cpp index 42dab2e45..d47f9f8c1 100644 --- a/modules/commands/cs_info.cpp +++ b/modules/commands/cs_info.cpp @@ -65,8 +65,8 @@ class CommandCSInfo : public Command std::vector replies; info.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/cs_list.cpp b/modules/commands/cs_list.cpp index e90ab9395..8323b6adb 100644 --- a/modules/commands/cs_list.cpp +++ b/modules/commands/cs_list.cpp @@ -75,13 +75,11 @@ class CommandCSList : public Command list.AddColumn(_("Name")).AddColumn(_("Description")); Anope::map ordered_map; - for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) - ordered_map[it->first] = it->second; + for (const auto &[cname, ci] : *RegisteredChannelList) + ordered_map[cname] = ci; - for (Anope::map::const_iterator it = ordered_map.begin(), it_end = ordered_map.end(); it != it_end; ++it) + for (const auto &[_, ci] : ordered_map) { - const ChannelInfo *ci = it->second; - if (!is_servadmin) { if (ci->HasExt("CS_PRIVATE") || ci->HasExt("CS_SUSPENDED")) @@ -124,8 +122,8 @@ class CommandCSList : public Command std::vector replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of list - %d/%d matches shown."), nchans > listmax ? listmax : nchans, nchans); } diff --git a/modules/commands/cs_log.cpp b/modules/commands/cs_log.cpp index 51f3ab8fe..2a6f2d0ec 100644 --- a/modules/commands/cs_log.cpp +++ b/modules/commands/cs_log.cpp @@ -144,8 +144,8 @@ public: std::vector replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } else if (params.size() > 2) @@ -199,12 +199,14 @@ public: return; } - for (unsigned i = 0; i < extra.length(); ++i) - if (ModeManager::GetStatusChar(extra[i]) == 0) + for (auto chr : extra) + { + if (ModeManager::GetStatusChar(chr) == 0) { - source.Reply(_("%c is an unknown status mode."), extra[i]); + source.Reply(_("%c is an unknown status mode."), chr); return; } + } bool override = !source.AccessFor(ci).HasPriv("SET"); @@ -326,10 +328,8 @@ class CSLog : public Module return; LogSettings *ls = logsettings.Require(ci); - for (unsigned i = 0; i < defaults.size(); ++i) + for (auto &d : defaults) { - LogDefault &d = defaults[i]; - LogSetting *log = new LogSettingImpl(); log->chan = ci->name; @@ -360,11 +360,10 @@ class CSLog : public Module LogSettings *ls = logsettings.Get(l->ci); if (ls) - for (unsigned i = 0; i < (*ls)->size(); ++i) + { + for (auto *log : *(*ls)) { - const LogSetting *log = (*ls)->at(i); - - /* wrong command */ + /* wrong command */ if (log->service_name != l->c->name) continue; @@ -393,6 +392,7 @@ class CSLog : public Module else if (log->method.equals_ci("NOTICE") && l->ci->c) IRCD->SendNotice(l->ci->WhoSends(), log->extra + l->ci->c->name, "%s", buffer.c_str()); } + } } }; diff --git a/modules/commands/cs_mode.cpp b/modules/commands/cs_mode.cpp index fcd6222d4..69e2247ba 100644 --- a/modules/commands/cs_mode.cpp +++ b/modules/commands/cs_mode.cpp @@ -46,9 +46,8 @@ struct ModeLocksImpl : ModeLocks { ModeList modelist; mlocks->swap(modelist); - for (ModeList::iterator it = modelist.begin(); it != modelist.end(); ++it) + for (auto *ml : modelist) { - ModeLock *ml = *it; delete ml; } } @@ -58,10 +57,8 @@ struct ModeLocksImpl : ModeLocks if (!mode) return false; - for (ModeList::const_iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it) + for (auto *ml : *this->mlocks) { - const ModeLock *ml = *it; - if (ml->name == mode->name && ml->set == status && ml->param == param) return true; } @@ -104,10 +101,8 @@ struct ModeLocksImpl : ModeLocks if (!mode) return false; - for (ModeList::iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it) + for (auto *m : *this->mlocks) { - ModeLock *m = *it; - if (m->name == mode->name) { // For list or status modes, we must check the parameter @@ -139,8 +134,8 @@ struct ModeLocksImpl : ModeLocks { ModeList ml; this->mlocks->swap(ml); - for (unsigned i = 0; i < ml.size(); ++i) - delete ml[i]; + for (const auto *lock : ml) + delete lock; } const ModeList &GetMLock() const override @@ -151,10 +146,9 @@ struct ModeLocksImpl : ModeLocks std::list GetModeLockList(const Anope::string &name) override { std::list mlist; - for (ModeList::const_iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it) + for (auto *m : *this->mlocks) { - ModeLock *m = *it; - if (m->name == name) + if (m->name == name) mlist.push_back(m); } return mlist; @@ -162,10 +156,8 @@ struct ModeLocksImpl : ModeLocks const ModeLock *GetMLock(const Anope::string &mname, const Anope::string ¶m = "") override { - for (ModeList::const_iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it) + for (auto *m : *this->mlocks) { - ModeLock *m = *it; - if (m->name == mname && m->param == param) return m; } @@ -177,9 +169,8 @@ struct ModeLocksImpl : ModeLocks { Anope::string pos = "+", neg = "-", params; - for (ModeList::const_iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it) + for (auto *ml : *this->mlocks) { - const ModeLock *ml = *it; ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); if (!cm || cm->type == MODE_LIST || cm->type == MODE_STATUS) @@ -281,9 +272,8 @@ class CommandCSMode : public Command if (subcommand.equals_ci("SET")) { const ModeLocks::ModeList mlocks = modelocks->GetMLock(); - for (ModeLocks::ModeList::const_iterator it = mlocks.begin(); it != mlocks.end(); ++it) + for (auto *ml : mlocks) { - const ModeLock *ml = *it; ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); if (cm && cm->CanSet(source.GetUser())) modelocks->RemoveMLock(cm, ml->set, ml->param); @@ -299,9 +289,9 @@ class CommandCSMode : public Command int adding = 1; bool needreply = true; - for (size_t i = 0; i < modes.length(); ++i) + for (auto mode : modes) { - switch (modes[i]) + switch (mode) { case '+': adding = 1; @@ -311,15 +301,15 @@ class CommandCSMode : public Command break; default: needreply = false; - ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(mode); if (!cm) { - source.Reply(_("Unknown mode character %c ignored."), modes[i]); + source.Reply(_("Unknown mode character %c ignored."), mode); break; } else if (u && !cm->CanSet(u)) { - source.Reply(_("You may not (un)lock mode %c."), modes[i]); + source.Reply(_("You may not (un)lock mode %c."), mode); break; } @@ -391,9 +381,9 @@ class CommandCSMode : public Command int adding = 1; bool needreply = true; - for (size_t i = 0; i < modes.length(); ++i) + for (auto mode : modes) { - switch (modes[i]) + switch (mode) { case '+': adding = 1; @@ -403,15 +393,15 @@ class CommandCSMode : public Command break; default: needreply = false; - ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(mode); if (!cm) { - source.Reply(_("Unknown mode character %c ignored."), modes[i]); + source.Reply(_("Unknown mode character %c ignored."), mode); break; } else if (u && !cm->CanSet(u)) { - source.Reply(_("You may not (un)lock mode %c."), modes[i]); + source.Reply(_("You may not (un)lock mode %c."), mode); break; } @@ -448,9 +438,8 @@ class CommandCSMode : public Command ListFormatter list(source.GetAccount()); list.AddColumn(_("Mode")).AddColumn(_("Param")).AddColumn(_("Creator")).AddColumn(_("Created")); - for (ModeLocks::ModeList::const_iterator it = mlocks.begin(), it_end = mlocks.end(); it != it_end; ++it) + for (auto *ml : mlocks) { - const ModeLock *ml = *it; ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); if (!cm) continue; @@ -468,8 +457,8 @@ class CommandCSMode : public Command std::vector replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } else @@ -489,9 +478,9 @@ class CommandCSMode : public Command bool override = !source.AccessFor(ci).HasPriv("MODE") && source.HasPriv("chanserv/administration"); int adding = -1; - for (size_t i = 0; i < modes.length(); ++i) + for (auto mode : modes) { - switch (modes[i]) + switch (mode) { case '+': adding = 1; @@ -521,7 +510,7 @@ class CommandCSMode : public Command default: if (adding == -1) break; - ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(mode); if (!cm || (u && !cm->CanSet(u) && !can_override)) continue; switch (cm->type) @@ -665,10 +654,11 @@ class CommandCSMode : public Command } else { - std::vector v = ci->c->GetModeList(cm->name); - for (unsigned j = 0; j < v.size(); ++j) - if (Anope::Match(v[j], param)) - ci->c->RemoveMode(NULL, cm, v[j]); + for (const auto &mode : ci->c->GetModeList(cm->name)) + { + if (Anope::Match(mode, param)) + ci->c->RemoveMode(NULL, cm, mode); + } } } } // switch @@ -963,10 +953,10 @@ class CSMode : public Module ModeLocks *locks = modelocks.Get(c->ci); if (locks) - for (ModeLocks::ModeList::const_iterator it = locks->GetMLock().begin(), it_end = locks->GetMLock().end(); it != it_end; ++it) + { + for (auto *ml : locks->GetMLock()) { - const ModeLock *ml = *it; - ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); + ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); if (!cm) continue; @@ -1003,6 +993,7 @@ class CSMode : public Module c->RemoveMode(NULL, cm, ml->param, false); } } + } } void OnChanRegistered(ChannelInfo *ci) override @@ -1013,21 +1004,21 @@ class CSMode : public Module if (sep.GetToken(mlock)) { bool add = true; - for (unsigned i = 0; i < mlock.length(); ++i) + for (auto mode : mlock) { - if (mlock[i] == '+') + if (mode == '+') { add = true; continue; } - if (mlock[i] == '-') + if (mode == '-') { add = false; continue; } - ChannelMode *cm = ModeManager::FindChannelModeByChar(mlock[i]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(mode); if (!cm) continue; diff --git a/modules/commands/cs_seen.cpp b/modules/commands/cs_seen.cpp index 0151a5a36..6bdb85bbf 100644 --- a/modules/commands/cs_seen.cpp +++ b/modules/commands/cs_seen.cpp @@ -125,14 +125,14 @@ class CommandOSSeen : public Command { size_t mem_counter; mem_counter = sizeof(database_map); - for (database_map::iterator it = database.begin(), it_end = database.end(); it != it_end; ++it) + for (auto &[nick, si] : database) { mem_counter += (5 * sizeof(Anope::string)) + sizeof(TypeInfo) + sizeof(time_t); - mem_counter += it->first.capacity(); - mem_counter += it->second->vhost.capacity(); - mem_counter += it->second->nick2.capacity(); - mem_counter += it->second->channel.capacity(); - mem_counter += it->second->message.capacity(); + mem_counter += nick.capacity(); + mem_counter += si->vhost.capacity(); + mem_counter += si->nick2.capacity(); + mem_counter += si->channel.capacity(); + mem_counter += si->message.capacity(); } source.Reply(_("%lu nicks are stored in the database, using %.2Lf kB of memory."), database.size(), static_cast(mem_counter) / 1024); } @@ -222,9 +222,8 @@ class CommandSeen : public Command return; } - for (Channel::ChanUserList::const_iterator it = source.c->users.begin(), it_end = source.c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : source.c->users) { - ChanUserContainer *uc = it->second; User *u = uc->user; if (u->Account() == na->nc) @@ -236,10 +235,8 @@ class CommandSeen : public Command AccessGroup ag = source.c->ci->AccessFor(na->nc); time_t last = 0; - for (unsigned int i = 0; i < ag.paths.size(); ++i) + for (const auto &p : ag.paths) { - ChanAccess::Path &p = ag.paths[i]; - if (p.empty()) continue; diff --git a/modules/commands/cs_set.cpp b/modules/commands/cs_set.cpp index 116db161e..0456f56b8 100644 --- a/modules/commands/cs_set.cpp +++ b/modules/commands/cs_set.cpp @@ -37,10 +37,8 @@ class CommandCSSet : public Command Anope::string this_name = source.command; bool hide_privileged_commands = Config->GetBlock("options")->Get("hideprivilegedcommands"), hide_registered_commands = Config->GetBlock("options")->Get("hideregisteredcommands"); - for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it) + for (const auto &[c_name, info] : source.service->commands) { - const Anope::string &c_name = it->first; - const CommandInfo &info = it->second; if (c_name.find_ci(this_name + " ") == 0) { if (info.hide) @@ -56,7 +54,7 @@ class CommandCSSet : public Command else if (hide_privileged_commands && !info.permission.empty() && !source.HasCommand(info.permission)) continue; - source.command = it->first; + source.command = c_name; c->OnServHelp(source); } } @@ -1112,13 +1110,13 @@ class CSSet : public Module const ChannelInfo *ci = anope_dynamic_static_cast(s); Anope::string modes; - for (Channel::ModeList::const_iterator it = ci->last_modes.begin(); it != ci->last_modes.end(); ++it) + for (const auto &[last_mode, last_value] : ci->last_modes) { if (!modes.empty()) modes += " "; - modes += it->first; - if (!it->second.empty()) - modes += "," + it->second; + modes += last_mode; + if (!last_value.empty()) + modes += "," + last_value; } data["last_modes"] << modes; } @@ -1199,8 +1197,8 @@ class CSSet : public Module if (c->ci && keep_modes.HasExt(c->ci)) { Channel::ModeList ml = c->ci->last_modes; - for (Channel::ModeList::iterator it = ml.begin(); it != ml.end(); ++it) - c->SetMode(c->ci->WhoSends(), it->first, it->second); + for (const auto &[last_mode, last_value] : c->ci->last_modes) + c->SetMode(c->ci->WhoSends(), last_mode, last_value); } } diff --git a/modules/commands/cs_set_misc.cpp b/modules/commands/cs_set_misc.cpp index 477595ad8..86233c97a 100644 --- a/modules/commands/cs_set_misc.cpp +++ b/modules/commands/cs_set_misc.cpp @@ -178,8 +178,8 @@ class CSSetMisc : public Module ~CSSetMisc() override { - for (Anope::map *>::iterator it = items.begin(); it != items.end(); ++it) - delete it->second; + for (const auto &[_, item] : items) + delete item; } void OnReload(Configuration::Conf *conf) override @@ -205,9 +205,8 @@ class CSSetMisc : public Module void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool) override { - for (Anope::map *>::iterator it = items.begin(); it != items.end(); ++it) + for (const auto &[_, e] : items) { - ExtensibleItem *e = it->second; MiscData *data = e->Get(ci); if (data != NULL) diff --git a/modules/commands/cs_status.cpp b/modules/commands/cs_status.cpp index dae9dd9d1..9d5f856f8 100644 --- a/modules/commands/cs_status.cpp +++ b/modules/commands/cs_status.cpp @@ -57,11 +57,9 @@ public: { source.Reply(_("Access for \002%s\002 on \002%s\002:"), nick.c_str(), ci->name.c_str()); - for (unsigned i = 0; i < ag.paths.size(); ++i) + for (const auto &p : ag.paths) { - ChanAccess::Path &p = ag.paths[i]; - - if (p.empty()) + if (p.empty()) continue; if (p.size() == 1) diff --git a/modules/commands/cs_suspend.cpp b/modules/commands/cs_suspend.cpp index 55fd83d27..ca8dfce56 100644 --- a/modules/commands/cs_suspend.cpp +++ b/modules/commands/cs_suspend.cpp @@ -109,16 +109,15 @@ class CommandCSSuspend : public Command { std::vector users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : ci->c->users) { - ChanUserContainer *uc = it->second; User *user = uc->user; if (!user->HasMode("OPER") && user->server != Me) users.push_back(user); } - for (unsigned i = 0; i < users.size(); ++i) - ci->c->Kick(NULL, users[i], "%s", !reason.empty() ? reason.c_str() : Language::Translate(users[i], _("This channel has been suspended."))); + for (auto *user : users) + ci->c->Kick(NULL, user, "%s", !reason.empty() ? reason.c_str() : Language::Translate(user, _("This channel has been suspended."))); } Log(LOG_ADMIN, source, this, ci) << "(" << (!reason.empty() ? reason : "No reason") << "), expires on " << (expiry_secs ? Anope::strftime(Anope::CurTime + expiry_secs) : "never"); diff --git a/modules/commands/cs_sync.cpp b/modules/commands/cs_sync.cpp index 60bc0a205..2610f521c 100644 --- a/modules/commands/cs_sync.cpp +++ b/modules/commands/cs_sync.cpp @@ -35,8 +35,8 @@ class CommandCSSync : public Command bool override = !source.AccessFor(ci).HasPriv("ACCESS_CHANGE") && source.HasPriv("chanserv/administration"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci); - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) - ci->c->SetCorrectModes(it->second->user, true); + for (const auto &[_, uc] : ci->c->users) + ci->c->SetCorrectModes(uc->user, true); source.Reply(_("All user modes on \002%s\002 have been synced."), ci->name.c_str()); } diff --git a/modules/commands/cs_unban.cpp b/modules/commands/cs_unban.cpp index de5ad1782..fec777cc0 100644 --- a/modules/commands/cs_unban.cpp +++ b/modules/commands/cs_unban.cpp @@ -38,17 +38,15 @@ class CommandCSUnban : public Command source.GetAccount()->GetChannelReferences(queue); unsigned count = 0; - for (unsigned i = 0; i < queue.size(); ++i) + for (auto *ci : queue) { - ChannelInfo *ci = queue[i]; - if (!ci->c || !source.AccessFor(ci).HasPriv("UNBAN")) continue; FOREACH_MOD(OnChannelUnban, (source.GetUser(), ci)); - for (unsigned j = 0; j < modes.size(); ++j) - if (ci->c->Unban(source.GetUser(), modes[j]->name, true)) + for (const auto *mode : modes) + if (ci->c->Unban(source.GetUser(), mode->name, true)) ++count; } @@ -92,8 +90,8 @@ class CommandCSUnban : public Command FOREACH_MOD(OnChannelUnban, (u2, ci)); - for (unsigned i = 0; i < modes.size(); ++i) - ci->c->Unban(u2, modes[i]->name, source.GetUser() == u2); + for (const auto *mode : modes) + ci->c->Unban(u2, mode->name, source.GetUser() == u2); if (u2 == source.GetUser()) source.Reply(_("You have been unbanned from \002%s\002."), ci->c->name.c_str()); else diff --git a/modules/commands/cs_updown.cpp b/modules/commands/cs_updown.cpp index 040e5917c..59bd19660 100644 --- a/modules/commands/cs_updown.cpp +++ b/modules/commands/cs_updown.cpp @@ -24,9 +24,8 @@ class CommandCSUp : public Command bool given = false; AccessGroup u_access = c->ci->AccessFor(u); - for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i) + for (auto *cm : ModeManager::GetStatusChannelModesByRank()) { - ChannelModeStatus *cm = ModeManager::GetStatusChannelModesByRank()[i]; bool has_priv = u_access.HasPriv("AUTO" + cm->name) || u_access.HasPriv(cm->name); if (has_priv) diff --git a/modules/commands/cs_xop.cpp b/modules/commands/cs_xop.cpp index 1d5cfb7d9..5bd9de696 100644 --- a/modules/commands/cs_xop.cpp +++ b/modules/commands/cs_xop.cpp @@ -58,25 +58,28 @@ class XOPChanAccess : public ChanAccess { std::map count; - for (std::map >::const_iterator it = permissions.begin(), it_end = permissions.end(); it != it_end; ++it) + for (const auto &[name, perms] : permissions) { - int &c = count[it->first]; - const std::vector &perms = it->second; - for (unsigned i = 0; i < perms.size(); ++i) - if (access->HasPriv(perms[i])) + int &c = count[name]; + for (const auto &perm : perms) + { + if (access->HasPriv(perm)) ++c; + } } - Anope::string max; - int maxn = 0; - for (std::map::iterator it = count.begin(), it_end = count.end(); it != it_end; ++it) - if (it->second > maxn) + Anope::string maxname; + int maxpriv = 0; + for (const auto &[name, priv] : count) + { + if (priv > maxpriv) { - maxn = it->second; - max = it->first; + maxname = name; + maxpriv = priv; } + } - return max; + return maxname; } } }; @@ -436,8 +439,8 @@ class CommandCSXOP : public Command list.Process(replies); source.Reply(_("%s list for %s"), source.command.c_str(), ci->name.c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } @@ -528,9 +531,9 @@ class CommandCSXOP : public Command " "), cmd.c_str(), cmd.c_str()); Anope::string buf; - for (unsigned i = 0; i < permissions[cmd].size(); ++i) + for (const auto &permission : permissions[cmd]) { - buf += ", " + permissions[cmd][i]; + buf += ", " + permission; if (buf.length() > 75) { source.Reply(" %s\n", buf.substr(2).c_str()); diff --git a/modules/commands/help.cpp b/modules/commands/help.cpp index 31b27e0ea..071161fcd 100644 --- a/modules/commands/help.cpp +++ b/modules/commands/help.cpp @@ -17,9 +17,8 @@ class CommandHelp : public Command static CommandGroup *FindGroup(const Anope::string &name) { - for (unsigned i = 0; i < Config->CommandGroups.size(); ++i) + for (auto &gr : Config->CommandGroups) { - CommandGroup &gr = Config->CommandGroups[i]; if (gr.name == name) return &gr; } @@ -56,18 +55,15 @@ class CommandHelp : public Command if (all) source.Reply(_("All available commands for \002%s\002:"), source.service->nick.c_str()); - for (CommandInfo::map::const_iterator it = map.begin(), it_end = map.end(); it != it_end; ++it) + for (const auto &[c_name, info] : map) { - const Anope::string &c_name = it->first; - const CommandInfo &info = it->second; - if (info.hide) continue; // Smaller command exists Anope::string cmd; spacesepstream(c_name).GetToken(cmd, 0); - if (cmd != it->first && map.count(cmd)) + if (cmd != c_name && map.count(cmd)) continue; ServiceReference c("Command", info.name); @@ -95,18 +91,14 @@ class CommandHelp : public Command } - for (GroupInfo::iterator it = groups.begin(), it_end = groups.end(); it != it_end; ++it) + for (auto &[gr, cmds] : groups) { - CommandGroup *gr = it->first; - source.Reply(" "); source.Reply("%s", gr->description.c_str()); Anope::string buf; - for (std::list::iterator it2 = it->second.begin(), it2_end = it->second.end(); it2 != it2_end; ++it2) + for (const auto &c_name : cmds) { - const Anope::string &c_name = *it2; - buf += ", " + c_name; if (buf.length() > help_wrap_len) diff --git a/modules/commands/hs_del.cpp b/modules/commands/hs_del.cpp index fd6e93bbb..9d4514907 100644 --- a/modules/commands/hs_del.cpp +++ b/modules/commands/hs_del.cpp @@ -74,9 +74,9 @@ class CommandHSDelAll : public Command { FOREACH_MOD(OnDeleteVhost, (na)); const NickCore *nc = na->nc; - for (unsigned i = 0; i < nc->aliases->size(); ++i) + for (auto *alias : *nc->aliases) { - na = nc->aliases->at(i); + na = alias; na->RemoveVhost(); } Log(LOG_ADMIN, source, this) << "for all nicks in group " << nc->display; diff --git a/modules/commands/hs_group.cpp b/modules/commands/hs_group.cpp index 33b204ad1..03e1dc333 100644 --- a/modules/commands/hs_group.cpp +++ b/modules/commands/hs_group.cpp @@ -25,9 +25,8 @@ class CommandHSGroup : public Command return; setting = true; - for (unsigned i = 0; i < na->nc->aliases->size(); ++i) + for (auto *nick : *na->nc->aliases) { - NickAlias *nick = na->nc->aliases->at(i); if (nick) { nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); diff --git a/modules/commands/hs_list.cpp b/modules/commands/hs_list.cpp index c2aa67a83..00f2915d1 100644 --- a/modules/commands/hs_list.cpp +++ b/modules/commands/hs_list.cpp @@ -57,10 +57,8 @@ class CommandHSList : public Command ListFormatter list(source.GetAccount()); list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Creator")).AddColumn(_("Created")); - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) + for (const auto &[_, na] : *NickAliasList) { - const NickAlias *na = it->second; - if (!na->HasVhost()) continue; @@ -125,8 +123,8 @@ class CommandHSList : public Command std::vector replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/hs_request.cpp b/modules/commands/hs_request.cpp index a1b504d27..c626deca2 100644 --- a/modules/commands/hs_request.cpp +++ b/modules/commands/hs_request.cpp @@ -132,12 +132,14 @@ class CommandHSRequest : public Command source.Reply(HOST_NO_VIDENT); return; } - for (Anope::string::iterator s = user.begin(), s_end = user.end(); s != s_end; ++s) - if (!isvalidchar(*s)) + for (const auto &chr : user) + { + if (!isvalidchar(chr)) { source.Reply(HOST_SET_IDENT_ERROR); return; } + } } if (host.length() > Config->GetBlock("networkinfo")->Get("hostlen")) @@ -304,9 +306,8 @@ class CommandHSWaiting : public Command list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Created")); - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) + for (const auto &[nick, na] : *NickAliasList) { - const NickAlias *na = it->second; HostRequest *hr = na->GetExt("hostrequest"); if (!hr) continue; @@ -317,7 +318,7 @@ class CommandHSWaiting : public Command ListFormatter::ListEntry entry; entry["Number"] = stringify(display_counter); - entry["Nick"] = it->first; + entry["Nick"] = nick; if (!hr->ident.empty()) entry["Vhost"] = hr->ident + "@" + hr->host; else @@ -331,8 +332,8 @@ class CommandHSWaiting : public Command std::vector replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("Displayed \002%d\002 records (\002%d\002 total)."), display_counter, counter); } @@ -369,18 +370,15 @@ class HSRequest : public Module static void req_send_memos(Module *me, CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost) { Anope::string host; - std::list >::iterator it, it_end; - if (!vIdent.empty()) host = vIdent + "@" + vHost; else host = vHost; if