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) : ServerInstance(Instance)
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 bool Channel::IsModeSet(char mode)
58 return modes[mode-65];
61 std::string Channel::GetModeParameter(char mode)
63 CustomModeList::iterator n = custom_mode_params.find(mode);
64 if (n != custom_mode_params.end())
69 int Channel::SetTopic(User *u, std::string &ntopic, bool forceset)
76 /* 0: check status, 1: don't, -1: disallow change silently */
78 FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(u,this,ntopic));
82 else if (MOD_RESULT == 0)
84 if (!this->HasUser(u))
86 u->WriteNumeric(442, "%s %s :You're not on that channel!",u->nick.c_str(), this->name.c_str());
89 if ((this->IsModeSet('t')) && (this->GetStatus(u) < STATUS_HOP))
91 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());
98 this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic);
101 this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128);
102 this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
106 this->setby.assign(ServerInstance->Config->ServerName);
107 this->WriteChannelWithServ(ServerInstance->Config->ServerName, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
110 this->topicset = ServerInstance->Time();
112 if (u && IS_LOCAL(u))
114 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(u, this, this->topic));
120 long Channel::GetUserCounter()
122 return (this->internal_userlist.size());
125 void Channel::AddUser(User* user)
127 internal_userlist[user] = user->nick;
130 unsigned long Channel::DelUser(User* user)
132 CUListIter a = internal_userlist.find(user);
134 if (a != internal_userlist.end())
136 internal_userlist.erase(a);
137 /* And tidy any others... */
139 DelHalfoppedUser(user);
143 return internal_userlist.size();
146 bool Channel::HasUser(User* user)
148 return (internal_userlist.find(user) != internal_userlist.end());
151 void Channel::AddOppedUser(User* user)
153 internal_op_userlist[user] = user->nick;
156 void Channel::DelOppedUser(User* user)
158 CUListIter a = internal_op_userlist.find(user);
159 if (a != internal_op_userlist.end())
161 internal_op_userlist.erase(a);
166 void Channel::AddHalfoppedUser(User* user)
168 internal_halfop_userlist[user] = user->nick;
171 void Channel::DelHalfoppedUser(User* user)
173 CUListIter a = internal_halfop_userlist.find(user);
175 if (a != internal_halfop_userlist.end())
177 internal_halfop_userlist.erase(a);
181 void Channel::AddVoicedUser(User* user)
183 internal_voice_userlist[user] = user->nick;
186 void Channel::DelVoicedUser(User* user)
188 CUListIter a = internal_voice_userlist.find(user);
190 if (a != internal_voice_userlist.end())
192 internal_voice_userlist.erase(a);
196 CUList* Channel::GetUsers()
198 return &internal_userlist;
201 CUList* Channel::GetOppedUsers()
203 return &internal_op_userlist;
206 CUList* Channel::GetHalfoppedUsers()
208 return &internal_halfop_userlist;
211 CUList* Channel::GetVoicedUsers()
213 return &internal_voice_userlist;
216 void Channel::SetDefaultModes()
218 ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes);
219 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
221 std::string parameter;
223 list.GetToken(modeseq);
225 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
227 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
230 if (mode->GetNumParams(true))
231 list.GetToken(parameter);
235 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
241 * add a channel to a user, creating the record for it if needed and linking
242 * it to the user record
244 Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
246 // Fix: unregistered users could be joined using /SAJOIN
247 if (!user || !cn || user->registered != REG_ALL)
256 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
257 * We restrict local users to MaxChans channels.
258 * We restrict local operators to OperMaxChans channels.
259 * This is a lot more logical than how it was formerly. -- w00t
261 if (IS_LOCAL(user) && !override)
263 // Checking MyClass exists because we *may* get here with NULL, not 100% sure.
264 if (user->MyClass && user->MyClass->maxchans)
266 if (user->HasPrivPermission("channels/high-join-limit"))
268 if (user->chans.size() >= Instance->Config->OperMaxChans)
270 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
276 if (user->chans.size() >= user->MyClass->maxchans)
278 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
285 strlcpy(cname, cn, Instance->Config->Limits.ChanMax);
286 Ptr = Instance->FindChan(cname);
287 bool created_by_local = false;
292 * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
297 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);
302 created_by_local = true;
305 if (IS_LOCAL(user) && override == false)
308 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, NULL, cname, privs, key ? key : ""));
313 Ptr = new Channel(Instance, cname, TS);
317 /* Already on the channel */
318 if (Ptr->HasUser(user))
322 * remote users are allowed us to bypass channel modes
323 * and bans (used by servers)
325 if (IS_LOCAL(user) && override == false)
328 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, Ptr, cname, privs, key ? key : ""));
333 else if (MOD_RESULT == 0)
335 std::string ckey = Ptr->GetModeParameter('k');
336 bool invited = user->IsInvited(Ptr->name.c_str());
337 bool can_bypass = Instance->Config->InvBypassModes && invited;
342 FOREACH_RESULT_I(Instance, I_OnCheckKey, OnCheckKey(user, Ptr, key ? key : ""));
345 // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
346 if ((!key || ckey != key) && !can_bypass)
348 user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
354 if (Ptr->IsModeSet('i'))
357 FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr));
362 user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
368 std::string limit = Ptr->GetModeParameter('l');
372 FOREACH_RESULT_I(Instance, I_OnCheckLimit, OnCheckLimit(user, Ptr));
375 long llimit = atol(limit.c_str());
376 if (Ptr->GetUserCounter() >= llimit && !can_bypass)
378 user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
384 if (Ptr->IsBanned(user) && !can_bypass)
386 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
391 * If the user has invites for this channel, remove them now
392 * after a successful join so they don't build up.
396 user->RemoveInvite(Ptr->name.c_str());
402 if (created_by_local)
404 /* As spotted by jilles, dont bother to set this on remote users */
405 Ptr->SetDefaultModes();
408 return Channel::ForceChan(Instance, Ptr, user, privs, bursting, created_by_local);
411 Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting, bool created)
413 std::string nick = user->nick;
418 /* Just in case they have no permissions */
419 user->chans[Ptr] = 0;
421 for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
423 const char status = *x;
424 ModeHandler* mh = Instance->Modes->FindPrefix(status);
427 /* Set, and make sure that the mode handler knows this mode was now set */
428 Ptr->SetPrefix(user, status, mh->GetPrefixRank(), true);
429 mh->OnModeChange(Instance->FakeClient, Instance->FakeClient, Ptr, nick, true);
431 switch (mh->GetPrefix())
433 /* These logic ops are SAFE IN THIS CASE because if the entry doesnt exist,
434 * addressing operator[] creates it. If they do exist, it points to it.
435 * At all other times where we dont want to create an item if it doesnt exist, we
436 * must stick to ::find().
439 user->chans[Ptr] |= UCMODE_OP;
442 user->chans[Ptr] |= UCMODE_HOP;
445 user->chans[Ptr] |= UCMODE_VOICE;
451 FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user, Ptr, bursting, silent, created));
454 Ptr->WriteChannel(user,"JOIN :%s",Ptr->name.c_str());
456 /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
457 std::string ms = Instance->Modes->ModeString(user, Ptr);
458 if ((Ptr->GetUserCounter() > 1) && (ms.length()))
459 Ptr->WriteAllExceptSender(user, true, 0, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
461 /* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
466 user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
467 user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
471 FOREACH_MOD_I(Instance,I_OnPostJoin,OnPostJoin(user, Ptr));
475 bool Channel::IsBanned(User* user)
478 DO_EACH_HOOK(ServerInstance, OnCheckBan, int modresult, (user, this))
480 result = banmatch_reduce(result, modresult);
482 WHILE_EACH_HOOK(ServerInstance, OnCheckBan);
488 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
489 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
491 if ((InspIRCd::Match(user->GetFullHost(),i->data, NULL)) || // host
492 (InspIRCd::Match(user->GetFullRealHost(),i->data, NULL)) || // uncloaked host
493 (InspIRCd::MatchCIDR(mask, i->data, NULL))) // ip
501 int Channel::GetExtBanStatus(const std::string &str, char type)
504 DO_EACH_HOOK(ServerInstance, OnCheckStringExtBan, int modresult, (str, this, type))
506 result = banmatch_reduce(result, modresult);
508 WHILE_EACH_HOOK(ServerInstance, OnCheckStringExtBan);
513 // nobody decided for us, check the ban list
514 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
516 if (i->data[0] != type || i->data[1] != ':')
519 std::string maskptr = i->data.substr(2);
520 ServerInstance->Logs->Log("EXTBANS", DEBUG, "Checking %s against %s, type is %c", str.c_str(), maskptr.c_str(), type);
522 if (InspIRCd::Match(str, maskptr, NULL))
529 int Channel::GetExtBanStatus(User *user, char type)
532 DO_EACH_HOOK(ServerInstance, OnCheckExtBan, int modresult, (user, this, type))
534 result = banmatch_reduce(result, modresult);
536 WHILE_EACH_HOOK(ServerInstance, OnCheckExtBan);
543 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
545 // XXX: we should probably hook cloaked hosts in here somehow too..
546 rv = banmatch_reduce(rv, this->GetExtBanStatus(mask, type));
547 rv = banmatch_reduce(rv, this->GetExtBanStatus(user->GetFullHost(), type));
548 rv = banmatch_reduce(rv, this->GetExtBanStatus(user->GetFullRealHost(), type));
553 * remove a channel from a users record, and return the number of users left.
554 * Therefore, if this function returns 0 the caller should delete the Channel.
556 long Channel::PartUser(User *user, std::string &reason)
561 return this->GetUserCounter();
563 UCListIter i = user->chans.find(this);
564 if (i != user->chans.end())
566 FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason, silent));
569 this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
571 user->chans.erase(i);
572 this->RemoveAllPrefixes(user);
575 if (!this->DelUser(user)) /* if there are no users left on the channel... */
577 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
578 /* kill the record */
579 if (iter != ServerInstance->chanlist->end())
582 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
584 return 1; // delete halted by module
585 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
586 ServerInstance->chanlist->erase(iter);
591 return this->GetUserCounter();
594 long Channel::ServerKickUser(User* user, const char* reason, const char* servername)
596 if (servername == NULL || *ServerInstance->Config->HideWhoisServer)
597 servername = ServerInstance->Config->ServerName;
599 ServerInstance->FakeClient->server = servername;
600 return this->KickUser(ServerInstance->FakeClient, user, reason);
603 long Channel::KickUser(User *src, User *user, const char* reason)
607 if (!src || !user || !reason)
608 return this->GetUserCounter();
612 if (!this->HasUser(user))
614 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());
615 return this->GetUserCounter();
617 if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
619 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());
620 return this->GetUserCounter();
624 if (!ServerInstance->ULine(src->server))
627 FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,this,reason));
629 return this->GetUserCounter();
631 /* Set to -1 by OnUserPreKick if explicit allow was set */
632 if (MOD_RESULT != -1)
634 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,this,AC_KICK));
635 if ((MOD_RESULT == ACR_DENY) && (!ServerInstance->ULine(src->server)))
636 return this->GetUserCounter();
638 if ((MOD_RESULT == ACR_DEFAULT) || (!ServerInstance->ULine(src->server)))
640 int them = this->GetStatus(src);
641 int us = this->GetStatus(user);
642 if ((them < STATUS_HOP) || (them < us))
644 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them == STATUS_HOP ? "" : "half-");
645 return this->GetUserCounter();
651 FOREACH_MOD(I_OnUserKick,OnUserKick(src, user, this, reason, silent));
653 UCListIter i = user->chans.find(this);
654 if (i != user->chans.end())
656 /* zap it from the channel list of the user */
658 this->WriteChannel(src, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
660 user->chans.erase(i);
661 this->RemoveAllPrefixes(user);
664 if (!this->DelUser(user))
665 /* if there are no users left on the channel */
667 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name.c_str());
669 /* kill the record */
670 if (iter != ServerInstance->chanlist->end())
673 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
675 return 1; // delete halted by module
676 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
677 ServerInstance->chanlist->erase(iter);
682 return this->GetUserCounter();
685 void Channel::WriteChannel(User* user, const char* text, ...)
687 char textbuffer[MAXBUF];
693 va_start(argsPtr, text);
694 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
697 this->WriteChannel(user, std::string(textbuffer));
700 void Channel::WriteChannel(User* user, const std::string &text)
702 CUList *ulist = this->GetUsers();
708 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
709 std::string out = tb;
711 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
713 if (IS_LOCAL(i->first))
714 i->first->Write(out);
718 void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...)
720 char textbuffer[MAXBUF];
726 va_start(argsPtr, text);
727 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
730 this->WriteChannelWithServ(ServName, std::string(textbuffer));
733 void Channel::WriteChannelWithServ(const char* ServName, const std::string &text)
735 CUList *ulist = this->GetUsers();
738 snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str());
739 std::string out = tb;
741 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
743 if (IS_LOCAL(i->first))
744 i->first->Write(out);
748 /* write formatted text from a source user to all users on a channel except
749 * for the sender (for privmsg etc) */
750 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
752 char textbuffer[MAXBUF];
758 va_start(argsPtr, text);
759 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
762 this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
765 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
767 char textbuffer[MAXBUF];
773 va_start(argsPtr, text);
774 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
777 this->WriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
780 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
782 CUList *ulist = this->GetUsers();
785 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
786 std::string out = tb;
788 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
790 if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
792 /* User doesnt have the status we're after */
793 if (status && !strchr(this->GetAllPrefixChars(i->first), status))
797 i->first->WriteServ(text);
799 i->first->Write(out);
804 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
807 except_list[user] = user->nick;
808 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
812 * return a count of the users on a specific channel accounting for
813 * invisible users who won't increase the count. e.g. for /LIST
815 int Channel::CountInvisible()
818 CUList *ulist= this->GetUsers();
819 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
821 if (!(i->first->IsModeSet('i')))
828 char* Channel::ChanModes(bool showkey)
830 static char scratch[MAXBUF];
831 static char sparam[MAXBUF];
832 char* offset = scratch;
833 std::string extparam;
838 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
839 for(int n = 0; n < 64; n++)
848 // Unfortunately this must be special-cased, as we definitely don't want to always display key.
851 extparam = this->GetModeParameter('k');
864 /* We know these have no parameters */
867 extparam = this->GetModeParameter(n + 65);
870 if (!extparam.empty())
872 charlcat(sparam,' ',MAXBUF);
873 strlcat(sparam,extparam.c_str(),MAXBUF);
878 /* Null terminate scratch */
880 strlcat(scratch,sparam,MAXBUF);
884 /* compile a userlist of a channel into a string, each nick seperated by
885 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
887 void Channel::UserList(User *user, CUList *ulist)
892 bool call_modules = true;
897 FOREACH_RESULT(I_OnUserList,OnUserList(user, this, ulist));
899 call_modules = false;
901 if (MOD_RESULT != -1)
903 if ((this->IsModeSet('s')) && (!this->HasUser(user)))
905 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
910 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
913 char* ptr = list + dlen;
916 ulist = this->GetUsers();
918 /* Improvement by Brain - this doesnt change in value, so why was it inside
921 bool has_user = this->HasUser(user);
923 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
925 if ((!has_user) && (i->first->IsModeSet('i')))
928 * user is +i, and source not on the channel, does not show
934 if (i->first->Visibility && !i->first->Visibility->VisibleTo(user))
937 std::string prefixlist = this->GetPrefixChar(i->first);
938 std::string nick = i->first->nick;
942 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->first, this, prefixlist, nick));
944 /* Nick was nuked, a module wants us to skip it */
951 if (curlen + prefixlist.length() + nick.length() + 1 > 480)
953 /* list overflowed into multiple numerics */
954 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
956 /* reset our lengths */
957 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
964 ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
972 /* if whats left in the list isnt empty, send it */
975 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
978 user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
981 long Channel::GetMaxBans()
983 /* Return the cached value if there is one */
985 return this->maxbans;
987 /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
988 for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
990 if (InspIRCd::Match(this->name, n->first, NULL))
992 this->maxbans = n->second;
997 /* Screw it, just return the default of 64 */
999 return this->maxbans;
1002 void Channel::ResetMaxBans()
1007 /* returns the status character for a given user on a channel, e.g. @ for op,
1008 * % for halfop etc. If the user has several modes set, the highest mode
1009 * the user has must be returned.
1011 const char* Channel::GetPrefixChar(User *user)
1013 static char pf[2] = {0, 0};
1015 prefixlist::iterator n = prefixes.find(user);
1016 if (n != prefixes.end())
1018 if (n->second.size())
1020 /* If the user has any prefixes, their highest prefix
1021 * will always be at the head of the list, as the list is
1022 * sorted in rank order highest first (see SetPrefix()
1025 *pf = n->second.begin()->first;
1035 const char* Channel::GetAllPrefixChars(User* user)
1037 static char prefix[MAXBUF];
1041 prefixlist::iterator n = prefixes.find(user);
1042 if (n != prefixes.end())
1044 for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
1046 prefix[ctr++] = x->first;
1055 unsigned int Channel::GetPrefixValue(User* user)
1057 prefixlist::iterator n = prefixes.find(user);
1058 if (n != prefixes.end())
1060 if (n->second.size())
1061 return n->second.begin()->second;
1066 int Channel::GetStatusFlags(User *user)
1068 UCListIter i = user->chans.find(this);
1069 if (i != user->chans.end())
1076 int Channel::GetStatus(User *user)
1078 if (ServerInstance->ULine(user->server))
1081 UCListIter i = user->chans.find(this);
1082 if (i != user->chans.end())
1084 if ((i->second & UCMODE_OP) > 0)
1088 if ((i->second & UCMODE_HOP) > 0)
1092 if ((i->second & UCMODE_VOICE) > 0)
1094 return STATUS_VOICE;
1096 return STATUS_NORMAL;
1098 return STATUS_NORMAL;
1101 void Channel::SetPrefix(User* user, char prefix, unsigned int prefix_value, bool adding)
1103 prefixlist::iterator n = prefixes.find(user);
1104 prefixtype pfx = std::make_pair(prefix,prefix_value);
1107 if (n != prefixes.end())
1109 if (std::find(n->second.begin(), n->second.end(), pfx) == n->second.end())
1111 n->second.push_back(pfx);
1112 /* We must keep prefixes in rank order, largest first.
1113 * This is for two reasons, firstly because x-chat *ass-u-me's* this
1114 * state, and secondly it turns out to be a benefit to us later.
1115 * See above in GetPrefix().
1117 std::sort(n->second.begin(), n->second.end(), ModeParser::PrefixComparison);
1124 prefixes.insert(std::make_pair<User*,pfxcontainer>(user, one));
1129 if (n != prefixes.end())
1131 pfxcontainer::iterator x = std::find(n->second.begin(), n->second.end(), pfx);
1132 if (x != n->second.end())
1138 void Channel::RemoveAllPrefixes(User* user)
1140 prefixlist::iterator n = prefixes.find(user);
1141 if (n != prefixes.end())