-
-long GetMaxBans(char* name)
-{
- std::string x;
- for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
- {
- x = n->first;
- if (match(name,x.c_str()))
- {
- return n->second;
- }
- }
- return 64;
-}
-
-void purge_empty_chans(userrec* u)
-{
- std::vector<chanrec*> to_delete;
-
- // firstly decrement the count on each channel
- for (std::vector<ucrec*>::iterator f = u->chans.begin(); f != u->chans.end(); f++)
- {
- ucrec* uc = (ucrec*)(*f);
- if (uc->channel)
- {
- if (uc->channel->DelUser(u) == 0)
- {
- /* No users left in here, mark it for deletion */
- to_delete.push_back(uc->channel);
- uc->channel = NULL;
- }
- }
- }
-
- log(DEBUG,"purge_empty_chans: %d channels to delete",to_delete.size());
-
- for (std::vector<chanrec*>::iterator n = to_delete.begin(); n != to_delete.end(); n++)
- {
- chanrec* thischan = (chanrec*)*n;
- chan_hash::iterator i2 = chanlist.find(thischan->name);
- if (i2 != chanlist.end())
- {
- FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
- DELETE(i2->second);
- chanlist.erase(i2);
- }
- }
-
- u->UnOper();
-}
-
-
-char* chanmodes(chanrec *chan, bool showkey)
-{
- static char scratch[MAXBUF];
- static char sparam[MAXBUF];
- char* offset = scratch;
- std::string extparam = "";
-
- if (!chan)
- {
- log(DEFAULT,"*** BUG *** chanmodes was given an invalid parameter");
- *scratch = '\0';
- return scratch;
- }
-
- *scratch = '\0';
- *sparam = '\0';
-
- /* This was still iterating up to 190, chanrec::custom_modes is only 64 elements -- Om */
- for(int n = 0; n < 64; n++)
- {
- if(chan->modes[n])
- {
- *offset++ = n+65;
- extparam = "";
- switch (n)
- {
- case CM_KEY:
- extparam = (showkey ? chan->key : "<key>");
- break;
- case CM_LIMIT:
- extparam = ConvToStr(chan->limit);
- break;
- case CM_NOEXTERNAL:
- case CM_TOPICLOCK:
- case CM_INVITEONLY:
- case CM_MODERATED:
- case CM_SECRET:
- case CM_PRIVATE:
- /* We know these have no parameters */
- break;
- default:
- extparam = chan->GetModeParameter(n+65);
- break;
- }
- if (extparam != "")
- {
- charlcat(sparam,' ',MAXBUF);
- strlcat(sparam,extparam.c_str(),MAXBUF);
- }
- }
- }
-
- /* Null terminate scratch */
- *offset = '\0';
- strlcat(scratch,sparam,MAXBUF);
- return scratch;
-}
-
-
-/* compile a userlist of a channel into a string, each nick seperated by
- * spaces and op, voice etc status shown as @ and + */
-
-void userlist(userrec *user,chanrec *c)
-{
- if ((!c) || (!user))
- {
- log(DEFAULT,"*** BUG *** userlist was given an invalid parameter");
- return;
- }
-
- char list[MAXBUF];
- size_t dlen, curlen;
-
- dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
-
- int numusers = 0;
- char* ptr = list + dlen;
-
- CUList *ulist= c->GetUsers();
-
- /* Improvement by Brain - this doesnt change in value, so why was it inside
- * the loop?
- */
- bool has_user = c->HasUser(user);
-
- for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
- {
- if ((!has_user) && (i->second->modes[UM_INVISIBLE]))
- {
- /*
- * user is +i, and source not on the channel, does not show
- * nick in NAMES list
- */
- continue;
- }
-
- size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", cmode(i->second, c), i->second->nick);
-
- curlen += ptrlen;
- ptr += ptrlen;
-
- numusers++;
-
- if (curlen > (480-NICKMAX))
- {
- /* list overflowed into multiple numerics */
- user->WriteServ(list);
-
- /* reset our lengths */
- dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
- ptr = list + dlen;
-
- ptrlen = 0;
- numusers = 0;
- }
- }
-
- /* if whats left in the list isnt empty, send it */
- if (numusers)
- {
- user->WriteServ(list);
- }
-}
-
-/*
- * return a count of the users on a specific channel accounting for
- * invisible users who won't increase the count. e.g. for /LIST
- */
-int usercount_i(chanrec *c)
-{
- int count = 0;
-
- if (!c)
- return 0;
-
- CUList *ulist= c->GetUsers();
- for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
- {
- if (!(i->second->modes[UM_INVISIBLE]))
- count++;
- }
-
- return count;
-}
-
-int usercount(chanrec *c)