+ virtual void OnBufferFlushed(userrec* user)
+ {
+ char buffer[MAXBUF];
+ ListData* ld;
+ if (user->GetExt("safelist_cache", ld))
+ {
+ chanrec* chan = NULL;
+ long amount_sent = 0;
+ do
+ {
+ chan = ServerInstance->GetChannelIndex(ld->list_position);
+ bool has_user = (chan && chan->HasUser(user));
+ long users = chan ? chan->GetUserCounter() : 0;
+
+ bool too_few = (ld->minusers && (users <= ld->minusers));
+ bool too_many = (ld->maxusers && (users >= ld->maxusers));
+
+ if (chan && (too_many || too_few))
+ {
+ ld->list_position++;
+ continue;
+ }
+
+ if ((chan) && (chan->modes[CM_PRIVATE]))
+ {
+ bool display = (match(chan->name, ld->glob.c_str()) || (*chan->topic && match(chan->topic, ld->glob.c_str())));
+ if ((users) && (display))
+ {
+ int counter = snprintf(buffer, MAXBUF, "322 %s *", user->nick);
+ amount_sent += counter + ServerNameSize;
+ user->WriteServ(std::string(buffer));
+ }
+ }
+ else if ((chan) && (((!(chan->modes[CM_PRIVATE])) && (!(chan->modes[CM_SECRET]))) || (has_user)))
+ {
+ bool display = (match(chan->name, ld->glob.c_str()) || (*chan->topic && match(chan->topic, ld->glob.c_str())));
+ if ((users) && (display))
+ {
+ int counter = snprintf(buffer, MAXBUF, "322 %s %s %ld :[+%s] %s",user->nick, chan->name, users, chan->ChanModes(has_user), chan->topic);
+ amount_sent += counter + ServerNameSize;
+ user->WriteServ(std::string(buffer));
+ }
+ }
+ else
+ {
+ if (!chan)
+ {
+ if (!ld->list_ended)
+ {
+ ld->list_ended = true;
+ user->WriteServ("323 %s :End of channel list.",user->nick);
+ }
+ }
+ }
+ ld->list_position++;
+ }
+ while ((chan != NULL) && (amount_sent < (user->sendqmax / 4)));
+ if (ld->list_ended)
+ {
+ user->Shrink("safelist_cache");
+ DELETE(ld);
+ global_listing--;
+ }
+ }
+ }
+
+ virtual void OnCleanup(int target_type, void* item)
+ {
+ if(target_type == TYPE_USER)