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 * ---------------------------------------------------
14 /* $Core: libIRCDchannels */
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;
33 maxbans = topicset = limit = 0;
34 memset(&modes, 0, 64);
37 void Channel::SetMode(char mode,bool mode_on)
39 modes[mode-65] = mode_on;
41 this->SetModeParam(mode,"",false);
45 void Channel::SetModeParam(char mode,const char* parameter,bool mode_on)
47 CustomModeList::iterator n = custom_mode_params.find(mode);
51 if (n == custom_mode_params.end())
52 custom_mode_params[mode] = strdup(parameter);
56 if (n != custom_mode_params.end())
59 custom_mode_params.erase(n);
64 bool Channel::IsModeSet(char mode)
66 return modes[mode-65];
69 std::string Channel::GetModeParameter(char mode)
76 return ConvToStr(this->limit);
78 CustomModeList::iterator n = custom_mode_params.find(mode);
79 if (n != custom_mode_params.end())
86 long Channel::GetUserCounter()
88 return (this->internal_userlist.size());
91 void Channel::AddUser(User* user)
93 internal_userlist[user] = user->nick;
96 unsigned long Channel::DelUser(User* user)
98 CUListIter a = internal_userlist.find(user);
100 if (a != internal_userlist.end())
102 internal_userlist.erase(a);
103 /* And tidy any others... */
105 DelHalfoppedUser(user);
109 return internal_userlist.size();
112 bool Channel::HasUser(User* user)
114 return (internal_userlist.find(user) != internal_userlist.end());
117 void Channel::AddOppedUser(User* user)
119 internal_op_userlist[user] = user->nick;
122 void Channel::DelOppedUser(User* user)
124 CUListIter a = internal_op_userlist.find(user);
125 if (a != internal_op_userlist.end())
127 internal_op_userlist.erase(a);
132 void Channel::AddHalfoppedUser(User* user)
134 internal_halfop_userlist[user] = user->nick;
137 void Channel::DelHalfoppedUser(User* user)
139 CUListIter a = internal_halfop_userlist.find(user);
141 if (a != internal_halfop_userlist.end())
143 internal_halfop_userlist.erase(a);
147 void Channel::AddVoicedUser(User* user)
149 internal_voice_userlist[user] = user->nick;
152 void Channel::DelVoicedUser(User* user)
154 CUListIter a = internal_voice_userlist.find(user);
156 if (a != internal_voice_userlist.end())
158 internal_voice_userlist.erase(a);
162 CUList* Channel::GetUsers()
164 return &internal_userlist;
167 CUList* Channel::GetOppedUsers()
169 return &internal_op_userlist;
172 CUList* Channel::GetHalfoppedUsers()
174 return &internal_halfop_userlist;
177 CUList* Channel::GetVoicedUsers()
179 return &internal_voice_userlist;
182 void Channel::SetDefaultModes()
184 ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes);
185 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
187 std::string parameter;
189 list.GetToken(modeseq);
191 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
193 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
196 if (mode->GetNumParams(true))
197 list.GetToken(parameter);
201 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
207 * add a channel to a user, creating the record for it if needed and linking
208 * it to the user record
210 Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
221 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
222 * We restrict local users to MaxChans channels.
223 * We restrict local operators to OperMaxChans channels.
224 * This is a lot more logical than how it was formerly. -- w00t
226 if (IS_LOCAL(user) && !override)
228 if (user->GetMaxChans())
230 if (user->chans.size() >= user->GetMaxChans())
232 user->WriteNumeric(405, "%s %s :You are on too many channels",user->nick.c_str(), cn);
240 if (user->chans.size() >= Instance->Config->OperMaxChans)
242 user->WriteNumeric(405, "%s %s :You are on too many channels",user->nick.c_str(), cn);
248 if (user->chans.size() >= Instance->Config->MaxChans)
250 user->WriteNumeric(405, "%s %s :You are on too many channels",user->nick.c_str(), cn);
257 strlcpy(cname, cn, Instance->Config->Limits.ChanMax);
258 Ptr = Instance->FindChan(cname);
263 * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
268 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);
275 if (IS_LOCAL(user) && override == false)
278 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, NULL, cname, privs, key ? key : ""));
283 Ptr = new Channel(Instance, cname, TS);
287 /* Already on the channel */
288 if (Ptr->HasUser(user))
292 * remote users are allowed us to bypass channel modes
293 * and bans (used by servers)
295 if (IS_LOCAL(user) && override == false)
298 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, Ptr, cname, privs, key ? key : ""));
303 else if (MOD_RESULT == 0)
305 if (!Ptr->key.empty())
308 FOREACH_RESULT_I(Instance,I_OnCheckKey,OnCheckKey(user, Ptr, key ? key : ""));
311 if ((!key) || Ptr->key == key)
313 user->WriteNumeric(475, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
318 if (Ptr->IsModeSet('i'))
321 FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr));
324 if (!user->IsInvited(Ptr->name.c_str()))
326 user->WriteNumeric(473, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
330 user->RemoveInvite(Ptr->name.c_str());
335 FOREACH_RESULT_I(Instance,I_OnCheckLimit,OnCheckLimit(user, Ptr));
338 if (Ptr->GetUserCounter() >= Ptr->limit)
340 user->WriteNumeric(471, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
345 if (Ptr->bans.size())
347 if (Ptr->IsBanned(user))
349 user->WriteNumeric(474, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
357 /* As spotted by jilles, dont bother to set this on remote users */
358 if (IS_LOCAL(user) && Ptr->GetUserCounter() == 0)
359 Ptr->SetDefaultModes();
361 return Channel::ForceChan(Instance, Ptr, user, privs, bursting);
364 Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting)
366 std::string nick = user->nick;
371 /* Just in case they have no permissions */
372 user->chans[Ptr] = 0;
374 for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
376 const char status = *x;
377 ModeHandler* mh = Instance->Modes->FindPrefix(status);
380 /* Set, and make sure that the mode handler knows this mode was now set */
381 Ptr->SetPrefix(user, status, mh->GetPrefixRank(), true);
382 mh->OnModeChange(Instance->FakeClient, Instance->FakeClient, Ptr, nick, true);
384 switch (mh->GetPrefix())
386 /* These logic ops are SAFE IN THIS CASE because if the entry doesnt exist,
387 * addressing operator[] creates it. If they do exist, it points to it.
388 * At all other times where we dont want to create an item if it doesnt exist, we
389 * must stick to ::find().
392 user->chans[Ptr] |= UCMODE_OP;
395 user->chans[Ptr] |= UCMODE_HOP;
398 user->chans[Ptr] |= UCMODE_VOICE;
404 FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user, Ptr, bursting, silent));
407 Ptr->WriteChannel(user,"JOIN :%s",Ptr->name.c_str());
409 /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
410 std::string ms = Instance->Modes->ModeString(user, Ptr);
411 if ((Ptr->GetUserCounter() > 1) && (ms.length()))
412 Ptr->WriteAllExceptSender(user, true, 0, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
414 /* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
419 user->WriteNumeric(332, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
420 user->WriteNumeric(333, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
424 FOREACH_MOD_I(Instance,I_OnPostJoin,OnPostJoin(user, Ptr));
428 bool Channel::IsBanned(User* user)
432 FOREACH_RESULT(I_OnCheckBan,OnCheckBan(user, this));
434 if (MOD_RESULT == -1)
436 else if (MOD_RESULT == 0)
438 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
439 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
441 /* This allows CIDR ban matching
443 * Full masked host Full unmasked host IP with/without CIDR
445 if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
454 bool Channel::IsExtBanned(User *user, char type)
458 FOREACH_RESULT(I_OnCheckExtBan,OnCheckExtBan(user, this, type));
460 if (MOD_RESULT == -1)
462 else if (MOD_RESULT == 0)
464 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
466 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
468 if (i->data[0] != type || i->data[1] != ':')
471 // Iterate past char and : to get to the mask without doing a data copy(!)
472 std::string maskptr = i->data.substr(2);
474 /* This allows CIDR ban matching
476 * Full masked host Full unmasked host IP with/without CIDR
478 if ((match(user->GetFullHost(), maskptr)) || (match(user->GetFullRealHost(), maskptr)) || (match(mask, maskptr, true)))
489 * remove a channel from a users record, and return the number of users left.
490 * Therefore, if this function returns 0 the caller should delete the Channel.
492 * XXX: bleh, string copy of reason, fixme! -- w00t
494 long Channel::PartUser(User *user, std::string &reason)
499 return this->GetUserCounter();
501 UCListIter i = user->chans.find(this);
502 if (i != user->chans.end())
504 FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason, silent));
507 this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : ":", reason.c_str());
509 user->chans.erase(i);
510 this->RemoveAllPrefixes(user);
513 if (!this->DelUser(user)) /* if there are no users left on the channel... */
515 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
516 /* kill the record */
517 if (iter != ServerInstance->chanlist->end())
520 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
522 return 1; // delete halted by module
523 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
524 ServerInstance->chanlist->erase(iter);
529 return this->GetUserCounter();
532 long Channel::ServerKickUser(User* user, const char* reason, bool triggerevents, const char* servername)
536 if (!user || !reason)
537 return this->GetUserCounter();
541 if (!this->HasUser(user))
544 return this->GetUserCounter();
548 if (servername == NULL || *ServerInstance->Config->HideWhoisServer)
549 servername = ServerInstance->Config->ServerName;
553 FOREACH_MOD(I_OnUserKick,OnUserKick(NULL, user, this, reason, silent));
556 UCListIter i = user->chans.find(this);
557 if (i != user->chans.end())
560 this->WriteChannelWithServ(servername, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
562 user->chans.erase(i);
563 this->RemoveAllPrefixes(user);
566 if (!this->DelUser(user))
568 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
569 /* kill the record */
570 if (iter != ServerInstance->chanlist->end())
573 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
575 return 1; // delete halted by module
576 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
577 ServerInstance->chanlist->erase(iter);
582 return this->GetUserCounter();
585 long Channel::KickUser(User *src, User *user, const char* reason)
589 if (!src || !user || !reason)
590 return this->GetUserCounter();
594 if (!this->HasUser(user))
596 src->WriteNumeric(441, "%s %s %s :They are not on that channel",src->nick.c_str(), user->nick.c_str(), this->name.c_str());
597 return this->GetUserCounter();
599 if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
601 src->WriteNumeric(482, "%s %s :Only a u-line may kick a u-line from a channel.",src->nick.c_str(), this->name.c_str());
602 return this->GetUserCounter();
606 if (!ServerInstance->ULine(src->server))
609 FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,this,reason));
611 return this->GetUserCounter();
613 /* Set to -1 by OnUserPreKick if explicit allow was set */
614 if (MOD_RESULT != -1)
616 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,this,AC_KICK));
617 if ((MOD_RESULT == ACR_DENY) && (!ServerInstance->ULine(src->server)))
618 return this->GetUserCounter();
620 if ((MOD_RESULT == ACR_DEFAULT) || (!ServerInstance->ULine(src->server)))
622 int them = this->GetStatus(src);
623 int us = this->GetStatus(user);
624 if ((them < STATUS_HOP) || (them < us))
626 src->WriteNumeric(482, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them == STATUS_HOP ? "" : "half-");
627 return this->GetUserCounter();
633 FOREACH_MOD(I_OnUserKick,OnUserKick(src, user, this, reason, silent));
635 UCListIter i = user->chans.find(this);
636 if (i != user->chans.end())
638 /* zap it from the channel list of the user */
640 this->WriteChannel(src, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
642 user->chans.erase(i);
643 this->RemoveAllPrefixes(user);
646 if (!this->DelUser(user))
647 /* if there are no users left on the channel */
649 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name.c_str());
651 /* kill the record */
652 if (iter != ServerInstance->chanlist->end())
655 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
657 return 1; // delete halted by module
658 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
659 ServerInstance->chanlist->erase(iter);
664 return this->GetUserCounter();
667 void Channel::WriteChannel(User* user, const char* text, ...)
669 char textbuffer[MAXBUF];
675 va_start(argsPtr, text);
676 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
679 this->WriteChannel(user, std::string(textbuffer));
682 void Channel::WriteChannel(User* user, const std::string &text)
684 CUList *ulist = this->GetUsers();
690 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
691 std::string out = tb;
693 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
695 if (IS_LOCAL(i->first))
696 i->first->Write(out);
700 void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...)
702 char textbuffer[MAXBUF];
708 va_start(argsPtr, text);
709 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
712 this->WriteChannelWithServ(ServName, std::string(textbuffer));
715 void Channel::WriteChannelWithServ(const char* ServName, const std::string &text)
717 CUList *ulist = this->GetUsers();
720 snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str());
721 std::string out = tb;
723 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
725 if (IS_LOCAL(i->first))
726 i->first->Write(out);
730 /* write formatted text from a source user to all users on a channel except
731 * for the sender (for privmsg etc) */
732 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
734 char textbuffer[MAXBUF];
740 va_start(argsPtr, text);
741 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
744 this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
747 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
749 char textbuffer[MAXBUF];
755 va_start(argsPtr, text);
756 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
759 this->WriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
762 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
764 CUList *ulist = this->GetUsers();
767 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
768 std::string out = tb;
770 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
772 if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
774 /* User doesnt have the status we're after */
775 if (status && !strchr(this->GetAllPrefixChars(i->first), status))
779 i->first->WriteServ(text);
781 i->first->Write(out);
786 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
789 except_list[user] = user->nick;
790 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
794 * return a count of the users on a specific channel accounting for
795 * invisible users who won't increase the count. e.g. for /LIST
797 int Channel::CountInvisible()
800 CUList *ulist= this->GetUsers();
801 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
803 if (!(i->first->IsModeSet('i')))
810 char* Channel::ChanModes(bool showkey)
812 static char scratch[MAXBUF];
813 static char sparam[MAXBUF];
814 char* offset = scratch;
815 std::string extparam;
820 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
821 for(int n = 0; n < 64; n++)
830 extparam = (showkey ? this->key : "<key>");
833 extparam = ConvToStr(this->limit);
841 /* We know these have no parameters */
844 extparam = this->GetModeParameter(n + 65);
847 if (!extparam.empty())
849 charlcat(sparam,' ',MAXBUF);
850 strlcat(sparam,extparam.c_str(),MAXBUF);
855 /* Null terminate scratch */
857 strlcat(scratch,sparam,MAXBUF);
861 /* compile a userlist of a channel into a string, each nick seperated by
862 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
864 void Channel::UserList(User *user, CUList *ulist)
869 bool call_modules = true;
874 FOREACH_RESULT(I_OnUserList,OnUserList(user, this, ulist));
876 call_modules = false;
878 if (MOD_RESULT != -1)
880 if ((this->IsModeSet('s')) && (!this->HasUser(user)))
882 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
887 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
890 char* ptr = list + dlen;
893 ulist = this->GetUsers();
895 /* Improvement by Brain - this doesnt change in value, so why was it inside
898 bool has_user = this->HasUser(user);
900 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
902 if ((!has_user) && (i->first->IsModeSet('i')))
905 * user is +i, and source not on the channel, does not show
911 if (i->first->Visibility && !i->first->Visibility->VisibleTo(user))
914 std::string prefixlist = this->GetPrefixChar(i->first);
915 std::string nick = i->first->nick;
919 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->first, this, prefixlist, nick));
921 /* Nick was nuked, a module wants us to skip it */
928 if (curlen + prefixlist.length() + nick.length() + 1 > 480)
930 /* list overflowed into multiple numerics */
931 user->WriteServ(std::string(list));
933 /* reset our lengths */
934 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
941 ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
949 /* if whats left in the list isnt empty, send it */
952 user->WriteNumeric(353,std::string(list));
955 user->WriteNumeric(366, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
958 long Channel::GetMaxBans()
960 /* Return the cached value if there is one */
962 return this->maxbans;
964 /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
965 for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
967 if (match(this->name,n->first))
969 this->maxbans = n->second;
974 /* Screw it, just return the default of 64 */
976 return this->maxbans;
979 void Channel::ResetMaxBans()
984 /* returns the status character for a given user on a channel, e.g. @ for op,
985 * % for halfop etc. If the user has several modes set, the highest mode
986 * the user has must be returned.
988 const char* Channel::GetPrefixChar(User *user)
990 static char pf[2] = {0, 0};
992 prefixlist::iterator n = prefixes.find(user);
993 if (n != prefixes.end())
995 if (n->second.size())
997 /* If the user has any prefixes, their highest prefix
998 * will always be at the head of the list, as the list is
999 * sorted in rank order highest first (see SetPrefix()
1002 *pf = n->second.begin()->first;
1012 const char* Channel::GetAllPrefixChars(User* user)
1014 static char prefix[MAXBUF];
1018 prefixlist::iterator n = prefixes.find(user);
1019 if (n != prefixes.end())
1021 for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
1023 prefix[ctr++] = x->first;
1032 unsigned int Channel::GetPrefixValue(User* user)
1034 prefixlist::iterator n = prefixes.find(user);
1035 if (n != prefixes.end())
1037 if (n->second.size())
1038 return n->second.begin()->second;
1043 int Channel::GetStatusFlags(User *user)
1045 UCListIter i = user->chans.find(this);
1046 if (i != user->chans.end())
1053 int Channel::GetStatus(User *user)
1055 if (ServerInstance->ULine(user->server))
1058 UCListIter i = user->chans.find(this);
1059 if (i != user->chans.end())
1061 if ((i->second & UCMODE_OP) > 0)
1065 if ((i->second & UCMODE_HOP) > 0)
1069 if ((i->second & UCMODE_VOICE) > 0)
1071 return STATUS_VOICE;
1073 return STATUS_NORMAL;
1075 return STATUS_NORMAL;
1078 void Channel::SetPrefix(User* user, char prefix, unsigned int prefix_value, bool adding)
1080 prefixlist::iterator n = prefixes.find(user);
1081 prefixtype pfx = std::make_pair(prefix,prefix_value);
1084 if (n != prefixes.end())
1086 if (std::find(n->second.begin(), n->second.end(), pfx) == n->second.end())
1088 n->second.push_back(pfx);
1089 /* We must keep prefixes in rank order, largest first.
1090 * This is for two reasons, firstly because x-chat *ass-u-me's* this
1091 * state, and secondly it turns out to be a benefit to us later.
1092 * See above in GetPrefix().
1094 std::sort(n->second.begin(), n->second.end(), ModeParser::PrefixComparison);
1101 prefixes.insert(std::make_pair<User*,pfxcontainer>(user, one));
1106 if (n != prefixes.end())
1108 pfxcontainer::iterator x = std::find(n->second.begin(), n->second.end(), pfx);
1109 if (x != n->second.end())
1115 void Channel::RemoveAllPrefixes(User* user)
1117 prefixlist::iterator n = prefixes.find(user);
1118 if (n != prefixes.end())