]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_ident.cpp
Wahhhhhhhhhhhh bwahahaha. Mass commit to tidy up tons of messy include lists
[user/henk/code/inspircd.git] / src / modules / m_ident.cpp
index 270457af75b8b8da07ada0439776537bab6dcfa6..669e9edbeb6f6f568d35d67d0e6ddf757f0c52a3 100644 (file)
@@ -23,8 +23,6 @@ using namespace std;
 #include "modules.h"
 #include "inspircd.h"
 
-extern userrec* fd_ref_table[MAX_DESCRIPTORS];
-
 /* $ModDesc: Provides support for RFC 1413 ident lookups */
 
 // Version 1.5.0.0 - Updated to use InspSocket, faster and neater.
@@ -32,7 +30,7 @@ extern userrec* fd_ref_table[MAX_DESCRIPTORS];
 class RFC1413 : public InspSocket
 {
  protected:
-       Server* Srv;             // Server* class used for core communications
+                        // Server* class used for core communications
        insp_sockaddr sock_us;   // our port number
        insp_sockaddr sock_them; // their port number
        socklen_t uslen;         // length of our port number
@@ -43,19 +41,19 @@ class RFC1413 : public InspSocket
        userrec* u;              // user record that the lookup is associated with
        int ufd;
 
-       RFC1413(userrec* user, int maxtime, Server* S) : InspSocket((char*)inet_ntoa(user->ip4), 113, false, maxtime), Srv(S), u(user), ufd(user->fd)
+       RFC1413(InspIRCd* SI, userrec* user, int maxtime) : InspSocket(SI, user->GetIPString(), 113, false, maxtime), u(user)
        {
-               Srv->Log(DEBUG,"Ident: associated.");
+               ufd = user->GetFd();
        }
 
        virtual void OnTimeout()
        {
                // When we timeout, the connection failed within the allowed timeframe,
                // so we just display a notice, and tidy off the ident_data.
-               if (u && (fd_ref_table[ufd] == u))
+               if (u && (Instance->SE->GetRef(ufd) == u))
                {
                        u->Shrink("ident_data");
-                       Srv->SendServ(u->fd,"NOTICE "+std::string(u->nick)+" :*** Could not find your ident, using "+std::string(u->ident)+" instead.");
+                       u->WriteServ("NOTICE "+std::string(u->nick)+" :*** Could not find your ident, using "+std::string(u->ident)+" instead.");
                }
        }
 
@@ -83,11 +81,14 @@ class RFC1413 : public InspSocket
                                                                *j = '\0'; // truncate at invalid chars
                                                        if (*section)
                                                        {
-                                                               if (u && (fd_ref_table[ufd] == u))
+                                                               if (u && (Instance->SE->GetRef(ufd) == u))
                                                                {
-                                                                       strlcpy(u->ident,section,IDENTMAX);
-                                                                       Srv->Log(DEBUG,"IDENT SET: "+std::string(u->ident));
-                                                                       Srv->SendServ(u->fd,"NOTICE "+std::string(u->nick)+" :*** Found your ident: "+std::string(u->ident));
+                                                                       if (this->Instance->IsIdent(section))
+                                                                       {
+                                                                               strlcpy(u->ident,section,IDENTMAX);
+                                                                               Instance->Log(DEBUG,"IDENT SET: "+std::string(u->ident));
+                                                                               u->WriteServ("NOTICE "+std::string(u->nick)+" :*** Found your ident: "+std::string(u->ident));
+                                                                       }
                                                                }
                                                        }
                                                        return false;
@@ -121,7 +122,7 @@ class RFC1413 : public InspSocket
                // descriptor that they were when the lookup began.
                //
                // Fixes issue reported by webs, 7 Jun 2006
-               if (u && (fd_ref_table[ufd] == u))
+               if (u && (Instance->SE->GetRef(ufd) == u))
                {
                        u->Shrink("ident_data");
                }
@@ -129,7 +130,7 @@ class RFC1413 : public InspSocket
 
        virtual void OnError(InspSocketError e)
        {
-               if (u && (fd_ref_table[ufd] == u))
+               if (u && (Instance->SE->GetRef(ufd) == u))
                {
                        u->Shrink("ident_data");
                }
@@ -137,21 +138,26 @@ class RFC1413 : public InspSocket
 
        virtual bool OnConnected()
        {
-               if (u && (fd_ref_table[ufd] == u))
+               Instance->Log(DEBUG,"Ident: connected");
+               if (u && (Instance->SE->GetRef(ufd) == u))
                {
                        uslen = sizeof(sock_us);
                        themlen = sizeof(sock_them);
-                       if ((getsockname(this->u->fd,(sockaddr*)&sock_us,&uslen) || getpeername(this->u->fd, (sockaddr*)&sock_them, &themlen)))
+                       if ((getsockname(this->u->GetFd(),(sockaddr*)&sock_us,&uslen) || getpeername(this->u->GetFd(), (sockaddr*)&sock_them, &themlen)))
                        {
-                               Srv->Log(DEBUG,"Ident: failed to get socket names, bailing");
+                               Instance->Log(DEBUG,"Ident: failed to get socket names, bailing");
                                return false;
                        }
                        else
                        {
                                // send the request in the following format: theirsocket,oursocket
+#ifdef IPV6
+                               snprintf(ident_request,127,"%d,%d\r\n",ntohs(sock_them.sin6_port),ntohs(sock_us.sin6_port));
+#else
                                snprintf(ident_request,127,"%d,%d\r\n",ntohs(sock_them.sin_port),ntohs(sock_us.sin_port));
+#endif
                                this->Write(ident_request);
-                               Srv->Log(DEBUG,"Sent ident request, waiting for reply");
+                               Instance->Log(DEBUG,"Sent ident request, waiting for reply");
                                return true;
                        }
                }
@@ -166,23 +172,23 @@ class ModuleIdent : public Module
 {
 
        ConfigReader* Conf;
-       Server* Srv;
+       
        int IdentTimeout;
 
  public:
        void ReadSettings()
        {
-               Conf = new ConfigReader;
+               Conf = new ConfigReader(ServerInstance);
                IdentTimeout = Conf->ReadInteger("ident","timeout",0,true);
                if (!IdentTimeout)
                        IdentTimeout = 1;
                DELETE(Conf);
        }
 
-       ModuleIdent(Server* Me)
+       ModuleIdent(InspIRCd* Me)
                : Module::Module(Me)
        {
-               Srv = Me;
+               
                ReadSettings();
        }
 
@@ -204,18 +210,9 @@ class ModuleIdent : public Module
                 * is derived from InspSocket, and inserting it into the socket engine using the
                 * Server::AddSocket() call.
                 */
-               Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :*** Looking up your ident...");
-               RFC1413* ident = new RFC1413(user, IdentTimeout, Srv);
-               if (ident->GetState() != I_ERROR)
-               {
-                       user->Extend("ident_data", (char*)ident);
-                       Srv->AddSocket(ident);
-               }
-               else
-               {
-                       Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :*** Could not find your ident, using "+std::string(user->ident)+" instead.");
-                       DELETE(ident);
-               }
+               user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Looking up your ident...");
+               RFC1413* ident = new RFC1413(ServerInstance, user, IdentTimeout);
+               user->Extend("ident_data", (char*)ident);
        }
 
        virtual bool OnCheckReady(userrec* user)
@@ -242,7 +239,6 @@ class ModuleIdent : public Module
                                // a user which has now vanished! To prevent this, set ident::u
                                // to NULL and check it so that we dont write users who have gone away.
                                ident->u = NULL;
-                               Srv->RemoveSocket(ident);
                        }
                }
        }
@@ -261,7 +257,6 @@ class ModuleIdent : public Module
                if (user->GetExt("ident_data", ident))
                {
                        ident->u = NULL;
-                       Srv->RemoveSocket(ident);
                }
        }
        
@@ -287,7 +282,7 @@ class ModuleIdentFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule(Server* Me)
+       virtual Module * CreateModule(InspIRCd* Me)
        {
                return new ModuleIdent(Me);
        }