1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
20 Channel::Channel(InspIRCd* Instance, const std::string &cname, time_t ts)
22 chan_hash::iterator findchan = ServerInstance->chanlist->find(cname);
23 if (findchan != Instance->chanlist->end())
24 throw CoreException("Cannot create duplicate channel " + cname);
26 (*(ServerInstance->chanlist))[cname.c_str()] = this;
27 this->name.assign(cname, 0, ServerInstance->Config->Limits.ChanMax);
28 this->age = ts ? ts : ServerInstance->Time();
30 maxbans = topicset = 0;
34 void Channel::SetMode(char mode,bool mode_on)
36 modes[mode-65] = mode_on;
39 void Channel::SetModeParam(char mode, std::string parameter)
41 CustomModeList::iterator n = custom_mode_params.find(mode);
42 // always erase, even if changing, so that the map gets the new value
43 if (n != custom_mode_params.end())
44 custom_mode_params.erase(n);
45 if (parameter.empty())
47 modes[mode-65] = false;
51 custom_mode_params[mode] = parameter;
52 modes[mode-65] = true;
56 std::string Channel::GetModeParameter(char mode)
58 CustomModeList::iterator n = custom_mode_params.find(mode);
59 if (n != custom_mode_params.end())
64 int Channel::SetTopic(User *u, std::string &ntopic, bool forceset)
71 /* 0: check status, 1: don't, -1: disallow change silently */
73 FIRST_MOD_RESULT(ServerInstance, OnPreTopicChange, res, (u,this,ntopic));
75 if (res == MOD_RES_DENY)
77 if (res != MOD_RES_ALLOW)
79 if (!this->HasUser(u))
81 u->WriteNumeric(442, "%s %s :You're not on that channel!",u->nick.c_str(), this->name.c_str());
84 if ((this->IsModeSet('t')) && (this->GetPrefixValue(u) < HALFOP_VALUE))
86 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());
93 this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic);
96 this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128);
97 this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
101 this->setby.assign(ServerInstance->Config->ServerName);
102 this->WriteChannelWithServ(ServerInstance->Config->ServerName, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
105 this->topicset = ServerInstance->Time();
107 // XXX: this check for 'u' is probably pre-fake-user, and it fucking sucks anyway. we need to change this.
110 FOREACH_MOD(I_OnPostTopicChange,OnPostTopicChange(u, this, this->topic));
116 long Channel::GetUserCounter()
118 return userlist.size();
121 Membership* Channel::AddUser(User* user)
123 Membership* memb = new Membership(user, this);
124 userlist[user] = memb;
128 unsigned long Channel::DelUser(User* user)
130 UserMembIter a = userlist.find(user);
132 if (a != userlist.end())
138 return userlist.size();
141 bool Channel::HasUser(User* user)
143 return (userlist.find(user) != userlist.end());
146 Membership* Channel::GetUser(User* user)
148 UserMembIter i = userlist.find(user);
149 if (i == userlist.end())
154 const UserMembList* Channel::GetUsers()
159 void Channel::SetDefaultModes()
161 ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes);
162 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
164 std::string parameter;
166 list.GetToken(modeseq);
168 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
170 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
173 if (mode->GetNumParams(true))
174 list.GetToken(parameter);
178 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
184 * add a channel to a user, creating the record for it if needed and linking
185 * it to the user record
187 Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
189 // Fix: unregistered users could be joined using /SAJOIN
190 if (!user || !cn || user->registered != REG_ALL)
198 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
199 * We restrict local users to MaxChans channels.
200 * We restrict local operators to OperMaxChans channels.
201 * This is a lot more logical than how it was formerly. -- w00t
203 if (IS_LOCAL(user) && !override)
205 // Checking MyClass exists because we *may* get here with NULL, not 100% sure.
206 if (user->MyClass && user->MyClass->maxchans)
208 if (user->HasPrivPermission("channels/high-join-limit"))
210 if (user->chans.size() >= Instance->Config->OperMaxChans)
212 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
218 if (user->chans.size() >= user->MyClass->maxchans)
220 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
227 strlcpy(cname, cn, Instance->Config->Limits.ChanMax);
228 Ptr = Instance->FindChan(cname);
229 bool created_by_local = false;
234 * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
239 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);
244 created_by_local = true;
247 if (IS_LOCAL(user) && override == false)
249 ModResult MOD_RESULT;
250 FIRST_MOD_RESULT(Instance, OnUserPreJoin, MOD_RESULT, (user, NULL, cname, privs, key ? key : ""));
251 if (MOD_RESULT == MOD_RES_DENY)
255 Ptr = new Channel(Instance, cname, TS);
259 /* Already on the channel */
260 if (Ptr->HasUser(user))
264 * remote users are allowed us to bypass channel modes
265 * and bans (used by servers)
267 if (IS_LOCAL(user) && override == false)
269 ModResult MOD_RESULT;
270 FIRST_MOD_RESULT(Instance, OnUserPreJoin, MOD_RESULT, (user, Ptr, cname, privs, key ? key : ""));
271 if (MOD_RESULT == MOD_RES_DENY)
275 else if (MOD_RESULT == MOD_RES_PASSTHRU)
277 std::string ckey = Ptr->GetModeParameter('k');
278 bool invited = user->IsInvited(Ptr->name.c_str());
279 bool can_bypass = Instance->Config->InvBypassModes && invited;
283 FIRST_MOD_RESULT(Instance, OnCheckKey, MOD_RESULT, (user, Ptr, key ? key : ""));
284 if (!MOD_RESULT.check((key && ckey == key) || can_bypass))
286 // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
287 user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
292 if (Ptr->IsModeSet('i'))
294 FIRST_MOD_RESULT(Instance, OnCheckInvite, MOD_RESULT, (user, Ptr));
295 if (!MOD_RESULT.check(invited))
297 user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
302 std::string limit = Ptr->GetModeParameter('l');
305 FIRST_MOD_RESULT(Instance, OnCheckLimit, MOD_RESULT, (user, Ptr));
306 if (!MOD_RESULT.check((Ptr->GetUserCounter() < atol(limit.c_str()) || can_bypass)))
308 user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
313 if (Ptr->IsBanned(user) && !can_bypass)
315 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
320 * If the user has invites for this channel, remove them now
321 * after a successful join so they don't build up.
325 user->RemoveInvite(Ptr->name.c_str());
331 if (created_by_local)
333 /* As spotted by jilles, dont bother to set this on remote users */
334 Ptr->SetDefaultModes();
337 return Channel::ForceChan(Instance, Ptr, user, privs, bursting, created_by_local);
340 Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting, bool created)
342 std::string nick = user->nick;
344 Membership* memb = Ptr->AddUser(user);
345 user->chans.insert(Ptr);
347 for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
349 const char status = *x;
350 ModeHandler* mh = Instance->Modes->FindMode(status, MODETYPE_CHANNEL);
353 /* Set, and make sure that the mode handler knows this mode was now set */
354 Ptr->SetPrefix(user, mh->GetModeChar(), true);
355 mh->OnModeChange(Instance->FakeClient, Instance->FakeClient, Ptr, nick, true);
360 FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(memb, bursting, created, except_list));
362 Ptr->WriteAllExcept(user, false, 0, except_list, "JOIN :%s", Ptr->name.c_str());
364 /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
365 std::string ms = Instance->Modes->ModeString(user, Ptr);
366 if ((Ptr->GetUserCounter() > 1) && (ms.length()))
367 Ptr->WriteAllExceptSender(user, true, 0, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
369 /* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
374 user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
375 user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
379 FOREACH_MOD_I(Instance,I_OnPostJoin,OnPostJoin(memb));
383 bool Channel::IsBanned(User* user)
386 FIRST_MOD_RESULT(ServerInstance, OnCheckChannelBan, result, (user, this));
388 if (result != MOD_RES_PASSTHRU)
389 return (result == MOD_RES_DENY);
391 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
393 if (CheckBan(user, i->data))
399 bool Channel::CheckBan(User* user, const std::string& mask)
402 FIRST_MOD_RESULT(ServerInstance, OnCheckBan, result, (user, this, mask));
403 if (result != MOD_RES_PASSTHRU)
404 return (result == MOD_RES_DENY);
406 // extbans were handled above, if this is one it obviously didn't match
410 std::string::size_type at = mask.find('@');
411 if (at == std::string::npos)
414 char tomatch[MAXBUF];
415 snprintf(tomatch, MAXBUF, "%s!%s", user->nick.c_str(), user->ident.c_str());
416 std::string prefix = mask.substr(0, at);
417 if (InspIRCd::Match(tomatch, prefix, NULL))
419 std::string suffix = mask.substr(at + 1);
420 if (InspIRCd::Match(user->host, suffix, NULL) ||
421 InspIRCd::Match(user->dhost, suffix, NULL) ||
422 InspIRCd::MatchCIDR(user->GetIPString(), suffix, NULL))
428 ModResult Channel::GetExtBanStatus(User *user, char type)
431 FIRST_MOD_RESULT(ServerInstance, OnExtBanCheck, rv, (user, this, type));
432 if (rv != MOD_RES_PASSTHRU)
434 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
436 if (i->data[0] == type && i->data[1] == ':')
438 std::string val = i->data.substr(2);
439 if (CheckBan(user, val))
443 return MOD_RES_ALLOW;
447 * remove a channel from a users record, and return the number of users left.
448 * Therefore, if this function returns 0 the caller should delete the Channel.
450 long Channel::PartUser(User *user, std::string &reason)
453 return this->GetUserCounter();
455 Membership* memb = GetUser(user);
460 FOREACH_MOD(I_OnUserPart,OnUserPart(memb, reason, except_list));
462 WriteAllExcept(user, false, 0, except_list, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
464 user->chans.erase(this);
465 this->RemoveAllPrefixes(user);
468 if (!this->DelUser(user)) /* if there are no users left on the channel... */
470 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
471 /* kill the record */
472 if (iter != ServerInstance->chanlist->end())
475 FIRST_MOD_RESULT(ServerInstance, OnChannelPreDelete, res, (this));
476 if (res == MOD_RES_DENY)
477 return 1; // delete halted by module
478 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
479 ServerInstance->chanlist->erase(iter);
484 return this->GetUserCounter();
487 long Channel::ServerKickUser(User* user, const char* reason, const char* servername)
489 if (servername == NULL || *ServerInstance->Config->HideWhoisServer)
490 servername = ServerInstance->Config->ServerName;
492 ServerInstance->FakeClient->server = servername;
493 return this->KickUser(ServerInstance->FakeClient, user, reason);
496 long Channel::KickUser(User *src, User *user, const char* reason)
498 if (!src || !user || !reason)
499 return this->GetUserCounter();
501 Membership* memb = GetUser(user);
506 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());
507 return this->GetUserCounter();
509 if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
511 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());
512 return this->GetUserCounter();
516 if (ServerInstance->ULine(src->server))
519 FIRST_MOD_RESULT(ServerInstance, OnUserPreKick, res, (src,memb,reason));
521 if (res == MOD_RES_DENY)
522 return this->GetUserCounter();
524 if (res == MOD_RES_PASSTHRU)
526 int them = this->GetPrefixValue(src);
527 int us = this->GetPrefixValue(user);
528 if ((them < HALFOP_VALUE) || (them < us))
530 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them >= HALFOP_VALUE ? "" : "half-");
531 return this->GetUserCounter();
539 FOREACH_MOD(I_OnUserKick,OnUserKick(src, memb, reason, except_list));
541 WriteAllExcept(src, false, 0, except_list, "KICK %s %s :%s", name.c_str(), user->nick.c_str(), reason);
543 user->chans.erase(this);
544 this->RemoveAllPrefixes(user);
547 if (!this->DelUser(user))
548 /* if there are no users left on the channel */
550 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name.c_str());
552 /* kill the record */
553 if (iter != ServerInstance->chanlist->end())
556 FIRST_MOD_RESULT(ServerInstance, OnChannelPreDelete, res, (this));
557 if (res == MOD_RES_DENY)
558 return 1; // delete halted by module
559 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
560 ServerInstance->chanlist->erase(iter);
565 return this->GetUserCounter();
568 void Channel::WriteChannel(User* user, const char* text, ...)
570 char textbuffer[MAXBUF];
576 va_start(argsPtr, text);
577 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
580 this->WriteChannel(user, std::string(textbuffer));
583 void Channel::WriteChannel(User* user, const std::string &text)
590 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
591 std::string out = tb;
593 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
595 if (IS_LOCAL(i->first))
596 i->first->Write(out);
600 void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...)
602 char textbuffer[MAXBUF];
608 va_start(argsPtr, text);
609 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
612 this->WriteChannelWithServ(ServName, std::string(textbuffer));
615 void Channel::WriteChannelWithServ(const char* ServName, const std::string &text)
619 snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str());
620 std::string out = tb;
622 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
624 if (IS_LOCAL(i->first))
625 i->first->Write(out);
629 /* write formatted text from a source user to all users on a channel except
630 * for the sender (for privmsg etc) */
631 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
633 char textbuffer[MAXBUF];
639 va_start(argsPtr, text);
640 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
643 this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
646 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
648 char textbuffer[MAXBUF];
654 int offset = snprintf(textbuffer,MAXBUF,":%s ", user->GetFullHost().c_str());
656 va_start(argsPtr, text);
657 vsnprintf(textbuffer + offset, MAXBUF - offset, text, argsPtr);
660 this->RawWriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
663 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
667 snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName : user->GetFullHost().c_str(), text.c_str());
668 std::string out = tb;
670 this->RawWriteAllExcept(user, serversource, status, except_list, std::string(tb));
673 void Channel::RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &out)
678 ModeHandler* mh = ServerInstance->Modes->FindPrefix(status);
680 statmode = mh->GetModeChar();
682 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
684 if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
686 /* User doesnt have the status we're after */
687 if (statmode && !i->second->hasMode(statmode))
690 i->first->Write(out);
695 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
698 except_list.insert(user);
699 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
703 * return a count of the users on a specific channel accounting for
704 * invisible users who won't increase the count. e.g. for /LIST
706 int Channel::CountInvisible()
709 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
711 if (!(i->first->IsModeSet('i')))
718 char* Channel::ChanModes(bool showkey)
720 static char scratch[MAXBUF];
721 static char sparam[MAXBUF];
722 char* offset = scratch;
723 std::string extparam;
728 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
729 for(int n = 0; n < 64; n++)
738 // Unfortunately this must be special-cased, as we definitely don't want to always display key.
741 extparam = this->GetModeParameter('k');
754 /* We know these have no parameters */
757 extparam = this->GetModeParameter(n + 65);
760 if (!extparam.empty())
762 charlcat(sparam,' ',MAXBUF);
763 strlcat(sparam,extparam.c_str(),MAXBUF);
768 /* Null terminate scratch */
770 strlcat(scratch,sparam,MAXBUF);
774 /* compile a userlist of a channel into a string, each nick seperated by
775 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
777 void Channel::UserList(User *user)
781 ModResult call_modules;
786 FIRST_MOD_RESULT(ServerInstance, OnUserList, call_modules, (user, this));
788 if (call_modules != MOD_RES_ALLOW)
790 if ((this->IsModeSet('s')) && (!this->HasUser(user)))
792 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
797 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
800 char* ptr = list + dlen;
802 /* Improvement by Brain - this doesnt change in value, so why was it inside
805 bool has_user = this->HasUser(user);
807 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
809 if ((!has_user) && (i->first->IsModeSet('i')))
812 * user is +i, and source not on the channel, does not show
818 std::string prefixlist = this->GetPrefixChar(i->first);
819 std::string nick = i->first->nick;
821 if (call_modules != MOD_RES_DENY)
823 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->second, prefixlist, nick));
825 /* Nick was nuked, a module wants us to skip it */
832 if (curlen + prefixlist.length() + nick.length() + 1 > 480)
834 /* list overflowed into multiple numerics */
835 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
837 /* reset our lengths */
838 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
845 ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
853 /* if whats left in the list isnt empty, send it */
856 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
859 user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
862 long Channel::GetMaxBans()
864 /* Return the cached value if there is one */
866 return this->maxbans;
868 /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
869 for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
871 if (InspIRCd::Match(this->name, n->first, NULL))
873 this->maxbans = n->second;
878 /* Screw it, just return the default of 64 */
880 return this->maxbans;
883 void Channel::ResetMaxBans()
888 /* returns the status character for a given user on a channel, e.g. @ for op,
889 * % for halfop etc. If the user has several modes set, the highest mode
890 * the user has must be returned.
892 const char* Channel::GetPrefixChar(User *user)
894 static char pf[2] = {0, 0};
896 unsigned int bestrank = 0;
898 UserMembIter m = userlist.find(user);
899 if (m != userlist.end())
901 for(unsigned int i=0; i < m->second->modes.length(); i++)
903 char mchar = m->second->modes[i];
904 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
905 if (mh && mh->GetPrefixRank() > bestrank && mh->GetPrefix())
907 bestrank = mh->GetPrefixRank();
908 pf[0] = mh->GetPrefix();
915 unsigned int Membership::getRank()
917 char mchar = modes.c_str()[0];
921 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
923 rv = mh->GetPrefixRank();
928 const char* Channel::GetAllPrefixChars(User* user)
930 static char prefix[64];
933 UserMembIter m = userlist.find(user);
934 if (m != userlist.end())
936 for(unsigned int i=0; i < m->second->modes.length(); i++)
938 char mchar = m->second->modes[i];
939 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
940 if (mh && mh->GetPrefix())
941 prefix[ctr++] = mh->GetPrefix();
949 unsigned int Channel::GetPrefixValue(User* user)
951 UserMembIter m = userlist.find(user);
952 if (m == userlist.end())
954 return m->second->getRank();
957 void Channel::SetPrefix(User* user, char prefix, bool adding)
959 ModeHandler* delta_mh = ServerInstance->Modes->FindMode(prefix, MODETYPE_CHANNEL);
962 UserMembIter m = userlist.find(user);
963 if (m == userlist.end())
965 for(unsigned int i=0; i < m->second->modes.length(); i++)
967 char mchar = m->second->modes[i];
968 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
969 if (mh && mh->GetPrefixRank() <= delta_mh->GetPrefixRank())
972 m->second->modes.substr(0,i) +
973 (adding ? std::string(1, prefix) : "") +
974 m->second->modes.substr(mchar == prefix ? i+1 : i);
979 m->second->modes += std::string(1, prefix);
982 void Channel::RemoveAllPrefixes(User* user)
984 UserMembIter m = userlist.find(user);
985 if (m != userlist.end())
987 m->second->modes.clear();