2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2006-2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2006, 2008 Oliver Lupton <oliverlupton@gmail.com>
7 * Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
8 * Copyright (C) 2003-2008 Craig Edwards <craigedwards@brainbox.cc>
9 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
10 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 Channel::Channel(const std::string &cname, time_t ts)
34 chan_hash::iterator findchan = ServerInstance->chanlist->find(cname);
35 if (findchan != ServerInstance->chanlist->end())
36 throw CoreException("Cannot create duplicate channel " + cname);
38 (*(ServerInstance->chanlist))[cname.c_str()] = this;
39 this->name.assign(cname, 0, ServerInstance->Config->Limits.ChanMax);
40 this->age = ts ? ts : ServerInstance->Time();
42 maxbans = topicset = 0;
46 void Channel::SetMode(char mode,bool mode_on)
48 modes[mode-65] = mode_on;
51 void Channel::SetMode(ModeHandler* mh, bool on)
53 modes[mh->GetModeChar() - 65] = on;
56 void Channel::SetModeParam(char mode, const std::string& parameter)
58 CustomModeList::iterator n = custom_mode_params.find(mode);
59 // always erase, even if changing, so that the map gets the new value
60 if (n != custom_mode_params.end())
61 custom_mode_params.erase(n);
62 if (parameter.empty())
64 modes[mode-65] = false;
68 custom_mode_params[mode] = parameter;
69 modes[mode-65] = true;
73 void Channel::SetModeParam(ModeHandler* mode, const std::string& parameter)
75 SetModeParam(mode->GetModeChar(), parameter);
78 std::string Channel::GetModeParameter(char mode)
80 CustomModeList::iterator n = custom_mode_params.find(mode);
81 if (n != custom_mode_params.end())
86 std::string Channel::GetModeParameter(ModeHandler* mode)
88 CustomModeList::iterator n = custom_mode_params.find(mode->GetModeChar());
89 if (n != custom_mode_params.end())
94 int Channel::SetTopic(User *u, std::string &ntopic, bool forceset)
97 u = ServerInstance->FakeClient;
98 if (IS_LOCAL(u) && !forceset)
101 FIRST_MOD_RESULT(OnPreTopicChange, res, (u,this,ntopic));
103 if (res == MOD_RES_DENY)
105 if (res != MOD_RES_ALLOW)
107 if (!this->HasUser(u))
109 u->WriteNumeric(442, "%s %s :You're not on that channel!",u->nick.c_str(), this->name.c_str());
112 if (IsModeSet('t') && !ServerInstance->OnCheckExemption(u,this,"topiclock").check(GetPrefixValue(u) >= HALFOP_VALUE))
114 u->WriteNumeric(482, "%s %s :You do not have access to change the topic on this channel", u->nick.c_str(), this->name.c_str());
120 this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic);
123 this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128);
124 this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
128 this->setby.assign(ServerInstance->Config->ServerName);
129 this->WriteChannelWithServ(ServerInstance->Config->ServerName, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
132 this->topicset = ServerInstance->Time();
134 FOREACH_MOD(I_OnPostTopicChange,OnPostTopicChange(u, this, this->topic));
139 long Channel::GetUserCounter()
141 return userlist.size();
144 Membership* Channel::AddUser(User* user)
146 Membership* memb = new Membership(user, this);
147 userlist[user] = memb;
151 void Channel::DelUser(User* user)
153 UserMembIter a = userlist.find(user);
155 if (a != userlist.end())
162 if (userlist.empty())
165 FIRST_MOD_RESULT(OnChannelPreDelete, res, (this));
166 if (res == MOD_RES_DENY)
168 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
169 /* kill the record */
170 if (iter != ServerInstance->chanlist->end())
172 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
173 ServerInstance->chanlist->erase(iter);
175 ServerInstance->GlobalCulls.AddItem(this);
179 bool Channel::HasUser(User* user)
181 return (userlist.find(user) != userlist.end());
184 Membership* Channel::GetUser(User* user)
186 UserMembIter i = userlist.find(user);
187 if (i == userlist.end())
192 const UserMembList* Channel::GetUsers()
197 void Channel::SetDefaultModes()
199 ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s",
200 ServerInstance->Config->DefaultModes.c_str());
201 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
203 std::string parameter;
205 list.GetToken(modeseq);
207 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
209 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
212 if (mode->GetNumParams(true))
213 list.GetToken(parameter);
217 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
223 * add a channel to a user, creating the record for it if needed and linking
224 * it to the user record
226 Channel* Channel::JoinUser(User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
228 // Fix: unregistered users could be joined using /SAJOIN
229 if (!user || !cn || user->registered != REG_ALL)
237 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
238 * We restrict local users to MaxChans channels.
239 * We restrict local operators to OperMaxChans channels.
240 * This is a lot more logical than how it was formerly. -- w00t
242 if (IS_LOCAL(user) && !override)
244 if (user->HasPrivPermission("channels/high-join-limit"))
246 if (user->chans.size() >= ServerInstance->Config->OperMaxChans)
248 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
254 unsigned int maxchans = user->GetClass()->maxchans;
256 maxchans = ServerInstance->Config->MaxChans;
257 if (user->chans.size() >= maxchans)
259 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
265 strlcpy(cname, cn, ServerInstance->Config->Limits.ChanMax);
266 Ptr = ServerInstance->FindChan(cname);
267 bool created_by_local = false;
272 * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
277 ServerInstance->Logs->Log("CHANNELS",DEBUG,"*** BUG *** Channel::JoinUser called for REMOTE user '%s' on channel '%s' but no TS given!", user->nick.c_str(), cn);
282 created_by_local = true;
285 if (IS_LOCAL(user) && override == false)
287 ModResult MOD_RESULT;
288 FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, NULL, cname, privs, key ? key : ""));
289 if (MOD_RESULT == MOD_RES_DENY)
293 Ptr = new Channel(cname, TS);
297 /* Already on the channel */
298 if (Ptr->HasUser(user))
302 * remote users are allowed us to bypass channel modes
303 * and bans (used by servers)
305 if (IS_LOCAL(user) && override == false)
307 ModResult MOD_RESULT;
308 FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, Ptr, cname, privs, key ? key : ""));
309 if (MOD_RESULT == MOD_RES_DENY)
313 else if (MOD_RESULT == MOD_RES_PASSTHRU)
315 std::string ckey = Ptr->GetModeParameter('k');
316 bool invited = IS_LOCAL(user)->IsInvited(Ptr->name.c_str());
317 bool can_bypass = ServerInstance->Config->InvBypassModes && invited;
321 FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, Ptr, key ? key : ""));
322 if (!MOD_RESULT.check((key && ckey == key) || can_bypass))
324 // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
325 user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
330 if (Ptr->IsModeSet('i'))
332 FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, Ptr));
333 if (!MOD_RESULT.check(invited))
335 user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
340 std::string limit = Ptr->GetModeParameter('l');
343 FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, Ptr));
344 if (!MOD_RESULT.check((Ptr->GetUserCounter() < atol(limit.c_str()) || can_bypass)))
346 user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
351 if (Ptr->IsBanned(user) && !can_bypass)
353 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
358 * If the user has invites for this channel, remove them now
359 * after a successful join so they don't build up.
363 IS_LOCAL(user)->RemoveInvite(Ptr->name.c_str());
369 if (created_by_local)
371 /* As spotted by jilles, dont bother to set this on remote users */
372 Ptr->SetDefaultModes();
375 return Channel::ForceChan(Ptr, user, privs, bursting, created_by_local);
378 Channel* Channel::ForceChan(Channel* Ptr, User* user, const std::string &privs, bool bursting, bool created)
380 std::string nick = user->nick;
382 Membership* memb = Ptr->AddUser(user);
383 user->chans.insert(Ptr);
385 for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
387 const char status = *x;
388 ModeHandler* mh = ServerInstance->Modes->FindMode(status, MODETYPE_CHANNEL);
391 /* Set, and make sure that the mode handler knows this mode was now set */
392 Ptr->SetPrefix(user, mh->GetModeChar(), true);
393 mh->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, Ptr, nick, true);
398 FOREACH_MOD(I_OnUserJoin,OnUserJoin(memb, bursting, created, except_list));
400 Ptr->WriteAllExcept(user, false, 0, except_list, "JOIN :%s", Ptr->name.c_str());
402 /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
403 if ((Ptr->GetUserCounter() > 1) && (!memb->modes.empty()))
405 std::string ms = memb->modes;
406 for(unsigned int i=0; i < memb->modes.length(); i++)
407 ms.append(" ").append(user->nick);
409 except_list.insert(user);
410 Ptr->WriteAllExcept(user, !ServerInstance->Config->CycleHostsFromUser, 0, except_list, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
417 user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
418 user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
422 FOREACH_MOD(I_OnPostJoin,OnPostJoin(memb));
426 bool Channel::IsBanned(User* user)
429 FIRST_MOD_RESULT(OnCheckChannelBan, result, (user, this));
431 if (result != MOD_RES_PASSTHRU)
432 return (result == MOD_RES_DENY);
434 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
436 if (CheckBan(user, i->data))
442 bool Channel::CheckBan(User* user, const std::string& mask)
445 FIRST_MOD_RESULT(OnCheckBan, result, (user, this, mask));
446 if (result != MOD_RES_PASSTHRU)
447 return (result == MOD_RES_DENY);
449 // extbans were handled above, if this is one it obviously didn't match
453 std::string::size_type at = mask.find('@');
454 if (at == std::string::npos)
457 char tomatch[MAXBUF];
458 snprintf(tomatch, MAXBUF, "%s!%s", user->nick.c_str(), user->ident.c_str());
459 std::string prefix = mask.substr(0, at);
460 if (InspIRCd::Match(tomatch, prefix, NULL))
462 std::string suffix = mask.substr(at + 1);
463 if (InspIRCd::Match(user->host, suffix, NULL) ||
464 InspIRCd::Match(user->dhost, suffix, NULL) ||
465 InspIRCd::MatchCIDR(user->GetIPString(), suffix, NULL))
471 ModResult Channel::GetExtBanStatus(User *user, char type)
474 FIRST_MOD_RESULT(OnExtBanCheck, rv, (user, this, type));
475 if (rv != MOD_RES_PASSTHRU)
477 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
479 if (i->data[0] == type && i->data[1] == ':')
481 std::string val = i->data.substr(2);
482 if (CheckBan(user, val))
486 return MOD_RES_PASSTHRU;
490 * remove a channel from a users record, and return the number of users left.
491 * Therefore, if this function returns 0 the caller should delete the Channel.
493 void Channel::PartUser(User *user, std::string &reason)
498 Membership* memb = GetUser(user);
503 FOREACH_MOD(I_OnUserPart,OnUserPart(memb, reason, except_list));
505 WriteAllExcept(user, false, 0, except_list, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
507 user->chans.erase(this);
508 this->RemoveAllPrefixes(user);
514 void Channel::KickUser(User *src, User *user, const char* reason)
516 if (!src || !user || !reason)
519 Membership* memb = GetUser(user);
524 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());
527 if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
529 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());
534 if (ServerInstance->ULine(src->server))
537 FIRST_MOD_RESULT(OnUserPreKick, res, (src,memb,reason));
539 if (res == MOD_RES_DENY)
542 if (res == MOD_RES_PASSTHRU)
544 unsigned int them = this->GetPrefixValue(src);
545 unsigned int req = HALFOP_VALUE;
546 for (std::string::size_type i = 0; i < memb->modes.length(); i++)
548 ModeHandler* mh = ServerInstance->Modes->FindMode(memb->modes[i], MODETYPE_CHANNEL);
549 if (mh && mh->GetLevelRequired() > req)
550 req = mh->GetLevelRequired();
555 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",
556 src->nick.c_str(), this->name.c_str(), req > HALFOP_VALUE ? "" : "half-");
565 FOREACH_MOD(I_OnUserKick,OnUserKick(src, memb, reason, except_list));
567 WriteAllExcept(src, false, 0, except_list, "KICK %s %s :%s", name.c_str(), user->nick.c_str(), reason);
569 user->chans.erase(this);
570 this->RemoveAllPrefixes(user);
576 void Channel::WriteChannel(User* user, const char* text, ...)
578 char textbuffer[MAXBUF];
584 va_start(argsPtr, text);
585 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
588 this->WriteChannel(user, std::string(textbuffer));
591 void Channel::WriteChannel(User* user, const std::string &text)
598 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
599 std::string out = tb;
601 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
603 if (IS_LOCAL(i->first))
604 i->first->Write(out);
608 void Channel::WriteChannelWithServ(const std::string& ServName, const char* text, ...)
610 char textbuffer[MAXBUF];
616 va_start(argsPtr, text);
617 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
620 this->WriteChannelWithServ(ServName, std::string(textbuffer));
623 void Channel::WriteChannelWithServ(const std::string& ServName, const std::string &text)
627 snprintf(tb,MAXBUF,":%s %s", ServName.empty() ? ServerInstance->Config->ServerName.c_str() : ServName.c_str(), text.c_str());
628 std::string out = tb;
630 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
632 if (IS_LOCAL(i->first))
633 i->first->Write(out);
637 /* write formatted text from a source user to all users on a channel except
638 * for the sender (for privmsg etc) */
639 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
641 char textbuffer[MAXBUF];
647 va_start(argsPtr, text);
648 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
651 this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
654 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
656 char textbuffer[MAXBUF];
662 int offset = snprintf(textbuffer,MAXBUF,":%s ", serversource ? ServerInstance->Config->ServerName.c_str() : user->GetFullHost().c_str());
664 va_start(argsPtr, text);
665 vsnprintf(textbuffer + offset, MAXBUF - offset, text, argsPtr);
668 this->RawWriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
671 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
675 snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName.c_str() : user->GetFullHost().c_str(), text.c_str());
676 std::string out = tb;
678 this->RawWriteAllExcept(user, serversource, status, except_list, std::string(tb));
681 void Channel::RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &out)
683 unsigned int minrank = 0;
686 ModeHandler* mh = ServerInstance->Modes->FindPrefix(status);
688 minrank = mh->GetPrefixRank();
690 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
692 if (IS_LOCAL(i->first) && (except_list.find(i->first) == except_list.end()))
694 /* User doesn't have the status we're after */
695 if (minrank && i->second->getRank() < minrank)
698 i->first->Write(out);
703 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
706 except_list.insert(user);
707 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
711 * return a count of the users on a specific channel accounting for
712 * invisible users who won't increase the count. e.g. for /LIST
714 int Channel::CountInvisible()
717 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
719 if (!(i->first->IsModeSet('i')))
726 char* Channel::ChanModes(bool showkey)
728 static char scratch[MAXBUF];
729 static char sparam[MAXBUF];
730 char* offset = scratch;
731 std::string extparam;
736 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
737 for(int n = 0; n < 64; n++)
743 if (n == 'k' - 65 && !showkey)
749 extparam = this->GetModeParameter(n + 65);
751 if (!extparam.empty())
753 charlcat(sparam,' ',MAXBUF);
754 strlcat(sparam,extparam.c_str(),MAXBUF);
759 /* Null terminate scratch */
761 strlcat(scratch,sparam,MAXBUF);
765 /* compile a userlist of a channel into a string, each nick seperated by
766 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
768 void Channel::UserList(User *user)
776 if (this->IsModeSet('s') && !this->HasUser(user) && !user->HasPrivPermission("channels/auspex"))
778 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
782 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
785 char* ptr = list + dlen;
787 /* Improvement by Brain - this doesnt change in value, so why was it inside
790 bool has_user = this->HasUser(user);
792 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
794 if ((!has_user) && (i->first->IsModeSet('i')))
797 * user is +i, and source not on the channel, does not show
803 std::string prefixlist = this->GetPrefixChar(i->first);
804 std::string nick = i->first->nick;
806 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->second, prefixlist, nick));
808 /* Nick was nuked, a module wants us to skip it */
814 if (curlen + prefixlist.length() + nick.length() + 1 > 480)
816 /* list overflowed into multiple numerics */
817 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
819 /* reset our lengths */
820 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
826 ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
834 /* if whats left in the list isnt empty, send it */
837 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
840 user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
843 long Channel::GetMaxBans()
845 /* Return the cached value if there is one */
847 return this->maxbans;
849 /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
850 for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
852 if (InspIRCd::Match(this->name, n->first, NULL))
854 this->maxbans = n->second;
859 /* Screw it, just return the default of 64 */
861 return this->maxbans;
864 void Channel::ResetMaxBans()
869 /* returns the status character for a given user on a channel, e.g. @ for op,
870 * % for halfop etc. If the user has several modes set, the highest mode
871 * the user has must be returned.
873 const char* Channel::GetPrefixChar(User *user)
875 static char pf[2] = {0, 0};
877 unsigned int bestrank = 0;
879 UserMembIter m = userlist.find(user);
880 if (m != userlist.end())
882 for(unsigned int i=0; i < m->second->modes.length(); i++)
884 char mchar = m->second->modes[i];
885 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
886 if (mh && mh->GetPrefixRank() > bestrank && mh->GetPrefix())
888 bestrank = mh->GetPrefixRank();
889 pf[0] = mh->GetPrefix();
896 unsigned int Membership::getRank()
898 char mchar = modes.c_str()[0];
902 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
904 rv = mh->GetPrefixRank();
909 const char* Channel::GetAllPrefixChars(User* user)
911 static char prefix[64];
914 UserMembIter m = userlist.find(user);
915 if (m != userlist.end())
917 for(unsigned int i=0; i < m->second->modes.length(); i++)
919 char mchar = m->second->modes[i];
920 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
921 if (mh && mh->GetPrefix())
922 prefix[ctr++] = mh->GetPrefix();
930 unsigned int Channel::GetPrefixValue(User* user)
932 UserMembIter m = userlist.find(user);
933 if (m == userlist.end())
935 return m->second->getRank();
938 bool Channel::SetPrefix(User* user, char prefix, bool adding)
940 ModeHandler* delta_mh = ServerInstance->Modes->FindMode(prefix, MODETYPE_CHANNEL);
943 UserMembIter m = userlist.find(user);
944 if (m == userlist.end())
946 for(unsigned int i=0; i < m->second->modes.length(); i++)
948 char mchar = m->second->modes[i];
949 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
950 if (mh && mh->GetPrefixRank() <= delta_mh->GetPrefixRank())
953 m->second->modes.substr(0,i) +
954 (adding ? std::string(1, prefix) : "") +
955 m->second->modes.substr(mchar == prefix ? i+1 : i);
956 return adding != (mchar == prefix);
960 m->second->modes += std::string(1, prefix);
964 void Channel::RemoveAllPrefixes(User* user)
966 UserMembIter m = userlist.find(user);
967 if (m != userlist.end())
969 m->second->modes.clear();