1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
21 Channel::Channel(InspIRCd* Instance, const std::string &cname, time_t ts) : ServerInstance(Instance)
23 chan_hash::iterator findchan = ServerInstance->chanlist->find(cname);
24 if (findchan != Instance->chanlist->end())
25 throw CoreException("Cannot create duplicate channel " + cname);
27 (*(ServerInstance->chanlist))[cname.c_str()] = this;
28 this->name.assign(cname, 0, ServerInstance->Config->Limits.ChanMax);
29 this->created = ts ? ts : ServerInstance->Time();
30 this->age = this->created;
32 maxbans = topicset = 0;
36 void Channel::SetMode(char mode,bool mode_on)
38 modes[mode-65] = mode_on;
40 this->SetModeParam(mode,"",false);
44 void Channel::SetModeParam(char mode,const char* parameter,bool mode_on)
46 CustomModeList::iterator n = custom_mode_params.find(mode);
50 if (n == custom_mode_params.end())
51 custom_mode_params[mode] = strdup(parameter);
55 if (n != custom_mode_params.end())
58 custom_mode_params.erase(n);
63 bool Channel::IsModeSet(char mode)
65 return modes[mode-65];
68 std::string Channel::GetModeParameter(char mode)
70 CustomModeList::iterator n = custom_mode_params.find(mode);
71 if (n != custom_mode_params.end())
76 int Channel::SetTopic(User *u, std::string &ntopic, bool forceset)
83 /* 0: check status, 1: don't, -1: disallow change silently */
85 FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(u,this,ntopic));
89 else if (MOD_RESULT == 0)
91 if (!this->HasUser(u))
93 u->WriteNumeric(442, "%s %s :You're not on that channel!",u->nick.c_str(), this->name.c_str());
96 if ((this->IsModeSet('t')) && (this->GetStatus(u) < STATUS_HOP))
98 u->WriteNumeric(482, "%s %s :You must be at least a half-operator to change the topic on this channel", u->nick.c_str(), this->name.c_str());
105 this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic);
106 this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128);
107 this->topicset = ServerInstance->Time();
108 this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
112 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(u, this, this->topic));
118 long Channel::GetUserCounter()
120 return (this->internal_userlist.size());
123 void Channel::AddUser(User* user)
125 internal_userlist[user] = user->nick;
128 unsigned long Channel::DelUser(User* user)
130 CUListIter a = internal_userlist.find(user);
132 if (a != internal_userlist.end())
134 internal_userlist.erase(a);
135 /* And tidy any others... */
137 DelHalfoppedUser(user);
141 return internal_userlist.size();
144 bool Channel::HasUser(User* user)
146 return (internal_userlist.find(user) != internal_userlist.end());
149 void Channel::AddOppedUser(User* user)
151 internal_op_userlist[user] = user->nick;
154 void Channel::DelOppedUser(User* user)
156 CUListIter a = internal_op_userlist.find(user);
157 if (a != internal_op_userlist.end())
159 internal_op_userlist.erase(a);
164 void Channel::AddHalfoppedUser(User* user)
166 internal_halfop_userlist[user] = user->nick;
169 void Channel::DelHalfoppedUser(User* user)
171 CUListIter a = internal_halfop_userlist.find(user);
173 if (a != internal_halfop_userlist.end())
175 internal_halfop_userlist.erase(a);
179 void Channel::AddVoicedUser(User* user)
181 internal_voice_userlist[user] = user->nick;
184 void Channel::DelVoicedUser(User* user)
186 CUListIter a = internal_voice_userlist.find(user);
188 if (a != internal_voice_userlist.end())
190 internal_voice_userlist.erase(a);
194 CUList* Channel::GetUsers()
196 return &internal_userlist;
199 CUList* Channel::GetOppedUsers()
201 return &internal_op_userlist;
204 CUList* Channel::GetHalfoppedUsers()
206 return &internal_halfop_userlist;
209 CUList* Channel::GetVoicedUsers()
211 return &internal_voice_userlist;
214 void Channel::SetDefaultModes()
216 ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes);
217 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
219 std::string parameter;
221 list.GetToken(modeseq);
223 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
225 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
228 if (mode->GetNumParams(true))
229 list.GetToken(parameter);
233 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
239 * add a channel to a user, creating the record for it if needed and linking
240 * it to the user record
242 Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
253 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
254 * We restrict local users to MaxChans channels.
255 * We restrict local operators to OperMaxChans channels.
256 * This is a lot more logical than how it was formerly. -- w00t
258 if (IS_LOCAL(user) && !override)
260 // Checking MyClass exists because we *may* get here with NULL, not 100% sure.
261 if (user->MyClass && user->MyClass->GetMaxChans())
263 if (user->chans.size() >= user->MyClass->GetMaxChans())
265 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
273 if (user->chans.size() >= Instance->Config->OperMaxChans)
275 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
281 if (user->chans.size() >= Instance->Config->MaxChans)
283 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
290 strlcpy(cname, cn, Instance->Config->Limits.ChanMax);
291 Ptr = Instance->FindChan(cname);
296 * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
301 Instance->Logs->Log("CHANNEL",DEBUG,"*** BUG *** Channel::JoinUser called for REMOTE user '%s' on channel '%s' but no TS given!", user->nick.c_str(), cn);
308 if (IS_LOCAL(user) && override == false)
311 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, NULL, cname, privs, key ? key : ""));
316 Ptr = new Channel(Instance, cname, TS);
320 /* Already on the channel */
321 if (Ptr->HasUser(user))
325 * remote users are allowed us to bypass channel modes
326 * and bans (used by servers)
328 if (IS_LOCAL(user) && override == false)
331 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, Ptr, cname, privs, key ? key : ""));
336 else if (MOD_RESULT == 0)
338 std::string ckey = Ptr->GetModeParameter('k');
339 bool invited = user->IsInvited(Ptr->name.c_str());
340 bool can_bypass = Instance->Config->InvBypassModes && invited;
345 FOREACH_RESULT_I(Instance, I_OnCheckKey, OnCheckKey(user, Ptr, key ? key : ""));
348 // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
349 if ((!key || ckey != key) && !can_bypass)
351 user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
357 if (Ptr->IsModeSet('i'))
360 FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr));
365 user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
371 std::string limit = Ptr->GetModeParameter('l');
375 FOREACH_RESULT_I(Instance, I_OnCheckLimit, OnCheckLimit(user, Ptr));
378 long llimit = atol(limit.c_str());
379 if (Ptr->GetUserCounter() >= llimit && !can_bypass)
381 user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
387 if (Ptr->bans.size())
389 if (Ptr->IsBanned(user) && !can_bypass)
391 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
397 * If the user has invites for this channel, remove them now
398 * after a successful join so they don't build up.
402 user->RemoveInvite(Ptr->name.c_str());
408 /* As spotted by jilles, dont bother to set this on remote users */
409 if (IS_LOCAL(user) && Ptr->GetUserCounter() == 0)
410 Ptr->SetDefaultModes();
412 return Channel::ForceChan(Instance, Ptr, user, privs, bursting);
415 Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting)
417 std::string nick = user->nick;
422 /* Just in case they have no permissions */
423 user->chans[Ptr] = 0;
425 for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
427 const char status = *x;
428 ModeHandler* mh = Instance->Modes->FindPrefix(status);
431 /* Set, and make sure that the mode handler knows this mode was now set */
432 Ptr->SetPrefix(user, status, mh->GetPrefixRank(), true);
433 mh->OnModeChange(Instance->FakeClient, Instance->FakeClient, Ptr, nick, true);
435 switch (mh->GetPrefix())
437 /* These logic ops are SAFE IN THIS CASE because if the entry doesnt exist,
438 * addressing operator[] creates it. If they do exist, it points to it.
439 * At all other times where we dont want to create an item if it doesnt exist, we
440 * must stick to ::find().
443 user->chans[Ptr] |= UCMODE_OP;
446 user->chans[Ptr] |= UCMODE_HOP;
449 user->chans[Ptr] |= UCMODE_VOICE;
455 FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user, Ptr, bursting, silent));
458 Ptr->WriteChannel(user,"JOIN :%s",Ptr->name.c_str());
460 /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
461 std::string ms = Instance->Modes->ModeString(user, Ptr);
462 if ((Ptr->GetUserCounter() > 1) && (ms.length()))
463 Ptr->WriteAllExceptSender(user, true, 0, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
465 /* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
470 user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
471 user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
475 FOREACH_MOD_I(Instance,I_OnPostJoin,OnPostJoin(user, Ptr));
479 bool Channel::IsBanned(User* user)
483 FOREACH_RESULT(I_OnCheckBan,OnCheckBan(user, this));
485 if (MOD_RESULT == -1)
487 else if (MOD_RESULT == 0)
489 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
490 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
492 /* This allows CIDR ban matching
494 * Full masked host Full unmasked host IP with/without CIDR
496 if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
505 bool Channel::IsExtBanned(const std::string &str, char type)
508 FOREACH_RESULT(I_OnCheckStringExtBan, OnCheckStringExtBan(str, this, type));
510 if (MOD_RESULT == -1)
512 else if (MOD_RESULT == 0)
514 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
516 if (i->data[0] != type || i->data[1] != ':')
519 // Iterate past char and : to get to the mask without doing a data copy(!)
520 std::string maskptr = i->data.substr(2);
521 ServerInstance->Logs->Log("EXTBANS", DEBUG, "Checking %s against %s, type is %c", str.c_str(), maskptr.c_str(), type);
523 if (match(str, maskptr))
531 bool Channel::IsExtBanned(User *user, char type)
534 FOREACH_RESULT(I_OnCheckExtBan, OnCheckExtBan(user, this, type));
536 if (MOD_RESULT == -1)
538 else if (MOD_RESULT == 0)
541 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
543 // XXX: we should probably hook cloaked hosts in here somehow too..
544 if (this->IsExtBanned(mask, type))
547 if (this->IsExtBanned(user->GetFullHost(), type))
550 if (this->IsExtBanned(user->GetFullRealHost(), type))
558 * remove a channel from a users record, and return the number of users left.
559 * Therefore, if this function returns 0 the caller should delete the Channel.
561 * XXX: bleh, string copy of reason, fixme! -- w00t
563 long Channel::PartUser(User *user, std::string &reason)
568 return this->GetUserCounter();
570 UCListIter i = user->chans.find(this);
571 if (i != user->chans.end())
573 FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason, silent));
576 this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
578 user->chans.erase(i);
579 this->RemoveAllPrefixes(user);
582 if (!this->DelUser(user)) /* if there are no users left on the channel... */
584 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
585 /* kill the record */
586 if (iter != ServerInstance->chanlist->end())
589 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
591 return 1; // delete halted by module
592 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
593 ServerInstance->chanlist->erase(iter);
598 return this->GetUserCounter();
601 long Channel::ServerKickUser(User* user, const char* reason, bool triggerevents, const char* servername)
605 if (!user || !reason)
606 return this->GetUserCounter();
610 if (!this->HasUser(user))
613 return this->GetUserCounter();
617 if (servername == NULL || *ServerInstance->Config->HideWhoisServer)
618 servername = ServerInstance->Config->ServerName;
622 FOREACH_MOD(I_OnUserKick,OnUserKick(NULL, user, this, reason, silent));
625 UCListIter i = user->chans.find(this);
626 if (i != user->chans.end())
629 this->WriteChannelWithServ(servername, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
631 user->chans.erase(i);
632 this->RemoveAllPrefixes(user);
635 if (!this->DelUser(user))
637 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
638 /* kill the record */
639 if (iter != ServerInstance->chanlist->end())
642 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
644 return 1; // delete halted by module
645 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
646 ServerInstance->chanlist->erase(iter);
651 return this->GetUserCounter();
654 long Channel::KickUser(User *src, User *user, const char* reason)
658 if (!src || !user || !reason)
659 return this->GetUserCounter();
663 if (!this->HasUser(user))
665 src->WriteNumeric(ERR_USERNOTINCHANNEL, "%s %s %s :They are not on that channel",src->nick.c_str(), user->nick.c_str(), this->name.c_str());
666 return this->GetUserCounter();
668 if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
670 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Only a u-line may kick a u-line from a channel.",src->nick.c_str(), this->name.c_str());
671 return this->GetUserCounter();
675 if (!ServerInstance->ULine(src->server))
678 FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,this,reason));
680 return this->GetUserCounter();
682 /* Set to -1 by OnUserPreKick if explicit allow was set */
683 if (MOD_RESULT != -1)
685 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,this,AC_KICK));
686 if ((MOD_RESULT == ACR_DENY) && (!ServerInstance->ULine(src->server)))
687 return this->GetUserCounter();
689 if ((MOD_RESULT == ACR_DEFAULT) || (!ServerInstance->ULine(src->server)))
691 int them = this->GetStatus(src);
692 int us = this->GetStatus(user);
693 if ((them < STATUS_HOP) || (them < us))
695 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them == STATUS_HOP ? "" : "half-");
696 return this->GetUserCounter();
702 FOREACH_MOD(I_OnUserKick,OnUserKick(src, user, this, reason, silent));
704 UCListIter i = user->chans.find(this);
705 if (i != user->chans.end())
707 /* zap it from the channel list of the user */
709 this->WriteChannel(src, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
711 user->chans.erase(i);
712 this->RemoveAllPrefixes(user);
715 if (!this->DelUser(user))
716 /* if there are no users left on the channel */
718 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name.c_str());
720 /* kill the record */
721 if (iter != ServerInstance->chanlist->end())
724 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
726 return 1; // delete halted by module
727 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
728 ServerInstance->chanlist->erase(iter);
733 return this->GetUserCounter();
736 void Channel::WriteChannel(User* user, const char* text, ...)
738 char textbuffer[MAXBUF];
744 va_start(argsPtr, text);
745 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
748 this->WriteChannel(user, std::string(textbuffer));
751 void Channel::WriteChannel(User* user, const std::string &text)
753 CUList *ulist = this->GetUsers();
759 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
760 std::string out = tb;
762 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
764 if (IS_LOCAL(i->first))
765 i->first->Write(out);
769 void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...)
771 char textbuffer[MAXBUF];
777 va_start(argsPtr, text);
778 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
781 this->WriteChannelWithServ(ServName, std::string(textbuffer));
784 void Channel::WriteChannelWithServ(const char* ServName, const std::string &text)
786 CUList *ulist = this->GetUsers();
789 snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str());
790 std::string out = tb;
792 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
794 if (IS_LOCAL(i->first))
795 i->first->Write(out);
799 /* write formatted text from a source user to all users on a channel except
800 * for the sender (for privmsg etc) */
801 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
803 char textbuffer[MAXBUF];
809 va_start(argsPtr, text);
810 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
813 this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
816 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
818 char textbuffer[MAXBUF];
824 va_start(argsPtr, text);
825 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
828 this->WriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
831 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
833 CUList *ulist = this->GetUsers();
836 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
837 std::string out = tb;
839 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
841 if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
843 /* User doesnt have the status we're after */
844 if (status && !strchr(this->GetAllPrefixChars(i->first), status))
848 i->first->WriteServ(text);
850 i->first->Write(out);
855 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
858 except_list[user] = user->nick;
859 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
863 * return a count of the users on a specific channel accounting for
864 * invisible users who won't increase the count. e.g. for /LIST
866 int Channel::CountInvisible()
869 CUList *ulist= this->GetUsers();
870 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
872 if (!(i->first->IsModeSet('i')))
879 char* Channel::ChanModes(bool showkey)
881 static char scratch[MAXBUF];
882 static char sparam[MAXBUF];
883 char* offset = scratch;
884 std::string extparam;
889 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
890 for(int n = 0; n < 64; n++)
899 // Unfortunately this must be special-cased, as we definitely don't want to always display key.
902 extparam = this->GetModeParameter('k');
915 /* We know these have no parameters */
918 extparam = this->GetModeParameter(n + 65);
921 if (!extparam.empty())
923 charlcat(sparam,' ',MAXBUF);
924 strlcat(sparam,extparam.c_str(),MAXBUF);
929 /* Null terminate scratch */
931 strlcat(scratch,sparam,MAXBUF);
935 /* compile a userlist of a channel into a string, each nick seperated by
936 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
938 void Channel::UserList(User *user, CUList *ulist)
943 bool call_modules = true;
948 FOREACH_RESULT(I_OnUserList,OnUserList(user, this, ulist));
950 call_modules = false;
952 if (MOD_RESULT != -1)
954 if ((this->IsModeSet('s')) && (!this->HasUser(user)))
956 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
961 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
964 char* ptr = list + dlen;
967 ulist = this->GetUsers();
969 /* Improvement by Brain - this doesnt change in value, so why was it inside
972 bool has_user = this->HasUser(user);
974 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
976 if ((!has_user) && (i->first->IsModeSet('i')))
979 * user is +i, and source not on the channel, does not show
985 if (i->first->Visibility && !i->first->Visibility->VisibleTo(user))
988 std::string prefixlist = this->GetPrefixChar(i->first);
989 std::string nick = i->first->nick;
993 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->first, this, prefixlist, nick));
995 /* Nick was nuked, a module wants us to skip it */
1002 if (curlen + prefixlist.length() + nick.length() + 1 > 480)
1004 /* list overflowed into multiple numerics */
1005 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
1007 /* reset our lengths */
1008 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
1015 ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
1023 /* if whats left in the list isnt empty, send it */
1026 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
1029 user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
1032 long Channel::GetMaxBans()
1034 /* Return the cached value if there is one */
1036 return this->maxbans;
1038 /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
1039 for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
1041 if (match(this->name,n->first))
1043 this->maxbans = n->second;
1048 /* Screw it, just return the default of 64 */
1050 return this->maxbans;
1053 void Channel::ResetMaxBans()
1058 /* returns the status character for a given user on a channel, e.g. @ for op,
1059 * % for halfop etc. If the user has several modes set, the highest mode
1060 * the user has must be returned.
1062 const char* Channel::GetPrefixChar(User *user)
1064 static char pf[2] = {0, 0};
1066 prefixlist::iterator n = prefixes.find(user);
1067 if (n != prefixes.end())
1069 if (n->second.size())
1071 /* If the user has any prefixes, their highest prefix
1072 * will always be at the head of the list, as the list is
1073 * sorted in rank order highest first (see SetPrefix()
1076 *pf = n->second.begin()->first;
1086 const char* Channel::GetAllPrefixChars(User* user)
1088 static char prefix[MAXBUF];
1092 prefixlist::iterator n = prefixes.find(user);
1093 if (n != prefixes.end())
1095 for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
1097 prefix[ctr++] = x->first;
1106 unsigned int Channel::GetPrefixValue(User* user)
1108 prefixlist::iterator n = prefixes.find(user);
1109 if (n != prefixes.end())
1111 if (n->second.size())
1112 return n->second.begin()->second;
1117 int Channel::GetStatusFlags(User *user)
1119 UCListIter i = user->chans.find(this);
1120 if (i != user->chans.end())
1127 int Channel::GetStatus(User *user)
1129 if (ServerInstance->ULine(user->server))
1132 UCListIter i = user->chans.find(this);
1133 if (i != user->chans.end())
1135 if ((i->second & UCMODE_OP) > 0)
1139 if ((i->second & UCMODE_HOP) > 0)
1143 if ((i->second & UCMODE_VOICE) > 0)
1145 return STATUS_VOICE;
1147 return STATUS_NORMAL;
1149 return STATUS_NORMAL;
1152 void Channel::SetPrefix(User* user, char prefix, unsigned int prefix_value, bool adding)
1154 prefixlist::iterator n = prefixes.find(user);
1155 prefixtype pfx = std::make_pair(prefix,prefix_value);
1158 if (n != prefixes.end())
1160 if (std::find(n->second.begin(), n->second.end(), pfx) == n->second.end())
1162 n->second.push_back(pfx);
1163 /* We must keep prefixes in rank order, largest first.
1164 * This is for two reasons, firstly because x-chat *ass-u-me's* this
1165 * state, and secondly it turns out to be a benefit to us later.
1166 * See above in GetPrefix().
1168 std::sort(n->second.begin(), n->second.end(), ModeParser::PrefixComparison);
1175 prefixes.insert(std::make_pair<User*,pfxcontainer>(user, one));
1180 if (n != prefixes.end())
1182 pfxcontainer::iterator x = std::find(n->second.begin(), n->second.end(), pfx);
1183 if (x != n->second.end())
1189 void Channel::RemoveAllPrefixes(User* user)
1191 prefixlist::iterator n = prefixes.find(user);
1192 if (n != prefixes.end())