summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2021-08-01 19:23:48 +0100
committerSadie Powell <sadie@witchery.services>2021-08-01 19:23:48 +0100
commite7e8447fa39ced57743eab51e8e2835ddddd7001 (patch)
tree2bc8d31f575616e612c0d7e3898bd94bd9165b18
parent561b205c4a3a125c12a7926ef18fa1eb822c387c (diff)
Deduplicate code for checking if a user is securely connected.
-rw-r--r--include/users.h5
-rw-r--r--modules/commands/cs_enforce.cpp2
-rw-r--r--modules/commands/ns_ajoin.cpp2
-rw-r--r--modules/extra/stats/irc2sql/irc2sql.cpp4
-rw-r--r--src/users.cpp5
5 files changed, 14 insertions, 4 deletions
diff --git a/include/users.h b/include/users.h
index f7756e7c2..c96cc8145 100644
--- a/include/users.h
+++ b/include/users.h
@@ -226,6 +226,11 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe
*/
bool IsRecognized(bool check_secure = true) const;
+ /** Check if the user is connected securely.
+ * @return True if the user is connected securely; otherwise, false.
+ */
+ bool IsSecurelyConnected() const;
+
/** Check if the user is a services oper
* @return true if they are an oper
*/
diff --git a/modules/commands/cs_enforce.cpp b/modules/commands/cs_enforce.cpp
index 8f21c8c35..968bd25cc 100644
--- a/modules/commands/cs_enforce.cpp
+++ b/modules/commands/cs_enforce.cpp
@@ -119,7 +119,7 @@ class CommandCSEnforce : public Command
if (user->IsProtected())
continue;
- if (!user->HasMode("SSL") && !user->HasExt("ssl"))
+ if (!user->IsSecurelyConnected())
users.push_back(user);
}
diff --git a/modules/commands/ns_ajoin.cpp b/modules/commands/ns_ajoin.cpp
index 4f4c75e1a..f2ea92c56 100644
--- a/modules/commands/ns_ajoin.cpp
+++ b/modules/commands/ns_ajoin.cpp
@@ -356,7 +356,7 @@ class NSAJoin : public Module
continue;
else if (c->HasMode("ADMINONLY") && !u->HasMode("ADMIN"))
continue;
- else if (c->HasMode("SSL") && !(u->HasMode("SSL") || u->HasExt("ssl")))
+ else if (c->HasMode("SSL") && !u->IsSecurelyConnected())
continue;
else if (c->MatchesList(u, "BAN") == true && c->MatchesList(u, "EXCEPT") == false)
need_invite = true;
diff --git a/modules/extra/stats/irc2sql/irc2sql.cpp b/modules/extra/stats/irc2sql/irc2sql.cpp
index 0d2d48d25..f0667e2e4 100644
--- a/modules/extra/stats/irc2sql/irc2sql.cpp
+++ b/modules/extra/stats/irc2sql/irc2sql.cpp
@@ -107,7 +107,7 @@ void IRC2SQL::OnUserConnect(User *u, bool &exempt)
query.SetValue("ip", u->ip.addr());
query.SetValue("ident", u->GetIdent());
query.SetValue("vident", u->GetVIdent());
- query.SetValue("secure", u->HasMode("SSL") || u->HasExt("ssl") ? "Y" : "N");
+ query.SetValue("secure", u->IsSecurelyConnected() ? "Y" : "N");
query.SetValue("account", u->Account() ? u->Account()->display : "");
query.SetValue("fingerprint", u->fingerprint);
query.SetValue("signon", u->signon);
@@ -152,7 +152,7 @@ void IRC2SQL::OnUserAway(User *u, const Anope::string &message)
void IRC2SQL::OnFingerprint(User *u)
{
query = "UPDATE `" + prefix + "user` SET secure=@secure@, fingerprint=@fingerprint@ WHERE nick=@nick@";
- query.SetValue("secure", u->HasMode("SSL") || u->HasExt("ssl") ? "Y" : "N");
+ query.SetValue("secure", u->IsSecurelyConnected() ? "Y" : "N");
query.SetValue("fingerprint", u->fingerprint);
query.SetValue("nick", u->nick);
this->RunQuery(query);
diff --git a/src/users.cpp b/src/users.cpp
index 1f0af4f63..c5fbfdcdb 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -448,6 +448,11 @@ bool User::IsRecognized(bool check_secure) const
return on_access;
}
+bool User::IsSecurelyConnected() const
+{
+ return HasMode("SSL") || HasExt("ssl");
+}
+
bool User::IsServicesOper()
{
if (!this->nc || !this->nc->IsServicesOper())