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;
38 this->SetModeParam(mode,"",false);
42 void Channel::SetModeParam(char mode,const char* parameter,bool mode_on)
44 CustomModeList::iterator n = custom_mode_params.find(mode);
48 if (n == custom_mode_params.end())
49 custom_mode_params[mode] = strdup(parameter);
53 if (n != custom_mode_params.end())
56 custom_mode_params.erase(n);
61 bool Channel::IsModeSet(char mode)
63 return modes[mode-65];
66 std::string Channel::GetModeParameter(char mode)
68 CustomModeList::iterator n = custom_mode_params.find(mode);
69 if (n != custom_mode_params.end())
74 int Channel::SetTopic(User *u, std::string &ntopic, bool forceset)
81 /* 0: check status, 1: don't, -1: disallow change silently */
83 FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(u,this,ntopic));
87 else if (MOD_RESULT == 0)
89 if (!this->HasUser(u))
91 u->WriteNumeric(442, "%s %s :You're not on that channel!",u->nick.c_str(), this->name.c_str());
94 if ((this->IsModeSet('t')) && (this->GetStatus(u) < STATUS_HOP))
96 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());
103 this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic);
106 this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128);
107 this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
111 this->setby.assign(ServerInstance->Config->ServerName);
112 this->WriteChannelWithServ(ServerInstance->Config->ServerName, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
115 this->topicset = ServerInstance->Time();
117 if (u && IS_LOCAL(u))
119 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(u, this, this->topic));
125 long Channel::GetUserCounter()
127 return (this->internal_userlist.size());
130 void Channel::AddUser(User* user)
132 internal_userlist[user] = user->nick;
135 unsigned long Channel::DelUser(User* user)
137 CUListIter a = internal_userlist.find(user);
139 if (a != internal_userlist.end())
141 internal_userlist.erase(a);
142 /* And tidy any others... */
144 DelHalfoppedUser(user);
148 return internal_userlist.size();
151 bool Channel::HasUser(User* user)
153 return (internal_userlist.find(user) != internal_userlist.end());
156 void Channel::AddOppedUser(User* user)
158 internal_op_userlist[user] = user->nick;
161 void Channel::DelOppedUser(User* user)
163 CUListIter a = internal_op_userlist.find(user);
164 if (a != internal_op_userlist.end())
166 internal_op_userlist.erase(a);
171 void Channel::AddHalfoppedUser(User* user)
173 internal_halfop_userlist[user] = user->nick;
176 void Channel::DelHalfoppedUser(User* user)
178 CUListIter a = internal_halfop_userlist.find(user);
180 if (a != internal_halfop_userlist.end())
182 internal_halfop_userlist.erase(a);
186 void Channel::AddVoicedUser(User* user)
188 internal_voice_userlist[user] = user->nick;
191 void Channel::DelVoicedUser(User* user)
193 CUListIter a = internal_voice_userlist.find(user);
195 if (a != internal_voice_userlist.end())
197 internal_voice_userlist.erase(a);
201 CUList* Channel::GetUsers()
203 return &internal_userlist;
206 CUList* Channel::GetOppedUsers()
208 return &internal_op_userlist;
211 CUList* Channel::GetHalfoppedUsers()
213 return &internal_halfop_userlist;
216 CUList* Channel::GetVoicedUsers()
218 return &internal_voice_userlist;
221 void Channel::SetDefaultModes()
223 ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes);
224 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
226 std::string parameter;
228 list.GetToken(modeseq);
230 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
232 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
235 if (mode->GetNumParams(true))
236 list.GetToken(parameter);
240 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
246 * add a channel to a user, creating the record for it if needed and linking
247 * it to the user record
249 Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
260 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
261 * We restrict local users to MaxChans channels.
262 * We restrict local operators to OperMaxChans channels.
263 * This is a lot more logical than how it was formerly. -- w00t
265 if (IS_LOCAL(user) && !override)
267 // Checking MyClass exists because we *may* get here with NULL, not 100% sure.
268 if (user->MyClass && user->MyClass->GetMaxChans())
270 if (user->chans.size() >= user->MyClass->GetMaxChans())
272 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
278 if (user->HasPrivPermission("channels/high-join-limit"))
280 if (user->chans.size() >= Instance->Config->OperMaxChans)
282 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
288 if (user->chans.size() >= Instance->Config->MaxChans)
290 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
297 strlcpy(cname, cn, Instance->Config->Limits.ChanMax);
298 Ptr = Instance->FindChan(cname);
299 bool created_by_local = false;
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);
314 created_by_local = true;
317 if (IS_LOCAL(user) && override == false)
320 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, NULL, cname, privs, key ? key : ""));
325 Ptr = new Channel(Instance, cname, TS);
329 /* Already on the channel */
330 if (Ptr->HasUser(user))
334 * remote users are allowed us to bypass channel modes
335 * and bans (used by servers)
337 if (IS_LOCAL(user) && override == false)
340 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, Ptr, cname, privs, key ? key : ""));
345 else if (MOD_RESULT == 0)
347 std::string ckey = Ptr->GetModeParameter('k');
348 bool invited = user->IsInvited(Ptr->name.c_str());
349 bool can_bypass = Instance->Config->InvBypassModes && invited;
354 FOREACH_RESULT_I(Instance, I_OnCheckKey, OnCheckKey(user, Ptr, key ? key : ""));
357 // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
358 if ((!key || ckey != key) && !can_bypass)
360 user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
366 if (Ptr->IsModeSet('i'))
369 FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr));
374 user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
380 std::string limit = Ptr->GetModeParameter('l');
384 FOREACH_RESULT_I(Instance, I_OnCheckLimit, OnCheckLimit(user, Ptr));
387 long llimit = atol(limit.c_str());
388 if (Ptr->GetUserCounter() >= llimit && !can_bypass)
390 user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
396 if (Ptr->IsBanned(user) && !can_bypass)
398 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
403 * If the user has invites for this channel, remove them now
404 * after a successful join so they don't build up.
408 user->RemoveInvite(Ptr->name.c_str());
414 if (created_by_local)
416 /* As spotted by jilles, dont bother to set this on remote users */
417 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)
490 FOREACH_RESULT_MAP(I_OnCheckBan, OnCheckBan(user, this),
491 result = banmatch_reduce(result, MOD_RESULT);
498 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
499 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
501 if ((InspIRCd::Match(user->GetFullHost(),i->data, NULL)) || // host
502 (InspIRCd::Match(user->GetFullRealHost(),i->data, NULL)) || // uncloaked host
503 (InspIRCd::MatchCIDR(mask, i->data, NULL))) // ip
511 int Channel::GetExtBanStatus(const std::string &str, char type)
514 FOREACH_RESULT_MAP(I_OnCheckStringExtBan, OnCheckStringExtBan(str, this, type),
515 result = banmatch_reduce(result, MOD_RESULT);
521 // nobody decided for us, check the ban list
522 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
524 if (i->data[0] != type || i->data[1] != ':')
527 std::string maskptr = i->data.substr(2);
528 ServerInstance->Logs->Log("EXTBANS", DEBUG, "Checking %s against %s, type is %c", str.c_str(), maskptr.c_str(), type);
530 if (InspIRCd::Match(str, maskptr, NULL))
537 int Channel::GetExtBanStatus(User *user, char type)
540 FOREACH_RESULT_MAP(I_OnCheckExtBan, OnCheckExtBan(user, this, type),
541 result = banmatch_reduce(result, MOD_RESULT);
549 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
551 // XXX: we should probably hook cloaked hosts in here somehow too..
552 rv = banmatch_reduce(rv, this->GetExtBanStatus(mask, type));
553 rv = banmatch_reduce(rv, this->GetExtBanStatus(user->GetFullHost(), type));
554 rv = banmatch_reduce(rv, this->GetExtBanStatus(user->GetFullRealHost(), type));
559 * remove a channel from a users record, and return the number of users left.
560 * Therefore, if this function returns 0 the caller should delete the Channel.
562 long Channel::PartUser(User *user, std::string &reason)
567 return this->GetUserCounter();
569 UCListIter i = user->chans.find(this);
570 if (i != user->chans.end())
572 FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason, silent));
575 this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
577 user->chans.erase(i);
578 this->RemoveAllPrefixes(user);
581 if (!this->DelUser(user)) /* if there are no users left on the channel... */
583 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
584 /* kill the record */
585 if (iter != ServerInstance->chanlist->end())
588 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
590 return 1; // delete halted by module
591 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
592 ServerInstance->chanlist->erase(iter);
597 return this->GetUserCounter();
600 long Channel::ServerKickUser(User* user, const char* reason, bool triggerevents, const char* servername)
604 if (!user || !reason)
605 return this->GetUserCounter();
609 if (!this->HasUser(user))
612 return this->GetUserCounter();
616 if (servername == NULL || *ServerInstance->Config->HideWhoisServer)
617 servername = ServerInstance->Config->ServerName;
621 FOREACH_MOD(I_OnUserKick,OnUserKick(NULL, user, this, reason, silent));
624 UCListIter i = user->chans.find(this);
625 if (i != user->chans.end())
628 this->WriteChannelWithServ(servername, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
630 user->chans.erase(i);
631 this->RemoveAllPrefixes(user);
634 if (!this->DelUser(user))
636 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
637 /* kill the record */
638 if (iter != ServerInstance->chanlist->end())
641 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
643 return 1; // delete halted by module
644 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
645 ServerInstance->chanlist->erase(iter);
650 return this->GetUserCounter();
653 long Channel::KickUser(User *src, User *user, const char* reason)
657 if (!src || !user || !reason)
658 return this->GetUserCounter();
662 if (!this->HasUser(user))
664 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());
665 return this->GetUserCounter();
667 if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
669 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());
670 return this->GetUserCounter();
674 if (!ServerInstance->ULine(src->server))
677 FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,this,reason));
679 return this->GetUserCounter();
681 /* Set to -1 by OnUserPreKick if explicit allow was set */
682 if (MOD_RESULT != -1)
684 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,this,AC_KICK));
685 if ((MOD_RESULT == ACR_DENY) && (!ServerInstance->ULine(src->server)))
686 return this->GetUserCounter();
688 if ((MOD_RESULT == ACR_DEFAULT) || (!ServerInstance->ULine(src->server)))
690 int them = this->GetStatus(src);
691 int us = this->GetStatus(user);
692 if ((them < STATUS_HOP) || (them < us))
694 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them == STATUS_HOP ? "" : "half-");
695 return this->GetUserCounter();
701 FOREACH_MOD(I_OnUserKick,OnUserKick(src, user, this, reason, silent));
703 UCListIter i = user->chans.find(this);
704 if (i != user->chans.end())
706 /* zap it from the channel list of the user */
708 this->WriteChannel(src, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
710 user->chans.erase(i);
711 this->RemoveAllPrefixes(user);
714 if (!this->DelUser(user))
715 /* if there are no users left on the channel */
717 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name.c_str());
719 /* kill the record */
720 if (iter != ServerInstance->chanlist->end())
723 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
725 return 1; // delete halted by module
726 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
727 ServerInstance->chanlist->erase(iter);
732 return this->GetUserCounter();
735 void Channel::WriteChannel(User* user, const char* text, ...)
737 char textbuffer[MAXBUF];
743 va_start(argsPtr, text);
744 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
747 this->WriteChannel(user, std::string(textbuffer));
750 void Channel::WriteChannel(User* user, const std::string &text)
752 CUList *ulist = this->GetUsers();
758 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
759 std::string out = tb;
761 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
763 if (IS_LOCAL(i->first))
764 i->first->Write(out);
768 void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...)
770 char textbuffer[MAXBUF];
776 va_start(argsPtr, text);
777 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
780 this->WriteChannelWithServ(ServName, std::string(textbuffer));
783 void Channel::WriteChannelWithServ(const char* ServName, const std::string &text)
785 CUList *ulist = this->GetUsers();
788 snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str());
789 std::string out = tb;
791 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
793 if (IS_LOCAL(i->first))
794 i->first->Write(out);
798 /* write formatted text from a source user to all users on a channel except
799 * for the sender (for privmsg etc) */
800 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
802 char textbuffer[MAXBUF];
808 va_start(argsPtr, text);
809 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
812 this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
815 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
817 char textbuffer[MAXBUF];
823 va_start(argsPtr, text);
824 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
827 this->WriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
830 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
832 CUList *ulist = this->GetUsers();
835 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
836 std::string out = tb;
838 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
840 if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
842 /* User doesnt have the status we're after */
843 if (status && !strchr(this->GetAllPrefixChars(i->first), status))
847 i->first->WriteServ(text);
849 i->first->Write(out);
854 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
857 except_list[user] = user->nick;
858 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
862 * return a count of the users on a specific channel accounting for
863 * invisible users who won't increase the count. e.g. for /LIST
865 int Channel::CountInvisible()
868 CUList *ulist= this->GetUsers();
869 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
871 if (!(i->first->IsModeSet('i')))
878 char* Channel::ChanModes(bool showkey)
880 static char scratch[MAXBUF];
881 static char sparam[MAXBUF];
882 char* offset = scratch;
883 std::string extparam;
888 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
889 for(int n = 0; n < 64; n++)
898 // Unfortunately this must be special-cased, as we definitely don't want to always display key.
901 extparam = this->GetModeParameter('k');
914 /* We know these have no parameters */
917 extparam = this->GetModeParameter(n + 65);
920 if (!extparam.empty())
922 charlcat(sparam,' ',MAXBUF);
923 strlcat(sparam,extparam.c_str(),MAXBUF);
928 /* Null terminate scratch */
930 strlcat(scratch,sparam,MAXBUF);
934 /* compile a userlist of a channel into a string, each nick seperated by
935 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
937 void Channel::UserList(User *user, CUList *ulist)
942 bool call_modules = true;
947 FOREACH_RESULT(I_OnUserList,OnUserList(user, this, ulist));
949 call_modules = false;
951 if (MOD_RESULT != -1)
953 if ((this->IsModeSet('s')) && (!this->HasUser(user)))
955 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
960 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
963 char* ptr = list + dlen;
966 ulist = this->GetUsers();
968 /* Improvement by Brain - this doesnt change in value, so why was it inside
971 bool has_user = this->HasUser(user);
973 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
975 if ((!has_user) && (i->first->IsModeSet('i')))
978 * user is +i, and source not on the channel, does not show
984 if (i->first->Visibility && !i->first->Visibility->VisibleTo(user))
987 std::string prefixlist = this->GetPrefixChar(i->first);
988 std::string nick = i->first->nick;
992 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->first, this, prefixlist, nick));
994 /* Nick was nuked, a module wants us to skip it */
1001 if (curlen + prefixlist.length() + nick.length() + 1 > 480)
1003 /* list overflowed into multiple numerics */
1004 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
1006 /* reset our lengths */
1007 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
1014 ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
1022 /* if whats left in the list isnt empty, send it */
1025 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
1028 user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
1031 long Channel::GetMaxBans()
1033 /* Return the cached value if there is one */
1035 return this->maxbans;
1037 /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
1038 for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
1040 if (InspIRCd::Match(this->name, n->first, NULL))
1042 this->maxbans = n->second;
1047 /* Screw it, just return the default of 64 */
1049 return this->maxbans;
1052 void Channel::ResetMaxBans()
1057 /* returns the status character for a given user on a channel, e.g. @ for op,
1058 * % for halfop etc. If the user has several modes set, the highest mode
1059 * the user has must be returned.
1061 const char* Channel::GetPrefixChar(User *user)
1063 static char pf[2] = {0, 0};
1065 prefixlist::iterator n = prefixes.find(user);
1066 if (n != prefixes.end())
1068 if (n->second.size())
1070 /* If the user has any prefixes, their highest prefix
1071 * will always be at the head of the list, as the list is
1072 * sorted in rank order highest first (see SetPrefix()
1075 *pf = n->second.begin()->first;
1085 const char* Channel::GetAllPrefixChars(User* user)
1087 static char prefix[MAXBUF];
1091 prefixlist::iterator n = prefixes.find(user);
1092 if (n != prefixes.end())
1094 for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
1096 prefix[ctr++] = x->first;
1105 unsigned int Channel::GetPrefixValue(User* user)
1107 prefixlist::iterator n = prefixes.find(user);
1108 if (n != prefixes.end())
1110 if (n->second.size())
1111 return n->second.begin()->second;
1116 int Channel::GetStatusFlags(User *user)
1118 UCListIter i = user->chans.find(this);
1119 if (i != user->chans.end())
1126 int Channel::GetStatus(User *user)
1128 if (ServerInstance->ULine(user->server))
1131 UCListIter i = user->chans.find(this);
1132 if (i != user->chans.end())
1134 if ((i->second & UCMODE_OP) > 0)
1138 if ((i->second & UCMODE_HOP) > 0)
1142 if ((i->second & UCMODE_VOICE) > 0)
1144 return STATUS_VOICE;
1146 return STATUS_NORMAL;
1148 return STATUS_NORMAL;
1151 void Channel::SetPrefix(User* user, char prefix, unsigned int prefix_value, bool adding)
1153 prefixlist::iterator n = prefixes.find(user);
1154 prefixtype pfx = std::make_pair(prefix,prefix_value);
1157 if (n != prefixes.end())
1159 if (std::find(n->second.begin(), n->second.end(), pfx) == n->second.end())
1161 n->second.push_back(pfx);
1162 /* We must keep prefixes in rank order, largest first.
1163 * This is for two reasons, firstly because x-chat *ass-u-me's* this
1164 * state, and secondly it turns out to be a benefit to us later.
1165 * See above in GetPrefix().
1167 std::sort(n->second.begin(), n->second.end(), ModeParser::PrefixComparison);
1174 prefixes.insert(std::make_pair<User*,pfxcontainer>(user, one));
1179 if (n != prefixes.end())
1181 pfxcontainer::iterator x = std::find(n->second.begin(), n->second.end(), pfx);
1182 if (x != n->second.end())
1188 void Channel::RemoveAllPrefixes(User* user)
1190 prefixlist::iterator n = prefixes.find(user);
1191 if (n != prefixes.end())