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());
104 this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic);
107 this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128);
108 this->topicset = ServerInstance->Time();
109 this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
113 FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(u, this, this->topic));
119 long Channel::GetUserCounter()
121 return (this->internal_userlist.size());
124 void Channel::AddUser(User* user)
126 internal_userlist[user] = user->nick;
129 unsigned long Channel::DelUser(User* user)
131 CUListIter a = internal_userlist.find(user);
133 if (a != internal_userlist.end())
135 internal_userlist.erase(a);
136 /* And tidy any others... */
138 DelHalfoppedUser(user);
142 return internal_userlist.size();
145 bool Channel::HasUser(User* user)
147 return (internal_userlist.find(user) != internal_userlist.end());
150 void Channel::AddOppedUser(User* user)
152 internal_op_userlist[user] = user->nick;
155 void Channel::DelOppedUser(User* user)
157 CUListIter a = internal_op_userlist.find(user);
158 if (a != internal_op_userlist.end())
160 internal_op_userlist.erase(a);
165 void Channel::AddHalfoppedUser(User* user)
167 internal_halfop_userlist[user] = user->nick;
170 void Channel::DelHalfoppedUser(User* user)
172 CUListIter a = internal_halfop_userlist.find(user);
174 if (a != internal_halfop_userlist.end())
176 internal_halfop_userlist.erase(a);
180 void Channel::AddVoicedUser(User* user)
182 internal_voice_userlist[user] = user->nick;
185 void Channel::DelVoicedUser(User* user)
187 CUListIter a = internal_voice_userlist.find(user);
189 if (a != internal_voice_userlist.end())
191 internal_voice_userlist.erase(a);
195 CUList* Channel::GetUsers()
197 return &internal_userlist;
200 CUList* Channel::GetOppedUsers()
202 return &internal_op_userlist;
205 CUList* Channel::GetHalfoppedUsers()
207 return &internal_halfop_userlist;
210 CUList* Channel::GetVoicedUsers()
212 return &internal_voice_userlist;
215 void Channel::SetDefaultModes()
217 ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes);
218 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
220 std::string parameter;
222 list.GetToken(modeseq);
224 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
226 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
229 if (mode->GetNumParams(true))
230 list.GetToken(parameter);
234 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
240 * add a channel to a user, creating the record for it if needed and linking
241 * it to the user record
243 Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS)
254 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
255 * We restrict local users to MaxChans channels.
256 * We restrict local operators to OperMaxChans channels.
257 * This is a lot more logical than how it was formerly. -- w00t
259 if (IS_LOCAL(user) && !override)
261 // Checking MyClass exists because we *may* get here with NULL, not 100% sure.
262 if (user->MyClass && user->MyClass->GetMaxChans())
264 if (user->chans.size() >= user->MyClass->GetMaxChans())
266 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
274 if (user->chans.size() >= Instance->Config->OperMaxChans)
276 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
282 if (user->chans.size() >= Instance->Config->MaxChans)
284 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
291 strlcpy(cname, cn, Instance->Config->Limits.ChanMax);
292 Ptr = Instance->FindChan(cname);
297 * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
302 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);
309 if (IS_LOCAL(user) && override == false)
312 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, NULL, cname, privs, key ? key : ""));
317 Ptr = new Channel(Instance, cname, TS);
321 /* Already on the channel */
322 if (Ptr->HasUser(user))
326 * remote users are allowed us to bypass channel modes
327 * and bans (used by servers)
329 if (IS_LOCAL(user) && override == false)
332 FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, Ptr, cname, privs, key ? key : ""));
337 else if (MOD_RESULT == 0)
339 std::string ckey = Ptr->GetModeParameter('k');
343 FOREACH_RESULT_I(Instance, I_OnCheckKey, OnCheckKey(user, Ptr, key ? key : ""));
346 if ((!key) || ckey != key)
348 user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
353 if (Ptr->IsModeSet('i'))
356 FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr));
359 if (!user->IsInvited(Ptr->name.c_str()))
361 user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
365 user->RemoveInvite(Ptr->name.c_str());
368 std::string limit = Ptr->GetModeParameter('l');
372 FOREACH_RESULT_I(Instance, I_OnCheckLimit, OnCheckLimit(user, Ptr));
375 long llimit = atol(limit.c_str());
376 if (Ptr->GetUserCounter() >= llimit)
378 user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
384 if (Ptr->bans.size())
386 if (Ptr->IsBanned(user))
388 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
396 /* As spotted by jilles, dont bother to set this on remote users */
397 if (IS_LOCAL(user) && Ptr->GetUserCounter() == 0)
398 Ptr->SetDefaultModes();
400 return Channel::ForceChan(Instance, Ptr, user, privs, bursting);
403 Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting)
405 std::string nick = user->nick;
410 /* Just in case they have no permissions */
411 user->chans[Ptr] = 0;
413 for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
415 const char status = *x;
416 ModeHandler* mh = Instance->Modes->FindPrefix(status);
419 /* Set, and make sure that the mode handler knows this mode was now set */
420 Ptr->SetPrefix(user, status, mh->GetPrefixRank(), true);
421 mh->OnModeChange(Instance->FakeClient, Instance->FakeClient, Ptr, nick, true);
423 switch (mh->GetPrefix())
425 /* These logic ops are SAFE IN THIS CASE because if the entry doesnt exist,
426 * addressing operator[] creates it. If they do exist, it points to it.
427 * At all other times where we dont want to create an item if it doesnt exist, we
428 * must stick to ::find().
431 user->chans[Ptr] |= UCMODE_OP;
434 user->chans[Ptr] |= UCMODE_HOP;
437 user->chans[Ptr] |= UCMODE_VOICE;
443 FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user, Ptr, bursting, silent));
446 Ptr->WriteChannel(user,"JOIN :%s",Ptr->name.c_str());
448 /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
449 std::string ms = Instance->Modes->ModeString(user, Ptr);
450 if ((Ptr->GetUserCounter() > 1) && (ms.length()))
451 Ptr->WriteAllExceptSender(user, true, 0, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
453 /* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
458 user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
459 user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
463 FOREACH_MOD_I(Instance,I_OnPostJoin,OnPostJoin(user, Ptr));
467 bool Channel::IsBanned(User* user)
471 FOREACH_RESULT(I_OnCheckBan,OnCheckBan(user, this));
473 if (MOD_RESULT == -1)
475 else if (MOD_RESULT == 0)
477 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
478 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
480 /* This allows CIDR ban matching
482 * Full masked host Full unmasked host IP with/without CIDR
484 if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
493 bool Channel::IsExtBanned(const std::string &str, char type)
496 FOREACH_RESULT(I_OnCheckStringExtBan, OnCheckStringExtBan(str, this, type));
498 if (MOD_RESULT == -1)
500 else if (MOD_RESULT == 0)
502 for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
504 if (i->data[0] != type || i->data[1] != ':')
507 // Iterate past char and : to get to the mask without doing a data copy(!)
508 std::string maskptr = i->data.substr(2);
509 ServerInstance->Logs->Log("EXTBANS", DEBUG, "Checking %s against %s, type is %c", str.c_str(), maskptr.c_str(), type);
511 if (match(str, maskptr))
519 bool Channel::IsExtBanned(User *user, char type)
522 FOREACH_RESULT(I_OnCheckExtBan, OnCheckExtBan(user, this, type));
524 if (MOD_RESULT == -1)
526 else if (MOD_RESULT == 0)
529 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
531 // XXX: we should probably hook cloaked hosts in here somehow too..
532 if (this->IsExtBanned(mask, type))
535 if (this->IsExtBanned(user->GetFullHost(), type))
538 if (this->IsExtBanned(user->GetFullRealHost(), type))
546 * remove a channel from a users record, and return the number of users left.
547 * Therefore, if this function returns 0 the caller should delete the Channel.
549 * XXX: bleh, string copy of reason, fixme! -- w00t
551 long Channel::PartUser(User *user, std::string &reason)
556 return this->GetUserCounter();
558 UCListIter i = user->chans.find(this);
559 if (i != user->chans.end())
561 FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason, silent));
564 this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
566 user->chans.erase(i);
567 this->RemoveAllPrefixes(user);
570 if (!this->DelUser(user)) /* if there are no users left on the channel... */
572 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
573 /* kill the record */
574 if (iter != ServerInstance->chanlist->end())
577 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
579 return 1; // delete halted by module
580 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
581 ServerInstance->chanlist->erase(iter);
586 return this->GetUserCounter();
589 long Channel::ServerKickUser(User* user, const char* reason, bool triggerevents, const char* servername)
593 if (!user || !reason)
594 return this->GetUserCounter();
598 if (!this->HasUser(user))
601 return this->GetUserCounter();
605 if (servername == NULL || *ServerInstance->Config->HideWhoisServer)
606 servername = ServerInstance->Config->ServerName;
610 FOREACH_MOD(I_OnUserKick,OnUserKick(NULL, user, this, reason, silent));
613 UCListIter i = user->chans.find(this);
614 if (i != user->chans.end())
617 this->WriteChannelWithServ(servername, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
619 user->chans.erase(i);
620 this->RemoveAllPrefixes(user);
623 if (!this->DelUser(user))
625 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
626 /* kill the record */
627 if (iter != ServerInstance->chanlist->end())
630 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
632 return 1; // delete halted by module
633 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
634 ServerInstance->chanlist->erase(iter);
639 return this->GetUserCounter();
642 long Channel::KickUser(User *src, User *user, const char* reason)
646 if (!src || !user || !reason)
647 return this->GetUserCounter();
651 if (!this->HasUser(user))
653 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());
654 return this->GetUserCounter();
656 if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
658 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());
659 return this->GetUserCounter();
663 if (!ServerInstance->ULine(src->server))
666 FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,this,reason));
668 return this->GetUserCounter();
670 /* Set to -1 by OnUserPreKick if explicit allow was set */
671 if (MOD_RESULT != -1)
673 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,this,AC_KICK));
674 if ((MOD_RESULT == ACR_DENY) && (!ServerInstance->ULine(src->server)))
675 return this->GetUserCounter();
677 if ((MOD_RESULT == ACR_DEFAULT) || (!ServerInstance->ULine(src->server)))
679 int them = this->GetStatus(src);
680 int us = this->GetStatus(user);
681 if ((them < STATUS_HOP) || (them < us))
683 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them == STATUS_HOP ? "" : "half-");
684 return this->GetUserCounter();
690 FOREACH_MOD(I_OnUserKick,OnUserKick(src, user, this, reason, silent));
692 UCListIter i = user->chans.find(this);
693 if (i != user->chans.end())
695 /* zap it from the channel list of the user */
697 this->WriteChannel(src, "KICK %s %s :%s", this->name.c_str(), user->nick.c_str(), reason);
699 user->chans.erase(i);
700 this->RemoveAllPrefixes(user);
703 if (!this->DelUser(user))
704 /* if there are no users left on the channel */
706 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name.c_str());
708 /* kill the record */
709 if (iter != ServerInstance->chanlist->end())
712 FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
714 return 1; // delete halted by module
715 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
716 ServerInstance->chanlist->erase(iter);
721 return this->GetUserCounter();
724 void Channel::WriteChannel(User* user, const char* text, ...)
726 char textbuffer[MAXBUF];
732 va_start(argsPtr, text);
733 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
736 this->WriteChannel(user, std::string(textbuffer));
739 void Channel::WriteChannel(User* user, const std::string &text)
741 CUList *ulist = this->GetUsers();
747 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
748 std::string out = tb;
750 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
752 if (IS_LOCAL(i->first))
753 i->first->Write(out);
757 void Channel::WriteChannelWithServ(const char* ServName, const char* text, ...)
759 char textbuffer[MAXBUF];
765 va_start(argsPtr, text);
766 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
769 this->WriteChannelWithServ(ServName, std::string(textbuffer));
772 void Channel::WriteChannelWithServ(const char* ServName, const std::string &text)
774 CUList *ulist = this->GetUsers();
777 snprintf(tb,MAXBUF,":%s %s", ServName ? ServName : ServerInstance->Config->ServerName, text.c_str());
778 std::string out = tb;
780 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
782 if (IS_LOCAL(i->first))
783 i->first->Write(out);
787 /* write formatted text from a source user to all users on a channel except
788 * for the sender (for privmsg etc) */
789 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
791 char textbuffer[MAXBUF];
797 va_start(argsPtr, text);
798 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
801 this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer));
804 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
806 char textbuffer[MAXBUF];
812 va_start(argsPtr, text);
813 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
816 this->WriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
819 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
821 CUList *ulist = this->GetUsers();
824 snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
825 std::string out = tb;
827 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
829 if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
831 /* User doesnt have the status we're after */
832 if (status && !strchr(this->GetAllPrefixChars(i->first), status))
836 i->first->WriteServ(text);
838 i->first->Write(out);
843 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
846 except_list[user] = user->nick;
847 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
851 * return a count of the users on a specific channel accounting for
852 * invisible users who won't increase the count. e.g. for /LIST
854 int Channel::CountInvisible()
857 CUList *ulist= this->GetUsers();
858 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
860 if (!(i->first->IsModeSet('i')))
867 char* Channel::ChanModes(bool showkey)
869 static char scratch[MAXBUF];
870 static char sparam[MAXBUF];
871 char* offset = scratch;
872 std::string extparam;
877 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
878 for(int n = 0; n < 64; n++)
887 // Unfortunately this must be special-cased, as we definitely don't want to always display key.
890 extparam = this->GetModeParameter('k');
903 /* We know these have no parameters */
906 extparam = this->GetModeParameter(n + 65);
909 if (!extparam.empty())
911 charlcat(sparam,' ',MAXBUF);
912 strlcat(sparam,extparam.c_str(),MAXBUF);
917 /* Null terminate scratch */
919 strlcat(scratch,sparam,MAXBUF);
923 /* compile a userlist of a channel into a string, each nick seperated by
924 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
926 void Channel::UserList(User *user, CUList *ulist)
931 bool call_modules = true;
936 FOREACH_RESULT(I_OnUserList,OnUserList(user, this, ulist));
938 call_modules = false;
940 if (MOD_RESULT != -1)
942 if ((this->IsModeSet('s')) && (!this->HasUser(user)))
944 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
949 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
952 char* ptr = list + dlen;
955 ulist = this->GetUsers();
957 /* Improvement by Brain - this doesnt change in value, so why was it inside
960 bool has_user = this->HasUser(user);
962 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
964 if ((!has_user) && (i->first->IsModeSet('i')))
967 * user is +i, and source not on the channel, does not show
973 if (i->first->Visibility && !i->first->Visibility->VisibleTo(user))
976 std::string prefixlist = this->GetPrefixChar(i->first);
977 std::string nick = i->first->nick;
981 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->first, this, prefixlist, nick));
983 /* Nick was nuked, a module wants us to skip it */
990 if (curlen + prefixlist.length() + nick.length() + 1 > 480)
992 /* list overflowed into multiple numerics */
993 user->WriteServ(std::string(list));
995 /* reset our lengths */
996 dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());
1003 ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str());
1011 /* if whats left in the list isnt empty, send it */
1014 user->WriteNumeric(RPL_NAMREPLY, std::string(list));
1017 user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
1020 long Channel::GetMaxBans()
1022 /* Return the cached value if there is one */
1024 return this->maxbans;
1026 /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
1027 for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
1029 if (match(this->name,n->first))
1031 this->maxbans = n->second;
1036 /* Screw it, just return the default of 64 */
1038 return this->maxbans;
1041 void Channel::ResetMaxBans()
1046 /* returns the status character for a given user on a channel, e.g. @ for op,
1047 * % for halfop etc. If the user has several modes set, the highest mode
1048 * the user has must be returned.
1050 const char* Channel::GetPrefixChar(User *user)
1052 static char pf[2] = {0, 0};
1054 prefixlist::iterator n = prefixes.find(user);
1055 if (n != prefixes.end())
1057 if (n->second.size())
1059 /* If the user has any prefixes, their highest prefix
1060 * will always be at the head of the list, as the list is
1061 * sorted in rank order highest first (see SetPrefix()
1064 *pf = n->second.begin()->first;
1074 const char* Channel::GetAllPrefixChars(User* user)
1076 static char prefix[MAXBUF];
1080 prefixlist::iterator n = prefixes.find(user);
1081 if (n != prefixes.end())
1083 for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
1085 prefix[ctr++] = x->first;
1094 unsigned int Channel::GetPrefixValue(User* user)
1096 prefixlist::iterator n = prefixes.find(user);
1097 if (n != prefixes.end())
1099 if (n->second.size())
1100 return n->second.begin()->second;
1105 int Channel::GetStatusFlags(User *user)
1107 UCListIter i = user->chans.find(this);
1108 if (i != user->chans.end())
1115 int Channel::GetStatus(User *user)
1117 if (ServerInstance->ULine(user->server))
1120 UCListIter i = user->chans.find(this);
1121 if (i != user->chans.end())
1123 if ((i->second & UCMODE_OP) > 0)
1127 if ((i->second & UCMODE_HOP) > 0)
1131 if ((i->second & UCMODE_VOICE) > 0)
1133 return STATUS_VOICE;
1135 return STATUS_NORMAL;
1137 return STATUS_NORMAL;
1140 void Channel::SetPrefix(User* user, char prefix, unsigned int prefix_value, bool adding)
1142 prefixlist::iterator n = prefixes.find(user);
1143 prefixtype pfx = std::make_pair(prefix,prefix_value);
1146 if (n != prefixes.end())
1148 if (std::find(n->second.begin(), n->second.end(), pfx) == n->second.end())
1150 n->second.push_back(pfx);
1151 /* We must keep prefixes in rank order, largest first.
1152 * This is for two reasons, firstly because x-chat *ass-u-me's* this
1153 * state, and secondly it turns out to be a benefit to us later.
1154 * See above in GetPrefix().
1156 std::sort(n->second.begin(), n->second.end(), ModeParser::PrefixComparison);
1163 prefixes.insert(std::make_pair<User*,pfxcontainer>(user, one));
1168 if (n != prefixes.end())
1170 pfxcontainer::iterator x = std::find(n->second.begin(), n->second.end(), pfx);
1171 if (x != n->second.end())
1177 void Channel::RemoveAllPrefixes(User* user)
1179 prefixlist::iterator n = prefixes.find(user);
1180 if (n != prefixes.end())