]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_ident.cpp
ident: rename nolookupprefix to prefixunqueried.
[user/henk/code/inspircd.git] / src / modules / m_ident.cpp
index 803c19846288e67dd93be7f5fac9a8ce6570a860..f3f8e7dd79eec16ada66b03baa1ccf11521eda8f 100644 (file)
@@ -254,9 +254,29 @@ class IdentRequestSocket : public EventHandler
 
 class ModuleIdent : public Module
 {
-       int RequestTimeout;
-       bool NoLookupPrefix;
+ private:
+       unsigned int timeout;
+       bool prefixunqueried;
        SimpleExtItem<IdentRequestSocket, stdalgo::culldeleter> ext;
+
+       static void PrefixIdent(LocalUser* user)
+       {
+               // Check that they haven't been prefixed already.
+               if (user->ident[0] == '~')
+                       return;
+               
+               // All invalid usernames are prefixed with a tilde.
+               std::string newident(user->ident);
+               newident.insert(newident.begin(), '~');
+
+               // If the username is too long then truncate it.
+               if (newident.length() > ServerInstance->Config->Limits.IdentMax)
+                       newident.erase(ServerInstance->Config->Limits.IdentMax);
+
+               // Apply the new username.
+               user->ChangeIdent(newident);
+       }
+
  public:
        ModuleIdent()
                : ext("ident_socket", ExtensionItem::EXT_USER, this)
@@ -271,8 +291,8 @@ class ModuleIdent : public Module
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("ident");
-               RequestTimeout = tag->getDuration("timeout", 5, 1);
-               NoLookupPrefix = tag->getBool("nolookupprefix", false);
+               timeout = tag->getDuration("timeout", 5, 1, 60);
+               prefixunqueried = tag->getBool("prefixunqueried");
        }
 
        void OnSetUserIP(LocalUser* user) CXX11_OVERRIDE
@@ -320,19 +340,19 @@ class ModuleIdent : public Module
                IdentRequestSocket *isock = ext.get(user);
                if (!isock)
                {
-                       if ((NoLookupPrefix) && (user->ident[0] != '~'))
-                               user->ident.insert(user->ident.begin(), 1, '~');
+                       if (prefixunqueried)
+                               PrefixIdent(user);
                        return MOD_RES_PASSTHRU;
                }
 
-               time_t compare = isock->age;
-               compare += RequestTimeout;
+               time_t compare = isock->age + timeout;
 
                /* Check for timeout of the socket */
                if (ServerInstance->Time() >= compare)
                {
                        /* Ident timeout */
-                       user->WriteNotice("*** Ident request timed out.");
+                       PrefixIdent(user);
+                       user->WriteNotice("*** Ident lookup timed out, using " + user->ident + " instead.");
                }
                else if (!isock->HasResult())
                {
@@ -341,18 +361,17 @@ class ModuleIdent : public Module
                }
 
                /* wooo, got a result (it will be good, or bad) */
-               if (isock->result.empty())
+               else if (isock->result.empty())
                {
-                       user->ident.insert(user->ident.begin(), 1, '~');
+                       PrefixIdent(user);
                        user->WriteNotice("*** Could not find your ident, using " + user->ident + " instead.");
                }
                else
                {
-                       user->ident = isock->result;
+                       user->ChangeIdent(isock->result);
                        user->WriteNotice("*** Found your ident, '" + user->ident + "'");
                }
 
-               user->InvalidateCache();
                isock->Close();
                ext.unset(user);
                return MOD_RES_PASSTHRU;