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;
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 long Channel::GetUserCounter()
78 return (this->internal_userlist.size());
81 void Channel::AddUser(User* user)
83 internal_userlist[user] = user->nick;
86 unsigned long Channel::DelUser(User* user)
88 CUListIter a = internal_userlist.find(user);
90 if (a != internal_userlist.end())
92 internal_userlist.erase(a);
93 /* And tidy any others... */
95 DelHalfoppedUser(user);
99 return internal_userlist.size();
102 bool Channel::HasUser(User* user)
104 return (internal_userlist.find(user) != internal_userlist.end());
107 void Channel::AddOppedUser(User* user)
109 internal_op_userlist[user] = user->nick;
112 void Channel::DelOppedUser(User* user)
114 CUListIter a = internal_op_userlist.find(user);
115 if (a != internal_op_userlist.end())
117 internal_op_userlist.erase(a);
122 void Channel::AddHalfoppedUser(User* user)
124 internal_halfop_userlist[user] = user->nick;
127 void Channel::DelHalfoppedUser(User* user)
129 CUListIter a = internal_halfop_userlist.find(user);
131 if (a != internal_halfop_userlist.end())
133 internal_halfop_userlist.erase(a);
137 void Channel::AddVoicedUser(User* user)
139 internal_voice_userlist[user] = user->nick;
142 void Channel::DelVoicedUser(User* user)
144 CUListIter a = internal_voice_userlist.find(user);
146 if (a != internal_voice_userlist.end())
148 internal_voice_userlist.erase(a);
152 CUList* Channel::GetUsers()
154 return &internal_userlist;
157 CUList* Channel::GetOppedUsers()
159 return &internal_op_userlist;
162 CUList* Channel::GetHalfoppedUsers()
164 return &internal_halfop_userlist;
167 CUList* Channel::GetVoicedUsers()
169 return &internal_voice_userlist;
172 void Channel::SetDefaultModes()
174 ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes);
175 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
177 std::string parameter;
179 list.GetToken(modeseq);
181 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
183 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
186 if (mode->GetNumParams(true))
187 list.GetToken(parameter);
191 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
197 * add a channel to a user, creating the record for it if needed and linking
198 * it to the user record
200 Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
211 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
212 * We restrict local users to MaxChans channels.
213 * We restrict local operators to OperMaxChans channels.
214 * This is a lot more logical than how it was formerly. -- w00t
216 if (IS_LOCAL(user) && !override)
218 if (user->GetMaxChans())
220 if (user->chans.size() >= user->GetMaxChans())
222 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
230 if (user->chans.size() >= Instance->Config->OperMaxChans)
232 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
238 if (user->chans.size() >= Instance->Config->MaxChans)
240 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
247 strlcpy(cname, cn, Instance->Config->Limits.ChanMax);
248 Ptr = Instance->FindChan(cname);
253 * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
258 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);
265 if (IS_LOCAL(user) && override == false)
268 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, NULL, cname, privs, key ? key : ""));
273 Ptr = new Channel(Instance, cname, TS);
277 /* Already on the channel */
278 if (Ptr->HasUser(user))
282 * remote users are allowed us to bypass channel modes
283 * and bans (used by servers)
285 if (IS_LOCAL(user) && override == false)
288 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, Ptr, cname, privs, key ? key : ""));
293 else if (MOD_RESULT == 0)
295 std::string ckey = Ptr->GetModeParameter('k');
299 FOREACH_RESULT_I(Instance, I_OnCheckKey, OnCheckKey(user, Ptr, key ? key : ""));
302 if ((!key) || ckey != key)
304 user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
309 if (Ptr->IsModeSet('i'))
312 FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr));
315 if (!user->IsInvited(Ptr->name.c_str()))
317 user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
321 user->RemoveInvite(Ptr->name.c_str());
324 std::string limit = Ptr->GetModeParameter('l');
328 FOREACH_RESULT_I(Instance, I_OnCheckLimit, OnCheckLimit(user, Ptr));
331 long llimit = atol(limit.c_str());
332 if (Ptr->GetUserCounter() >= llimit)
334 user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
340 if (Ptr->bans.size())
342 if (Ptr->IsBanned(user))
344 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
352 /* As spotted by jilles, dont bother to set this on remote users */
353 if (IS_LOCAL(user) && Ptr->GetUserCounter() == 0)
354 Ptr->SetDefaultModes();
356 return Channel::ForceChan(Instance, Ptr, user, privs, bursting);
359 Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting)
361 std::string nick = user->nick;
366 /* Just in case they have no permissions */
367 user->chans[Ptr] = 0;
369 for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
371 const char status = *x;
372 ModeHandler* mh = Instance->Modes->FindPrefix(status);
375 /* Set, and make sure that the mode handler knows this mode was now set */
376 Ptr->SetPrefix(user, status, mh->GetPrefixRank(), true);
377 mh->OnModeChange(Instance->FakeClient, Instance->FakeClient, Ptr, nick, true);
379 switch (mh->GetPrefix())
381 /* These logic ops are SAFE IN THIS CASE because if the entry doesnt exist,
382 * addressing operator[] creates it. If they do exist, it points to it.
383 * At all other times where we dont want to create an item if it doesnt exist, we
384 * must stick to ::find().
387 user->chans[Ptr] |= UCMODE_OP;
390 user->chans[Ptr] |= UCMODE_HOP;
393 user->chans[Ptr] |= UCMODE_VOICE;
399 FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user, Ptr, bursting, silent));
402 Ptr->WriteChannel(user,"JOIN :%s",Ptr->name.c_str());
404 /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
405 std::string ms = Instance->Modes->ModeString(user, Ptr);
406 if ((Ptr->GetUserCounter() > 1) && (ms.length()))
407 Ptr->WriteAllExceptSender(user, true, 0, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
409 /* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
414 user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
415 user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
419 FOREACH_MOD_I(Instance,I_OnPostJoin,OnPostJoin(user, Ptr));
423 bool Channel::IsBanned(User* user)
427 FOREACH_RESULT(I_OnCheckBan,OnCheckBan(user, this));
429 if (MOD_RESULT == -1)
431 else if (MOD_RESULT == 0)
433 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
434 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
436 /* This allows CIDR ban matching
438 * Full masked host Full unmasked host IP with/without CIDR
440 if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
449 bool Channel::IsExtBanned(const std::string &str, char type)
452 FOREACH_RESULT(I_OnCheckStringExtBan, OnCheckStringExtBan(str, this, type));
454 if (MOD_RESULT == -1)
456 else if (MOD_RESULT == 0)
458 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
460 if (i->data[0] != type || i->data[1] != ':')
463 // Iterate past char and : to get to the mask without doing a data copy(!)
464 std::string maskptr = i->data.substr(2);
465 ServerInstance->Logs->Log("EXTBANS", DEBUG, "Checking %s against %s, type is %c", str.c_str(), maskptr.c_str(), type);
467 if (match(str, maskptr))
475 bool Channel::IsExtBanned(User *user, char type)
478 FOREACH_RESULT(I_OnCheckExtBan, OnCheckExtBan(user, this, type));
480 if (MOD_RESULT == -1)
482 else if (MOD_RESULT == 0)
485 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
487 // XXX: we should probably hook cloaked hosts in here somehow too..
488 if (this->IsExtBanned(mask, type))
491 if (this->IsExtBanned(user->GetFullHost(), type))
494 if (this->IsExtBanned(user->GetFullRealHost(), type))
502 * remove a channel from a users record, and return the number of users left.
503 * Therefore, if this function returns 0 the caller should delete the Channel.
505 * XXX: bleh, string copy of reason, fixme! -- w00t
507 long Channel::PartUser(User *user, std::string &reason)
512 return this->GetUserCounter();
514 UCListIter i = user->chans.find(this);
515 if (i != user->chans.end())
517 FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason, silent));
520 this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
522 user->chans.erase(i);
523 this->RemoveAllPrefixes(user);
526 if (!this->DelUser(user)) /* if there are no users left on the channel... */
528 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
529 /* kill the record */
530 if (iter != ServerInstance->chanlist->end())
533 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
535 return 1; // delete halted by module
536 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
537 ServerInstance->chanlist->erase(iter);
542 return this->GetUserCounter();
545 long Channel::ServerKickUser(User* user, const char* reason, bool triggerevents, const char* servername)
549 if (!user || !reason)
550 return this->GetUserCounter();
554 if (!this->HasUser(user))
557 return this->GetUserCounter();
561 if (servername == NULL || *ServerInstance->Config->HideWhoisServer)
562 servername = ServerInstance->Config->ServerName;
566 FOREACH_MOD(I_OnUserKick,OnUserKick(NULL, user, this, reason, silent));
569 UCListIter i = user->chans.find(this);
570 if (i != user->chans.end())
573 this->WriteChannelWithServ(servername, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
575 user->chans.erase(i);
576 this->RemoveAllPrefixes(user);
579 if (!this->DelUser(user))
581 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
582 /* kill the record */
583 if (iter != ServerInstance->chanlist->end())
586 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
588 return 1; // delete halted by module
589 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
590 ServerInstance->chanlist->erase(iter);
595 return this->GetUserCounter();
598 long Channel::KickUser(User *src, User *user, const char* reason)
602 if (!src || !user || !reason)
603 return this->GetUserCounter();
607 if (!this->HasUser(user))
609 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());
610 return this->GetUserCounter();
612 if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
614 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());
615 return this->GetUserCounter();
619 if (!ServerInstance->ULine(src->server))
622 FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,this,reason));
624 return this->GetUserCounter();
626 /* Set to -1 by OnUserPreKick if explicit allow was set */
627 if (MOD_RESULT != -1)
629 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,this,AC_KICK));
630 if ((MOD_RESULT == ACR_DENY) && (!ServerInstance->ULine(src->server)))
631 return this->GetUserCounter();
633 if ((MOD_RESULT == ACR_DEFAULT) || (!ServerInstance->ULine(src->server)))
635 int them = this->GetStatus(src);
636 int us = this->GetStatus(user);
637 if ((them < STATUS_HOP) || (them < us))
639 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them == STATUS_HOP ? "" : "half-");
640 return this->GetUserCounter();
646 FOREACH_MOD(I_OnUserKick,OnUserKick(src, user, this, reason, silent));
648 UCListIter i = user->chans.find(this);
649 if (i != user->chans.end())
651 /* zap it from the channel list of the user */
653 this->WriteChannel(src, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
655 user->chans.erase(i);
656 this->RemoveAllPrefixes(user);
659 if (!this->DelUser(user))
660 /* if there are no users left on the channel */
662 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name.c_str());
664 /* kill the record */
665 if (iter != ServerInstance->chanlist->end())
668 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
670 return 1; // delete halted by module
671 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
672 ServerInstance->chanlist->erase(iter);
677 return this->GetUserCounter();
680 void Channel::WriteChannel(User* user, const char* text, ...)
682 char textbuffer[MAXBUF];
688 va_start(argsPtr, text);
689 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
692 this->WriteChannel(user, std::string(textbuffer));
695 void Channel::WriteChannel(User* user, const std::string &text)
697 CUList *ulist = this->GetUsers();
703 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
704 std::string out = tb;
706 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
708 if (IS_LOCAL(i->first))
709 i->first->Write(out);
713 void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...)
715 char textbuffer[MAXBUF];
721 va_start(argsPtr, text);
722 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
725 this->WriteChannelWithServ(ServName, std::string(textbuffer));
728 void Channel::WriteChannelWithServ(const char* ServName, const std::string &text)
730 CUList *ulist = this->GetUsers();
733 snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str());
734 std::string out = tb;
736 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
738 if (IS_LOCAL(i->first))
739 i->first->Write(out);
743 /* write formatted text from a source user to all users on a channel except
744 * for the sender (for privmsg etc) */
745 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
747 char textbuffer[MAXBUF];
753 va_start(argsPtr, text);
754 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
757 this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
760 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
762 char textbuffer[MAXBUF];
768 va_start(argsPtr, text);
769 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
772 this->WriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
775 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
777 CUList *ulist = this->GetUsers();
780 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
781 std::string out = tb;
783 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
785 if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
787 /* User doesnt have the status we're after */
788 if (status && !strchr(this->GetAllPrefixChars(i->first), status))
792 i->first->WriteServ(text);
794 i->first->Write(out);
799 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
802 except_list[user] = user->nick;
803 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
807 * return a count of the users on a specific channel accounting for
808 * invisible users who won't increase the count. e.g. for /LIST
810 int Channel::CountInvisible()
813 CUList *ulist= this->GetUsers();
814 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
816 if (!(i->first->IsModeSet('i')))
823 char* Channel::ChanModes(bool showkey)
825 static char scratch[MAXBUF];
826 static char sparam[MAXBUF];
827 char* offset = scratch;
828 std::string extparam;
833 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
834 for(int n = 0; n < 64; n++)
843 // Unfortunately this must be special-cased, as we definitely don't want to always display key.
846 extparam = this->GetModeParameter('k');
859 /* We know these have no parameters */
862 extparam = this->GetModeParameter(n + 65);
865 if (!extparam.empty())
867 charlcat(sparam,' ',MAXBUF);
868 strlcat(sparam,extparam.c_str(),MAXBUF);
873 /* Null terminate scratch */
875 strlcat(scratch,sparam,MAXBUF);
879 /* compile a userlist of a channel into a string, each nick seperated by
880 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
882 void Channel::UserList(User *user, CUList *ulist)
887 bool call_modules = true;
892 FOREACH_RESULT(I_OnUserList,OnUserList(user, this, ulist));
894 call_modules = false;
896 if (MOD_RESULT != -1)
898 if ((this->IsModeSet('s')) && (!this->HasUser(user)))
900 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
905 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
908 char* ptr = list + dlen;
911 ulist = this->GetUsers();
913 /* Improvement by Brain - this doesnt change in value, so why was it inside
916 bool has_user = this->HasUser(user);
918 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
920 if ((!has_user) && (i->first->IsModeSet('i')))
923 * user is +i, and source not on the channel, does not show
929 if (i->first->Visibility && !i->first->Visibility->VisibleTo(user))
932 std::string prefixlist = this->GetPrefixChar(i->first);
933 std::string nick = i->first->nick;
937 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->first, this, prefixlist, nick));
939 /* Nick was nuked, a module wants us to skip it */
946 if (curlen + prefixlist.length() + nick.length() + 1 > 480)
948 /* list overflowed into multiple numerics */
949 user->WriteServ(std::string(list));
951 /* reset our lengths */
952 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
959 ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
967 /* if whats left in the list isnt empty, send it */
970 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
973 user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
976 long Channel::GetMaxBans()
978 /* Return the cached value if there is one */
980 return this->maxbans;
982 /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
983 for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
985 if (match(this->name,n->first))
987 this->maxbans = n->second;
992 /* Screw it, just return the default of 64 */
994 return this->maxbans;
997 void Channel::ResetMaxBans()
1002 /* returns the status character for a given user on a channel, e.g. @ for op,
1003 * % for halfop etc. If the user has several modes set, the highest mode
1004 * the user has must be returned.
1006 const char* Channel::GetPrefixChar(User *user)
1008 static char pf[2] = {0, 0};
1010 prefixlist::iterator n = prefixes.find(user);
1011 if (n != prefixes.end())
1013 if (n->second.size())
1015 /* If the user has any prefixes, their highest prefix
1016 * will always be at the head of the list, as the list is
1017 * sorted in rank order highest first (see SetPrefix()
1020 *pf = n->second.begin()->first;
1030 const char* Channel::GetAllPrefixChars(User* user)
1032 static char prefix[MAXBUF];
1036 prefixlist::iterator n = prefixes.find(user);
1037 if (n != prefixes.end())
1039 for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
1041 prefix[ctr++] = x->first;
1050 unsigned int Channel::GetPrefixValue(User* user)
1052 prefixlist::iterator n = prefixes.find(user);
1053 if (n != prefixes.end())
1055 if (n->second.size())
1056 return n->second.begin()->second;
1061 int Channel::GetStatusFlags(User *user)
1063 UCListIter i = user->chans.find(this);
1064 if (i != user->chans.end())
1071 int Channel::GetStatus(User *user)
1073 if (ServerInstance->ULine(user->server))
1076 UCListIter i = user->chans.find(this);
1077 if (i != user->chans.end())
1079 if ((i->second & UCMODE_OP) > 0)
1083 if ((i->second & UCMODE_HOP) > 0)
1087 if ((i->second & UCMODE_VOICE) > 0)
1089 return STATUS_VOICE;
1091 return STATUS_NORMAL;
1093 return STATUS_NORMAL;
1096 void Channel::SetPrefix(User* user, char prefix, unsigned int prefix_value, bool adding)
1098 prefixlist::iterator n = prefixes.find(user);
1099 prefixtype pfx = std::make_pair(prefix,prefix_value);
1102 if (n != prefixes.end())
1104 if (std::find(n->second.begin(), n->second.end(), pfx) == n->second.end())
1106 n->second.push_back(pfx);
1107 /* We must keep prefixes in rank order, largest first.
1108 * This is for two reasons, firstly because x-chat *ass-u-me's* this
1109 * state, and secondly it turns out to be a benefit to us later.
1110 * See above in GetPrefix().
1112 std::sort(n->second.begin(), n->second.end(), ModeParser::PrefixComparison);
1119 prefixes.insert(std::make_pair<User*,pfxcontainer>(user, one));
1124 if (n != prefixes.end())
1126 pfxcontainer::iterator x = std::find(n->second.begin(), n->second.end(), pfx);
1127 if (x != n->second.end())
1133 void Channel::RemoveAllPrefixes(User* user)
1135 prefixlist::iterator n = prefixes.find(user);
1136 if (n != prefixes.end())