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(const std::string &cname, time_t ts)
22 chan_hash::iterator findchan = ServerInstance->chanlist->find(cname);
23 if (findchan != ServerInstance->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(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",
162 ServerInstance->Config->DefaultModes.c_str());
163 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
165 std::string parameter;
167 list.GetToken(modeseq);
169 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
171 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
174 if (mode->GetNumParams(true))
175 list.GetToken(parameter);
179 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
185 * add a channel to a user, creating the record for it if needed and linking
186 * it to the user record
188 Channel* Channel::JoinUser(User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
190 // Fix: unregistered users could be joined using /SAJOIN
191 if (!user || !cn || user->registered != REG_ALL)
199 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
200 * We restrict local users to MaxChans channels.
201 * We restrict local operators to OperMaxChans channels.
202 * This is a lot more logical than how it was formerly. -- w00t
204 if (IS_LOCAL(user) && !override)
206 // Checking MyClass exists because we *may* get here with NULL, not 100% sure.
207 if (user->MyClass && user->MyClass->maxchans)
209 if (user->HasPrivPermission("channels/high-join-limit"))
211 if (user->chans.size() >= ServerInstance->Config->OperMaxChans)
213 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
219 if (user->chans.size() >= user->MyClass->maxchans)
221 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
228 strlcpy(cname, cn, ServerInstance->Config->Limits.ChanMax);
229 Ptr = ServerInstance->FindChan(cname);
230 bool created_by_local = false;
235 * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
240 ServerInstance->Logs->Log("CHANNEL",DEBUG,"*** BUG *** Channel::JoinUser called for REMOTE user '%s' on channel '%s' but no TS given!", user->nick.c_str(), cn);
245 created_by_local = true;
248 if (IS_LOCAL(user) && override == false)
250 ModResult MOD_RESULT;
251 FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, NULL, cname, privs, key ? key : ""));
252 if (MOD_RESULT == MOD_RES_DENY)
256 Ptr = new Channel(cname, TS);
260 /* Already on the channel */
261 if (Ptr->HasUser(user))
265 * remote users are allowed us to bypass channel modes
266 * and bans (used by servers)
268 if (IS_LOCAL(user) && override == false)
270 ModResult MOD_RESULT;
271 FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, Ptr, cname, privs, key ? key : ""));
272 if (MOD_RESULT == MOD_RES_DENY)
276 else if (MOD_RESULT == MOD_RES_PASSTHRU)
278 std::string ckey = Ptr->GetModeParameter('k');
279 bool invited = user->IsInvited(Ptr->name.c_str());
280 bool can_bypass = ServerInstance->Config->InvBypassModes && invited;
284 FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, Ptr, key ? key : ""));
285 if (!MOD_RESULT.check((key && ckey == key) || can_bypass))
287 // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
288 user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
293 if (Ptr->IsModeSet('i'))
295 FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, Ptr));
296 if (!MOD_RESULT.check(invited))
298 user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
303 std::string limit = Ptr->GetModeParameter('l');
306 FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, Ptr));
307 if (!MOD_RESULT.check((Ptr->GetUserCounter() < atol(limit.c_str()) || can_bypass)))
309 user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
314 if (Ptr->IsBanned(user) && !can_bypass)
316 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
321 * If the user has invites for this channel, remove them now
322 * after a successful join so they don't build up.
326 user->RemoveInvite(Ptr->name.c_str());
332 if (created_by_local)
334 /* As spotted by jilles, dont bother to set this on remote users */
335 Ptr->SetDefaultModes();
338 return Channel::ForceChan(Ptr, user, privs, bursting, created_by_local);
341 Channel* Channel::ForceChan(Channel* Ptr, User* user, const std::string &privs, bool bursting, bool created)
343 std::string nick = user->nick;
345 Membership* memb = Ptr->AddUser(user);
346 user->chans.insert(Ptr);
348 for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
350 const char status = *x;
351 ModeHandler* mh = ServerInstance->Modes->FindMode(status, MODETYPE_CHANNEL);
354 /* Set, and make sure that the mode handler knows this mode was now set */
355 Ptr->SetPrefix(user, mh->GetModeChar(), true);
356 mh->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, Ptr, nick, true);
361 FOREACH_MOD(I_OnUserJoin,OnUserJoin(memb, bursting, created, except_list));
363 Ptr->WriteAllExcept(user, false, 0, except_list, "JOIN :%s", Ptr->name.c_str());
365 /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
366 std::string ms = ServerInstance->Modes->ModeString(user, Ptr);
367 if ((Ptr->GetUserCounter() > 1) && (ms.length()))
368 Ptr->WriteAllExceptSender(user, true, 0, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
370 /* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
375 user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
376 user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
380 FOREACH_MOD(I_OnPostJoin,OnPostJoin(memb));
384 bool Channel::IsBanned(User* user)
387 FIRST_MOD_RESULT(OnCheckChannelBan, result, (user, this));
389 if (result != MOD_RES_PASSTHRU)
390 return (result == MOD_RES_DENY);
392 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
394 if (CheckBan(user, i->data))
400 bool Channel::CheckBan(User* user, const std::string& mask)
403 FIRST_MOD_RESULT(OnCheckBan, result, (user, this, mask));
404 if (result != MOD_RES_PASSTHRU)
405 return (result == MOD_RES_DENY);
407 // extbans were handled above, if this is one it obviously didn't match
411 std::string::size_type at = mask.find('@');
412 if (at == std::string::npos)
415 char tomatch[MAXBUF];
416 snprintf(tomatch, MAXBUF, "%s!%s", user->nick.c_str(), user->ident.c_str());
417 std::string prefix = mask.substr(0, at);
418 if (InspIRCd::Match(tomatch, prefix, NULL))
420 std::string suffix = mask.substr(at + 1);
421 if (InspIRCd::Match(user->host, suffix, NULL) ||
422 InspIRCd::Match(user->dhost, suffix, NULL) ||
423 InspIRCd::MatchCIDR(user->GetIPString(), suffix, NULL))
429 ModResult Channel::GetExtBanStatus(User *user, char type)
432 FIRST_MOD_RESULT(OnExtBanCheck, rv, (user, this, type));
433 if (rv != MOD_RES_PASSTHRU)
435 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
437 if (i->data[0] == type && i->data[1] == ':')
439 std::string val = i->data.substr(2);
440 if (CheckBan(user, val))
444 return MOD_RES_PASSTHRU;
448 * remove a channel from a users record, and return the number of users left.
449 * Therefore, if this function returns 0 the caller should delete the Channel.
451 long Channel::PartUser(User *user, std::string &reason)
454 return this->GetUserCounter();
456 Membership* memb = GetUser(user);
461 FOREACH_MOD(I_OnUserPart,OnUserPart(memb, reason, except_list));
463 WriteAllExcept(user, false, 0, except_list, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
465 user->chans.erase(this);
466 this->RemoveAllPrefixes(user);
469 if (!this->DelUser(user)) /* if there are no users left on the channel... */
471 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
472 /* kill the record */
473 if (iter != ServerInstance->chanlist->end())
476 FIRST_MOD_RESULT(OnChannelPreDelete, res, (this));
477 if (res == MOD_RES_DENY)
478 return 1; // delete halted by module
479 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
480 ServerInstance->chanlist->erase(iter);
485 return this->GetUserCounter();
488 long Channel::ServerKickUser(User* user, const char* reason, const std::string& servername)
490 if (servername.empty() || !ServerInstance->Config->HideWhoisServer.empty())
491 ServerInstance->FakeClient->server = ServerInstance->Config->ServerName;
493 ServerInstance->FakeClient->server = servername;
495 return this->KickUser(ServerInstance->FakeClient, user, reason);
498 long Channel::KickUser(User *src, User *user, const char* reason)
500 if (!src || !user || !reason)
501 return this->GetUserCounter();
503 Membership* memb = GetUser(user);
508 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());
509 return this->GetUserCounter();
511 if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
513 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());
514 return this->GetUserCounter();
518 if (ServerInstance->ULine(src->server))
521 FIRST_MOD_RESULT(OnUserPreKick, res, (src,memb,reason));
523 if (res == MOD_RES_DENY)
524 return this->GetUserCounter();
526 if (res == MOD_RES_PASSTHRU)
528 int them = this->GetPrefixValue(src);
529 int us = this->GetPrefixValue(user);
530 if ((them < HALFOP_VALUE) || (them < us))
532 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them >= HALFOP_VALUE ? "" : "half-");
533 return this->GetUserCounter();
541 FOREACH_MOD(I_OnUserKick,OnUserKick(src, memb, reason, except_list));
543 WriteAllExcept(src, false, 0, except_list, "KICK %s %s :%s", name.c_str(), user->nick.c_str(), reason);
545 user->chans.erase(this);
546 this->RemoveAllPrefixes(user);
549 if (!this->DelUser(user))
550 /* if there are no users left on the channel */
552 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name.c_str());
554 /* kill the record */
555 if (iter != ServerInstance->chanlist->end())
558 FIRST_MOD_RESULT(OnChannelPreDelete, res, (this));
559 if (res == MOD_RES_DENY)
560 return 1; // delete halted by module
561 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
562 ServerInstance->chanlist->erase(iter);
567 return this->GetUserCounter();
570 void Channel::WriteChannel(User* user, const char* text, ...)
572 char textbuffer[MAXBUF];
578 va_start(argsPtr, text);
579 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
582 this->WriteChannel(user, std::string(textbuffer));
585 void Channel::WriteChannel(User* user, const std::string &text)
592 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
593 std::string out = tb;
595 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
597 if (IS_LOCAL(i->first))
598 i->first->Write(out);
602 void Channel::WriteChannelWithServ(const std::string& ServName, const char* text, ...)
604 char textbuffer[MAXBUF];
610 va_start(argsPtr, text);
611 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
614 this->WriteChannelWithServ(ServName, std::string(textbuffer));
617 void Channel::WriteChannelWithServ(const std::string& ServName, const std::string &text)
621 snprintf(tb,MAXBUF,":%s %s", ServName.empty() ? ServerInstance->Config->ServerName.c_str() : ServName.c_str(), text.c_str());
622 std::string out = tb;
624 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
626 if (IS_LOCAL(i->first))
627 i->first->Write(out);
631 /* write formatted text from a source user to all users on a channel except
632 * for the sender (for privmsg etc) */
633 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
635 char textbuffer[MAXBUF];
641 va_start(argsPtr, text);
642 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
645 this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
648 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
650 char textbuffer[MAXBUF];
656 int offset = snprintf(textbuffer,MAXBUF,":%s ", user->GetFullHost().c_str());
658 va_start(argsPtr, text);
659 vsnprintf(textbuffer + offset, MAXBUF - offset, text, argsPtr);
662 this->RawWriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
665 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
669 snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName.c_str() : user->GetFullHost().c_str(), text.c_str());
670 std::string out = tb;
672 this->RawWriteAllExcept(user, serversource, status, except_list, std::string(tb));
675 void Channel::RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &out)
680 ModeHandler* mh = ServerInstance->Modes->FindPrefix(status);
682 statmode = mh->GetModeChar();
684 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
686 if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
688 /* User doesnt have the status we're after */
689 if (statmode && !i->second->hasMode(statmode))
692 i->first->Write(out);
697 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
700 except_list.insert(user);
701 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
705 * return a count of the users on a specific channel accounting for
706 * invisible users who won't increase the count. e.g. for /LIST
708 int Channel::CountInvisible()
711 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
713 if (!(i->first->IsModeSet('i')))
720 char* Channel::ChanModes(bool showkey)
722 static char scratch[MAXBUF];
723 static char sparam[MAXBUF];
724 char* offset = scratch;
725 std::string extparam;
730 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
731 for(int n = 0; n < 64; n++)
740 // Unfortunately this must be special-cased, as we definitely don't want to always display key.
743 extparam = this->GetModeParameter('k');
756 /* We know these have no parameters */
759 extparam = this->GetModeParameter(n + 65);
762 if (!extparam.empty())
764 charlcat(sparam,' ',MAXBUF);
765 strlcat(sparam,extparam.c_str(),MAXBUF);
770 /* Null terminate scratch */
772 strlcat(scratch,sparam,MAXBUF);
776 /* compile a userlist of a channel into a string, each nick seperated by
777 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
779 void Channel::UserList(User *user)
783 ModResult call_modules;
788 FIRST_MOD_RESULT(OnUserList, call_modules, (user, this));
790 if (call_modules != MOD_RES_ALLOW)
792 if ((this->IsModeSet('s')) && (!this->HasUser(user)))
794 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
799 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
802 char* ptr = list + dlen;
804 /* Improvement by Brain - this doesnt change in value, so why was it inside
807 bool has_user = this->HasUser(user);
809 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
811 if ((!has_user) && (i->first->IsModeSet('i')))
814 * user is +i, and source not on the channel, does not show
820 std::string prefixlist = this->GetPrefixChar(i->first);
821 std::string nick = i->first->nick;
823 if (call_modules != MOD_RES_DENY)
825 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->second, prefixlist, nick));
827 /* Nick was nuked, a module wants us to skip it */
834 if (curlen + prefixlist.length() + nick.length() + 1 > 480)
836 /* list overflowed into multiple numerics */
837 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
839 /* reset our lengths */
840 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
847 ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
855 /* if whats left in the list isnt empty, send it */
858 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
861 user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
864 long Channel::GetMaxBans()
866 /* Return the cached value if there is one */
868 return this->maxbans;
870 /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
871 for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
873 if (InspIRCd::Match(this->name, n->first, NULL))
875 this->maxbans = n->second;
880 /* Screw it, just return the default of 64 */
882 return this->maxbans;
885 void Channel::ResetMaxBans()
890 /* returns the status character for a given user on a channel, e.g. @ for op,
891 * % for halfop etc. If the user has several modes set, the highest mode
892 * the user has must be returned.
894 const char* Channel::GetPrefixChar(User *user)
896 static char pf[2] = {0, 0};
898 unsigned int bestrank = 0;
900 UserMembIter m = userlist.find(user);
901 if (m != userlist.end())
903 for(unsigned int i=0; i < m->second->modes.length(); i++)
905 char mchar = m->second->modes[i];
906 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
907 if (mh && mh->GetPrefixRank() > bestrank && mh->GetPrefix())
909 bestrank = mh->GetPrefixRank();
910 pf[0] = mh->GetPrefix();
917 unsigned int Membership::getRank()
919 char mchar = modes.c_str()[0];
923 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
925 rv = mh->GetPrefixRank();
930 const char* Channel::GetAllPrefixChars(User* user)
932 static char prefix[64];
935 UserMembIter m = userlist.find(user);
936 if (m != userlist.end())
938 for(unsigned int i=0; i < m->second->modes.length(); i++)
940 char mchar = m->second->modes[i];
941 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
942 if (mh && mh->GetPrefix())
943 prefix[ctr++] = mh->GetPrefix();
951 unsigned int Channel::GetPrefixValue(User* user)
953 UserMembIter m = userlist.find(user);
954 if (m == userlist.end())
956 return m->second->getRank();
959 void Channel::SetPrefix(User* user, char prefix, bool adding)
961 ModeHandler* delta_mh = ServerInstance->Modes->FindMode(prefix, MODETYPE_CHANNEL);
964 UserMembIter m = userlist.find(user);
965 if (m == userlist.end())
967 for(unsigned int i=0; i < m->second->modes.length(); i++)
969 char mchar = m->second->modes[i];
970 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
971 if (mh && mh->GetPrefixRank() <= delta_mh->GetPrefixRank())
974 m->second->modes.substr(0,i) +
975 (adding ? std::string(1, prefix) : "") +
976 m->second->modes.substr(mchar == prefix ? i+1 : i);
981 m->second->modes += std::string(1, prefix);
984 void Channel::RemoveAllPrefixes(User* user)
986 UserMembIter m = userlist.find(user);
987 if (m != userlist.end())
989 m->second->modes.clear();