]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/helperfuncs.cpp
Probably wont compile yet - purge_empty_channels refactor
[user/henk/code/inspircd.git] / src / helperfuncs.cpp
index 7c0d371969e36bbcaeaa1e73f26f72a8ad86162b..f728516f90752b45b59f1cd720ce281c8d078092 100644 (file)
@@ -1219,49 +1219,37 @@ long GetMaxBans(char* name)
 void purge_empty_chans(userrec* u)
 {
        int purge = 0;
+       std::vector<chanrec*> to_delete;
 
        // firstly decrement the count on each channel
-       for (unsigned int f = 0; f < u->chans.size(); f++)
+       for (std::vector<ucrec*>::iterator f = u->chans.begin(); f != u->chans.end(); f++)
        {
-               if (u->chans[f].channel)
+               ucrec* (ucrec*)*f;
+               if (f->channel)
                {
-                       u->chans[f].channel->DelUser(u);
+                       if (f->channel->DelUser(u) == 0)
+                       {
+                               /* No users left in here, mark it for deletion */
+                               to_delete.push_back(f->channel);
+                               f->channel = NULL;
+                       }
                }
        }
 
-       for (unsigned int i = 0; i < u->chans.size(); i++)
+       for (std::vector<chanrec*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
        {
-               if (u->chans[i].channel)
+               chanrec* thischan = (chanrec*)*n;
+               chan_hash::iterator i2 = chanlist.find(thischan->name);
+               if (i2 != chanlist.end())
                {
-                       if (!usercount(u->chans[i].channel))
-                       {
-                               chan_hash::iterator i2 = chanlist.find(u->chans[i].channel->name);
-
-                               /* kill the record */
-                               if (i2 != chanlist.end())
-                               {
-                                       log(DEBUG,"del_channel: destroyed: %s",i2->second->name);
-
-                                       if (i2->second)
-                                       {
-                                               FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
-                                               delete i2->second;
-                                       }
-
-                                       chanlist.erase(i2);
-                                       purge++;
-                                       u->chans[i].channel = NULL;
-                               }
-                       }
-                       else
-                       {
-                               log(DEBUG,"skipped purge for %s",u->chans[i].channel->name);
-                       }
+                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
+                       delete i2->second;
+                       chanlist.erase(i2);
                }
        }
 
-       log(DEBUG,"completed channel purge, killed %lu",(unsigned long)purge);
-       DeleteOper(u);
+       if (*u->oper)
+               DeleteOper(u);
 }
 
 
@@ -1310,9 +1298,10 @@ char* chanmodes(chanrec *chan, bool showkey)
                strlcat(sparam,foo,MAXBUF);
        }
 
-       for (int n = 0; n < 190; n++)
+       /* This was still iterating up to 190, chanrec::custom_modes is only 64 elements -- Om */
+       for(int n = 0; n < 64; n++)
        {
-               if (chan->custom_modes[n])
+               if(chan->custom_modes[n])
                {
                        *offset++ = n+65;
                        std::string extparam = chan->GetModeParameter(n+65);
@@ -1791,9 +1780,8 @@ bool charremove(char* mp, char remove)
                if (shift_down)
                        *mptr = *(mptr+1);
 
-               *mptr++;
+               mptr++;
        }
 
        return shift_down;
 }
-