1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
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->created = ts ? ts : ServerInstance->Time();
29 this->age = this->created;
31 maxbans = topicset = 0;
35 void Channel::SetMode(char mode,bool mode_on)
37 modes[mode-65] = mode_on;
39 this->SetModeParam(mode,"",false);
43 void Channel::SetModeParam(char mode,const char* parameter,bool mode_on)
45 CustomModeList::iterator n = custom_mode_params.find(mode);
49 if (n == custom_mode_params.end())
50 custom_mode_params[mode] = strdup(parameter);
54 if (n != custom_mode_params.end())
57 custom_mode_params.erase(n);
62 bool Channel::IsModeSet(char mode)
64 return modes[mode-65];
67 std::string Channel::GetModeParameter(char mode)
69 CustomModeList::iterator n = custom_mode_params.find(mode);
70 if (n != custom_mode_params.end())
75 int Channel::SetTopic(User *u, std::string &ntopic, bool forceset)
82 /* 0: check status, 1: don't, -1: disallow change silently */
84 FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(u,this,ntopic));
88 else if (MOD_RESULT == 0)
90 if (!this->HasUser(u))
92 u->WriteNumeric(442, "%s %s :You're not on that channel!",u->nick.c_str(), this->name.c_str());
95 if ((this->IsModeSet('t')) && (this->GetStatus(u) < STATUS_HOP))
97 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());
104 this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic);
107 this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128);
108 this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
112 this->setby.assign(ServerInstance->Config->ServerName);
113 this->WriteChannelWithServ(ServerInstance->Config->ServerName, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
116 this->topicset = ServerInstance->Time();
118 if (u && IS_LOCAL(u))
120 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(u, this, this->topic));
126 long Channel::GetUserCounter()
128 return (this->internal_userlist.size());
131 void Channel::AddUser(User* user)
133 internal_userlist[user] = user->nick;
136 unsigned long Channel::DelUser(User* user)
138 CUListIter a = internal_userlist.find(user);
140 if (a != internal_userlist.end())
142 internal_userlist.erase(a);
143 /* And tidy any others... */
145 DelHalfoppedUser(user);
149 return internal_userlist.size();
152 bool Channel::HasUser(User* user)
154 return (internal_userlist.find(user) != internal_userlist.end());
157 void Channel::AddOppedUser(User* user)
159 internal_op_userlist[user] = user->nick;
162 void Channel::DelOppedUser(User* user)
164 CUListIter a = internal_op_userlist.find(user);
165 if (a != internal_op_userlist.end())
167 internal_op_userlist.erase(a);
172 void Channel::AddHalfoppedUser(User* user)
174 internal_halfop_userlist[user] = user->nick;
177 void Channel::DelHalfoppedUser(User* user)
179 CUListIter a = internal_halfop_userlist.find(user);
181 if (a != internal_halfop_userlist.end())
183 internal_halfop_userlist.erase(a);
187 void Channel::AddVoicedUser(User* user)
189 internal_voice_userlist[user] = user->nick;
192 void Channel::DelVoicedUser(User* user)
194 CUListIter a = internal_voice_userlist.find(user);
196 if (a != internal_voice_userlist.end())
198 internal_voice_userlist.erase(a);
202 CUList* Channel::GetUsers()
204 return &internal_userlist;
207 CUList* Channel::GetOppedUsers()
209 return &internal_op_userlist;
212 CUList* Channel::GetHalfoppedUsers()
214 return &internal_halfop_userlist;
217 CUList* Channel::GetVoicedUsers()
219 return &internal_voice_userlist;
222 void Channel::SetDefaultModes()
224 ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes);
225 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
227 std::string parameter;
229 list.GetToken(modeseq);
231 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
233 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
236 if (mode->GetNumParams(true))
237 list.GetToken(parameter);
241 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
247 * add a channel to a user, creating the record for it if needed and linking
248 * it to the user record
250 Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
261 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
262 * We restrict local users to MaxChans channels.
263 * We restrict local operators to OperMaxChans channels.
264 * This is a lot more logical than how it was formerly. -- w00t
266 if (IS_LOCAL(user) && !override)
268 // Checking MyClass exists because we *may* get here with NULL, not 100% sure.
269 if (user->MyClass && user->MyClass->GetMaxChans())
271 if (user->chans.size() >= user->MyClass->GetMaxChans())
273 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
279 if (user->HasPrivPermission("channels/high-join-limit"))
281 if (user->chans.size() >= Instance->Config->OperMaxChans)
283 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
289 if (user->chans.size() >= Instance->Config->MaxChans)
291 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
298 strlcpy(cname, cn, Instance->Config->Limits.ChanMax);
299 Ptr = Instance->FindChan(cname);
304 * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
309 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);
316 if (IS_LOCAL(user) && override == false)
319 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, NULL, cname, privs, key ? key : ""));
324 Ptr = new Channel(Instance, cname, TS);
328 /* Already on the channel */
329 if (Ptr->HasUser(user))
333 * remote users are allowed us to bypass channel modes
334 * and bans (used by servers)
336 if (IS_LOCAL(user) && override == false)
339 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, Ptr, cname, privs, key ? key : ""));
344 else if (MOD_RESULT == 0)
346 std::string ckey = Ptr->GetModeParameter('k');
347 bool invited = user->IsInvited(Ptr->name.c_str());
348 bool can_bypass = Instance->Config->InvBypassModes && invited;
353 FOREACH_RESULT_I(Instance, I_OnCheckKey, OnCheckKey(user, Ptr, key ? key : ""));
356 // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
357 if ((!key || ckey != key) && !can_bypass)
359 user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
365 if (Ptr->IsModeSet('i'))
368 FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr));
373 user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
379 std::string limit = Ptr->GetModeParameter('l');
383 FOREACH_RESULT_I(Instance, I_OnCheckLimit, OnCheckLimit(user, Ptr));
386 long llimit = atol(limit.c_str());
387 if (Ptr->GetUserCounter() >= llimit && !can_bypass)
389 user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
395 if (Ptr->bans.size())
397 if (Ptr->IsBanned(user) && !can_bypass)
399 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
405 * If the user has invites for this channel, remove them now
406 * after a successful join so they don't build up.
410 user->RemoveInvite(Ptr->name.c_str());
416 /* As spotted by jilles, dont bother to set this on remote users */
417 if (IS_LOCAL(user) && Ptr->GetUserCounter() == 0)
418 Ptr->SetDefaultModes();
420 return Channel::ForceChan(Instance, Ptr, user, privs, bursting);
423 Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting)
425 std::string nick = user->nick;
430 /* Just in case they have no permissions */
431 user->chans[Ptr] = 0;
433 for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
435 const char status = *x;
436 ModeHandler* mh = Instance->Modes->FindPrefix(status);
439 /* Set, and make sure that the mode handler knows this mode was now set */
440 Ptr->SetPrefix(user, status, mh->GetPrefixRank(), true);
441 mh->OnModeChange(Instance->FakeClient, Instance->FakeClient, Ptr, nick, true);
443 switch (mh->GetPrefix())
445 /* These logic ops are SAFE IN THIS CASE because if the entry doesnt exist,
446 * addressing operator[] creates it. If they do exist, it points to it.
447 * At all other times where we dont want to create an item if it doesnt exist, we
448 * must stick to ::find().
451 user->chans[Ptr] |= UCMODE_OP;
454 user->chans[Ptr] |= UCMODE_HOP;
457 user->chans[Ptr] |= UCMODE_VOICE;
463 FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user, Ptr, bursting, silent));
466 Ptr->WriteChannel(user,"JOIN :%s",Ptr->name.c_str());
468 /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
469 std::string ms = Instance->Modes->ModeString(user, Ptr);
470 if ((Ptr->GetUserCounter() > 1) && (ms.length()))
471 Ptr->WriteAllExceptSender(user, true, 0, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
473 /* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
478 user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
479 user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
483 FOREACH_MOD_I(Instance,I_OnPostJoin,OnPostJoin(user, Ptr));
487 bool Channel::IsBanned(User* user)
491 FOREACH_RESULT(I_OnCheckBan,OnCheckBan(user, this));
493 if (MOD_RESULT == -1)
495 else if (MOD_RESULT == 0)
497 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
498 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
500 if ((InspIRCd::Match(user->GetFullHost(),i->data, NULL)) || // host
501 (InspIRCd::Match(user->GetFullRealHost(),i->data, NULL)) || // uncloaked host
502 (InspIRCd::MatchCIDR(mask, i->data, NULL))) // ip
511 bool Channel::IsExtBanned(const std::string &str, char type)
514 FOREACH_RESULT(I_OnCheckStringExtBan, OnCheckStringExtBan(str, this, type));
516 if (MOD_RESULT == -1)
518 else if (MOD_RESULT == 0)
520 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
522 if (i->data[0] != type || i->data[1] != ':')
525 // Iterate past char and : to get to the mask without doing a data copy(!)
526 std::string maskptr = i->data.substr(2);
527 ServerInstance->Logs->Log("EXTBANS", DEBUG, "Checking %s against %s, type is %c", str.c_str(), maskptr.c_str(), type);
529 if (InspIRCd::Match(str, maskptr, NULL))
537 bool Channel::IsExtBanned(User *user, char type)
540 FOREACH_RESULT(I_OnCheckExtBan, OnCheckExtBan(user, this, type));
542 if (MOD_RESULT == -1)
544 else if (MOD_RESULT == 0)
547 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
549 // XXX: we should probably hook cloaked hosts in here somehow too..
550 if (this->IsExtBanned(mask, type))
553 if (this->IsExtBanned(user->GetFullHost(), type))
556 if (this->IsExtBanned(user->GetFullRealHost(), type))
564 * remove a channel from a users record, and return the number of users left.
565 * Therefore, if this function returns 0 the caller should delete the Channel.
567 long Channel::PartUser(User *user, std::string &reason)
572 return this->GetUserCounter();
574 UCListIter i = user->chans.find(this);
575 if (i != user->chans.end())
577 FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason, silent));
580 this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
582 user->chans.erase(i);
583 this->RemoveAllPrefixes(user);
586 if (!this->DelUser(user)) /* if there are no users left on the channel... */
588 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
589 /* kill the record */
590 if (iter != ServerInstance->chanlist->end())
593 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
595 return 1; // delete halted by module
596 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
597 ServerInstance->chanlist->erase(iter);
602 return this->GetUserCounter();
605 long Channel::ServerKickUser(User* user, const char* reason, bool triggerevents, const char* servername)
609 if (!user || !reason)
610 return this->GetUserCounter();
614 if (!this->HasUser(user))
617 return this->GetUserCounter();
621 if (servername == NULL || *ServerInstance->Config->HideWhoisServer)
622 servername = ServerInstance->Config->ServerName;
626 FOREACH_MOD(I_OnUserKick,OnUserKick(NULL, user, this, reason, silent));
629 UCListIter i = user->chans.find(this);
630 if (i != user->chans.end())
633 this->WriteChannelWithServ(servername, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
635 user->chans.erase(i);
636 this->RemoveAllPrefixes(user);
639 if (!this->DelUser(user))
641 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
642 /* kill the record */
643 if (iter != ServerInstance->chanlist->end())
646 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
648 return 1; // delete halted by module
649 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
650 ServerInstance->chanlist->erase(iter);
655 return this->GetUserCounter();
658 long Channel::KickUser(User *src, User *user, const char* reason)
662 if (!src || !user || !reason)
663 return this->GetUserCounter();
667 if (!this->HasUser(user))
669 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());
670 return this->GetUserCounter();
672 if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
674 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());
675 return this->GetUserCounter();
679 if (!ServerInstance->ULine(src->server))
682 FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,this,reason));
684 return this->GetUserCounter();
686 /* Set to -1 by OnUserPreKick if explicit allow was set */
687 if (MOD_RESULT != -1)
689 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,this,AC_KICK));
690 if ((MOD_RESULT == ACR_DENY) && (!ServerInstance->ULine(src->server)))
691 return this->GetUserCounter();
693 if ((MOD_RESULT == ACR_DEFAULT) || (!ServerInstance->ULine(src->server)))
695 int them = this->GetStatus(src);
696 int us = this->GetStatus(user);
697 if ((them < STATUS_HOP) || (them < us))
699 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them == STATUS_HOP ? "" : "half-");
700 return this->GetUserCounter();
706 FOREACH_MOD(I_OnUserKick,OnUserKick(src, user, this, reason, silent));
708 UCListIter i = user->chans.find(this);
709 if (i != user->chans.end())
711 /* zap it from the channel list of the user */
713 this->WriteChannel(src, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
715 user->chans.erase(i);
716 this->RemoveAllPrefixes(user);
719 if (!this->DelUser(user))
720 /* if there are no users left on the channel */
722 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name.c_str());
724 /* kill the record */
725 if (iter != ServerInstance->chanlist->end())
728 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
730 return 1; // delete halted by module
731 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
732 ServerInstance->chanlist->erase(iter);
737 return this->GetUserCounter();
740 void Channel::WriteChannel(User* user, const char* text, ...)
742 char textbuffer[MAXBUF];
748 va_start(argsPtr, text);
749 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
752 this->WriteChannel(user, std::string(textbuffer));
755 void Channel::WriteChannel(User* user, const std::string &text)
757 CUList *ulist = this->GetUsers();
763 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
764 std::string out = tb;
766 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
768 if (IS_LOCAL(i->first))
769 i->first->Write(out);
773 void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...)
775 char textbuffer[MAXBUF];
781 va_start(argsPtr, text);
782 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
785 this->WriteChannelWithServ(ServName, std::string(textbuffer));
788 void Channel::WriteChannelWithServ(const char* ServName, const std::string &text)
790 CUList *ulist = this->GetUsers();
793 snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str());
794 std::string out = tb;
796 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
798 if (IS_LOCAL(i->first))
799 i->first->Write(out);
803 /* write formatted text from a source user to all users on a channel except
804 * for the sender (for privmsg etc) */
805 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
807 char textbuffer[MAXBUF];
813 va_start(argsPtr, text);
814 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
817 this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
820 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
822 char textbuffer[MAXBUF];
828 va_start(argsPtr, text);
829 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
832 this->WriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
835 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
837 CUList *ulist = this->GetUsers();
840 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
841 std::string out = tb;
843 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
845 if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
847 /* User doesnt have the status we're after */
848 if (status && !strchr(this->GetAllPrefixChars(i->first), status))
852 i->first->WriteServ(text);
854 i->first->Write(out);
859 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
862 except_list[user] = user->nick;
863 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
867 * return a count of the users on a specific channel accounting for
868 * invisible users who won't increase the count. e.g. for /LIST
870 int Channel::CountInvisible()
873 CUList *ulist= this->GetUsers();
874 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
876 if (!(i->first->IsModeSet('i')))
883 char* Channel::ChanModes(bool showkey)
885 static char scratch[MAXBUF];
886 static char sparam[MAXBUF];
887 char* offset = scratch;
888 std::string extparam;
893 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
894 for(int n = 0; n < 64; n++)
903 // Unfortunately this must be special-cased, as we definitely don't want to always display key.
906 extparam = this->GetModeParameter('k');
919 /* We know these have no parameters */
922 extparam = this->GetModeParameter(n + 65);
925 if (!extparam.empty())
927 charlcat(sparam,' ',MAXBUF);
928 strlcat(sparam,extparam.c_str(),MAXBUF);
933 /* Null terminate scratch */
935 strlcat(scratch,sparam,MAXBUF);
939 /* compile a userlist of a channel into a string, each nick seperated by
940 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
942 void Channel::UserList(User *user, CUList *ulist)
947 bool call_modules = true;
952 FOREACH_RESULT(I_OnUserList,OnUserList(user, this, ulist));
954 call_modules = false;
956 if (MOD_RESULT != -1)
958 if ((this->IsModeSet('s')) && (!this->HasUser(user)))
960 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
965 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
968 char* ptr = list + dlen;
971 ulist = this->GetUsers();
973 /* Improvement by Brain - this doesnt change in value, so why was it inside
976 bool has_user = this->HasUser(user);
978 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
980 if ((!has_user) && (i->first->IsModeSet('i')))
983 * user is +i, and source not on the channel, does not show
989 if (i->first->Visibility && !i->first->Visibility->VisibleTo(user))
992 std::string prefixlist = this->GetPrefixChar(i->first);
993 std::string nick = i->first->nick;
997 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->first, this, prefixlist, nick));
999 /* Nick was nuked, a module wants us to skip it */
1006 if (curlen + prefixlist.length() + nick.length() + 1 > 480)
1008 /* list overflowed into multiple numerics */
1009 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
1011 /* reset our lengths */
1012 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
1019 ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
1027 /* if whats left in the list isnt empty, send it */
1030 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
1033 user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
1036 long Channel::GetMaxBans()
1038 /* Return the cached value if there is one */
1040 return this->maxbans;
1042 /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
1043 for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
1045 if (InspIRCd::Match(this->name, n->first, NULL))
1047 this->maxbans = n->second;
1052 /* Screw it, just return the default of 64 */
1054 return this->maxbans;
1057 void Channel::ResetMaxBans()
1062 /* returns the status character for a given user on a channel, e.g. @ for op,
1063 * % for halfop etc. If the user has several modes set, the highest mode
1064 * the user has must be returned.
1066 const char* Channel::GetPrefixChar(User *user)
1068 static char pf[2] = {0, 0};
1070 prefixlist::iterator n = prefixes.find(user);
1071 if (n != prefixes.end())
1073 if (n->second.size())
1075 /* If the user has any prefixes, their highest prefix
1076 * will always be at the head of the list, as the list is
1077 * sorted in rank order highest first (see SetPrefix()
1080 *pf = n->second.begin()->first;
1090 const char* Channel::GetAllPrefixChars(User* user)
1092 static char prefix[MAXBUF];
1096 prefixlist::iterator n = prefixes.find(user);
1097 if (n != prefixes.end())
1099 for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
1101 prefix[ctr++] = x->first;
1110 unsigned int Channel::GetPrefixValue(User* user)
1112 prefixlist::iterator n = prefixes.find(user);
1113 if (n != prefixes.end())
1115 if (n->second.size())
1116 return n->second.begin()->second;
1121 int Channel::GetStatusFlags(User *user)
1123 UCListIter i = user->chans.find(this);
1124 if (i != user->chans.end())
1131 int Channel::GetStatus(User *user)
1133 if (ServerInstance->ULine(user->server))
1136 UCListIter i = user->chans.find(this);
1137 if (i != user->chans.end())
1139 if ((i->second & UCMODE_OP) > 0)
1143 if ((i->second & UCMODE_HOP) > 0)
1147 if ((i->second & UCMODE_VOICE) > 0)
1149 return STATUS_VOICE;
1151 return STATUS_NORMAL;
1153 return STATUS_NORMAL;
1156 void Channel::SetPrefix(User* user, char prefix, unsigned int prefix_value, bool adding)
1158 prefixlist::iterator n = prefixes.find(user);
1159 prefixtype pfx = std::make_pair(prefix,prefix_value);
1162 if (n != prefixes.end())
1164 if (std::find(n->second.begin(), n->second.end(), pfx) == n->second.end())
1166 n->second.push_back(pfx);
1167 /* We must keep prefixes in rank order, largest first.
1168 * This is for two reasons, firstly because x-chat *ass-u-me's* this
1169 * state, and secondly it turns out to be a benefit to us later.
1170 * See above in GetPrefix().
1172 std::sort(n->second.begin(), n->second.end(), ModeParser::PrefixComparison);
1179 prefixes.insert(std::make_pair<User*,pfxcontainer>(user, one));
1184 if (n != prefixes.end())
1186 pfxcontainer::iterator x = std::find(n->second.begin(), n->second.end(), pfx);
1187 if (x != n->second.end())
1193 void Channel::RemoveAllPrefixes(User* user)
1195 prefixlist::iterator n = prefixes.find(user);
1196 if (n != prefixes.end())