diff options
| author | Sadie Powell <sadie@witchery.services> | 2023-10-10 21:14:50 +0100 |
|---|---|---|
| committer | Sadie Powell <sadie@witchery.services> | 2023-10-11 15:51:52 +0100 |
| commit | a3241065c55fd2a69e8793b89a5d0b1a957b3fd0 (patch) | |
| tree | 82f80ce2f3bbbdc1c1ef05fe611093cf0b34eab6 /modules/commands | |
| parent | dc371aad6d059dbf7f30f6878c680532bedd4146 (diff) | |
Start migrating to range-based for loops.
Diffstat (limited to 'modules/commands')
64 files changed, 471 insertions, 589 deletions
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<Anope::string> &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<Anope::string> 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<Anope::string> 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<Anope::string> 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("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>("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<bool>("hideprivilegedcommands"), hide_registered_commands = Config->GetBlock("options")->Get<bool>("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<Anope::string, int16_t, ci::less> defaultLevels; static inline void reset_levels(ChannelInfo *ci) { ci->ClearLevels(); - for (std::map<Anope::string, int16_t, ci::less>::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<Privilege> &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<Anope::string> 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<Privilege> &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<Anope::string> 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<Anope::string> 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<int16_t> &cilevels = ci->GetLevelEntries(); - - for (Anope::map<int16_t>::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<bool>("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<User *> 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<User *> 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<User *> 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<User *> 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<Anope::string> 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<EntryMessageList>("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<char> buffer; - for (std::map<Anope::string, char>::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<Anope::string, char>::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<Anope::string, char>::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<char, Anope::string, ci::less> reverse_map; reverse_map reverse; - for (std::map<Anope::string, char>::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<Anope::string> 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<ChannelInfo *> 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<ChannelInfo *>::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<Anope::string> 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<Anope::string> 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<ModeLock *> GetModeLockList(const Anope::string &name) override { std::list<ModeLock *> 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<Anope::string> 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<Anope::string> 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<long double>(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<bool>("hideprivilegedcommands"), hide_registered_commands = Config->GetBlock("options")->Get<bool>("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<const ChannelInfo *>(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<ExtensibleItem<CSMiscData> *>::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<ExtensibleItem<CSMiscData> *>::iterator it = items.begin(); it != items.end(); ++it) + for (const auto &[_, e] : items) { - ExtensibleItem<CSMiscData> *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<User *> 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<Anope::string, int> count; - for (std::map<Anope::string, std::vector<Anope::string> >::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<Anope::string> &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<Anope::string, int>::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<Command> 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<Anope::string>::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<Anope::string> 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<unsigned>("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>("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<Anope::string> 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<std::pair<Anope::string, Anope::string> >::iterator it, it_end; - if (!vIdent.empty()) host = vIdent + "@" + vHost; else host = vHost; if (Config->GetModule(me)->Get<bool>("memooper") && memoserv) - for (unsigned i = 0; i < Oper::opers.size(); ++i) + { + for (auto *o : Oper::opers) { - Oper *o = Oper::opers[i]; - const NickAlias *na = NickAlias::Find(o->name); if (!na) continue; @@ -389,6 +387,7 @@ static void req_send_memos(Module *me, CommandSource &source, const Anope::strin memoserv->Send(source.service->nick, na->nick, message, true); } + } } MODULE_INIT(HSRequest) diff --git a/modules/commands/hs_set.cpp b/modules/commands/hs_set.cpp index 4487723f9..926dc3bfe 100644 --- a/modules/commands/hs_set.cpp +++ b/modules/commands/hs_set.cpp @@ -111,9 +111,8 @@ class CommandHSSetAll : public Command if (!na || !na->HasVhost()) return; - 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/ms_ignore.cpp b/modules/commands/ms_ignore.cpp index 452b1e977..ca6e1ae86 100644 --- a/modules/commands/ms_ignore.cpp +++ b/modules/commands/ms_ignore.cpp @@ -84,10 +84,10 @@ class CommandMSIgnore : public Command { ListFormatter list(source.GetAccount()); list.AddColumn(_("Mask")); - for (unsigned i = 0; i < mi->ignores.size(); ++i) + for (const auto &ignore : mi->ignores) { ListFormatter::ListEntry entry; - entry["Mask"] = mi->ignores[i]; + entry["Mask"] = ignore; list.AddEntry(entry); } @@ -96,8 +96,8 @@ class CommandMSIgnore : public Command std::vector<Anope::string> 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/ms_list.cpp b/modules/commands/ms_list.cpp index 35a199e2a..728fe1a71 100644 --- a/modules/commands/ms_list.cpp +++ b/modules/commands/ms_list.cpp @@ -129,8 +129,8 @@ class CommandMSList : public Command list.Process(replies); source.Reply(_("Memos for %s:"), ci ? ci->name.c_str() : source.GetNick().c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } return; } diff --git a/modules/commands/ms_sendall.cpp b/modules/commands/ms_sendall.cpp index eeb8e94e4..904e5e161 100644 --- a/modules/commands/ms_sendall.cpp +++ b/modules/commands/ms_sendall.cpp @@ -34,10 +34,8 @@ class CommandMSSendAll : public Command Log(LOG_ADMIN, source, this) << "to send " << text; - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - const NickCore *nc = it->second; - if (nc != source.nc) memoserv->Send(source.GetNick(), nc->display, text); } diff --git a/modules/commands/ms_staff.cpp b/modules/commands/ms_staff.cpp index e85566ca4..2b0efae6d 100644 --- a/modules/commands/ms_staff.cpp +++ b/modules/commands/ms_staff.cpp @@ -32,10 +32,8 @@ class CommandMSStaff : public Command const Anope::string &text = params[0]; - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - const NickCore *nc = it->second; - if (source.nc != nc && nc->IsServicesOper()) memoserv->Send(source.GetNick(), nc->display, text, true); } diff --git a/modules/commands/ns_ajoin.cpp b/modules/commands/ns_ajoin.cpp index 1bee6faf8..a783708a9 100644 --- a/modules/commands/ns_ajoin.cpp +++ b/modules/commands/ns_ajoin.cpp @@ -82,8 +82,8 @@ struct AJoinEntry : Serializable AJoinList::~AJoinList() { - for (unsigned i = 0; i < (*this)->size(); ++i) - delete (*this)->at(i); + for (const auto *ajoin : *(*this)) + delete ajoin; } class CommandNSAJoin : public Command @@ -113,8 +113,8 @@ class CommandNSAJoin : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } @@ -327,9 +327,8 @@ class NSAJoin : public Module /* Set +r now, so we can ajoin users into +R channels */ ModeManager::ProcessModes(); - for (unsigned i = 0; i < (*channels)->size(); ++i) + for (auto *entry : *(*channels)) { - AJoinEntry *entry = (*channels)->at(i); Channel *c = Channel::Find(entry->channel); ChannelInfo *ci; diff --git a/modules/commands/ns_alist.cpp b/modules/commands/ns_alist.cpp index e9b69809c..e0f160aa2 100644 --- a/modules/commands/ns_alist.cpp +++ b/modules/commands/ns_alist.cpp @@ -51,9 +51,8 @@ class CommandNSAList : public Command nc->GetChannelReferences(queue); std::sort(queue.begin(), queue.end(), ChannelSort); - for (unsigned i = 0; i < queue.size(); ++i) + for (auto *ci : queue) { - ChannelInfo *ci = queue[i]; ListFormatter::ListEntry entry; if (ci->GetFounder() == nc) @@ -86,10 +85,8 @@ class CommandNSAList : public Command entry["Number"] = stringify(chan_count); entry["Channel"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name; - for (unsigned j = 0; j < access.paths.size(); ++j) + for (auto &p : access.paths) { - ChanAccess::Path &p = access.paths[j]; - // not interested in indirect access if (p.size() != 1) continue; @@ -113,8 +110,8 @@ class CommandNSAList : public Command { source.Reply(_("Channels that \002%s\002 has access on:"), nc->display.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 list - %d channels shown."), chan_count); } diff --git a/modules/commands/ns_cert.cpp b/modules/commands/ns_cert.cpp index e21d1e6f3..4e42d9fb5 100644 --- a/modules/commands/ns_cert.cpp +++ b/modules/commands/ns_cert.cpp @@ -108,8 +108,8 @@ struct NSCertListImpl : NSCertList void ClearCert() override { FOREACH_MOD(OnNickClearCert, (this->nc)); - for (unsigned i = 0; i < certs.size(); ++i) - certmap.erase(certs[i]); + for (const auto &cert : certs) + certmap.erase(cert); this->certs.clear(); } @@ -148,8 +148,8 @@ struct NSCertListImpl : NSCertList Anope::string buf; data["cert"] >> buf; spacesepstream sep(buf); - for (unsigned i = 0; i < c->certs.size(); ++i) - certmap.erase(c->certs[i]); + for (const auto &cert : c->certs) + certmap.erase(cert); c->certs.clear(); while (sep.GetToken(buf)) { diff --git a/modules/commands/ns_getemail.cpp b/modules/commands/ns_getemail.cpp index 765b50b93..de418cd0c 100644 --- a/modules/commands/ns_getemail.cpp +++ b/modules/commands/ns_getemail.cpp @@ -31,10 +31,8 @@ class CommandNSGetEMail : public Command Log(LOG_ADMIN, source, this) << "on " << email; - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - const NickCore *nc = it->second; - if (!nc->email.empty() && Anope::Match(nc->email, email)) { ++j; diff --git a/modules/commands/ns_group.cpp b/modules/commands/ns_group.cpp index 43ccc9388..af9b71584 100644 --- a/modules/commands/ns_group.cpp +++ b/modules/commands/ns_group.cpp @@ -128,16 +128,16 @@ class CommandNSGroup : public Command } if (Config->GetModule("nickserv")->Get<bool>("restrictopernicks")) - for (unsigned i = 0; i < Oper::opers.size(); ++i) + { + for (auto *o : Oper::opers) { - Oper *o = Oper::opers[i]; - if (user != NULL && !user->HasMode("OPER") && user->nick.find_ci(o->name) != Anope::string::npos) { source.Reply(NICK_CANNOT_BE_REGISTERED, user->nick.c_str()); return; } } + } NickAlias *target, *na = NickAlias::Find(source.GetNick()); const Anope::string &guestnick = Config->GetModule("nickserv")->Get<const Anope::string>("guestnickprefix", "Guest"); @@ -327,10 +327,8 @@ class CommandNSGList : public Command list.AddColumn(_("Nick")).AddColumn(_("Expires")); time_t nickserv_expire = Config->GetModule("nickserv")->Get<time_t>("expire", "90d"), unconfirmed_expire = Config->GetModule("ns_register")->Get<time_t>("unconfirmedexpire", "1d"); - for (unsigned i = 0; i < nc->aliases->size(); ++i) + for (auto *na2 : *nc->aliases) { - const NickAlias *na2 = nc->aliases->at(i); - Anope::string expires; if (na2->HasExt("NS_NO_EXPIRE")) expires = NO_EXPIRE; @@ -351,8 +349,8 @@ class CommandNSGList : public Command std::vector<Anope::string> 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(_("%d nickname(s) in the group."), nc->aliases->size()); } diff --git a/modules/commands/ns_info.cpp b/modules/commands/ns_info.cpp index 6b1f391e5..abe423acb 100644 --- a/modules/commands/ns_info.cpp +++ b/modules/commands/ns_info.cpp @@ -114,8 +114,8 @@ class CommandNSInfo : public Command std::vector<Anope::string> replies; info.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } diff --git a/modules/commands/ns_list.cpp b/modules/commands/ns_list.cpp index 4ee7743b5..3c690984e 100644 --- a/modules/commands/ns_list.cpp +++ b/modules/commands/ns_list.cpp @@ -75,13 +75,11 @@ class CommandNSList : public Command list.AddColumn(_("Nick")).AddColumn(_("Last usermask")); Anope::map<NickAlias *> ordered_map; - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) - ordered_map[it->first] = it->second; + for (const auto &[nick, na] : *NickAliasList) + ordered_map[nick] = na; - for (Anope::map<NickAlias *>::const_iterator it = ordered_map.begin(), it_end = ordered_map.end(); it != it_end; ++it) + for (const auto &[_, na] : ordered_map) { - const NickAlias *na = it->second; - /* Don't show private nicks to non-services admins. */ if (na->nc->HasExt("NS_PRIVATE") && !is_servadmin && na->nc != mync) continue; @@ -125,8 +123,8 @@ class CommandNSList : public Command std::vector<Anope::string> 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."), nnicks > listmax ? listmax : nnicks, nnicks); return; diff --git a/modules/commands/ns_recover.cpp b/modules/commands/ns_recover.cpp index 776080afb..f8ca00329 100644 --- a/modules/commands/ns_recover.cpp +++ b/modules/commands/ns_recover.cpp @@ -69,8 +69,8 @@ class NSRecoverRequest : public IdentifyRequest if (!u->chans.empty()) { NSRecoverInfo *ei = source.GetUser()->Extend<NSRecoverInfo>("recover"); - for (User::ChanUserList::iterator it = u->chans.begin(), it_end = u->chans.end(); it != it_end; ++it) - (*ei)[it->first->name] = it->second->status; + for (auto &[chan, cuc] : u->chans) + (*ei)[chan->name] = cuc->status; } } @@ -283,8 +283,8 @@ class NSRecover : public Module NSRecoverInfo::iterator it = ei->find(c->name); if (it != ei->end()) { - for (size_t i = 0; i < it->second.Modes().length(); ++i) - c->SetMode(c->WhoSends(), ModeManager::FindChannelModeByChar(it->second.Modes()[i]), u->GetUID()); + for (auto mode : it->second.Modes()) + c->SetMode(c->WhoSends(), ModeManager::FindChannelModeByChar(mode), u->GetUID()); ei->erase(it); if (ei->empty()) diff --git a/modules/commands/ns_register.cpp b/modules/commands/ns_register.cpp index ab113b934..6fd47ad38 100644 --- a/modules/commands/ns_register.cpp +++ b/modules/commands/ns_register.cpp @@ -180,10 +180,8 @@ class CommandNSRegister : public Command if (Config->GetModule("nickserv")->Get<bool>("restrictopernicks")) { - for (unsigned i = 0; i < Oper::opers.size(); ++i) + for (auto *o : Oper::opers) { - Oper *o = Oper::opers[i]; - if (!source.IsOper() && u_nick.find_ci(o->name) != Anope::string::npos) { source.Reply(NICK_CANNOT_BE_REGISTERED, u_nick.c_str()); diff --git a/modules/commands/ns_set.cpp b/modules/commands/ns_set.cpp index 9c4101540..b18bb9cff 100644 --- a/modules/commands/ns_set.cpp +++ b/modules/commands/ns_set.cpp @@ -35,11 +35,8 @@ class CommandNSSet : public Command Anope::string this_name = source.command; bool hide_privileged_commands = Config->GetBlock("options")->Get<bool>("hideprivilegedcommands"), hide_registered_commands = Config->GetBlock("options")->Get<bool>("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) @@ -88,11 +85,8 @@ class CommandNSSASet : public Command source.Reply(_("Sets various nickname options. \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("Command", info.name); @@ -858,12 +852,12 @@ class CommandNSSetLanguage : public Command "supported languages:")); source.Reply(" en_US (English)"); - for (unsigned j = 0; j < Language::Languages.size(); ++j) + for (const auto &language : Language::Languages) { - const Anope::string &langname = Language::Translate(Language::Languages[j].c_str(), _("English")); + const Anope::string &langname = Language::Translate(language.c_str(), _("English")); if (langname == "English") continue; - source.Reply(" %s (%s)", Language::Languages[j].c_str(), langname.c_str()); + source.Reply(" %s (%s)", language.c_str(), langname.c_str()); } return true; @@ -893,12 +887,12 @@ class CommandNSSASetLanguage : public CommandNSSetLanguage "\037language\037 should be chosen from the following list of\n" "supported languages:")); source.Reply(" en (English)"); - for (unsigned j = 0; j < Language::Languages.size(); ++j) + for (const auto &language : Language::Languages) { - const Anope::string &langname = Language::Translate(Language::Languages[j].c_str(), _("English")); + const Anope::string &langname = Language::Translate(language.c_str(), _("English")); if (langname == "English") continue; - source.Reply(" %s (%s)", Language::Languages[j].c_str(), langname.c_str()); + source.Reply(" %s (%s)", language.c_str(), langname.c_str()); } return true; } @@ -1205,13 +1199,13 @@ class NSSet : public Module const NickCore *nc = anope_dynamic_static_cast<const NickCore *>(s); Anope::string modes; - for (User::ModeList::const_iterator it = nc->last_modes.begin(); it != nc->last_modes.end(); ++it) + for (const auto &[last_mode, last_value] : nc->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; } @@ -1342,13 +1336,12 @@ class NSSet : public Module { if (keep_modes.HasExt(u->Account())) { - User::ModeList modes = u->Account()->last_modes; - for (User::ModeList::iterator it = modes.begin(); it != modes.end(); ++it) + for (const auto &[last_mode, last_value] : u->Account()->last_modes) { - UserMode *um = ModeManager::FindUserModeByName(it->first); + UserMode *um = ModeManager::FindUserModeByName(last_mode); /* if the null user can set the mode, then it's probably safe */ if (um && um->CanSet(NULL)) - u->SetMode(NULL, it->first, it->second); + u->SetMode(NULL, last_mode, last_value); } } } diff --git a/modules/commands/ns_set_misc.cpp b/modules/commands/ns_set_misc.cpp index db7a1e8ef..be2804f04 100644 --- a/modules/commands/ns_set_misc.cpp +++ b/modules/commands/ns_set_misc.cpp @@ -191,8 +191,8 @@ class NSSetMisc : public Module ~NSSetMisc() override { - for (Anope::map<ExtensibleItem<NSMiscData> *>::iterator it = items.begin(); it != items.end(); ++it) - delete it->second; + for (const auto &[_, data] : items) + delete data; } void OnReload(Configuration::Conf *conf) override @@ -220,9 +220,8 @@ class NSSetMisc : public Module void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool) override { - for (Anope::map<ExtensibleItem<NSMiscData> *>::iterator it = items.begin(); it != items.end(); ++it) + for (const auto &[_, e] : items) { - ExtensibleItem<NSMiscData> *e = it->second; NSMiscData *data = e->Get(na->nc); if (data != NULL) diff --git a/modules/commands/ns_suspend.cpp b/modules/commands/ns_suspend.cpp index d9f26fe9c..28ca99b68 100644 --- a/modules/commands/ns_suspend.cpp +++ b/modules/commands/ns_suspend.cpp @@ -116,10 +116,8 @@ class CommandNSSuspend : public Command si->when = Anope::CurTime; si->expires = expiry_secs ? expiry_secs + Anope::CurTime : 0; - for (unsigned i = 0; i < nc->aliases->size(); ++i) + for (auto *na2 : *nc->aliases) { - NickAlias *na2 = nc->aliases->at(i); - if (na2 && *na2->nc == *na->nc) { na2->last_quit = reason; diff --git a/modules/commands/os_akill.cpp b/modules/commands/os_akill.cpp index 56203e4c1..31f96b507 100644 --- a/modules/commands/os_akill.cpp +++ b/modules/commands/os_akill.cpp @@ -172,8 +172,8 @@ class CommandOSAKill : public Command x->id = XLineManager::GenerateUID(); unsigned int affected = 0; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (akills->Check(it->second, x)) + for (const auto &[_, user] : UserListByNick) + if (akills->Check(user, x)) ++affected; float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; @@ -325,8 +325,8 @@ class CommandOSAKill : public Command std::vector<Anope::string> 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 AKILL list.")); } diff --git a/modules/commands/os_chankill.cpp b/modules/commands/os_chankill.cpp index 5f2563bcf..a22eae178 100644 --- a/modules/commands/os_chankill.cpp +++ b/modules/commands/os_chankill.cpp @@ -69,10 +69,8 @@ class CommandOSChanKill : public Command if ((c = Channel::Find(channel))) { - for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : c->users) { - ChanUserContainer *uc = it->second; - if (uc->user->server == Me || uc->user->HasMode("OPER")) continue; diff --git a/modules/commands/os_config.cpp b/modules/commands/os_config.cpp index f94491a5c..3f211d695 100644 --- a/modules/commands/os_config.cpp +++ b/modules/commands/os_config.cpp @@ -62,11 +62,11 @@ class CommandOSConfig : public Command ListFormatter lflist(source.GetAccount()); lflist.AddColumn(_("Name")).AddColumn(_("Value")); - for (Configuration::Block::item_map::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it) + for (const auto &[name, value] : items) { ListFormatter::ListEntry entry; - entry["Name"] = it->first; - entry["Value"] = it->second; + entry["Name"] = name; + entry["Value"] = value; lflist.AddEntry(entry); } @@ -75,8 +75,8 @@ class CommandOSConfig : public Command source.Reply(_("%s settings:"), block->GetName().c_str()); - for (unsigned j = 0; j < replies.size(); ++j) - source.Reply(replies[j]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(" "); } @@ -95,10 +95,10 @@ class CommandOSConfig : public Command ListFormatter::ListEntry entry; entry["Module Name"] = block->Get<Anope::string>("name"); - for (Configuration::Block::item_map::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it) + for (const auto &[name, value] : items) { - entry["Name"] = it->first; - entry["Value"] = it->second; + entry["Name"] = name; + entry["Value"] = value; lflist.AddEntry(entry); } } @@ -108,8 +108,8 @@ class CommandOSConfig : public Command source.Reply(_("Module settings:")); - for (unsigned j = 0; j < replies.size(); ++j) - source.Reply(replies[j]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of configuration.")); } diff --git a/modules/commands/os_defcon.cpp b/modules/commands/os_defcon.cpp index 7721d7815..8a93a7f7b 100644 --- a/modules/commands/os_defcon.cpp +++ b/modules/commands/os_defcon.cpp @@ -253,7 +253,6 @@ class OSDefcon : public Module void ParseModeString() { int add = -1; /* 1 if adding, 0 if deleting, -1 if neither */ - unsigned char mode; ChannelMode *cm; ChannelModeParam *cmp; Anope::string modes, param; @@ -265,10 +264,8 @@ class OSDefcon : public Module ss.GetToken(modes); /* Loop while there are modes to set */ - for (unsigned i = 0, end = modes.length(); i < end; ++i) + for (auto mode : modes) { - mode = modes[i]; - switch (mode) { case '+': @@ -559,8 +556,8 @@ static void runDefCon() { Log(OperServ, "operserv/defcon") << "DEFCON: setting " << DConfig.chanmodes << " on all channels"; DefConModesSet = true; - for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) - it->second->SetModes(OperServ, false, "%s", DConfig.chanmodes.c_str()); + for (const auto &[_, chan] : ChannelList) + chan->SetModes(OperServ, false, "%s", DConfig.chanmodes.c_str()); } } } @@ -575,8 +572,8 @@ static void runDefCon() if (!newmodes.empty()) { Log(OperServ, "operserv/defcon") << "DEFCON: setting " << newmodes << " on all channels"; - for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) - it->second->SetModes(OperServ, true, "%s", newmodes.c_str()); + for (const auto &[_, chan] : ChannelList) + chan->SetModes(OperServ, true, "%s", newmodes.c_str()); } } } @@ -588,14 +585,14 @@ static Anope::string defconReverseModes(const Anope::string &modes) if (modes.empty()) return ""; Anope::string newmodes; - for (unsigned i = 0, end = modes.length(); i < end; ++i) + for (auto mode : modes) { - if (modes[i] == '+') + if (mode == '+') newmodes += '-'; - else if (modes[i] == '-') + else if (mode == '-') newmodes += '+'; else - newmodes += modes[i]; + newmodes += mode; } return newmodes; } diff --git a/modules/commands/os_dns.cpp b/modules/commands/os_dns.cpp index bcc1eaef0..c297ec062 100644 --- a/modules/commands/os_dns.cpp +++ b/modules/commands/os_dns.cpp @@ -40,8 +40,8 @@ struct DNSZone : Serializable { data["name"] << name; unsigned count = 0; - for (std::set<Anope::string, ci::less>::iterator it = servers.begin(), it_end = servers.end(); it != it_end; ++it) - data["server" + stringify(count++)] << *it; + for (const auto &server : servers) + data["server" + stringify(count++)] << server; } static Serializable* Unserialize(Serializable *obj, Serialize::Data &data) @@ -74,13 +74,14 @@ struct DNSZone : Serializable static DNSZone *Find(const Anope::string &name) { - for (unsigned i = 0; i < zones->size(); ++i) - if (zones->at(i)->name.equals_ci(name)) + for (auto *zone : *zones) + { + if (zone->name.equals_ci(name)) { - DNSZone *z = zones->at(i); - z->QueueUpdate(); - return z; + zone->QueueUpdate(); + return zone; } + } return NULL; } }; @@ -134,8 +135,8 @@ class DNSServer : public Serializable if (dnsmanager) { dnsmanager->UpdateSerial(); - for (std::set<Anope::string, ci::less>::iterator it = zones.begin(), it_end = zones.end(); it != it_end; ++it) - dnsmanager->Notify(*it); + for (const auto &zone : zones) + dnsmanager->Notify(zone); } } @@ -147,8 +148,8 @@ class DNSServer : public Serializable data["limit"] << limit; data["pooled"] << pooled; unsigned count = 0; - for (std::set<Anope::string, ci::less>::iterator it = zones.begin(), it_end = zones.end(); it != it_end; ++it) - data["zone" + stringify(count++)] << *it; + for (const auto &zone : zones) + data["zone" + stringify(count++)] << zone; } static Serializable* Unserialize(Serializable *obj, Serialize::Data &data) @@ -193,10 +194,9 @@ class DNSServer : public Serializable static DNSServer *Find(const Anope::string &s) { - for (unsigned i = 0; i < dns_servers->size(); ++i) - if (dns_servers->at(i)->GetName().equals_ci(s)) + for (auto *serv : *dns_servers) + if (serv->GetName().equals_ci(s)) { - DNSServer *serv = dns_servers->at(i); serv->QueueUpdate(); return serv; } @@ -216,9 +216,8 @@ class CommandOSDNS : public Command ListFormatter lf(source.GetAccount()); lf.AddColumn(_("Server")).AddColumn(_("IP")).AddColumn(_("Limit")).AddColumn(_("State")); - for (unsigned i = 0; i < dns_servers->size(); ++i) + for (auto *s : *dns_servers) { - DNSServer *s = dns_servers->at(i); Server *srv = Server::Find(s->GetName(), true); ListFormatter::ListEntry entry; @@ -226,8 +225,8 @@ class CommandOSDNS : public Command entry["Limit"] = s->GetLimit() ? stringify(s->GetLimit()) : Language::Translate(source.GetAccount(), _("None")); Anope::string ip_str; - for (unsigned j = 0; j < s->GetIPs().size(); ++j) - ip_str += s->GetIPs()[j] + " "; + for (const auto &ip : s->GetIPs()) + ip_str += ip + " "; ip_str.trim(); if (ip_str.empty()) ip_str = "None"; @@ -254,16 +253,14 @@ class CommandOSDNS : public Command ListFormatter lf2(source.GetAccount()); lf2.AddColumn(_("Zone")).AddColumn(_("Servers")); - for (unsigned i = 0; i < zones->size(); ++i) + for (auto *z : *zones) { - const DNSZone *z = zones->at(i); - ListFormatter::ListEntry entry; entry["Zone"] = z->name; Anope::string server_str; - for (std::set<Anope::string, ci::less>::iterator it = z->servers.begin(), it_end = z->servers.end(); it != it_end; ++it) - server_str += *it + " "; + for (const auto &server : z->servers) + server_str += server + " "; server_str.trim(); if (server_str.empty()) @@ -277,8 +274,8 @@ class CommandOSDNS : public Command lf2.Process(replies); } - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } void AddZone(CommandSource &source, const std::vector<Anope::string> ¶ms) @@ -316,9 +313,9 @@ class CommandOSDNS : public Command Log(LOG_ADMIN, source, this) << "to delete zone " << z->name; - for (std::set<Anope::string, ci::less>::iterator it = z->servers.begin(), it_end = z->servers.end(); it != it_end; ++it) + for (const auto &server : z->servers) { - DNSServer *s = DNSServer::Find(*it); + DNSServer *s = DNSServer::Find(server); if (s) s->zones.erase(z->name); } @@ -466,9 +463,9 @@ class CommandOSDNS : public Command return; } - for (std::set<Anope::string, ci::less>::iterator it = s->zones.begin(), it_end = s->zones.end(); it != it_end; ++it) + for (const auto &zone : s->zones) { - DNSZone *z = DNSZone::Find(*it); + DNSZone *z = DNSZone::Find(zone); if (z) z->servers.erase(s->GetName()); } @@ -494,12 +491,14 @@ class CommandOSDNS : public Command return; } - for (unsigned i = 0; i < s->GetIPs().size(); ++i) - if (params[2].equals_ci(s->GetIPs()[i])) + for (const auto &ip : s->GetIPs()) + { + if (params[2].equals_ci(ip)) { - source.Reply(_("IP %s already exists for %s."), s->GetIPs()[i].c_str(), s->GetName().c_str()); + source.Reply(_("IP %s already exists for %s."), ip.c_str(), s->GetName().c_str()); return; } + } sockaddrs addr(params[2]); if (!addr.valid()) @@ -518,8 +517,8 @@ class CommandOSDNS : public Command if (s->Active() && dnsmanager) { dnsmanager->UpdateSerial(); - for (std::set<Anope::string, ci::less>::iterator it = s->zones.begin(), it_end = s->zones.end(); it != it_end; ++it) - dnsmanager->Notify(*it); + for (const auto &zone : s->zones) + dnsmanager->Notify(zone); } } @@ -552,8 +551,8 @@ class CommandOSDNS : public Command if (s->Active() && dnsmanager) { dnsmanager->UpdateSerial(); - for (std::set<Anope::string, ci::less>::iterator it = s->zones.begin(), it_end = s->zones.end(); it != it_end; ++it) - dnsmanager->Notify(*it); + for (const auto &zone : s->zones) + dnsmanager->Notify(zone); } return; @@ -735,9 +734,8 @@ class ModuleDNS : public Module ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), zone_type("DNSZone", DNSZone::Unserialize), dns_type("DNSServer", DNSServer::Unserialize), commandosdns(this) { - for (unsigned j = 0; j < dns_servers->size(); ++j) + for (auto *s : *dns_servers) { - DNSServer *s = dns_servers->at(j); if (s->Pooled() && Server::Find(s->GetName(), true)) s->SetActive(true); } @@ -862,21 +860,21 @@ class ModuleDNS : public Module size_t answer_size = packet->answers.size(); if (zone) { - for (std::set<Anope::string, ci::less>::iterator it = zone->servers.begin(), it_end = zone->servers.end(); it != it_end; ++it) + for (const auto &server : zone->servers) { - DNSServer *s = DNSServer::Find(*it); + DNSServer *s = DNSServer::Find(server); if (!s || !s->Active()) continue; - for (unsigned j = 0; j < s->GetIPs().size(); ++j) + for (const auto &ip : s->GetIPs()) { - DNS::QueryType q_type = s->GetIPs()[j].find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; + DNS::QueryType q_type = ip.find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; if (q.type == DNS::QUERY_AXFR || q.type == DNS::QUERY_ANY || q_type == q.type) { DNS::ResourceRecord rr(q.name, q_type); rr.ttl = this->ttl; - rr.rdata = s->GetIPs()[j]; + rr.rdata = ip; packet->answers.push_back(rr); } } @@ -886,21 +884,20 @@ class ModuleDNS : public Module if (packet->answers.size() == answer_size) { /* Default zone */ - for (unsigned i = 0; i < dns_servers->size(); ++i) + for (auto *s : *dns_servers) { - DNSServer *s = dns_servers->at(i); if (!s->Active()) continue; - for (unsigned j = 0; j < s->GetIPs().size(); ++j) + for (const auto &ip : s->GetIPs()) { - DNS::QueryType q_type = s->GetIPs()[j].find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; + DNS::QueryType q_type = ip.find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; if (q.type == DNS::QUERY_AXFR || q.type == DNS::QUERY_ANY || q_type == q.type) { DNS::ResourceRecord rr(q.name, q_type); rr.ttl = this->ttl; - rr.rdata = s->GetIPs()[j]; + rr.rdata = ip; packet->answers.push_back(rr); } } @@ -916,19 +913,17 @@ class ModuleDNS : public Module } /* Something messed up, just return them all and hope one is available */ - for (unsigned i = 0; i < dns_servers->size(); ++i) + for (auto *s : *dns_servers) { - DNSServer *s = dns_servers->at(i); - - for (unsigned j = 0; j < s->GetIPs().size(); ++j) + for (const auto &ip : s->GetIPs()) { - DNS::QueryType q_type = s->GetIPs()[j].find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; + DNS::QueryType q_type = ip.find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; if (q.type == DNS::QUERY_AXFR || q.type == DNS::QUERY_ANY || q_type == q.type) { DNS::ResourceRecord rr(q.name, q_type); rr.ttl = this->ttl; - rr.rdata = s->GetIPs()[j]; + rr.rdata = ip; packet->answers.push_back(rr); } } diff --git a/modules/commands/os_forbid.cpp b/modules/commands/os_forbid.cpp index 7c907a9f7..c17a719b7 100644 --- a/modules/commands/os_forbid.cpp +++ b/modules/commands/os_forbid.cpp @@ -70,9 +70,8 @@ class MyForbidService : public ForbidService ~MyForbidService() override { - std::vector<ForbidData *> f = GetForbids(); - for (unsigned i = 0; i < f.size(); ++i) - delete f[i]; + for (const auto *forbid : GetForbids()) + delete forbid; } void AddForbid(ForbidData *d) override @@ -245,8 +244,8 @@ class CommandOSForbid : public Command { int na_matches = 0; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - module->OnUserNickChange(it->second, ""); + for (const auto &[_, user] : UserListByNick) + module->OnUserNickChange(user, ""); for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end;) { @@ -358,31 +357,29 @@ class CommandOSForbid : public Command list.AddColumn(_("Mask")).AddColumn(_("Type")).AddColumn(_("Creator")).AddColumn(_("Expires")).AddColumn(_("Reason")); unsigned shown = 0; - for (unsigned i = 0; i < forbids.size(); ++i) + for (auto *forbid : forbids) { - ForbidData *d = forbids[i]; - - if (ftype != FT_SIZE && ftype != d->type) + if (ftype != FT_SIZE && ftype != forbid->type) continue; Anope::string stype; - if (d->type == FT_NICK) + if (forbid->type == FT_NICK) stype = "NICK"; - else if (d->type == FT_CHAN) + else if (forbid->type == FT_CHAN) stype = "CHAN"; - else if (d->type == FT_EMAIL) + else if (forbid->type == FT_EMAIL) stype = "EMAIL"; - else if (d->type == FT_REGISTER) + else if (forbid->type == FT_REGISTER) stype = "REGISTER"; else continue; ListFormatter::ListEntry entry; - entry["Mask"] = d->mask; + entry["Mask"] = forbid->mask; entry["Type"] = stype; - entry["Creator"] = d->creator; - entry["Expires"] = d->expires ? Anope::strftime(d->expires, NULL, true).c_str() : Language::Translate(source.GetAccount(), _("Never")); - entry["Reason"] = d->reason; + entry["Creator"] = forbid->creator; + entry["Expires"] = forbid->expires ? Anope::strftime(forbid->expires, NULL, true).c_str() : Language::Translate(source.GetAccount(), _("Never")); + entry["Reason"] = forbid->reason; list.AddEntry(entry); ++shown; } @@ -398,8 +395,8 @@ class CommandOSForbid : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); if (shown >= forbids.size()) source.Reply(_("End of forbid list.")); diff --git a/modules/commands/os_ignore.cpp b/modules/commands/os_ignore.cpp index 685e49d36..f779840fb 100644 --- a/modules/commands/os_ignore.cpp +++ b/modules/commands/os_ignore.cpp @@ -282,8 +282,8 @@ class CommandOSIgnore : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } diff --git a/modules/commands/os_info.cpp b/modules/commands/os_info.cpp index 95d48ba16..8015f835d 100644 --- a/modules/commands/os_info.cpp +++ b/modules/commands/os_info.cpp @@ -148,10 +148,8 @@ class CommandOSInfo : public Command return; } - for (unsigned i = 0; i < (*oi)->size(); ++i) + for (auto *o : *(*oi)) { - OperInfo *o = (*oi)->at(i); - if (o->info.equals_ci(info)) { source.Reply(_("The oper info already exists on \002%s\002."), target.c_str()); @@ -262,9 +260,8 @@ class OSInfo : public Module if (!oi) return; - for (unsigned i = 0; i < (*oi)->size(); ++i) + for (auto *o : *(*oi)) { - OperInfo *o = (*oi)->at(i); info[_("Oper Info")] = Anope::printf(_("(by %s on %s) %s"), o->adder.c_str(), Anope::strftime(o->created, source.GetAccount(), true).c_str(), o->info.c_str()); } } diff --git a/modules/commands/os_list.cpp b/modules/commands/os_list.cpp index d2b94c089..163044210 100644 --- a/modules/commands/os_list.cpp +++ b/modules/commands/os_list.cpp @@ -46,14 +46,16 @@ class CommandOSChanList : public Command { source.Reply(_("\002%s\002 channel list:"), u2->nick.c_str()); - for (User::ChanUserList::iterator uit = u2->chans.begin(), uit_end = u2->chans.end(); uit != uit_end; ++uit) + for (const auto &[_, cc]: u2->chans) { - ChanUserContainer *cc = uit->second; - if (!modes.empty()) - for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it) - if (!cc->chan->HasMode(*it)) + { + for (const auto &mode : modes) + { + if (!cc->chan->HasMode(mode)) continue; + } + } ListFormatter::ListEntry entry; entry["Name"] = cc->chan->name; @@ -69,16 +71,18 @@ class CommandOSChanList : public Command { source.Reply(_("Channel list:")); - for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit) + for (const auto &[_, c] : ChannelList) { - Channel *c = cit->second; - if (!pattern.empty() && !Anope::Match(c->name, pattern, false, true)) continue; if (!modes.empty()) - for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it) - if (!c->HasMode(*it)) + { + for (const auto &mode : modes) + { + if (!c->HasMode(mode)) continue; + } + } ListFormatter::ListEntry entry; entry["Name"] = c->name; @@ -94,8 +98,8 @@ class CommandOSChanList : public Command std::vector<Anope::string> 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 channel list. \002%u\002 channels shown."), count); } @@ -156,14 +160,16 @@ class CommandOSUserList : public Command { source.Reply(_("\002%s\002 users list:"), pattern.c_str()); - for (Channel::ChanUserList::iterator cuit = c->users.begin(), cuit_end = c->users.end(); cuit != cuit_end; ++cuit) + for (const auto &[_, uc] : c->users) { - ChanUserContainer *uc = cuit->second; - if (!modes.empty()) - for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it) - if (!uc->user->HasMode(*it)) + { + for (const auto &mode : modes) + { + if (!uc->user->HasMode(mode)) continue; + } + } ListFormatter::ListEntry entry; entry["Name"] = uc->user->nick; @@ -178,8 +184,8 @@ class CommandOSUserList : public Command { /* Historically this has been ordered, so... */ Anope::map<User *> ordered_map; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - ordered_map[it->first] = it->second; + for (const auto &[nick, user] : UserListByNick) + ordered_map[nick] = user; source.Reply(_("Users list:")); @@ -197,10 +203,10 @@ class CommandOSUserList : public Command }; bool match = false; - for (unsigned int i = 0; i < sizeof(masks) / sizeof(*masks); ++i) + for (const auto &mask : masks) { /* Check mask with realname included, too */ - if (Anope::Match(masks[i], pattern, false, true) || Anope::Match(masks[i] + "#" + u2->realname, pattern, false, true)) + if (Anope::Match(mask, pattern, false, true) || Anope::Match(mask + "#" + u2->realname, pattern, false, true)) { match = true; break; @@ -211,9 +217,13 @@ class CommandOSUserList : public Command continue; if (!modes.empty()) - for (std::set<Anope::string>::iterator mit = modes.begin(), mit_end = modes.end(); mit != mit_end; ++mit) - if (!u2->HasMode(*mit)) + { + for (const auto &mode : modes) + { + if (!u2->HasMode(mode)) continue; + } + } } ListFormatter::ListEntry entry; @@ -229,8 +239,8 @@ class CommandOSUserList : public Command std::vector<Anope::string> 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 users list. \002%u\002 users shown."), count); return; diff --git a/modules/commands/os_logsearch.cpp b/modules/commands/os_logsearch.cpp index eed329c04..ecea323c5 100644 --- a/modules/commands/os_logsearch.cpp +++ b/modules/commands/os_logsearch.cpp @@ -147,8 +147,8 @@ class CommandOSLogSearch : public Command source.Reply(_("Matches for \002%s\002:"), search_string.c_str()); unsigned int count = 0; - for (std::vector<Anope::string>::iterator it = matches.begin(), it_end = matches.end(); it != it_end; ++it) - source.Reply("#%d: %s", ++count, it->c_str()); + for (const auto &match : matches) + source.Reply("#%d: %s", ++count, match.c_str()); source.Reply(_("Showed %d/%d matches for \002%s\002."), matches.size(), found, search_string.c_str()); } diff --git a/modules/commands/os_mode.cpp b/modules/commands/os_mode.cpp index 541aa8fbc..096f50118 100644 --- a/modules/commands/os_mode.cpp +++ b/modules/commands/os_mode.cpp @@ -35,9 +35,8 @@ class CommandOSMode : public Command { bool all = params.size() > 2 && params[2].equals_ci("ALL"); - const Channel::ModeList chmodes = c->GetModes(); - for (Channel::ModeList::const_iterator it = chmodes.begin(), it_end = chmodes.end(); it != it_end && c; ++it) - c->RemoveMode(c->WhoSends(), it->first, it->second, false); + for (const auto &[mode, value] : c->GetModes()) + c->RemoveMode(c->WhoSends(), mode, value, false); if (!c) { @@ -47,10 +46,8 @@ class CommandOSMode : public Command if (all) { - for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : c->users) { - ChanUserContainer *uc = it->second; - if (uc->user->HasMode("OPER")) continue; diff --git a/modules/commands/os_modinfo.cpp b/modules/commands/os_modinfo.cpp index 1dfa519ae..5d6de2e6c 100644 --- a/modules/commands/os_modinfo.cpp +++ b/modules/commands/os_modinfo.cpp @@ -34,22 +34,18 @@ class CommandOSModInfo : public Command source.Reply(_(" Loaded at: %p"), m->handle); std::vector<Anope::string> servicekeys = Service::GetServiceKeys("Command"); - for (unsigned i = 0; i < servicekeys.size(); ++i) + for (const auto &servicekey : servicekeys) { - ServiceReference<Command> c("Command", servicekeys[i]); + ServiceReference<Command> c("Command", servicekey); if (!c || c->owner != m) continue; source.Reply(_(" Providing service: \002%s\002"), c->name.c_str()); - for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (const auto &[_, bi] : *BotListByNick) { - const BotInfo *bi = it->second; - - for (CommandInfo::map::const_iterator cit = bi->commands.begin(), cit_end = bi->commands.end(); cit != cit_end; ++cit) + for (const auto &[c_name, info] : bi->commands) { - const Anope::string &c_name = cit->first; - const CommandInfo &info = cit->second; if (info.name != c->name) continue; source.Reply(_(" Command \002%s\002 on \002%s\002 is linked to \002%s\002"), c_name.c_str(), bi->nick.c_str(), c->name.c_str()); @@ -116,10 +112,8 @@ class CommandOSModList : public Command source.Reply(_("Current module list:")); int count = 0; - for (std::list<Module *>::iterator it = ModuleManager::Modules.begin(), it_end = ModuleManager::Modules.end(); it != it_end; ++it) + for (auto *m : ModuleManager::Modules) { - Module *m = *it; - bool show = false; Anope::string mtype; diff --git a/modules/commands/os_news.cpp b/modules/commands/os_news.cpp index 373774570..68c9f2629 100644 --- a/modules/commands/os_news.cpp +++ b/modules/commands/os_news.cpp @@ -101,9 +101,11 @@ class MyNewsService : public NewsService ~MyNewsService() override { - for (unsigned i = 0; i < 3; ++i) - for (unsigned j = 0; j < newsItems[i].size(); ++j) - delete newsItems[i][j]; + for (const auto &newstype : newsItems) + { + for (const auto *newsitem : newstype) + delete newsitem; + } } NewsItem *CreateNewsItem() override @@ -134,9 +136,9 @@ class MyNewsService : public NewsService #define lenof(a) (sizeof(a) / sizeof(*(a))) static const char **findmsgs(NewsType type) { - for (unsigned i = 0; i < lenof(msgarray); ++i) - if (msgarray[i].type == type) - return msgarray[i].msgs; + for (auto &msg : msgarray) + if (msg.type == type) + return msg.msgs; return NULL; } @@ -170,8 +172,8 @@ class NewsBase : public Command std::vector<Anope::string> replies; lflist.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 news list.")); } diff --git a/modules/commands/os_noop.cpp b/modules/commands/os_noop.cpp index bfcb28a5d..23cf83142 100644 --- a/modules/commands/os_noop.cpp +++ b/modules/commands/os_noop.cpp @@ -42,10 +42,8 @@ class CommandOSNOOP : public Command Anope::string reason = "NOOP command used by " + source.GetNick(); /* Kill all the IRCops of the server */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, u2] : UserListByNick) { - User *u2 = it->second; - if (u2->server == s && u2->HasMode("OPER")) u2->Kill(*source.service, reason); } diff --git a/modules/commands/os_oper.cpp b/modules/commands/os_oper.cpp index 0d17b0cd6..67612ea74 100644 --- a/modules/commands/os_oper.cpp +++ b/modules/commands/os_oper.cpp @@ -50,15 +50,17 @@ class CommandOSOper : public Command { bool HasPrivs(CommandSource &source, OperType *ot) const { - std::list<Anope::string> commands = ot->GetCommands(), privs = ot->GetPrivs(); - - for (std::list<Anope::string>::iterator it = commands.begin(); it != commands.end(); ++it) - if (!source.HasCommand(*it)) + for (const auto &command : ot->GetCommands()) + { + if (!source.HasCommand(command)) return false; + } - for (std::list<Anope::string>::iterator it = privs.begin(); it != privs.end(); ++it) - if (!source.HasPriv(*it)) + for (const auto &priv : ot->GetPrivs()) + { + if (!source.HasPriv(priv)) return false; + } return true; } @@ -151,20 +153,17 @@ class CommandOSOper : public Command else if (subcommand.equals_ci("LIST")) { source.Reply(_("Name Type")); - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - const NickCore *nc = it->second; - if (!nc->o) continue; source.Reply(_("%-8s %s"), nc->o->name.c_str(), nc->o->ot->GetName().c_str()); if (std::find(Config->Opers.begin(), Config->Opers.end(), nc->o) != Config->Opers.end()) source.Reply(_(" This oper is configured in the configuration file.")); - for (std::list<User *>::const_iterator uit = nc->users.begin(); uit != nc->users.end(); ++uit) + for (auto *u : nc->users) { - User *u = *uit; - source.Reply(_(" %s is online using this oper block."), u->nick.c_str()); + source.Reply(_(" %s is online using this oper block."), u->nick.c_str()); } } } @@ -173,9 +172,8 @@ class CommandOSOper : public Command if (params.size() < 2) { source.Reply(_("Available opertypes:")); - for (unsigned i = 0; i < Config->MyOperTypes.size(); ++i) + for (auto *ot : Config->MyOperTypes) { - OperType *ot = Config->MyOperTypes[i]; source.Reply("%s", ot->GetName().c_str()); } return; @@ -196,9 +194,9 @@ class CommandOSOper : public Command source.Reply(_("Available commands for \002%s\002:"), ot->GetName().c_str()); Anope::string buf; std::list<Anope::string> cmds = ot->GetCommands(); - for (std::list<Anope::string>::const_iterator it = cmds.begin(), it_end = cmds.end(); it != it_end; ++it) + for (const auto &cmd : cmds) { - buf += *it + " "; + buf += cmd + " "; if (buf.length() > 400) { source.Reply("%s", buf.c_str()); @@ -218,9 +216,9 @@ class CommandOSOper : public Command source.Reply(_("Available privileges for \002%s\002:"), ot->GetName().c_str()); Anope::string buf; std::list<Anope::string> privs = ot->GetPrivs(); - for (std::list<Anope::string>::const_iterator it = privs.begin(), it_end = privs.end(); it != it_end; ++it) + for (const auto &priv : privs) { - buf += *it + " "; + buf += priv + " "; if (buf.length() > 400) { source.Reply("%s", buf.c_str()); @@ -267,10 +265,8 @@ class OSOper : public Module ~OSOper() override { - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - NickCore *nc = it->second; - if (nc->o && dynamic_cast<MyOper *>(nc->o)) { delete nc->o; diff --git a/modules/commands/os_session.cpp b/modules/commands/os_session.cpp index 517b22279..07e1e551f 100644 --- a/modules/commands/os_session.cpp +++ b/modules/commands/os_session.cpp @@ -61,9 +61,8 @@ class MySessionService : public SessionService Exception *FindException(User *u) override { - for (std::vector<Exception *>::const_iterator it = this->Exceptions->begin(), it_end = this->Exceptions->end(); it != it_end; ++it) + for (auto *e : *this->Exceptions) { - Exception *e = *it; if (Anope::Match(u->host, e->mask) || Anope::Match(u->ip.addr(), e->mask)) return e; @@ -75,9 +74,8 @@ class MySessionService : public SessionService Exception *FindException(const Anope::string &host) override { - for (std::vector<Exception *>::const_iterator it = this->Exceptions->begin(), it_end = this->Exceptions->end(); it != it_end; ++it) + for (auto *e : *this->Exceptions) { - Exception *e = *it; if (Anope::Match(host, e->mask)) return e; @@ -191,10 +189,8 @@ class CommandOSSession : public Command ListFormatter list(source.GetAccount()); list.AddColumn(_("Session")).AddColumn(_("Host")); - for (SessionService::SessionMap::iterator it = session_service->GetSessions().begin(), it_end = session_service->GetSessions().end(); it != it_end; ++it) + for (const auto &[_, session] : session_service->GetSessions()) { - Session *session = it->second; - if (session->count >= mincount) { ListFormatter::ListEntry entry; @@ -210,8 +206,8 @@ class CommandOSSession : public Command list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } return; @@ -347,9 +343,8 @@ class CommandOSException : public Command return; } - for (std::vector<Exception *>::iterator it = session_service->GetExceptions().begin(), it_end = session_service->GetExceptions().end(); it != it_end; ++it) + for (auto *e : session_service->GetExceptions()) { - Exception *e = *it; if (e->mask.equals_ci(mask)) { if (e->limit != limit) @@ -495,8 +490,8 @@ class CommandOSException : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } diff --git a/modules/commands/os_stats.cpp b/modules/commands/os_stats.cpp index 302addceb..2fe23ddaf 100644 --- a/modules/commands/os_stats.cpp +++ b/modules/commands/os_stats.cpp @@ -50,8 +50,10 @@ static int stats_count_servers(Server *s) int count = 1; if (!s->GetLinks().empty()) - for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i) - count += stats_count_servers(s->GetLinks()[i]); + { + for (auto *link : s->GetLinks()) + count += stats_count_servers(link); + } return count; } @@ -145,8 +147,8 @@ class CommandOSStats : public Command void DoStatsUplink(CommandSource &source) { Anope::string buf; - for (std::set<Anope::string>::iterator it = Servers::Capab.begin(); it != Servers::Capab.end(); ++it) - buf += " " + *it; + for (const auto &capab : Servers::Capab) + buf += " " + capab; if (!buf.empty()) buf.erase(buf.begin()); diff --git a/modules/commands/os_sxline.cpp b/modules/commands/os_sxline.cpp index b280297a8..f08b64933 100644 --- a/modules/commands/os_sxline.cpp +++ b/modules/commands/os_sxline.cpp @@ -182,8 +182,8 @@ class CommandOSSXLineBase : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } @@ -371,8 +371,8 @@ class CommandOSSNLine : public CommandOSSXLineBase x->id = XLineManager::GenerateUID(); unsigned int affected = 0; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (this->xlm()->Check(it->second, x)) + for (const auto &[_, user] : UserListByNick) + if (this->xlm()->Check(user, x)) ++affected; float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; @@ -401,10 +401,8 @@ class CommandOSSNLine : public CommandOSSXLineBase { Anope::string rreason = "G-Lined: " + reason; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, user] : UserListByNick) { - User *user = it->second; - if (!user->HasMode("OPER") && user->server != Me && this->xlm()->Check(user, x)) user->Kill(Me, rreason); } @@ -579,8 +577,8 @@ class CommandOSSQLine : public CommandOSSXLineBase x->id = XLineManager::GenerateUID(); unsigned int affected = 0; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (this->xlm()->Check(it->second, x)) + for (const auto &[_, user] : UserListByNick) + if (this->xlm()->Check(user, x)) ++affected; float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; @@ -611,33 +609,28 @@ class CommandOSSQLine : public CommandOSSXLineBase if (mask[0] == '#') { - for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit) + for (const auto &[_, c] : ChannelList) { - Channel *c = cit->second; - if (!Anope::Match(c->name, mask, false, true)) continue; std::vector<User *> users; - for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : 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) - c->Kick(NULL, users[i], "%s", reason.c_str()); + for (auto *user : users) + c->Kick(NULL, user, "%s", reason.c_str()); } } else { - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, user] : UserListByNick) { - User *user = it->second; - if (!user->HasMode("OPER") && user->server != Me && this->xlm()->Check(user, x)) user->Kill(Me, rreason); } |
