]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/userprocess.cpp
Getting a bit further
[user/henk/code/inspircd.git] / src / userprocess.cpp
index a401efeb113682674f1fac0934336458d011de32..a6f86d2f28aabece0bff1a35c97c4669e401a7b1 100644 (file)
@@ -320,76 +320,87 @@ void DoBackgroundUserStuff(time_t TIME)
 {
        CullList GlobalGoners;
 
-       for (std::vector<userrec*>::iterator count2 = local_users.begin(); count2 != local_users.end(); count2++)
+       int cfd = 0;
+
+       /* XXX: IT IS NOT SAFE TO USE AN ITERATOR HERE. DON'T EVEN THINK ABOUT IT. */
+       for (unsigned long count2 = 0; count2 != local_users.size(); count2++)
        {
-               /* Sanity checks for corrupted iterators (yes, really) */
-               userrec* curr = NULL;
+               if (count2 >= local_users.size())
+                       break;
 
-               if (*count2)
-                       curr = (userrec*)(*count2);
-               if ((long)curr == -1)
-                       return;
+               userrec* curr = local_users[count2];
 
                if (curr)
                {
-                       /*
-                        * registration timeout -- didnt send USER/NICK/HOST
-                        * in the time specified in their connection class.
-                        */
-                       if (((unsigned)TIME > (unsigned)curr->timeout) && (curr->registered != 7))
-                       {
-                               log(DEBUG,"InspIRCd: registration timeout: %s",curr->nick);
-                               ZapThisDns(curr->fd);
-                               GlobalGoners.AddItem(curr,"Registration timeout");
-                               continue;
-                       }
-
-                       /*
-                        * user has signed on with USER/NICK/PASS, and dns has completed, all the modules
-                        * say this user is ok to proceed, fully connect them.
-                        */
-                       if ((TIME > curr->signon) && (curr->registered == 3) && (AllModulesReportReady(curr)))
-                       {
-                               curr->dns_done = true;
-                               ZapThisDns(curr->fd);
-                               ServerInstance->stats->statsDnsBad++;
-                               FullConnectUser(curr,&GlobalGoners);
-                               continue;
-                       }
+                       cfd = curr->fd;
 
-                       if ((curr->dns_done) && (curr->registered == 3) && (AllModulesReportReady(curr)))
+                       if ((cfd > 0) && (cfd < MAX_DESCRIPTORS) && (fd_ref_table[cfd] == curr) && (curr))
                        {
-                               log(DEBUG,"dns done, registered=3, and modules ready, OK");
-                               FullConnectUser(curr,&GlobalGoners);
-                               ZapThisDns(curr->fd);
-                               continue;
-                       }
-
-                       // It's time to PING this user. Send them a ping.
-                       if ((TIME > curr->nping) && (curr->registered == 7))
-                       {
-                               // This user didn't answer the last ping, remove them
-                               if (!curr->lastping)
+                               /*
+                                * registration timeout -- didnt send USER/NICK/HOST
+                                * in the time specified in their connection class.
+                                */
+                               if (((unsigned)TIME > (unsigned)curr->timeout) && (curr->registered != 7))
                                {
-                                       GlobalGoners.AddItem(curr,"Ping timeout");
+                                       log(DEBUG,"InspIRCd: registration timeout: %s",curr->nick);
+                                       ZapThisDns(curr->fd);
+                                       GlobalGoners.AddItem(curr,"Registration timeout");
                                        continue;
                                }
 
-                               Write(curr->fd,"PING :%s",Config->ServerName);
-                               curr->lastping = 0;
-                               curr->nping = TIME+curr->pingmax;
+                               /*
+                                * user has signed on with USER/NICK/PASS, and dns has completed, all the modules
+                                * say this user is ok to proceed, fully connect them.
+                                */
+                               if ((TIME > curr->signon) && (curr->registered == 3) && (AllModulesReportReady(curr)))
+                               {
+                                       curr->dns_done = true;
+                                       ZapThisDns(curr->fd);
+                                       ServerInstance->stats->statsDnsBad++;
+                                       FullConnectUser(curr,&GlobalGoners);
+                                       continue;
+                               }
+       
+                               if ((curr->dns_done) && (curr->registered == 3) && (AllModulesReportReady(curr)))
+                               {
+                                       log(DEBUG,"dns done, registered=3, and modules ready, OK");
+                                       FullConnectUser(curr,&GlobalGoners);
+                                       ZapThisDns(curr->fd);
+                                       continue;
+                               }
+               
+                               // It's time to PING this user. Send them a ping.
+                               if ((TIME > curr->nping) && (curr->registered == 7))
+                               {
+                                       // This user didn't answer the last ping, remove them
+                                       if (!curr->lastping)
+                                       {
+                                               GlobalGoners.AddItem(curr,"Ping timeout");
+                                               curr->lastping = 1;
+                                               curr->nping = TIME+curr->pingmax;
+                                               continue;
+                                       }
+       
+                                       Write(curr->fd,"PING :%s",Config->ServerName);
+                                       curr->lastping = 0;
+                                       curr->nping = TIME+curr->pingmax;
+                               }
                        }
 
                        /*
                         * We can flush the write buffer as the last thing we do, because if they
                         * match any of the above conditions its no use flushing their buffer anyway.
                         */
-                       curr->FlushWriteBuf();
 
-                       if (*curr->GetWriteError())
+                       /* Check again that theyre still here (something above may have changed that) */
+                       if ((cfd > 0) && (cfd < MAX_DESCRIPTORS) && (fd_ref_table[cfd] == curr) && (curr))
                        {
-                               GlobalGoners.AddItem(curr,curr->GetWriteError());
-                               continue;
+                               curr->FlushWriteBuf();
+                               if (*curr->GetWriteError())
+                               {
+                                       GlobalGoners.AddItem(curr,curr->GetWriteError());
+                                       continue;
+                               }
                        }
                }
        }