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 * ---------------------------------------------------
21 Channel::Channel(InspIRCd* Instance, const std::string &cname, time_t ts) : ServerInstance(Instance)
23 chan_hash::iterator findchan = ServerInstance->chanlist->find(cname);
24 if (findchan != Instance->chanlist->end())
25 throw CoreException("Cannot create duplicate channel " + cname);
27 (*(ServerInstance->chanlist))[cname.c_str()] = this;
28 this->name.assign(cname, 0, ServerInstance->Config->Limits.ChanMax);
29 this->created = ts ? ts : ServerInstance->Time();
30 this->age = this->created;
32 maxbans = topicset = 0;
36 void Channel::SetMode(char mode,bool mode_on)
38 modes[mode-65] = mode_on;
40 this->SetModeParam(mode,"",false);
44 void Channel::SetModeParam(char mode,const char* parameter,bool mode_on)
46 CustomModeList::iterator n = custom_mode_params.find(mode);
50 if (n == custom_mode_params.end())
51 custom_mode_params[mode] = strdup(parameter);
55 if (n != custom_mode_params.end())
58 custom_mode_params.erase(n);
63 bool Channel::IsModeSet(char mode)
65 return modes[mode-65];
68 std::string Channel::GetModeParameter(char mode)
70 CustomModeList::iterator n = custom_mode_params.find(mode);
71 if (n != custom_mode_params.end())
76 int Channel::SetTopic(User *u, std::string &ntopic, bool forceset)
83 /* 0: check status, 1: don't, -1: disallow change silently */
85 FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(u,this,ntopic));
89 else if (MOD_RESULT == 0)
91 if (!this->HasUser(u))
93 u->WriteNumeric(442, "%s %s :You're not on that channel!",u->nick.c_str(), this->name.c_str());
96 if ((this->IsModeSet('t')) && (this->GetStatus(u) < STATUS_HOP))
98 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());
105 this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic);
106 this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128);
107 this->topicset = ServerInstance->Time();
108 this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
112 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(u, this, this->topic));
118 long Channel::GetUserCounter()
120 return (this->internal_userlist.size());
123 void Channel::AddUser(User* user)
125 internal_userlist[user] = user->nick;
128 unsigned long Channel::DelUser(User* user)
130 CUListIter a = internal_userlist.find(user);
132 if (a != internal_userlist.end())
134 internal_userlist.erase(a);
135 /* And tidy any others... */
137 DelHalfoppedUser(user);
141 return internal_userlist.size();
144 bool Channel::HasUser(User* user)
146 return (internal_userlist.find(user) != internal_userlist.end());
149 void Channel::AddOppedUser(User* user)
151 internal_op_userlist[user] = user->nick;
154 void Channel::DelOppedUser(User* user)
156 CUListIter a = internal_op_userlist.find(user);
157 if (a != internal_op_userlist.end())
159 internal_op_userlist.erase(a);
164 void Channel::AddHalfoppedUser(User* user)
166 internal_halfop_userlist[user] = user->nick;
169 void Channel::DelHalfoppedUser(User* user)
171 CUListIter a = internal_halfop_userlist.find(user);
173 if (a != internal_halfop_userlist.end())
175 internal_halfop_userlist.erase(a);
179 void Channel::AddVoicedUser(User* user)
181 internal_voice_userlist[user] = user->nick;
184 void Channel::DelVoicedUser(User* user)
186 CUListIter a = internal_voice_userlist.find(user);
188 if (a != internal_voice_userlist.end())
190 internal_voice_userlist.erase(a);
194 CUList* Channel::GetUsers()
196 return &internal_userlist;
199 CUList* Channel::GetOppedUsers()
201 return &internal_op_userlist;
204 CUList* Channel::GetHalfoppedUsers()
206 return &internal_halfop_userlist;
209 CUList* Channel::GetVoicedUsers()
211 return &internal_voice_userlist;
214 void Channel::SetDefaultModes()
216 ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes);
217 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
219 std::string parameter;
221 list.GetToken(modeseq);
223 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
225 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
228 if (mode->GetNumParams(true))
229 list.GetToken(parameter);
233 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
239 * add a channel to a user, creating the record for it if needed and linking
240 * it to the user record
242 Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
253 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
254 * We restrict local users to MaxChans channels.
255 * We restrict local operators to OperMaxChans channels.
256 * This is a lot more logical than how it was formerly. -- w00t
258 if (IS_LOCAL(user) && !override)
260 // Checking MyClass exists because we *may* get here with NULL, not 100% sure.
261 if (user->MyClass && user->MyClass->GetMaxChans())
263 if (user->chans.size() >= user->MyClass->GetMaxChans())
265 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
273 if (user->chans.size() >= Instance->Config->OperMaxChans)
275 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
281 if (user->chans.size() >= Instance->Config->MaxChans)
283 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
290 strlcpy(cname, cn, Instance->Config->Limits.ChanMax);
291 Ptr = Instance->FindChan(cname);
296 * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
301 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);
308 if (IS_LOCAL(user) && override == false)
311 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, NULL, cname, privs, key ? key : ""));
316 Ptr = new Channel(Instance, cname, TS);
320 /* Already on the channel */
321 if (Ptr->HasUser(user))
325 * remote users are allowed us to bypass channel modes
326 * and bans (used by servers)
328 if (IS_LOCAL(user) && override == false)
331 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, Ptr, cname, privs, key ? key : ""));
336 else if (MOD_RESULT == 0)
338 std::string ckey = Ptr->GetModeParameter('k');
342 FOREACH_RESULT_I(Instance, I_OnCheckKey, OnCheckKey(user, Ptr, key ? key : ""));
345 if ((!key) || ckey != key)
347 user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
352 if (Ptr->IsModeSet('i'))
355 FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr));
358 if (!user->IsInvited(Ptr->name.c_str()))
360 user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
364 user->RemoveInvite(Ptr->name.c_str());
367 std::string limit = Ptr->GetModeParameter('l');
371 FOREACH_RESULT_I(Instance, I_OnCheckLimit, OnCheckLimit(user, Ptr));
374 long llimit = atol(limit.c_str());
375 if (Ptr->GetUserCounter() >= llimit)
377 user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
383 if (Ptr->bans.size())
385 if (Ptr->IsBanned(user))
387 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
395 /* As spotted by jilles, dont bother to set this on remote users */
396 if (IS_LOCAL(user) && Ptr->GetUserCounter() == 0)
397 Ptr->SetDefaultModes();
399 return Channel::ForceChan(Instance, Ptr, user, privs, bursting);
402 Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting)
404 std::string nick = user->nick;
409 /* Just in case they have no permissions */
410 user->chans[Ptr] = 0;
412 for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
414 const char status = *x;
415 ModeHandler* mh = Instance->Modes->FindPrefix(status);
418 /* Set, and make sure that the mode handler knows this mode was now set */
419 Ptr->SetPrefix(user, status, mh->GetPrefixRank(), true);
420 mh->OnModeChange(Instance->FakeClient, Instance->FakeClient, Ptr, nick, true);
422 switch (mh->GetPrefix())
424 /* These logic ops are SAFE IN THIS CASE because if the entry doesnt exist,
425 * addressing operator[] creates it. If they do exist, it points to it.
426 * At all other times where we dont want to create an item if it doesnt exist, we
427 * must stick to ::find().
430 user->chans[Ptr] |= UCMODE_OP;
433 user->chans[Ptr] |= UCMODE_HOP;
436 user->chans[Ptr] |= UCMODE_VOICE;
442 FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user, Ptr, bursting, silent));
445 Ptr->WriteChannel(user,"JOIN :%s",Ptr->name.c_str());
447 /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
448 std::string ms = Instance->Modes->ModeString(user, Ptr);
449 if ((Ptr->GetUserCounter() > 1) && (ms.length()))
450 Ptr->WriteAllExceptSender(user, true, 0, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
452 /* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
457 user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
458 user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
462 FOREACH_MOD_I(Instance,I_OnPostJoin,OnPostJoin(user, Ptr));
466 bool Channel::IsBanned(User* user)
470 FOREACH_RESULT(I_OnCheckBan,OnCheckBan(user, this));
472 if (MOD_RESULT == -1)
474 else if (MOD_RESULT == 0)
476 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
477 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
479 /* This allows CIDR ban matching
481 * Full masked host Full unmasked host IP with/without CIDR
483 if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
492 bool Channel::IsExtBanned(const std::string &str, char type)
495 FOREACH_RESULT(I_OnCheckStringExtBan, OnCheckStringExtBan(str, this, type));
497 if (MOD_RESULT == -1)
499 else if (MOD_RESULT == 0)
501 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
503 if (i->data[0] != type || i->data[1] != ':')
506 // Iterate past char and : to get to the mask without doing a data copy(!)
507 std::string maskptr = i->data.substr(2);
508 ServerInstance->Logs->Log("EXTBANS", DEBUG, "Checking %s against %s, type is %c", str.c_str(), maskptr.c_str(), type);
510 if (match(str, maskptr))
518 bool Channel::IsExtBanned(User *user, char type)
521 FOREACH_RESULT(I_OnCheckExtBan, OnCheckExtBan(user, this, type));
523 if (MOD_RESULT == -1)
525 else if (MOD_RESULT == 0)
528 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
530 // XXX: we should probably hook cloaked hosts in here somehow too..
531 if (this->IsExtBanned(mask, type))
534 if (this->IsExtBanned(user->GetFullHost(), type))
537 if (this->IsExtBanned(user->GetFullRealHost(), type))
545 * remove a channel from a users record, and return the number of users left.
546 * Therefore, if this function returns 0 the caller should delete the Channel.
548 * XXX: bleh, string copy of reason, fixme! -- w00t
550 long Channel::PartUser(User *user, std::string &reason)
555 return this->GetUserCounter();
557 UCListIter i = user->chans.find(this);
558 if (i != user->chans.end())
560 FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason, silent));
563 this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
565 user->chans.erase(i);
566 this->RemoveAllPrefixes(user);
569 if (!this->DelUser(user)) /* if there are no users left on the channel... */
571 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
572 /* kill the record */
573 if (iter != ServerInstance->chanlist->end())
576 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
578 return 1; // delete halted by module
579 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
580 ServerInstance->chanlist->erase(iter);
585 return this->GetUserCounter();
588 long Channel::ServerKickUser(User* user, const char* reason, bool triggerevents, const char* servername)
592 if (!user || !reason)
593 return this->GetUserCounter();
597 if (!this->HasUser(user))
600 return this->GetUserCounter();
604 if (servername == NULL || *ServerInstance->Config->HideWhoisServer)
605 servername = ServerInstance->Config->ServerName;
609 FOREACH_MOD(I_OnUserKick,OnUserKick(NULL, user, this, reason, silent));
612 UCListIter i = user->chans.find(this);
613 if (i != user->chans.end())
616 this->WriteChannelWithServ(servername, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
618 user->chans.erase(i);
619 this->RemoveAllPrefixes(user);
622 if (!this->DelUser(user))
624 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
625 /* kill the record */
626 if (iter != ServerInstance->chanlist->end())
629 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
631 return 1; // delete halted by module
632 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
633 ServerInstance->chanlist->erase(iter);
638 return this->GetUserCounter();
641 long Channel::KickUser(User *src, User *user, const char* reason)
645 if (!src || !user || !reason)
646 return this->GetUserCounter();
650 if (!this->HasUser(user))
652 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());
653 return this->GetUserCounter();
655 if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
657 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());
658 return this->GetUserCounter();
662 if (!ServerInstance->ULine(src->server))
665 FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,this,reason));
667 return this->GetUserCounter();
669 /* Set to -1 by OnUserPreKick if explicit allow was set */
670 if (MOD_RESULT != -1)
672 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,this,AC_KICK));
673 if ((MOD_RESULT == ACR_DENY) && (!ServerInstance->ULine(src->server)))
674 return this->GetUserCounter();
676 if ((MOD_RESULT == ACR_DEFAULT) || (!ServerInstance->ULine(src->server)))
678 int them = this->GetStatus(src);
679 int us = this->GetStatus(user);
680 if ((them < STATUS_HOP) || (them < us))
682 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them == STATUS_HOP ? "" : "half-");
683 return this->GetUserCounter();
689 FOREACH_MOD(I_OnUserKick,OnUserKick(src, user, this, reason, silent));
691 UCListIter i = user->chans.find(this);
692 if (i != user->chans.end())
694 /* zap it from the channel list of the user */
696 this->WriteChannel(src, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
698 user->chans.erase(i);
699 this->RemoveAllPrefixes(user);
702 if (!this->DelUser(user))
703 /* if there are no users left on the channel */
705 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name.c_str());
707 /* kill the record */
708 if (iter != ServerInstance->chanlist->end())
711 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
713 return 1; // delete halted by module
714 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
715 ServerInstance->chanlist->erase(iter);
720 return this->GetUserCounter();
723 void Channel::WriteChannel(User* user, const char* text, ...)
725 char textbuffer[MAXBUF];
731 va_start(argsPtr, text);
732 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
735 this->WriteChannel(user, std::string(textbuffer));
738 void Channel::WriteChannel(User* user, const std::string &text)
740 CUList *ulist = this->GetUsers();
746 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
747 std::string out = tb;
749 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
751 if (IS_LOCAL(i->first))
752 i->first->Write(out);
756 void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...)
758 char textbuffer[MAXBUF];
764 va_start(argsPtr, text);
765 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
768 this->WriteChannelWithServ(ServName, std::string(textbuffer));
771 void Channel::WriteChannelWithServ(const char* ServName, const std::string &text)
773 CUList *ulist = this->GetUsers();
776 snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str());
777 std::string out = tb;
779 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
781 if (IS_LOCAL(i->first))
782 i->first->Write(out);
786 /* write formatted text from a source user to all users on a channel except
787 * for the sender (for privmsg etc) */
788 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
790 char textbuffer[MAXBUF];
796 va_start(argsPtr, text);
797 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
800 this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
803 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
805 char textbuffer[MAXBUF];
811 va_start(argsPtr, text);
812 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
815 this->WriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
818 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
820 CUList *ulist = this->GetUsers();
823 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
824 std::string out = tb;
826 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
828 if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
830 /* User doesnt have the status we're after */
831 if (status && !strchr(this->GetAllPrefixChars(i->first), status))
835 i->first->WriteServ(text);
837 i->first->Write(out);
842 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
845 except_list[user] = user->nick;
846 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
850 * return a count of the users on a specific channel accounting for
851 * invisible users who won't increase the count. e.g. for /LIST
853 int Channel::CountInvisible()
856 CUList *ulist= this->GetUsers();
857 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
859 if (!(i->first->IsModeSet('i')))
866 char* Channel::ChanModes(bool showkey)
868 static char scratch[MAXBUF];
869 static char sparam[MAXBUF];
870 char* offset = scratch;
871 std::string extparam;
876 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
877 for(int n = 0; n < 64; n++)
886 // Unfortunately this must be special-cased, as we definitely don't want to always display key.
889 extparam = this->GetModeParameter('k');
902 /* We know these have no parameters */
905 extparam = this->GetModeParameter(n + 65);
908 if (!extparam.empty())
910 charlcat(sparam,' ',MAXBUF);
911 strlcat(sparam,extparam.c_str(),MAXBUF);
916 /* Null terminate scratch */
918 strlcat(scratch,sparam,MAXBUF);
922 /* compile a userlist of a channel into a string, each nick seperated by
923 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
925 void Channel::UserList(User *user, CUList *ulist)
930 bool call_modules = true;
935 FOREACH_RESULT(I_OnUserList,OnUserList(user, this, ulist));
937 call_modules = false;
939 if (MOD_RESULT != -1)
941 if ((this->IsModeSet('s')) && (!this->HasUser(user)))
943 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
948 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
951 char* ptr = list + dlen;
954 ulist = this->GetUsers();
956 /* Improvement by Brain - this doesnt change in value, so why was it inside
959 bool has_user = this->HasUser(user);
961 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
963 if ((!has_user) && (i->first->IsModeSet('i')))
966 * user is +i, and source not on the channel, does not show
972 if (i->first->Visibility && !i->first->Visibility->VisibleTo(user))
975 std::string prefixlist = this->GetPrefixChar(i->first);
976 std::string nick = i->first->nick;
980 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->first, this, prefixlist, nick));
982 /* Nick was nuked, a module wants us to skip it */
989 if (curlen + prefixlist.length() + nick.length() + 1 > 480)
991 /* list overflowed into multiple numerics */
992 user->WriteServ(std::string(list));
994 /* reset our lengths */
995 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
1002 ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
1010 /* if whats left in the list isnt empty, send it */
1013 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
1016 user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
1019 long Channel::GetMaxBans()
1021 /* Return the cached value if there is one */
1023 return this->maxbans;
1025 /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
1026 for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
1028 if (match(this->name,n->first))
1030 this->maxbans = n->second;
1035 /* Screw it, just return the default of 64 */
1037 return this->maxbans;
1040 void Channel::ResetMaxBans()
1045 /* returns the status character for a given user on a channel, e.g. @ for op,
1046 * % for halfop etc. If the user has several modes set, the highest mode
1047 * the user has must be returned.
1049 const char* Channel::GetPrefixChar(User *user)
1051 static char pf[2] = {0, 0};
1053 prefixlist::iterator n = prefixes.find(user);
1054 if (n != prefixes.end())
1056 if (n->second.size())
1058 /* If the user has any prefixes, their highest prefix
1059 * will always be at the head of the list, as the list is
1060 * sorted in rank order highest first (see SetPrefix()
1063 *pf = n->second.begin()->first;
1073 const char* Channel::GetAllPrefixChars(User* user)
1075 static char prefix[MAXBUF];
1079 prefixlist::iterator n = prefixes.find(user);
1080 if (n != prefixes.end())
1082 for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
1084 prefix[ctr++] = x->first;
1093 unsigned int Channel::GetPrefixValue(User* user)
1095 prefixlist::iterator n = prefixes.find(user);
1096 if (n != prefixes.end())
1098 if (n->second.size())
1099 return n->second.begin()->second;
1104 int Channel::GetStatusFlags(User *user)
1106 UCListIter i = user->chans.find(this);
1107 if (i != user->chans.end())
1114 int Channel::GetStatus(User *user)
1116 if (ServerInstance->ULine(user->server))
1119 UCListIter i = user->chans.find(this);
1120 if (i != user->chans.end())
1122 if ((i->second & UCMODE_OP) > 0)
1126 if ((i->second & UCMODE_HOP) > 0)
1130 if ((i->second & UCMODE_VOICE) > 0)
1132 return STATUS_VOICE;
1134 return STATUS_NORMAL;
1136 return STATUS_NORMAL;
1139 void Channel::SetPrefix(User* user, char prefix, unsigned int prefix_value, bool adding)
1141 prefixlist::iterator n = prefixes.find(user);
1142 prefixtype pfx = std::make_pair(prefix,prefix_value);
1145 if (n != prefixes.end())
1147 if (std::find(n->second.begin(), n->second.end(), pfx) == n->second.end())
1149 n->second.push_back(pfx);
1150 /* We must keep prefixes in rank order, largest first.
1151 * This is for two reasons, firstly because x-chat *ass-u-me's* this
1152 * state, and secondly it turns out to be a benefit to us later.
1153 * See above in GetPrefix().
1155 std::sort(n->second.begin(), n->second.end(), ModeParser::PrefixComparison);
1162 prefixes.insert(std::make_pair<User*,pfxcontainer>(user, one));
1167 if (n != prefixes.end())
1169 pfxcontainer::iterator x = std::find(n->second.begin(), n->second.end(), pfx);
1170 if (x != n->second.end())
1176 void Channel::RemoveAllPrefixes(User* user)
1178 prefixlist::iterator n = prefixes.find(user);
1179 if (n != prefixes.end())