]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/commands/cmd_hostname_lookup.cpp
Automatically register ServiceProviders created by modules
[user/henk/code/inspircd.git] / src / commands / cmd_hostname_lookup.cpp
index 04592c6e5773762a20b0a273db75bcba45565097..3287f3662d228399c87db85e4639e62d5aba26fd 100644 (file)
@@ -92,9 +92,9 @@ class UserResolver : public DNS::Request
                        catch (DNS::Exception& e)
                        {
                                delete res_forward;
-                               ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG,"Error in resolver: %s",e.GetReason());
+                               ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Error in resolver: %s",e.GetReason());
 
-                               bound_user->WriteServ("NOTICE Auth :*** There was an internal error resolving your host, using your IP address (%s) instead.", bound_user->GetIPString().c_str());
+                               bound_user->WriteNotice("*** There was an internal error resolving your host, using your IP address (" + bound_user->GetIPString() + ") instead.");
                                dl->set(bound_user, 0);
                        }
                }
@@ -130,7 +130,7 @@ class UserResolver : public DNS::Request
                                if (hostname == NULL)
                                {
                                        ServerInstance->Logs->Log("RESOLVER", LOG_DEFAULT, "ERROR: User has no hostname attached when doing a forward lookup");
-                                       bound_user->WriteServ("NOTICE Auth :*** There was an internal error resolving your host, using your IP address (%s) instead.", bound_user->GetIPString().c_str());
+                                       bound_user->WriteNotice("*** There was an internal error resolving your host, using your IP address (" + bound_user->GetIPString() + ") instead.");
                                        return;
                                }
                                else if (hostname->length() < 65)
@@ -139,7 +139,7 @@ class UserResolver : public DNS::Request
                                        if ((*hostname)[0] == ':')
                                                hostname->insert(0, "0");
 
-                                       bound_user->WriteServ("NOTICE Auth :*** Found your hostname (%s)%s", hostname->c_str(), (r->cached ? " -- cached" : ""));
+                                       bound_user->WriteNotice("*** Found your hostname (" + *hostname + (r->cached ? ") -- cached" : ")"));
                                        bound_user->host.assign(*hostname, 0, 64);
                                        bound_user->dhost = bound_user->host;
 
@@ -148,14 +148,14 @@ class UserResolver : public DNS::Request
                                }
                                else
                                {
-                                       bound_user->WriteServ("NOTICE Auth :*** Your hostname is longer than the maximum of 64 characters, using your IP address (%s) instead.", bound_user->GetIPString().c_str());
+                                       bound_user->WriteNotice("*** Your hostname is longer than the maximum of 64 characters, using your IP address (" + bound_user->GetIPString() + ") instead.");
                                }
 
                                ph->unset(bound_user);
                        }
                        else
                        {
-                               bound_user->WriteServ("NOTICE Auth :*** Your hostname does not match up with your IP address. Sorry, using your IP address (%s) instead.", bound_user->GetIPString().c_str());
+                               bound_user->WriteNotice("*** Your hostname does not match up with your IP address. Sorry, using your IP address (" + bound_user->GetIPString() + ") instead.");
                        }
                }
        }
@@ -168,7 +168,7 @@ class UserResolver : public DNS::Request
                LocalUser* bound_user = (LocalUser*)ServerInstance->FindUUID(uuid);
                if (bound_user)
                {
-                       bound_user->WriteServ("NOTICE Auth :*** Could not resolve your hostname: %s; using your IP address (%s) instead.", this->manager->GetErrorStr(query->error).c_str(), bound_user->GetIPString().c_str());
+                       bound_user->WriteNotice("*** Could not resolve your hostname: " + this->manager->GetErrorStr(query->error) + "; using your IP address (" + bound_user->GetIPString() + ") instead.");
                        dl->set(bound_user, 0);
                        ServerInstance->stats->statsDnsBad++;
                }
@@ -177,7 +177,6 @@ class UserResolver : public DNS::Request
 
 class ModuleHostnameLookup : public Module
 {
-       bool nouserdns;
        LocalIntExt dnsLookup;
        LocalStringExt ptrHosts;
        dynamic_reference<DNS::Manager> DNS;
@@ -192,30 +191,15 @@ class ModuleHostnameLookup : public Module
                ph = &ptrHosts;
        }
 
-       void init()
-       {
-               OnRehash(NULL);
-               ServerInstance->Modules->AddService(this->dnsLookup);
-               ServerInstance->Modules->AddService(this->ptrHosts);
-
-               Implementation i[] = { I_OnUserInit, I_OnCheckReady, I_OnRehash };
-               ServerInstance->Modules->Attach(i, this, sizeof(i) / sizeof(Implementation));
-       }
-
-       void OnRehash(User* user)
-       {
-               nouserdns =     ServerInstance->Config->ConfValue("performance")->getBool("nouserdns");
-       }
-
        void OnUserInit(LocalUser *user)
        {
-               if (!DNS || nouserdns)
+               if (!DNS || !user->MyClass->resolvehostnames)
                {
-                       user->WriteServ("NOTICE %s :*** Skipping host resolution (disabled by server administrator)", user->nick.c_str());
+                       user->WriteNotice("*** Skipping host resolution (disabled by server administrator)");
                        return;
                }
 
-               user->WriteServ("NOTICE Auth :*** Looking up your hostname...");
+               user->WriteNotice("*** Looking up your hostname...");
 
                UserResolver* res_reverse = new UserResolver(*this->DNS, this, user, user->GetIPString(), DNS::QUERY_PTR);
                try
@@ -230,7 +214,7 @@ class ModuleHostnameLookup : public Module
                {
                        this->dnsLookup.set(user, 0);
                        delete res_reverse;
-                       ServerInstance->Logs->Log("USERS", LOG_DEBUG,"Error in resolver: %s", e.GetReason());
+                       ServerInstance->Logs->Log("USERS", LOG_DEBUG, "Error in resolver: %s", e.GetReason());
                        ServerInstance->stats->statsDnsBad++;
                }
        }