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 std::string Channel::GetModeParameter(char mode)
58 CustomModeList::iterator n = custom_mode_params.find(mode);
59 if (n != custom_mode_params.end())
64 int Channel::SetTopic(User *u, std::string &ntopic, bool forceset)
71 /* 0: check status, 1: don't, -1: disallow change silently */
73 FIRST_MOD_RESULT(ServerInstance, OnLocalTopicChange, 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->GetStatus(u) < STATUS_HOP))
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 (this->internal_userlist.size());
121 void Channel::AddUser(User* user)
123 internal_userlist[user] = user->nick;
126 unsigned long Channel::DelUser(User* user)
128 CUListIter a = internal_userlist.find(user);
130 if (a != internal_userlist.end())
132 internal_userlist.erase(a);
133 /* And tidy any others... */
135 DelHalfoppedUser(user);
139 return internal_userlist.size();
142 bool Channel::HasUser(User* user)
144 return (internal_userlist.find(user) != internal_userlist.end());
147 void Channel::AddOppedUser(User* user)
149 internal_op_userlist[user] = user->nick;
152 void Channel::DelOppedUser(User* user)
154 CUListIter a = internal_op_userlist.find(user);
155 if (a != internal_op_userlist.end())
157 internal_op_userlist.erase(a);
162 void Channel::AddHalfoppedUser(User* user)
164 internal_halfop_userlist[user] = user->nick;
167 void Channel::DelHalfoppedUser(User* user)
169 CUListIter a = internal_halfop_userlist.find(user);
171 if (a != internal_halfop_userlist.end())
173 internal_halfop_userlist.erase(a);
177 void Channel::AddVoicedUser(User* user)
179 internal_voice_userlist[user] = user->nick;
182 void Channel::DelVoicedUser(User* user)
184 CUListIter a = internal_voice_userlist.find(user);
186 if (a != internal_voice_userlist.end())
188 internal_voice_userlist.erase(a);
192 CUList* Channel::GetUsers()
194 return &internal_userlist;
197 CUList* Channel::GetOppedUsers()
199 return &internal_op_userlist;
202 CUList* Channel::GetHalfoppedUsers()
204 return &internal_halfop_userlist;
207 CUList* Channel::GetVoicedUsers()
209 return &internal_voice_userlist;
212 void Channel::SetDefaultModes()
214 ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes);
215 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
217 std::string parameter;
219 list.GetToken(modeseq);
221 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
223 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
226 if (mode->GetNumParams(true))
227 list.GetToken(parameter);
231 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
237 * add a channel to a user, creating the record for it if needed and linking
238 * it to the user record
240 Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
242 // Fix: unregistered users could be joined using /SAJOIN
243 if (!user || !cn || user->registered != REG_ALL)
251 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
252 * We restrict local users to MaxChans channels.
253 * We restrict local operators to OperMaxChans channels.
254 * This is a lot more logical than how it was formerly. -- w00t
256 if (IS_LOCAL(user) && !override)
258 // Checking MyClass exists because we *may* get here with NULL, not 100% sure.
259 if (user->MyClass && user->MyClass->maxchans)
261 if (user->HasPrivPermission("channels/high-join-limit"))
263 if (user->chans.size() >= Instance->Config->OperMaxChans)
265 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
271 if (user->chans.size() >= user->MyClass->maxchans)
273 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
280 strlcpy(cname, cn, Instance->Config->Limits.ChanMax);
281 Ptr = Instance->FindChan(cname);
282 bool created_by_local = false;
287 * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
292 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);
297 created_by_local = true;
300 if (IS_LOCAL(user) && override == false)
302 ModResult MOD_RESULT;
303 FIRST_MOD_RESULT(Instance, OnUserPreJoin, MOD_RESULT, (user, NULL, cname, privs, key ? key : ""));
304 if (MOD_RESULT == MOD_RES_DENY)
308 Ptr = new Channel(Instance, cname, TS);
312 /* Already on the channel */
313 if (Ptr->HasUser(user))
317 * remote users are allowed us to bypass channel modes
318 * and bans (used by servers)
320 if (IS_LOCAL(user) && override == false)
322 ModResult MOD_RESULT;
323 FIRST_MOD_RESULT(Instance, OnUserPreJoin, MOD_RESULT, (user, Ptr, cname, privs, key ? key : ""));
324 if (MOD_RESULT == MOD_RES_DENY)
328 else if (MOD_RESULT == MOD_RES_PASSTHRU)
330 std::string ckey = Ptr->GetModeParameter('k');
331 bool invited = user->IsInvited(Ptr->name.c_str());
332 bool can_bypass = Instance->Config->InvBypassModes && invited;
336 FIRST_MOD_RESULT(Instance, OnCheckKey, MOD_RESULT, (user, Ptr, key ? key : ""));
337 if (!MOD_RESULT.check((key && ckey == key) || can_bypass))
339 // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
340 user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
345 if (Ptr->IsModeSet('i'))
347 FIRST_MOD_RESULT(Instance, OnCheckInvite, MOD_RESULT, (user, Ptr));
348 if (!MOD_RESULT.check(invited))
350 user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
355 std::string limit = Ptr->GetModeParameter('l');
358 FIRST_MOD_RESULT(Instance, OnCheckLimit, MOD_RESULT, (user, Ptr));
359 if (!MOD_RESULT.check((Ptr->GetUserCounter() < atol(limit.c_str()) || can_bypass)))
361 user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
366 if (Ptr->IsBanned(user) && !can_bypass)
368 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
373 * If the user has invites for this channel, remove them now
374 * after a successful join so they don't build up.
378 user->RemoveInvite(Ptr->name.c_str());
384 if (created_by_local)
386 /* As spotted by jilles, dont bother to set this on remote users */
387 Ptr->SetDefaultModes();
390 return Channel::ForceChan(Instance, Ptr, user, privs, bursting, created_by_local);
393 Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting, bool created)
395 std::string nick = user->nick;
400 /* Just in case they have no permissions */
401 user->chans[Ptr] = 0;
403 for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
405 const char status = *x;
406 ModeHandler* mh = Instance->Modes->FindPrefix(status);
409 /* Set, and make sure that the mode handler knows this mode was now set */
410 Ptr->SetPrefix(user, status, mh->GetPrefixRank(), true);
411 mh->OnModeChange(Instance->FakeClient, Instance->FakeClient, Ptr, nick, true);
413 switch (mh->GetPrefix())
415 /* These logic ops are SAFE IN THIS CASE because if the entry doesnt exist,
416 * addressing operator[] creates it. If they do exist, it points to it.
417 * At all other times where we dont want to create an item if it doesnt exist, we
418 * must stick to ::find().
421 user->chans[Ptr] |= UCMODE_OP;
424 user->chans[Ptr] |= UCMODE_HOP;
427 user->chans[Ptr] |= UCMODE_VOICE;
433 FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user, Ptr, bursting, silent, created));
436 Ptr->WriteChannel(user,"JOIN :%s",Ptr->name.c_str());
438 /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
439 std::string ms = Instance->Modes->ModeString(user, Ptr);
440 if ((Ptr->GetUserCounter() > 1) && (ms.length()))
441 Ptr->WriteAllExceptSender(user, true, 0, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
443 /* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
448 user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
449 user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
453 FOREACH_MOD_I(Instance,I_OnPostJoin,OnPostJoin(user, Ptr));
457 bool Channel::IsBanned(User* user)
460 DO_EACH_HOOK(ServerInstance, OnCheckBan, ModResult modresult, (user, this))
462 result = result + modresult;
464 WHILE_EACH_HOOK(ServerInstance, OnCheckBan);
466 if (result != MOD_RES_PASSTHRU)
467 return (result == MOD_RES_DENY);
470 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
471 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
473 if ((InspIRCd::Match(user->GetFullHost(),i->data, NULL)) || // host
474 (InspIRCd::Match(user->GetFullRealHost(),i->data, NULL)) || // uncloaked host
475 (InspIRCd::MatchCIDR(mask, i->data, NULL))) // ip
483 ModResult Channel::GetExtBanStatus(const std::string &str, char type)
486 DO_EACH_HOOK(ServerInstance, OnCheckStringExtBan, ModResult modresult, (str, this, type))
488 result = result + modresult;
490 WHILE_EACH_HOOK(ServerInstance, OnCheckStringExtBan);
492 if (result != MOD_RES_PASSTHRU)
495 // nobody decided for us, check the ban list
496 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
498 if (i->data[0] != type || i->data[1] != ':')
501 std::string maskptr = i->data.substr(2);
502 ServerInstance->Logs->Log("EXTBANS", DEBUG, "Checking %s against %s, type is %c", str.c_str(), maskptr.c_str(), type);
504 if (InspIRCd::Match(str, maskptr, NULL))
508 return MOD_RES_PASSTHRU;
511 ModResult Channel::GetExtBanStatus(User *user, char type)
514 DO_EACH_HOOK(ServerInstance, OnCheckExtBan, ModResult modresult, (user, this, type))
518 WHILE_EACH_HOOK(ServerInstance, OnCheckExtBan);
520 if (rv != MOD_RES_PASSTHRU)
524 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
526 rv = rv + this->GetExtBanStatus(mask, type);
527 rv = rv + this->GetExtBanStatus(user->GetFullHost(), type);
528 rv = rv + this->GetExtBanStatus(user->GetFullRealHost(), type);
533 * remove a channel from a users record, and return the number of users left.
534 * Therefore, if this function returns 0 the caller should delete the Channel.
536 long Channel::PartUser(User *user, std::string &reason)
541 return this->GetUserCounter();
543 UCListIter i = user->chans.find(this);
544 if (i != user->chans.end())
546 FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason, silent));
549 this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
551 user->chans.erase(i);
552 this->RemoveAllPrefixes(user);
555 if (!this->DelUser(user)) /* if there are no users left on the channel... */
557 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
558 /* kill the record */
559 if (iter != ServerInstance->chanlist->end())
562 FIRST_MOD_RESULT(ServerInstance, OnChannelPreDelete, res, (this));
563 if (res == MOD_RES_DENY)
564 return 1; // delete halted by module
565 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
566 ServerInstance->chanlist->erase(iter);
571 return this->GetUserCounter();
574 long Channel::ServerKickUser(User* user, const char* reason, const char* servername)
576 if (servername == NULL || *ServerInstance->Config->HideWhoisServer)
577 servername = ServerInstance->Config->ServerName;
579 ServerInstance->FakeClient->server = servername;
580 return this->KickUser(ServerInstance->FakeClient, user, reason);
583 long Channel::KickUser(User *src, User *user, const char* reason)
587 if (!src || !user || !reason)
588 return this->GetUserCounter();
592 if (!this->HasUser(user))
594 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());
595 return this->GetUserCounter();
597 if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
599 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());
600 return this->GetUserCounter();
604 if (ServerInstance->ULine(src->server))
606 if (res == MOD_RES_PASSTHRU)
607 FIRST_MOD_RESULT(ServerInstance, OnUserPreKick, res, (src,user,this,reason));
608 if (res == MOD_RES_PASSTHRU)
609 FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, res, (src,user,this,AC_KICK));
611 if (res == MOD_RES_DENY)
612 return this->GetUserCounter();
614 if (res == MOD_RES_PASSTHRU)
616 int them = this->GetStatus(src);
617 int us = this->GetStatus(user);
618 if ((them < STATUS_HOP) || (them < us))
620 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them == STATUS_HOP ? "" : "half-");
621 return this->GetUserCounter();
626 FOREACH_MOD(I_OnUserKick,OnUserKick(src, user, this, reason, silent));
628 UCListIter i = user->chans.find(this);
629 if (i != user->chans.end())
631 /* zap it from the channel list of the user */
633 this->WriteChannel(src, "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))
640 /* if there are no users left on the channel */
642 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name.c_str());
644 /* kill the record */
645 if (iter != ServerInstance->chanlist->end())
648 FIRST_MOD_RESULT(ServerInstance, OnChannelPreDelete, res, (this));
649 if (res == MOD_RES_DENY)
650 return 1; // delete halted by module
651 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
652 ServerInstance->chanlist->erase(iter);
657 return this->GetUserCounter();
660 void Channel::WriteChannel(User* user, const char* text, ...)
662 char textbuffer[MAXBUF];
668 va_start(argsPtr, text);
669 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
672 this->WriteChannel(user, std::string(textbuffer));
675 void Channel::WriteChannel(User* user, const std::string &text)
677 CUList *ulist = this->GetUsers();
683 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
684 std::string out = tb;
686 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
688 if (IS_LOCAL(i->first))
689 i->first->Write(out);
693 void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...)
695 char textbuffer[MAXBUF];
701 va_start(argsPtr, text);
702 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
705 this->WriteChannelWithServ(ServName, std::string(textbuffer));
708 void Channel::WriteChannelWithServ(const char* ServName, const std::string &text)
710 CUList *ulist = this->GetUsers();
713 snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str());
714 std::string out = tb;
716 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
718 if (IS_LOCAL(i->first))
719 i->first->Write(out);
723 /* write formatted text from a source user to all users on a channel except
724 * for the sender (for privmsg etc) */
725 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
727 char textbuffer[MAXBUF];
733 va_start(argsPtr, text);
734 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
737 this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
740 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
742 char textbuffer[MAXBUF];
748 int offset = snprintf(textbuffer,MAXBUF,":%s ", user->GetFullHost().c_str());
750 va_start(argsPtr, text);
751 vsnprintf(textbuffer + offset, MAXBUF - offset, text, argsPtr);
754 this->RawWriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
757 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
761 snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName : user->GetFullHost().c_str(), text.c_str());
762 std::string out = tb;
764 this->RawWriteAllExcept(user, serversource, status, except_list, std::string(tb));
767 void Channel::RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &out)
769 CUList *ulist = this->GetUsers();
770 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
772 if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
774 /* User doesnt have the status we're after */
775 if (status && !strchr(this->GetAllPrefixChars(i->first), status))
778 i->first->Write(out);
783 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
786 except_list[user] = user->nick;
787 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
791 * return a count of the users on a specific channel accounting for
792 * invisible users who won't increase the count. e.g. for /LIST
794 int Channel::CountInvisible()
797 CUList *ulist= this->GetUsers();
798 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
800 if (!(i->first->IsModeSet('i')))
807 char* Channel::ChanModes(bool showkey)
809 static char scratch[MAXBUF];
810 static char sparam[MAXBUF];
811 char* offset = scratch;
812 std::string extparam;
817 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
818 for(int n = 0; n < 64; n++)
827 // Unfortunately this must be special-cased, as we definitely don't want to always display key.
830 extparam = this->GetModeParameter('k');
843 /* We know these have no parameters */
846 extparam = this->GetModeParameter(n + 65);
849 if (!extparam.empty())
851 charlcat(sparam,' ',MAXBUF);
852 strlcat(sparam,extparam.c_str(),MAXBUF);
857 /* Null terminate scratch */
859 strlcat(scratch,sparam,MAXBUF);
863 /* compile a userlist of a channel into a string, each nick seperated by
864 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
866 void Channel::UserList(User *user, CUList *ulist)
870 ModResult call_modules;
875 FIRST_MOD_RESULT(ServerInstance, OnUserList, call_modules, (user, this, ulist));
877 if (call_modules != MOD_RES_ALLOW)
879 if ((this->IsModeSet('s')) && (!this->HasUser(user)))
881 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
886 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
889 char* ptr = list + dlen;
892 ulist = this->GetUsers();
894 /* Improvement by Brain - this doesnt change in value, so why was it inside
897 bool has_user = this->HasUser(user);
899 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
901 if ((!has_user) && (i->first->IsModeSet('i')))
904 * user is +i, and source not on the channel, does not show
910 std::string prefixlist = this->GetPrefixChar(i->first);
911 std::string nick = i->first->nick;
913 if (call_modules != MOD_RES_DENY)
915 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->first, this, prefixlist, nick));
917 /* Nick was nuked, a module wants us to skip it */
924 if (curlen + prefixlist.length() + nick.length() + 1 > 480)
926 /* list overflowed into multiple numerics */
927 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
929 /* reset our lengths */
930 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
937 ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
945 /* if whats left in the list isnt empty, send it */
948 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
951 user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
954 long Channel::GetMaxBans()
956 /* Return the cached value if there is one */
958 return this->maxbans;
960 /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
961 for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
963 if (InspIRCd::Match(this->name, n->first, NULL))
965 this->maxbans = n->second;
970 /* Screw it, just return the default of 64 */
972 return this->maxbans;
975 void Channel::ResetMaxBans()
980 /* returns the status character for a given user on a channel, e.g. @ for op,
981 * % for halfop etc. If the user has several modes set, the highest mode
982 * the user has must be returned.
984 const char* Channel::GetPrefixChar(User *user)
986 static char pf[2] = {0, 0};
988 prefixlist::iterator n = prefixes.find(user);
989 if (n != prefixes.end())
991 if (n->second.size())
993 /* If the user has any prefixes, their highest prefix
994 * will always be at the head of the list, as the list is
995 * sorted in rank order highest first (see SetPrefix()
998 *pf = n->second.begin()->first;
1008 const char* Channel::GetAllPrefixChars(User* user)
1010 static char prefix[MAXBUF];
1014 prefixlist::iterator n = prefixes.find(user);
1015 if (n != prefixes.end())
1017 for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
1019 prefix[ctr++] = x->first;
1028 unsigned int Channel::GetPrefixValue(User* user)
1030 prefixlist::iterator n = prefixes.find(user);
1031 if (n != prefixes.end())
1033 if (n->second.size())
1034 return n->second.begin()->second;
1039 int Channel::GetStatusFlags(User *user)
1041 UCListIter i = user->chans.find(this);
1042 if (i != user->chans.end())
1049 int Channel::GetStatus(User *user)
1051 if (ServerInstance->ULine(user->server))
1054 UCListIter i = user->chans.find(this);
1055 if (i != user->chans.end())
1057 if ((i->second & UCMODE_OP) > 0)
1061 if ((i->second & UCMODE_HOP) > 0)
1065 if ((i->second & UCMODE_VOICE) > 0)
1067 return STATUS_VOICE;
1069 return STATUS_NORMAL;
1071 return STATUS_NORMAL;
1074 void Channel::SetPrefix(User* user, char prefix, unsigned int prefix_value, bool adding)
1076 prefixlist::iterator n = prefixes.find(user);
1077 prefixtype pfx = std::make_pair(prefix,prefix_value);
1080 if (n != prefixes.end())
1082 if (std::find(n->second.begin(), n->second.end(), pfx) == n->second.end())
1084 n->second.push_back(pfx);
1085 /* We must keep prefixes in rank order, largest first.
1086 * This is for two reasons, firstly because x-chat *ass-u-me's* this
1087 * state, and secondly it turns out to be a benefit to us later.
1088 * See above in GetPrefix().
1090 std::sort(n->second.begin(), n->second.end(), ModeParser::PrefixComparison);
1097 prefixes.insert(std::make_pair<User*,pfxcontainer>(user, one));
1102 if (n != prefixes.end())
1104 pfxcontainer::iterator x = std::find(n->second.begin(), n->second.end(), pfx);
1105 if (x != n->second.end())
1111 void Channel::RemoveAllPrefixes(User* user)
1113 prefixlist::iterator n = prefixes.find(user);
1114 if (n != prefixes.end())