summaryrefslogtreecommitdiff
path: root/src/helperfuncs.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-09 11:24:30 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-09 11:24:30 +0000
commitc2a5839bcbd6bebf0dd102a8dfd283e92c8a0507 (patch)
treed3fc6e91877a0c91e8cdd11cf163c071d701edf6 /src/helperfuncs.cpp
parent2e83826fd35c2b82caec575bc4e34e9437965354 (diff)
Probably wont compile yet - purge_empty_channels refactor
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3579 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/helperfuncs.cpp')
-rw-r--r--src/helperfuncs.cpp50
1 files changed, 19 insertions, 31 deletions
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index d2ec1f7d0..f728516f9 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -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);
}