diff options
author | Sadie Powell <sadie@witchery.services> | 2024-02-27 10:16:05 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-02-27 10:19:44 +0000 |
commit | 7640fad30cc2a3d61e67a7075c27f26400d4779f (patch) | |
tree | f313f0e7cf6fafd1c94f7bd2b3650a207f941ccc | |
parent | 9f6d3787559febb48611b1477eaa6a35beadf71a (diff) |
Simplify several boolean expressions.
27 files changed, 40 insertions, 50 deletions
diff --git a/modules/chanserv/cs_flags.cpp b/modules/chanserv/cs_flags.cpp index 38de5c49f..0c1e088da 100644 --- a/modules/chanserv/cs_flags.cpp +++ b/modules/chanserv/cs_flags.cpp @@ -26,9 +26,7 @@ public: bool HasPriv(const Anope::string &priv) const override { std::map<Anope::string, char>::iterator it = defaultFlags.find(priv); - if (it != defaultFlags.end() && this->flags.count(it->second) > 0) - return true; - return false; + return it != defaultFlags.end() && this->flags.count(it->second) > 0; } Anope::string AccessSerialize() const override @@ -324,7 +322,7 @@ class CommandCSFlags final for (size_t j = 1; j < arg.length(); ++j) if (flags.find(arg[j]) == Anope::string::npos) pass = false; - if (pass == false) + if (!pass) continue; } else if (!Anope::Match(access->Mask(), arg)) diff --git a/modules/chanserv/cs_topic.cpp b/modules/chanserv/cs_topic.cpp index f774dca65..f21ea11f8 100644 --- a/modules/chanserv/cs_topic.cpp +++ b/modules/chanserv/cs_topic.cpp @@ -262,7 +262,7 @@ public: ModeLocks *ml = ci->GetExt<ModeLocks>("modelocks"); const ModeLock *secret = ml ? ml->GetMLock("SECRET") : NULL; - if (!ci->last_topic.empty() && (show_all || ((!secret || secret->set == false) && (!ci->c || !ci->c->HasMode("SECRET"))))) + if (!ci->last_topic.empty() && (show_all || ((!secret || !secret->set) && (!ci->c || !ci->c->HasMode("SECRET"))))) { info[_("Last topic")] = ci->last_topic; info[_("Topic set by")] = ci->last_topic_setter; diff --git a/modules/chanserv/cs_unban.cpp b/modules/chanserv/cs_unban.cpp index c214136eb..5b08511b3 100644 --- a/modules/chanserv/cs_unban.cpp +++ b/modules/chanserv/cs_unban.cpp @@ -81,7 +81,7 @@ public: } if (!source.AccessFor(ci).HasPriv("UNBAN") && - !(u2 == source.GetUser() && source.AccessFor(ci).HasPriv("UNBANME")) && + (u2 != source.GetUser() || !source.AccessFor(ci).HasPriv("UNBANME")) && !source.HasPriv("chanserv/kick")) { source.Reply(ACCESS_DENIED); diff --git a/modules/dns.cpp b/modules/dns.cpp index 221b533c8..0430f0817 100644 --- a/modules/dns.cpp +++ b/modules/dns.cpp @@ -72,7 +72,7 @@ class Packet final throw SocketException("Unable to unpack name - bogus compression header"); /* Place pos at the second byte of the first (farthest) compression pointer */ - if (compressed == false) + if (!compressed) { ++pos; compressed = true; @@ -95,7 +95,7 @@ class Packet final name += input[pos_ptr + i]; pos_ptr += offset + 1; - if (compressed == false) + if (!compressed) /* Move up pos */ pos = pos_ptr; } diff --git a/modules/help.cpp b/modules/help.cpp index 66c22a589..8b8542fdf 100644 --- a/modules/help.cpp +++ b/modules/help.cpp @@ -173,7 +173,7 @@ public: break; } - if (helped == false) + if (!helped) source.Reply(_("No help available for \002%s\002."), params[0].c_str()); } diff --git a/modules/hostserv/hs_request.cpp b/modules/hostserv/hs_request.cpp index 1156d0538..dac9fc738 100644 --- a/modules/hostserv/hs_request.cpp +++ b/modules/hostserv/hs_request.cpp @@ -69,9 +69,7 @@ class CommandHSRequest final { bool isvalidchar(char c) { - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-') - return true; - return false; + return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-'; } public: diff --git a/modules/httpd.cpp b/modules/httpd.cpp index b2eed517d..226d750fe 100644 --- a/modules/httpd.cpp +++ b/modules/httpd.cpp @@ -106,7 +106,7 @@ public: /* Close connection once all data is written */ bool ProcessWrite() override { - return !BinarySocket::ProcessWrite() || this->write_buffer.empty() ? false : true; + return !(!BinarySocket::ProcessWrite() || this->write_buffer.empty()); } const Anope::string GetIP() override diff --git a/modules/nickserv/ns_ajoin.cpp b/modules/nickserv/ns_ajoin.cpp index 19355f861..a21f66fd0 100644 --- a/modules/nickserv/ns_ajoin.cpp +++ b/modules/nickserv/ns_ajoin.cpp @@ -146,7 +146,7 @@ class CommandNSAJoin final } else if (i != (*channels)->size()) alreadyadded += chan + ", "; - else if (IRCD->IsChannelValid(chan) == false) + else if (!IRCD->IsChannelValid(chan)) source.Reply(CHAN_X_INVALID, chan.c_str()); else { @@ -361,9 +361,9 @@ public: continue; else if (c->HasMode("SSL") && !u->IsSecurelyConnected()) continue; - else if (c->MatchesList(u, "BAN") == true && c->MatchesList(u, "EXCEPT") == false) + else if (c->MatchesList(u, "BAN") && !c->MatchesList(u, "EXCEPT")) need_invite = true; - else if (c->HasMode("INVITE") && c->MatchesList(u, "INVITEOVERRIDE") == false) + else if (c->HasMode("INVITE") && !c->MatchesList(u, "INVITEOVERRIDE")) need_invite = true; if (c->HasMode("KEY")) diff --git a/modules/nickserv/ns_group.cpp b/modules/nickserv/ns_group.cpp index 3afec1061..58ded41b4 100644 --- a/modules/nickserv/ns_group.cpp +++ b/modules/nickserv/ns_group.cpp @@ -178,7 +178,7 @@ public: if (user != NULL && !user->fingerprint.empty() && cl && cl->FindCert(user->fingerprint)) ok = true; - if (ok == false && !pass.empty()) + if (!ok && !pass.empty()) { auto *req = new NSGroupRequest(owner, source, this, source.GetNick(), target, pass); FOREACH_MOD(OnCheckAuthentication, (source.GetUser(), req)); diff --git a/modules/nickserv/ns_recover.cpp b/modules/nickserv/ns_recover.cpp index 7460dbd33..f12929f3a 100644 --- a/modules/nickserv/ns_recover.cpp +++ b/modules/nickserv/ns_recover.cpp @@ -192,7 +192,7 @@ public: if (source.HasPriv("nickserv/recover")) ok = true; - if (ok == false && !pass.empty()) + if (!ok && !pass.empty()) { auto *req = new NSRecoverRequest(owner, source, this, na->nick, pass); FOREACH_MOD(OnCheckAuthentication, (source.GetUser(), req)); diff --git a/modules/nickserv/ns_register.cpp b/modules/nickserv/ns_register.cpp index 5ee5fccb2..34a76d973 100644 --- a/modules/nickserv/ns_register.cpp +++ b/modules/nickserv/ns_register.cpp @@ -35,7 +35,7 @@ public: NickAlias *na = NickAlias::Find(nick); if (na == NULL) source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); - else if (na->nc->HasExt("UNCONFIRMED") == false) + else if (!na->nc->HasExt("UNCONFIRMED")) source.Reply(_("Nick \002%s\002 is already confirmed."), na->nick.c_str()); else { diff --git a/modules/operserv/os_logsearch.cpp b/modules/operserv/os_logsearch.cpp index 145e12b53..606a74d78 100644 --- a/modules/operserv/os_logsearch.cpp +++ b/modules/operserv/os_logsearch.cpp @@ -93,7 +93,7 @@ public: Log(LOG_ADMIN, source, this) << "for " << search_string; bool wildcard = search_string.find_first_of("?*") != Anope::string::npos; - bool regex = search_string.empty() == false && search_string[0] == '/' && search_string[search_string.length() - 1] == '/'; + bool regex = !search_string.empty() && search_string[0] == '/' && search_string[search_string.length() - 1] == '/'; const Anope::string &logfile_name = Config->GetModule(this->owner)->Get<const Anope::string>("logname"); std::vector<Anope::string> matches; diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index a1aa63ec7..a0ee2a2eb 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -209,7 +209,7 @@ public: void SendLogin(User *u, NickAlias *na) override { - if (UseSVSAccount == false) + if (!UseSVSAccount) IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", na->nc->display); else Uplink::Send("SVSACCOUNT", u->GetUID(), u->timestamp, na->nc->display); @@ -217,7 +217,7 @@ public: void SendLogout(User *u) override { - if (UseSVSAccount == false) + if (!UseSVSAccount) IRCD->SendMode(Config->GetClient("NickServ"), u, "+d", '*'); else Uplink::Send("SVSACCOUNT", u->GetUID(), u->timestamp, '*'); diff --git a/modules/protocol/unrealircd.cpp b/modules/protocol/unrealircd.cpp index 0c863ce0c..b8160d1b7 100644 --- a/modules/protocol/unrealircd.cpp +++ b/modules/protocol/unrealircd.cpp @@ -687,7 +687,7 @@ public: size_t p = 0; while (p < arg.length() && isdigit(arg[p])) ++p; - if (p == arg.length() || !(arg[p] == 'c' || arg[p] == 'j' || arg[p] == 'k' || arg[p] == 'm' || arg[p] == 'n' || arg[p] == 't')) + if (p == arg.length() || (arg[p] != 'c' && arg[p] != 'j' && arg[p] != 'k' && arg[p] != 'm' && arg[p] != 'n' && arg[p] != 't')) continue; /* continue instead of break for forward compatibility. */ try { diff --git a/modules/proxyscan.cpp b/modules/proxyscan.cpp index 3b4999cd4..42beb37e5 100644 --- a/modules/proxyscan.cpp +++ b/modules/proxyscan.cpp @@ -40,7 +40,7 @@ class ProxyCallbackListener final bool ProcessWrite() override { - return !BufferedSocket::ProcessWrite() || this->write_buffer.empty() ? false : true; + return !(!BufferedSocket::ProcessWrite() || this->write_buffer.empty()); } }; diff --git a/modules/webcpanel/pages/chanserv/access.cpp b/modules/webcpanel/pages/chanserv/access.cpp index c33e6ca49..c0403b0d7 100644 --- a/modules/webcpanel/pages/chanserv/access.cpp +++ b/modules/webcpanel/pages/chanserv/access.cpp @@ -48,7 +48,7 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s if (u_access.HasPriv("ACCESS_CHANGE") || has_priv) { - if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false) + if (!message.get_data["del"].empty() && !message.get_data["mask"].empty()) { std::vector<Anope::string> params; params.push_back(ci->name); @@ -57,7 +57,7 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s WebPanel::RunCommand(client, na->nc->display, na->nc, "ChanServ", "chanserv/access", params, replacements); } - else if (message.post_data["mask"].empty() == false && message.post_data["access"].empty() == false && message.post_data["provider"].empty() == false) + else if (!message.post_data["mask"].empty() && !message.post_data["access"].empty() && !message.post_data["provider"].empty()) { const Anope::string &provider = message.post_data["provider"]; diff --git a/modules/webcpanel/pages/chanserv/akick.cpp b/modules/webcpanel/pages/chanserv/akick.cpp index 3688d6b70..182883eda 100644 --- a/modules/webcpanel/pages/chanserv/akick.cpp +++ b/modules/webcpanel/pages/chanserv/akick.cpp @@ -46,7 +46,7 @@ bool WebCPanel::ChanServ::Akick::OnRequest(HTTPProvider *server, const Anope::st replacements["AKICK"] = "YES"; - if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false) + if (!message.get_data["del"].empty() && !message.get_data["mask"].empty()) { std::vector<Anope::string> params; params.push_back(ci->name); @@ -55,13 +55,13 @@ bool WebCPanel::ChanServ::Akick::OnRequest(HTTPProvider *server, const Anope::st WebPanel::RunCommand(client, na->nc->display, na->nc, "ChanServ", "chanserv/akick", params, replacements); } - else if (message.post_data["mask"].empty() == false) + else if (!message.post_data["mask"].empty()) { std::vector<Anope::string> params; params.push_back(ci->name); params.emplace_back("ADD"); params.push_back(message.post_data["mask"]); - if (message.post_data["reason"].empty() == false) + if (!message.post_data["reason"].empty()) params.push_back(message.post_data["reason"]); WebPanel::RunCommand(client, na->nc->display, na->nc, "ChanServ", "chanserv/akick", params, replacements); diff --git a/modules/webcpanel/pages/chanserv/modes.cpp b/modules/webcpanel/pages/chanserv/modes.cpp index 28f849d11..4e9a10614 100644 --- a/modules/webcpanel/pages/chanserv/modes.cpp +++ b/modules/webcpanel/pages/chanserv/modes.cpp @@ -73,7 +73,7 @@ bool WebCPanel::ChanServ::Modes::OnRequest(HTTPProvider *server, const Anope::st ChannelMode *cm = ModeManager::FindChannelModeByChar(mode[0]); if (cm) { - if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false) + if (!message.get_data["del"].empty() && !message.get_data["mask"].empty()) { std::vector<Anope::string> params; params.push_back(ci->name); @@ -82,7 +82,7 @@ bool WebCPanel::ChanServ::Modes::OnRequest(HTTPProvider *server, const Anope::st params.push_back(message.get_data["mask"]); WebPanel::RunCommand(client, na->nc->display, na->nc, "ChanServ", "chanserv/mode", params, replacements); } - else if (message.post_data["mask"].empty() == false) + else if (!message.post_data["mask"].empty()) { std::vector<Anope::string> params; params.push_back(ci->name); diff --git a/modules/webcpanel/pages/chanserv/set.cpp b/modules/webcpanel/pages/chanserv/set.cpp index ddf53f693..f04accf9c 100644 --- a/modules/webcpanel/pages/chanserv/set.cpp +++ b/modules/webcpanel/pages/chanserv/set.cpp @@ -42,7 +42,7 @@ bool WebCPanel::ChanServ::Set::OnRequest(HTTPProvider *server, const Anope::stri can_set = true; } - if (can_set && message.post_data.empty() == false) + if (can_set && !message.post_data.empty()) { if (ci->HasExt("KEEPTOPIC") != message.post_data.count("keeptopic")) { diff --git a/modules/webcpanel/pages/hostserv/request.cpp b/modules/webcpanel/pages/hostserv/request.cpp index 030999d1e..373686600 100644 --- a/modules/webcpanel/pages/hostserv/request.cpp +++ b/modules/webcpanel/pages/hostserv/request.cpp @@ -23,7 +23,7 @@ bool WebCPanel::HostServ::Request::OnRequest(HTTPProvider *server, const Anope:: if (na->HasVhost()) { - if (na->GetVhostIdent().empty() == false) + if (!na->GetVhostIdent().empty()) replacements["VHOST"] = na->GetVhostIdent() + "@" + na->GetVhostHost(); else replacements["VHOST"] = na->GetVhostHost(); diff --git a/modules/webcpanel/pages/nickserv/info.cpp b/modules/webcpanel/pages/nickserv/info.cpp index 0a7c63f61..f32ee8c82 100644 --- a/modules/webcpanel/pages/nickserv/info.cpp +++ b/modules/webcpanel/pages/nickserv/info.cpp @@ -13,7 +13,7 @@ WebCPanel::NickServ::Info::Info(const Anope::string &cat, const Anope::string &u bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) { - if (message.post_data.empty() == false) + if (!message.post_data.empty()) { if (message.post_data.count("email") > 0) { @@ -85,12 +85,12 @@ bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::str } replacements["DISPLAY"] = na->nc->display; - if (na->nc->email.empty() == false) + if (!na->nc->email.empty()) replacements["EMAIL"] = na->nc->email; replacements["TIME_REGISTERED"] = Anope::strftime(na->time_registered, na->nc); if (na->HasVhost()) { - if (na->GetVhostIdent().empty() == false) + if (!na->GetVhostIdent().empty()) replacements["VHOST"] = na->GetVhostIdent() + "@" + na->GetVhostHost(); else replacements["VHOST"] = na->GetVhostHost(); diff --git a/modules/xmlrpc.cpp b/modules/xmlrpc.cpp index 319730be0..a6844bb9a 100644 --- a/modules/xmlrpc.cpp +++ b/modules/xmlrpc.cpp @@ -57,7 +57,7 @@ public: Anope::string Sanitize(const Anope::string &string) override { Anope::string ret = string; - for (int i = 0; special[i].character.empty() == false; ++i) + for (int i = 0; !special[i].character.empty(); ++i) ret = ret.replace_all_cs(special[i].character, special[i].replace); return ret; } @@ -65,7 +65,7 @@ public: static Anope::string Unescape(const Anope::string &string) { Anope::string ret = string; - for (int i = 0; special[i].character.empty() == false; ++i) + for (int i = 0; !special[i].character.empty(); ++i) if (!special[i].replace.empty()) ret = ret.replace_all_cs(special[i].replace, special[i].character); diff --git a/src/misc.cpp b/src/misc.cpp index 6d8c1ce9a..b8095af41 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -260,10 +260,7 @@ void InfoFormatter::AddOption(const Anope::string &opt) bool Anope::IsFile(const Anope::string &filename) { struct stat fileinfo; - if (!stat(filename.c_str(), &fileinfo)) - return true; - - return false; + return stat(filename.c_str(), &fileinfo) == 0; } time_t Anope::DoTime(const Anope::string &s) diff --git a/src/modes.cpp b/src/modes.cpp index 6cf99f61e..876492e98 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -233,10 +233,7 @@ bool UserModeNoone::CanSet(User *u) const bool ChannelModeKey::IsValid(Anope::string &value) const { - if (!value.empty() && value.find(':') == Anope::string::npos && value.find(',') == Anope::string::npos) - return true; - - return false; + return !value.empty() && value.find(':') == Anope::string::npos && value.find(',') == Anope::string::npos; } bool ChannelModeOperOnly::CanSet(User *u) const diff --git a/src/protocol.cpp b/src/protocol.cpp index bc97e58c8..007627114 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -271,10 +271,10 @@ bool IRCDProto::IsNickValid(const Anope::string &nick) Anope::string special = "[]\\`_^{|}"; for (unsigned i = 0; i < nick.length(); ++i) - if (!(nick[i] >= 'A' && nick[i] <= 'Z') && !(nick[i] >= 'a' && nick[i] <= 'z') + if ((nick[i] < 'A' || nick[i] > 'Z') && (nick[i] < 'a' || nick[i] > 'z') && special.find(nick[i]) == Anope::string::npos && (Config && Config->NickChars.find(nick[i]) == Anope::string::npos) - && (!i || (!(nick[i] >= '0' && nick[i] <= '9') && nick[i] != '-'))) + && (!i || ((nick[i] < '0' || nick[i] > '9') && nick[i] != '-'))) return false; return true; diff --git a/src/uplink.cpp b/src/uplink.cpp index dece54ba8..baa878db3 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -148,7 +148,7 @@ UplinkSocket::~UplinkSocket() bool UplinkSocket::ProcessRead() { bool b = BufferedSocket::ProcessRead(); - for (Anope::string buf; (buf = this->GetLine()).empty() == false;) + for (Anope::string buf; !(buf = this->GetLine()).empty();) { Anope::Process(buf); User::QuitUsers(); diff --git a/src/users.cpp b/src/users.cpp index e47cf93a6..285fe2c40 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -443,7 +443,7 @@ bool User::IsIdentified(bool check_nick) const return na && *na->nc == *this->nc; } - return this->nc ? true : false; + return this->nc; } bool User::IsRecognized(bool check_secure) const |