aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Sadie Powell2025-03-23 07:42:47 +0000
committerGravatar Sadie Powell2025-03-23 07:42:47 +0000
commitfb219052c8a09bb8fa9635521756819482da2cdd (patch)
treee6d6f5fb492c588969d8ac89e1ab312454c23047 /src
parentOnly include <sstream> from files that actually use it. (diff)
Move DefaultIsNick/DefaultIsUser/IsNick/IsUser to UserManager.
Diffstat (limited to 'src')
-rw-r--r--src/helperfuncs.cpp47
-rw-r--r--src/usermanager.cpp38
2 files changed, 38 insertions, 47 deletions
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index c259a5ada..cf92be745 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -241,53 +241,6 @@ void InspIRCd::ProcessColors(std::string& line)
}
}
-/* true for valid nickname, false else */
-bool InspIRCd::DefaultIsNick(const std::string_view& n)
-{
- if (n.empty() || n.length() > ServerInstance->Config->Limits.MaxNick)
- return false;
-
- for (std::string_view::const_iterator i = n.begin(); i != n.end(); ++i)
- {
- if ((*i >= 'A') && (*i <= '}'))
- {
- /* "A"-"}" can occur anywhere in a nickname */
- continue;
- }
-
- if ((((*i >= '0') && (*i <= '9')) || (*i == '-')) && (i != n.begin()))
- {
- /* "0"-"9", "-" can occur anywhere BUT the first char of a nickname */
- continue;
- }
-
- /* invalid character! abort */
- return false;
- }
-
- return true;
-}
-
-/* return true for good username, false else */
-bool InspIRCd::DefaultIsUser(const std::string_view& n)
-{
- if (n.empty())
- return false;
-
- for (const auto chr : n)
- {
- if (chr >= 'A' && chr <= '}')
- continue;
-
- if ((chr >= '0' && chr <= '9') || chr == '-' || chr == '.')
- continue;
-
- return false;
- }
-
- return true;
-}
-
bool InspIRCd::IsHost(const std::string_view& host, bool allowsimple)
{
// Hostnames must be non-empty and shorter than the maximum hostname length.
diff --git a/src/usermanager.cpp b/src/usermanager.cpp
index b8c355524..491cfdb71 100644
--- a/src/usermanager.cpp
+++ b/src/usermanager.cpp
@@ -465,3 +465,41 @@ User* UserManager::FindUUID(const std::string& uuid, bool fullyconnected)
return user;
}
+
+/* true for valid nickname, false else */
+bool UserManager::DefaultIsNick(const std::string_view& nick)
+{
+ if (nick.empty() || nick.length() > ServerInstance->Config->Limits.MaxNick)
+ return false;
+
+ for (auto it = nick.cbegin(); it != nick.cend(); ++it)
+ {
+ const auto chr = *it;
+ if (chr >= 'A' && chr <= '}')
+ continue; // "A"-"}" can occur anywhere in a nickname.
+
+ if (((chr >= '0' && chr <= '9') || (chr == '-')) && it != nick.begin())
+ continue; // "0"-"9", "-" can occur anywhere BUT the first char of a nickname.
+
+ return false;
+ }
+ return true;
+}
+
+bool UserManager::DefaultIsUser(const std::string_view& user)
+{
+ if (user.empty())
+ return false;
+
+ for (const auto chr : user)
+ {
+ if (chr >= 'A' && chr <= '}')
+ continue;
+
+ if ((chr >= '0' && chr <= '9') || chr == '-' || chr == '.')
+ continue;
+
+ return false;
+ }
+ return true;
+}