]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/channels.cpp
a78b926428650ada612eee18e12c4074d21c896a
[user/henk/code/inspircd.git] / src / channels.cpp
1 /*   +------------------------------------+
2  *   | Inspire Internet Relay Chat Daemon |
3  *   +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *   E-mail:
7  *        <brain@chatspike.net>
8  *        <Craig@chatspike.net>
9  * 
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *      the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include <string>
20 #include <map>
21 #include <sstream>
22 #include <vector>
23 #include <deque>
24 #include <stdarg.h>
25 #include "configreader.h"
26 #include "inspircd.h"
27 #include "hash_map.h"
28 #include "users.h"
29 #include "ctables.h"
30 #include "globals.h"
31 #include "modules.h"
32 #include "dynamic.h"
33 #include "commands.h"
34 #include "wildcard.h"
35 #include "message.h"
36 #include "mode.h"
37 #include "xline.h"
38 #include "inspstring.h"
39 #include "helperfuncs.h"
40 #include "typedefs.h"
41
42 extern int MODCOUNT;
43 extern std::vector<Module*> modules;
44 extern std::vector<ircd_module*> factory;
45 extern time_t TIME;
46
47 chanrec::chanrec(InspIRCd* Instance) : ServerInstance(Instance)
48 {
49         *name = *topic = *setby = *key = 0;
50         created = topicset = limit = 0;
51         internal_userlist.clear();
52         memset(&modes,0,64);
53 }
54
55 void chanrec::SetMode(char mode,bool mode_on)
56 {
57         modes[mode-65] = mode_on;
58         if (!mode_on)
59                 this->SetModeParam(mode,"",false);
60 }
61
62
63 void chanrec::SetModeParam(char mode,const char* parameter,bool mode_on)
64 {
65         log(DEBUG,"SetModeParam called");
66         
67         CustomModeList::iterator n = custom_mode_params.find(mode);     
68
69         if (mode_on)
70         {
71                 if (n == custom_mode_params.end())
72                 {
73                         custom_mode_params[mode] = strdup(parameter);
74                         log(DEBUG,"Custom mode parameter %c %s added",mode,parameter);
75                 }
76                 else
77                 {
78                         log(DEBUG, "Tried to set custom mode parameter for %c '%s' when it was already '%s'", mode, parameter, n->second);
79                 }
80         }
81         else
82         {
83                 if (n != custom_mode_params.end())
84                 {
85                         free(n->second);
86                         custom_mode_params.erase(n);
87                 }
88         }
89 }
90
91 bool chanrec::IsModeSet(char mode)
92 {
93         return modes[mode-65];
94 }
95
96 std::string chanrec::GetModeParameter(char mode)
97 {
98         if (mode == 'k')
99         {
100                 return this->key;
101         }
102         else if (mode == 'l')
103         {
104                 return ConvToStr(this->limit);
105         }
106         else
107         {
108                 CustomModeList::iterator n = custom_mode_params.find(mode);
109                 if (n != custom_mode_params.end())
110                 {
111                         return n->second;
112                 }
113                 return "";
114         }
115 }
116
117 long chanrec::GetUserCounter()
118 {
119         return (this->internal_userlist.size());
120 }
121
122 void chanrec::AddUser(userrec* user)
123 {
124         internal_userlist[user] = user;
125 }
126
127 unsigned long chanrec::DelUser(userrec* user)
128 {
129         CUListIter a = internal_userlist.find(user);
130         
131         if (a != internal_userlist.end())
132         {
133                 internal_userlist.erase(a);
134                 /* And tidy any others... */
135                 DelOppedUser(user);
136                 DelHalfoppedUser(user);
137                 DelVoicedUser(user);
138         }
139         
140         return internal_userlist.size();
141 }
142
143 bool chanrec::HasUser(userrec* user)
144 {
145         return (internal_userlist.find(user) != internal_userlist.end());
146 }
147
148 void chanrec::AddOppedUser(userrec* user)
149 {
150         internal_op_userlist[user] = user;
151 }
152
153 void chanrec::DelOppedUser(userrec* user)
154 {
155         CUListIter a = internal_op_userlist.find(user);
156         if (a != internal_op_userlist.end())
157         {
158                 internal_op_userlist.erase(a);
159                 return;
160         }
161 }
162
163 void chanrec::AddHalfoppedUser(userrec* user)
164 {
165         internal_halfop_userlist[user] = user;
166 }
167
168 void chanrec::DelHalfoppedUser(userrec* user)
169 {
170         CUListIter a = internal_halfop_userlist.find(user);
171
172         if (a != internal_halfop_userlist.end())
173         {   
174                 internal_halfop_userlist.erase(a);
175         }
176 }
177
178 void chanrec::AddVoicedUser(userrec* user)
179 {
180         internal_voice_userlist[user] = user;
181 }
182
183 void chanrec::DelVoicedUser(userrec* user)
184 {
185         CUListIter a = internal_voice_userlist.find(user);
186         
187         if (a != internal_voice_userlist.end())
188         {
189                 internal_voice_userlist.erase(a);
190         }
191 }
192
193 CUList* chanrec::GetUsers()
194 {
195         return &internal_userlist;
196 }
197
198 CUList* chanrec::GetOppedUsers()
199 {
200         return &internal_op_userlist;
201 }
202
203 CUList* chanrec::GetHalfoppedUsers()
204 {
205         return &internal_halfop_userlist;
206 }
207
208 CUList* chanrec::GetVoicedUsers()
209 {
210         return &internal_voice_userlist;
211 }
212
213 /* 
214  * add a channel to a user, creating the record for it if needed and linking
215  * it to the user record 
216  */
217 chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bool override, const char* key)
218 {
219         if (!user || !cn)
220                 return NULL;
221
222         int created = 0;
223         char cname[MAXBUF];
224         int MOD_RESULT = 0;
225         strlcpy(cname,cn,CHANMAX);
226
227         chanrec* Ptr = Instance->FindChan(cname);
228
229         if (!Ptr)
230         {
231                 if (user->fd > -1)
232                 {
233                         MOD_RESULT = 0;
234                         FOREACH_RESULT_I(Instance,I_OnUserPreJoin,OnUserPreJoin(user,NULL,cname));
235                         if (MOD_RESULT == 1)
236                                 return NULL;
237                 }
238
239                 /* create a new one */
240                 Ptr = new chanrec(Instance);
241                 Instance->chanlist[cname] = Ptr;
242
243                 strlcpy(Ptr->name, cname,CHANMAX);
244                 Ptr->modes[CM_TOPICLOCK] = Ptr->modes[CM_NOEXTERNAL] = 1;
245                 Ptr->created = TIME;
246                 *Ptr->topic = 0;
247                 strlcpy(Ptr->setby, user->nick,NICKMAX-1);
248                 Ptr->topicset = 0;
249                 log(DEBUG,"chanrec::JoinUser(): created: %s",cname);
250                 /*
251                  * set created to 2 to indicate user
252                  * is the first in the channel
253                  * and should be given ops
254                  */
255                 created = 2;
256         }
257         else
258         {
259                 /* Already on the channel */
260                 if (Ptr->HasUser(user))
261                         return NULL;
262
263                 /*
264                  * remote users are allowed us to bypass channel modes
265                  * and bans (used by servers)
266                  */
267                 if (IS_LOCAL(user)) /* was a check on fd > -1 */
268                 {
269                         MOD_RESULT = 0;
270                         FOREACH_RESULT_I(Instance,I_OnUserPreJoin,OnUserPreJoin(user,Ptr,cname));
271                         if (MOD_RESULT == 1)
272                         {
273                                 return NULL;
274                         }
275                         else if (MOD_RESULT == 0)
276                         {
277                                 if (*Ptr->key)
278                                 {
279                                         MOD_RESULT = 0;
280                                         FOREACH_RESULT_I(Instance,I_OnCheckKey,OnCheckKey(user, Ptr, key ? key : ""));
281                                         if (!MOD_RESULT)
282                                         {
283                                                 if (!key)
284                                                 {
285                                                         log(DEBUG,"chanrec::JoinUser(): no key given in JOIN");
286                                                         user->WriteServ("475 %s %s :Cannot join channel (Requires key)",user->nick, Ptr->name);
287                                                         return NULL;
288                                                 }
289                                                 else
290                                                 {
291                                                         if (strcmp(key,Ptr->key))
292                                                         {
293                                                                 log(DEBUG,"chanrec::JoinUser(): bad key given in JOIN");
294                                                                 user->WriteServ("475 %s %s :Cannot join channel (Incorrect key)",user->nick, Ptr->name);
295                                                                 return NULL;
296                                                         }
297                                                 }
298                                         }
299                                 }
300                                 if (Ptr->modes[CM_INVITEONLY])
301                                 {
302                                         MOD_RESULT = 0;
303                                         irc::string xname(Ptr->name);
304                                         FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr));
305                                         if (!MOD_RESULT)
306                                         {
307                                                 if (user->IsInvited(xname))
308                                                 {
309                                                         /* user was invited to channel */
310                                                         /* there may be an optional channel NOTICE here */
311                                                 }
312                                                 else
313                                                 {
314                                                         user->WriteServ("473 %s %s :Cannot join channel (Invite only)",user->nick, Ptr->name);
315                                                         return NULL;
316                                                 }
317                                         }
318                                         user->RemoveInvite(xname);
319                                 }
320                                 if (Ptr->limit)
321                                 {
322                                         MOD_RESULT = 0;
323                                         FOREACH_RESULT_I(Instance,I_OnCheckLimit,OnCheckLimit(user, Ptr));
324                                         if (!MOD_RESULT)
325                                         {
326                                                 if (Ptr->GetUserCounter() >= Ptr->limit)
327                                                 {
328                                                         user->WriteServ("471 %s %s :Cannot join channel (Channel is full)",user->nick, Ptr->name);
329                                                         return NULL;
330                                                 }
331                                         }
332                                 }
333                                 if (Ptr->bans.size())
334                                 {
335                                         MOD_RESULT = 0;
336                                         FOREACH_RESULT_I(Instance,I_OnCheckBan,OnCheckBan(user, Ptr));
337                                         char mask[MAXBUF];
338                                         sprintf(mask,"%s!%s@%s",user->nick, user->ident, user->GetIPString());
339                                         if (!MOD_RESULT)
340                                         {
341                                                 for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
342                                                 {
343                                                         /* This allows CIDR ban matching
344                                                          * 
345                                                          *        Full masked host                      Full unmasked host                   IP with/without CIDR
346                                                          */
347                                                         if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
348                                                         {
349                                                                 user->WriteServ("474 %s %s :Cannot join channel (You're banned)",user->nick, Ptr->name);
350                                                                 return NULL;
351                                                         }
352                                                 }
353                                         }
354                                 }
355                         }
356                 }
357                 else
358                 {
359                         log(DEBUG,"chanrec::JoinUser(): Overridden checks");
360                 }
361                 created = 1;
362         }
363
364         for (UserChanList::const_iterator index = user->chans.begin(); index != user->chans.end(); index++)
365         {
366                 if ((*index)->channel == NULL)
367                 {
368                         return chanrec::ForceChan(Instance, Ptr, *index, user, created);
369                 }
370         }
371
372         /*
373          * XXX: If the user is an oper here, we can just extend their user->chans vector by one
374          * and put the channel in here. Same for remote users which are not bound by
375          * the channel limits. Otherwise, nope, youre boned.
376          */
377         if (!IS_LOCAL(user)) /* was a check on fd < 0 */
378         {
379                 ucrec* a = new ucrec();
380                 chanrec* c = chanrec::ForceChan(Instance, Ptr,a,user,created);
381                 user->chans.push_back(a);
382                 return c;
383         }
384         else if (*user->oper)
385         {
386                 /* Oper allows extension up to the OPERMAXCHANS value */
387                 if (user->chans.size() < OPERMAXCHANS)
388                 {
389                         ucrec* a = new ucrec();
390                         chanrec* c = chanrec::ForceChan(Instance, Ptr,a,user,created);
391                         user->chans.push_back(a);
392                         return c;
393                 }
394         }
395
396         user->WriteServ("405 %s %s :You are on too many channels",user->nick, cname);
397
398         if (created == 2)
399         {
400                 log(DEBUG,"BLAMMO, Whacking channel.");
401                 /* Things went seriously pear shaped, so take this away. bwahaha. */
402                 chan_hash::iterator n = Instance->chanlist.find(cname);
403                 if (n != Instance->chanlist.end())
404                 {
405                         Ptr->DelUser(user);
406                         DELETE(Ptr);
407                         Instance->chanlist.erase(n);
408                         for (unsigned int index =0; index < user->chans.size(); index++)
409                         {
410                                 if (user->chans[index]->channel == Ptr)
411                                 {
412                                         user->chans[index]->channel = NULL;
413                                         user->chans[index]->uc_modes = 0;       
414                                 }
415                         }
416                 }
417         }
418         else
419         {
420                 for (unsigned int index =0; index < user->chans.size(); index++)
421                 {
422                         if (user->chans[index]->channel == Ptr)
423                         {
424                                 user->chans[index]->channel = NULL;
425                                 user->chans[index]->uc_modes = 0;
426                         }
427                 }
428         }
429         return NULL;
430 }
431
432 chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr,ucrec *a,userrec* user, int created)
433 {
434         if (created == 2)
435         {
436                 /* first user in is given ops */
437                 a->uc_modes = UCMODE_OP;
438                 Ptr->AddOppedUser(user);
439         }
440         else
441         {
442                 a->uc_modes = 0;
443         }
444
445         a->channel = Ptr;
446         Ptr->AddUser(user);
447         Ptr->WriteChannel(user,"JOIN :%s",Ptr->name);
448
449         /* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
450         if (IS_LOCAL(user))
451         {
452                 log(DEBUG,"Sent JOIN to client");
453                 if (Ptr->topicset)
454                 {
455                         user->WriteServ("332 %s %s :%s", user->nick, Ptr->name, Ptr->topic);
456                         user->WriteServ("333 %s %s %s %lu", user->nick, Ptr->name, Ptr->setby, (unsigned long)Ptr->topicset);
457                 }
458                 Ptr->UserList(user);
459                 user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, Ptr->name);
460         }
461         FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user,Ptr));
462         return Ptr;
463 }
464
465 /* chanrec::PartUser
466  * remove a channel from a users record, and remove the record from the hash
467  * if the channel has become empty
468  */
469 long chanrec::PartUser(userrec *user, const char* reason)
470 {
471         if (!user)
472                 return this->GetUserCounter();
473
474         for (unsigned int i =0; i < user->chans.size(); i++)
475         {
476                 /* zap it from the channel list of the user */
477                 if (user->chans[i]->channel == this)
478                 {
479                         if (reason)
480                         {
481                                 FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason));
482                                 this->WriteChannel(user, "PART %s :%s", this->name, reason);
483                         }
484                         else
485                         {
486                                 FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, ""));
487                                 this->WriteChannel(user, "PART :%s", this->name);
488                         }
489                         user->chans[i]->uc_modes = 0;
490                         user->chans[i]->channel = NULL;
491                         break;
492                 }
493         }
494
495         if (!this->DelUser(user)) /* if there are no users left on the channel... */
496         {
497                 chan_hash::iterator iter = ServerInstance->chanlist.find(this->name);
498                 /* kill the record */
499                 if (iter != ServerInstance->chanlist.end())
500                 {
501                         log(DEBUG,"del_channel: destroyed: %s", this->name);
502                         FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
503                         ServerInstance->chanlist.erase(iter);
504                 }
505                 return 0;
506         }
507
508         return this->GetUserCounter();
509 }
510
511 long chanrec::ServerKickUser(userrec* user, const char* reason, bool triggerevents)
512 {
513         if (!user || !reason)
514                 return this->GetUserCounter();
515
516         if (IS_LOCAL(user))
517         {
518                 if (!this->HasUser(user))
519                 {
520                         /* Not on channel */
521                         return this->GetUserCounter();
522                 }
523         }
524
525         if (triggerevents)
526         {
527                 FOREACH_MOD(I_OnUserKick,OnUserKick(NULL,user,this,reason));
528         }
529
530         for (unsigned int i =0; i < user->chans.size(); i++)
531         {
532                 if (user->chans[i]->channel == this)
533                 {
534                         this->WriteChannelWithServ(ServerInstance->Config->ServerName, "KICK %s %s :%s", this->name, user->nick, reason);
535                         user->chans[i]->uc_modes = 0;
536                         user->chans[i]->channel = NULL;
537                         break;
538                 }
539         }
540
541         if (!this->DelUser(user))
542         {
543                 chan_hash::iterator iter = ServerInstance->chanlist.find(this->name);
544                 /* kill the record */
545                 if (iter != ServerInstance->chanlist.end())
546                 {
547                         FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
548                         ServerInstance->chanlist.erase(iter);
549                 }
550                 return 0;
551         }
552
553         return this->GetUserCounter();
554 }
555
556 long chanrec::KickUser(userrec *src, userrec *user, const char* reason)
557 {
558         if (!src || !user || !reason)
559                 return this->GetUserCounter();
560
561         if (IS_LOCAL(src))
562         {
563                 if (!this->HasUser(user))
564                 {
565                         src->WriteServ("441 %s %s %s :They are not on that channel",src->nick, user->nick, this->name);
566                         return this->GetUserCounter();
567                 }
568                 if ((is_uline(user->server)) && (!is_uline(src->server)))
569                 {
570                         src->WriteServ("482 %s %s :Only a u-line may kick a u-line from a channel.",src->nick, this->name);
571                         return this->GetUserCounter();
572                 }
573                 int MOD_RESULT = 0;
574
575                 if (!is_uline(src->server))
576                 {
577                         MOD_RESULT = 0;
578                         FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,this,reason));
579                         if (MOD_RESULT == 1)
580                                 return this->GetUserCounter();
581                 }
582                 /* Set to -1 by OnUserPreKick if explicit allow was set */
583                 if (MOD_RESULT != -1)
584                 {
585                         FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,this,AC_KICK));
586                         if ((MOD_RESULT == ACR_DENY) && (!is_uline(src->server)))
587                                 return this->GetUserCounter();
588         
589                         if ((MOD_RESULT == ACR_DEFAULT) || (!is_uline(src->server)))
590                         {
591                                 int them = cstatus(src, this);
592                                 int us = cstatus(user, this);
593                                 if ((them < STATUS_HOP) || (them < us))
594                                 {
595                                         if (them == STATUS_HOP)
596                                         {
597                                                 src->WriteServ("482 %s %s :You must be a channel operator",src->nick, this->name);
598                                         }
599                                         else
600                                         {
601                                                 src->WriteServ("482 %s %s :You must be at least a half-operator",src->nick, this->name);
602                                         }
603                                         return this->GetUserCounter();
604                                 }
605                         }
606                 }
607         }
608
609         FOREACH_MOD(I_OnUserKick,OnUserKick(src,user,this,reason));
610                         
611         for (UserChanList::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
612         {
613                 /* zap it from the channel list of the user */
614                 if ((*i)->channel == this)
615                 {
616                         this->WriteChannel(src, "KICK %s %s :%s", this->name, user->nick, reason);
617                         (*i)->uc_modes = 0;
618                         (*i)->channel = NULL;
619                         break;
620                 }
621         }
622
623         if (!this->DelUser(user))
624         /* if there are no users left on the channel */
625         {
626                 chan_hash::iterator iter = ServerInstance->chanlist.find(this->name);
627
628                 /* kill the record */
629                 if (iter != ServerInstance->chanlist.end())
630                 {
631                         FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
632                         ServerInstance->chanlist.erase(iter);
633                 }
634                 return 0;
635         }
636
637         return this->GetUserCounter();
638 }
639
640 void chanrec::WriteChannel(userrec* user, char* text, ...)
641 {
642         char textbuffer[MAXBUF];
643         va_list argsPtr;
644
645         if (!user || !text)
646                 return;
647
648         va_start(argsPtr, text);
649         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
650         va_end(argsPtr);
651
652         this->WriteChannel(user, std::string(textbuffer));
653 }
654
655 void chanrec::WriteChannel(userrec* user, const std::string &text)
656 {
657         CUList *ulist = this->GetUsers();
658
659         if (!user)
660                 return;
661
662         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
663         {
664                 if (i->second->fd != FD_MAGIC_NUMBER)
665                         user->WriteTo(i->second,text);
666         }
667 }
668
669 void chanrec::WriteChannelWithServ(const char* ServName, const char* text, ...)
670 {
671         char textbuffer[MAXBUF];
672         va_list argsPtr;
673
674         if (!text)
675                 return;
676
677         va_start(argsPtr, text);
678         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
679         va_end(argsPtr);
680
681         this->WriteChannelWithServ(ServName, std::string(textbuffer));
682 }
683
684 void chanrec::WriteChannelWithServ(const char* ServName, const std::string &text)
685 {
686         CUList *ulist = this->GetUsers();
687
688         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
689         {
690                 if (IS_LOCAL(i->second))
691                         i->second->WriteServ(text);
692         }
693 }
694
695 /* write formatted text from a source user to all users on a channel except
696  * for the sender (for privmsg etc) */
697 void chanrec::WriteAllExceptSender(userrec* user, char status, char* text, ...)
698 {
699         char textbuffer[MAXBUF];
700         va_list argsPtr;
701
702         if (!user || !text)
703                 return;
704
705         va_start(argsPtr, text);
706         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
707         va_end(argsPtr);
708
709         this->WriteAllExceptSender(user, status, std::string(textbuffer));
710 }
711
712 void chanrec::WriteAllExceptSender(userrec* user, char status, const std::string& text)
713 {
714         CUList *ulist;
715
716         if (!user)
717                 return;
718
719         switch (status)
720         {
721                 case '@':
722                         ulist = this->GetOppedUsers();
723                         break;
724                 case '%':
725                         ulist = this->GetHalfoppedUsers();
726                         break;
727                 case '+':
728                         ulist = this->GetVoicedUsers();
729                         break;
730                 default:
731                         ulist = this->GetUsers();
732                         break;
733         }
734
735         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
736         {
737                 if ((IS_LOCAL(i->second)) && (user != i->second))
738                         i->second->WriteFrom(user,text);
739         }
740 }
741
742 /*
743  * return a count of the users on a specific channel accounting for
744  * invisible users who won't increase the count. e.g. for /LIST
745  */
746 int chanrec::CountInvisible()
747 {
748         int count = 0;
749         CUList *ulist= this->GetUsers();
750         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
751         {
752                 if (!(i->second->modes[UM_INVISIBLE]))
753                         count++;
754         }
755
756         return count;
757 }
758
759 char* chanrec::ChanModes(bool showkey)
760 {
761         static char scratch[MAXBUF];
762         static char sparam[MAXBUF];
763         char* offset = scratch;
764         std::string extparam = "";
765
766         *scratch = '\0';
767         *sparam = '\0';
768
769         /* This was still iterating up to 190, chanrec::custom_modes is only 64 elements -- Om */
770         for(int n = 0; n < 64; n++)
771         {
772                 if(this->modes[n])
773                 {
774                         *offset++ = n + 65;
775                         extparam = "";
776                         switch (n)
777                         {
778                                 case CM_KEY:
779                                         extparam = (showkey ? this->key : "<key>");
780                                 break;
781                                 case CM_LIMIT:
782                                         extparam = ConvToStr(this->limit);
783                                 break;
784                                 case CM_NOEXTERNAL:
785                                 case CM_TOPICLOCK:
786                                 case CM_INVITEONLY:
787                                 case CM_MODERATED:
788                                 case CM_SECRET:
789                                 case CM_PRIVATE:
790                                         /* We know these have no parameters */
791                                 break;
792                                 default:
793                                         extparam = this->GetModeParameter(n + 65);
794                                 break;
795                         }
796                         if (extparam != "")
797                         {
798                                 charlcat(sparam,' ',MAXBUF);
799                                 strlcat(sparam,extparam.c_str(),MAXBUF);
800                         }
801                 }
802         }
803
804         /* Null terminate scratch */
805         *offset = '\0';
806         strlcat(scratch,sparam,MAXBUF);
807         return scratch;
808 }
809
810 /* compile a userlist of a channel into a string, each nick seperated by
811  * spaces and op, voice etc status shown as @ and +, and send it to 'user'
812  */
813 void chanrec::UserList(userrec *user)
814 {
815         char list[MAXBUF];
816         size_t dlen, curlen;
817
818         dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, this->name);
819
820         int numusers = 0;
821         char* ptr = list + dlen;
822
823         CUList *ulist= this->GetUsers();
824
825         /* Improvement by Brain - this doesnt change in value, so why was it inside
826          * the loop?
827          */
828         bool has_user = this->HasUser(user);
829
830         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
831         {
832                 if ((!has_user) && (i->second->modes[UM_INVISIBLE]))
833                 {
834                         /*
835                          * user is +i, and source not on the channel, does not show
836                          * nick in NAMES list
837                          */
838                         continue;
839                 }
840
841                 size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", cmode(i->second, this), i->second->nick);
842
843                 curlen += ptrlen;
844                 ptr += ptrlen;
845
846                 numusers++;
847
848                 if (curlen > (480-NICKMAX))
849                 {
850                         /* list overflowed into multiple numerics */
851                         user->WriteServ(list);
852
853                         /* reset our lengths */
854                         dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, this->name);
855                         ptr = list + dlen;
856
857                         ptrlen = 0;
858                         numusers = 0;
859                 }
860         }
861
862         /* if whats left in the list isnt empty, send it */
863         if (numusers)
864         {
865                 user->WriteServ(list);
866         }
867 }
868
869 long chanrec::GetMaxBans()
870 {
871         std::string x;
872         for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
873         {
874                 x = n->first;
875                 if (match(this->name,x.c_str()))
876                 {
877                         return n->second;
878                 }
879         }
880         return 64;
881 }
882
883