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 if (u && IS_LOCAL(u))
109 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(u, this, this->topic));
115 long Channel::GetUserCounter()
117 return (this->internal_userlist.size());
120 void Channel::AddUser(User* user)
122 internal_userlist[user] = user->nick;
125 unsigned long Channel::DelUser(User* user)
127 CUListIter a = internal_userlist.find(user);
129 if (a != internal_userlist.end())
131 internal_userlist.erase(a);
132 /* And tidy any others... */
134 DelHalfoppedUser(user);
138 return internal_userlist.size();
141 bool Channel::HasUser(User* user)
143 return (internal_userlist.find(user) != internal_userlist.end());
146 void Channel::AddOppedUser(User* user)
148 internal_op_userlist[user] = user->nick;
151 void Channel::DelOppedUser(User* user)
153 CUListIter a = internal_op_userlist.find(user);
154 if (a != internal_op_userlist.end())
156 internal_op_userlist.erase(a);
161 void Channel::AddHalfoppedUser(User* user)
163 internal_halfop_userlist[user] = user->nick;
166 void Channel::DelHalfoppedUser(User* user)
168 CUListIter a = internal_halfop_userlist.find(user);
170 if (a != internal_halfop_userlist.end())
172 internal_halfop_userlist.erase(a);
176 void Channel::AddVoicedUser(User* user)
178 internal_voice_userlist[user] = user->nick;
181 void Channel::DelVoicedUser(User* user)
183 CUListIter a = internal_voice_userlist.find(user);
185 if (a != internal_voice_userlist.end())
187 internal_voice_userlist.erase(a);
191 CUList* Channel::GetUsers()
193 return &internal_userlist;
196 CUList* Channel::GetOppedUsers()
198 return &internal_op_userlist;
201 CUList* Channel::GetHalfoppedUsers()
203 return &internal_halfop_userlist;
206 CUList* Channel::GetVoicedUsers()
208 return &internal_voice_userlist;
211 void Channel::SetDefaultModes()
213 ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes);
214 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
216 std::string parameter;
218 list.GetToken(modeseq);
220 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
222 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
225 if (mode->GetNumParams(true))
226 list.GetToken(parameter);
230 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
236 * add a channel to a user, creating the record for it if needed and linking
237 * it to the user record
239 Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
241 // Fix: unregistered users could be joined using /SAJOIN
242 if (!user || !cn || user->registered != REG_ALL)
250 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
251 * We restrict local users to MaxChans channels.
252 * We restrict local operators to OperMaxChans channels.
253 * This is a lot more logical than how it was formerly. -- w00t
255 if (IS_LOCAL(user) && !override)
257 // Checking MyClass exists because we *may* get here with NULL, not 100% sure.
258 if (user->MyClass && user->MyClass->maxchans)
260 if (user->HasPrivPermission("channels/high-join-limit"))
262 if (user->chans.size() >= Instance->Config->OperMaxChans)
264 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
270 if (user->chans.size() >= user->MyClass->maxchans)
272 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
279 strlcpy(cname, cn, Instance->Config->Limits.ChanMax);
280 Ptr = Instance->FindChan(cname);
281 bool created_by_local = false;
286 * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
291 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);
296 created_by_local = true;
299 if (IS_LOCAL(user) && override == false)
301 ModResult MOD_RESULT;
302 FIRST_MOD_RESULT(Instance, OnUserPreJoin, MOD_RESULT, (user, NULL, cname, privs, key ? key : ""));
303 if (MOD_RESULT == MOD_RES_DENY)
307 Ptr = new Channel(Instance, cname, TS);
311 /* Already on the channel */
312 if (Ptr->HasUser(user))
316 * remote users are allowed us to bypass channel modes
317 * and bans (used by servers)
319 if (IS_LOCAL(user) && override == false)
321 ModResult MOD_RESULT;
322 FIRST_MOD_RESULT(Instance, OnUserPreJoin, MOD_RESULT, (user, Ptr, cname, privs, key ? key : ""));
323 if (MOD_RESULT == MOD_RES_DENY)
327 else if (MOD_RESULT == MOD_RES_PASSTHRU)
329 std::string ckey = Ptr->GetModeParameter('k');
330 bool invited = user->IsInvited(Ptr->name.c_str());
331 bool can_bypass = Instance->Config->InvBypassModes && invited;
335 FIRST_MOD_RESULT(Instance, OnCheckKey, MOD_RESULT, (user, Ptr, key ? key : ""));
336 if (!MOD_RESULT.check((key && ckey == key) || can_bypass))
338 // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
339 user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
344 if (Ptr->IsModeSet('i'))
346 FIRST_MOD_RESULT(Instance, OnCheckInvite, MOD_RESULT, (user, Ptr));
347 if (!MOD_RESULT.check(invited))
349 user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
354 std::string limit = Ptr->GetModeParameter('l');
357 FIRST_MOD_RESULT(Instance, OnCheckLimit, MOD_RESULT, (user, Ptr));
358 if (!MOD_RESULT.check((Ptr->GetUserCounter() < atol(limit.c_str()) || can_bypass)))
360 user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
365 if (Ptr->IsBanned(user) && !can_bypass)
367 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
372 * If the user has invites for this channel, remove them now
373 * after a successful join so they don't build up.
377 user->RemoveInvite(Ptr->name.c_str());
383 if (created_by_local)
385 /* As spotted by jilles, dont bother to set this on remote users */
386 Ptr->SetDefaultModes();
389 return Channel::ForceChan(Instance, Ptr, user, privs, bursting, created_by_local);
392 Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting, bool created)
394 std::string nick = user->nick;
399 /* Just in case they have no permissions */
400 user->chans[Ptr] = 0;
402 for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
404 const char status = *x;
405 ModeHandler* mh = Instance->Modes->FindPrefix(status);
408 /* Set, and make sure that the mode handler knows this mode was now set */
409 Ptr->SetPrefix(user, status, mh->GetPrefixRank(), true);
410 mh->OnModeChange(Instance->FakeClient, Instance->FakeClient, Ptr, nick, true);
412 switch (mh->GetPrefix())
414 /* These logic ops are SAFE IN THIS CASE because if the entry doesnt exist,
415 * addressing operator[] creates it. If they do exist, it points to it.
416 * At all other times where we dont want to create an item if it doesnt exist, we
417 * must stick to ::find().
420 user->chans[Ptr] |= UCMODE_OP;
423 user->chans[Ptr] |= UCMODE_HOP;
426 user->chans[Ptr] |= UCMODE_VOICE;
432 FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user, Ptr, bursting, silent, created));
435 Ptr->WriteChannel(user,"JOIN :%s",Ptr->name.c_str());
437 /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
438 std::string ms = Instance->Modes->ModeString(user, Ptr);
439 if ((Ptr->GetUserCounter() > 1) && (ms.length()))
440 Ptr->WriteAllExceptSender(user, true, 0, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
442 /* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
447 user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
448 user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
452 FOREACH_MOD_I(Instance,I_OnPostJoin,OnPostJoin(user, Ptr));
456 bool Channel::IsBanned(User* user)
459 DO_EACH_HOOK(ServerInstance, OnCheckBan, ModResult modresult, (user, this))
461 result = result + modresult;
463 WHILE_EACH_HOOK(ServerInstance, OnCheckBan);
465 if (result != MOD_RES_PASSTHRU)
466 return (result == MOD_RES_DENY);
469 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
470 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
472 if ((InspIRCd::Match(user->GetFullHost(),i->data, NULL)) || // host
473 (InspIRCd::Match(user->GetFullRealHost(),i->data, NULL)) || // uncloaked host
474 (InspIRCd::MatchCIDR(mask, i->data, NULL))) // ip
482 ModResult Channel::GetExtBanStatus(const std::string &str, char type)
485 DO_EACH_HOOK(ServerInstance, OnCheckStringExtBan, ModResult modresult, (str, this, type))
487 result = result + modresult;
489 WHILE_EACH_HOOK(ServerInstance, OnCheckStringExtBan);
491 if (result != MOD_RES_PASSTHRU)
494 // nobody decided for us, check the ban list
495 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
497 if (i->data[0] != type || i->data[1] != ':')
500 std::string maskptr = i->data.substr(2);
501 ServerInstance->Logs->Log("EXTBANS", DEBUG, "Checking %s against %s, type is %c", str.c_str(), maskptr.c_str(), type);
503 if (InspIRCd::Match(str, maskptr, NULL))
507 return MOD_RES_PASSTHRU;
510 ModResult Channel::GetExtBanStatus(User *user, char type)
513 DO_EACH_HOOK(ServerInstance, OnCheckExtBan, ModResult modresult, (user, this, type))
517 WHILE_EACH_HOOK(ServerInstance, OnCheckExtBan);
519 if (rv != MOD_RES_PASSTHRU)
523 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
525 rv = rv + this->GetExtBanStatus(mask, type);
526 rv = rv + this->GetExtBanStatus(user->GetFullHost(), type);
527 rv = rv + this->GetExtBanStatus(user->GetFullRealHost(), type);
532 * remove a channel from a users record, and return the number of users left.
533 * Therefore, if this function returns 0 the caller should delete the Channel.
535 long Channel::PartUser(User *user, std::string &reason)
540 return this->GetUserCounter();
542 UCListIter i = user->chans.find(this);
543 if (i != user->chans.end())
545 FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason, silent));
548 this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
550 user->chans.erase(i);
551 this->RemoveAllPrefixes(user);
554 if (!this->DelUser(user)) /* if there are no users left on the channel... */
556 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
557 /* kill the record */
558 if (iter != ServerInstance->chanlist->end())
561 FIRST_MOD_RESULT(ServerInstance, OnChannelPreDelete, res, (this));
562 if (res == MOD_RES_DENY)
563 return 1; // delete halted by module
564 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
565 ServerInstance->chanlist->erase(iter);
570 return this->GetUserCounter();
573 long Channel::ServerKickUser(User* user, const char* reason, const char* servername)
575 if (servername == NULL || *ServerInstance->Config->HideWhoisServer)
576 servername = ServerInstance->Config->ServerName;
578 ServerInstance->FakeClient->server = servername;
579 return this->KickUser(ServerInstance->FakeClient, user, reason);
582 long Channel::KickUser(User *src, User *user, const char* reason)
586 if (!src || !user || !reason)
587 return this->GetUserCounter();
591 if (!this->HasUser(user))
593 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());
594 return this->GetUserCounter();
596 if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
598 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());
599 return this->GetUserCounter();
603 if (ServerInstance->ULine(src->server))
605 if (res == MOD_RES_PASSTHRU)
606 FIRST_MOD_RESULT(ServerInstance, OnUserPreKick, res, (src,user,this,reason));
607 if (res == MOD_RES_PASSTHRU)
608 FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, res, (src,user,this,AC_KICK));
610 if (res == MOD_RES_DENY)
611 return this->GetUserCounter();
613 if (res == MOD_RES_PASSTHRU)
615 int them = this->GetStatus(src);
616 int us = this->GetStatus(user);
617 if ((them < STATUS_HOP) || (them < us))
619 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them == STATUS_HOP ? "" : "half-");
620 return this->GetUserCounter();
625 FOREACH_MOD(I_OnUserKick,OnUserKick(src, user, this, reason, silent));
627 UCListIter i = user->chans.find(this);
628 if (i != user->chans.end())
630 /* zap it from the channel list of the user */
632 this->WriteChannel(src, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
634 user->chans.erase(i);
635 this->RemoveAllPrefixes(user);
638 if (!this->DelUser(user))
639 /* if there are no users left on the channel */
641 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name.c_str());
643 /* kill the record */
644 if (iter != ServerInstance->chanlist->end())
647 FIRST_MOD_RESULT(ServerInstance, OnChannelPreDelete, res, (this));
648 if (res == MOD_RES_DENY)
649 return 1; // delete halted by module
650 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
651 ServerInstance->chanlist->erase(iter);
656 return this->GetUserCounter();
659 void Channel::WriteChannel(User* user, const char* text, ...)
661 char textbuffer[MAXBUF];
667 va_start(argsPtr, text);
668 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
671 this->WriteChannel(user, std::string(textbuffer));
674 void Channel::WriteChannel(User* user, const std::string &text)
676 CUList *ulist = this->GetUsers();
682 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
683 std::string out = tb;
685 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
687 if (IS_LOCAL(i->first))
688 i->first->Write(out);
692 void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...)
694 char textbuffer[MAXBUF];
700 va_start(argsPtr, text);
701 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
704 this->WriteChannelWithServ(ServName, std::string(textbuffer));
707 void Channel::WriteChannelWithServ(const char* ServName, const std::string &text)
709 CUList *ulist = this->GetUsers();
712 snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str());
713 std::string out = tb;
715 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
717 if (IS_LOCAL(i->first))
718 i->first->Write(out);
722 /* write formatted text from a source user to all users on a channel except
723 * for the sender (for privmsg etc) */
724 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
726 char textbuffer[MAXBUF];
732 va_start(argsPtr, text);
733 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
736 this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
739 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
741 char textbuffer[MAXBUF];
747 int offset = snprintf(textbuffer,MAXBUF,":%s ", user->GetFullHost().c_str());
749 va_start(argsPtr, text);
750 vsnprintf(textbuffer + offset, MAXBUF - offset, text, argsPtr);
753 this->RawWriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
756 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
760 snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName : user->GetFullHost().c_str(), text.c_str());
761 std::string out = tb;
763 this->RawWriteAllExcept(user, serversource, status, except_list, std::string(tb));
766 void Channel::RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &out)
768 CUList *ulist = this->GetUsers();
769 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
771 if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
773 /* User doesnt have the status we're after */
774 if (status && !strchr(this->GetAllPrefixChars(i->first), status))
777 i->first->Write(out);
782 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
785 except_list[user] = user->nick;
786 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
790 * return a count of the users on a specific channel accounting for
791 * invisible users who won't increase the count. e.g. for /LIST
793 int Channel::CountInvisible()
796 CUList *ulist= this->GetUsers();
797 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
799 if (!(i->first->IsModeSet('i')))
806 char* Channel::ChanModes(bool showkey)
808 static char scratch[MAXBUF];
809 static char sparam[MAXBUF];
810 char* offset = scratch;
811 std::string extparam;
816 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
817 for(int n = 0; n < 64; n++)
826 // Unfortunately this must be special-cased, as we definitely don't want to always display key.
829 extparam = this->GetModeParameter('k');
842 /* We know these have no parameters */
845 extparam = this->GetModeParameter(n + 65);
848 if (!extparam.empty())
850 charlcat(sparam,' ',MAXBUF);
851 strlcat(sparam,extparam.c_str(),MAXBUF);
856 /* Null terminate scratch */
858 strlcat(scratch,sparam,MAXBUF);
862 /* compile a userlist of a channel into a string, each nick seperated by
863 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
865 void Channel::UserList(User *user, CUList *ulist)
869 ModResult call_modules;
874 FIRST_MOD_RESULT(ServerInstance, OnUserList, call_modules, (user, this, ulist));
876 if (call_modules != MOD_RES_ALLOW)
878 if ((this->IsModeSet('s')) && (!this->HasUser(user)))
880 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
885 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
888 char* ptr = list + dlen;
891 ulist = this->GetUsers();
893 /* Improvement by Brain - this doesnt change in value, so why was it inside
896 bool has_user = this->HasUser(user);
898 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
900 if ((!has_user) && (i->first->IsModeSet('i')))
903 * user is +i, and source not on the channel, does not show
909 std::string prefixlist = this->GetPrefixChar(i->first);
910 std::string nick = i->first->nick;
912 if (call_modules != MOD_RES_DENY)
914 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->first, this, prefixlist, nick));
916 /* Nick was nuked, a module wants us to skip it */
923 if (curlen + prefixlist.length() + nick.length() + 1 > 480)
925 /* list overflowed into multiple numerics */
926 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
928 /* reset our lengths */
929 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
936 ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
944 /* if whats left in the list isnt empty, send it */
947 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
950 user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
953 long Channel::GetMaxBans()
955 /* Return the cached value if there is one */
957 return this->maxbans;
959 /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
960 for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
962 if (InspIRCd::Match(this->name, n->first, NULL))
964 this->maxbans = n->second;
969 /* Screw it, just return the default of 64 */
971 return this->maxbans;
974 void Channel::ResetMaxBans()
979 /* returns the status character for a given user on a channel, e.g. @ for op,
980 * % for halfop etc. If the user has several modes set, the highest mode
981 * the user has must be returned.
983 const char* Channel::GetPrefixChar(User *user)
985 static char pf[2] = {0, 0};
987 prefixlist::iterator n = prefixes.find(user);
988 if (n != prefixes.end())
990 if (n->second.size())
992 /* If the user has any prefixes, their highest prefix
993 * will always be at the head of the list, as the list is
994 * sorted in rank order highest first (see SetPrefix()
997 *pf = n->second.begin()->first;
1007 const char* Channel::GetAllPrefixChars(User* user)
1009 static char prefix[MAXBUF];
1013 prefixlist::iterator n = prefixes.find(user);
1014 if (n != prefixes.end())
1016 for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
1018 prefix[ctr++] = x->first;
1027 unsigned int Channel::GetPrefixValue(User* user)
1029 prefixlist::iterator n = prefixes.find(user);
1030 if (n != prefixes.end())
1032 if (n->second.size())
1033 return n->second.begin()->second;
1038 int Channel::GetStatusFlags(User *user)
1040 UCListIter i = user->chans.find(this);
1041 if (i != user->chans.end())
1048 int Channel::GetStatus(User *user)
1050 if (ServerInstance->ULine(user->server))
1053 UCListIter i = user->chans.find(this);
1054 if (i != user->chans.end())
1056 if ((i->second & UCMODE_OP) > 0)
1060 if ((i->second & UCMODE_HOP) > 0)
1064 if ((i->second & UCMODE_VOICE) > 0)
1066 return STATUS_VOICE;
1068 return STATUS_NORMAL;
1070 return STATUS_NORMAL;
1073 void Channel::SetPrefix(User* user, char prefix, unsigned int prefix_value, bool adding)
1075 prefixlist::iterator n = prefixes.find(user);
1076 prefixtype pfx = std::make_pair(prefix,prefix_value);
1079 if (n != prefixes.end())
1081 if (std::find(n->second.begin(), n->second.end(), pfx) == n->second.end())
1083 n->second.push_back(pfx);
1084 /* We must keep prefixes in rank order, largest first.
1085 * This is for two reasons, firstly because x-chat *ass-u-me's* this
1086 * state, and secondly it turns out to be a benefit to us later.
1087 * See above in GetPrefix().
1089 std::sort(n->second.begin(), n->second.end(), ModeParser::PrefixComparison);
1096 prefixes.insert(std::make_pair<User*,pfxcontainer>(user, one));
1101 if (n != prefixes.end())
1103 pfxcontainer::iterator x = std::find(n->second.begin(), n->second.end(), pfx);
1104 if (x != n->second.end())
1110 void Channel::RemoveAllPrefixes(User* user)
1112 prefixlist::iterator n = prefixes.find(user);
1113 if (n != prefixes.end())