2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2006-2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2006, 2008 Oliver Lupton <oliverlupton@gmail.com>
7 * Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
8 * Copyright (C) 2003-2008 Craig Edwards <craigedwards@brainbox.cc>
9 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
10 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 static ModeReference ban(NULL, "ban");
33 Channel::Channel(const std::string &cname, time_t ts)
35 if (!ServerInstance->chanlist->insert(std::make_pair(cname, this)).second)
36 throw CoreException("Cannot create duplicate channel " + cname);
39 this->age = ts ? ts : ServerInstance->Time();
45 void Channel::SetMode(ModeHandler* mh, bool on)
47 modes[mh->GetModeChar() - 65] = on;
50 void Channel::SetModeParam(char mode, const std::string& parameter)
52 if (parameter.empty())
54 custom_mode_params.erase(mode);
55 modes[mode-65] = false;
59 custom_mode_params[mode] = parameter;
60 modes[mode-65] = true;
64 void Channel::SetModeParam(ModeHandler* mode, const std::string& parameter)
66 SetModeParam(mode->GetModeChar(), parameter);
69 std::string Channel::GetModeParameter(char mode)
71 CustomModeList::iterator n = custom_mode_params.find(mode);
72 if (n != custom_mode_params.end())
77 std::string Channel::GetModeParameter(ModeHandler* mode)
79 CustomModeList::iterator n = custom_mode_params.find(mode->GetModeChar());
80 if (n != custom_mode_params.end())
85 void Channel::SetTopic(User* u, const std::string& ntopic)
87 this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic);
88 this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128);
89 this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
90 this->topicset = ServerInstance->Time();
92 FOREACH_MOD(I_OnPostTopicChange,OnPostTopicChange(u, this, this->topic));
95 Membership* Channel::AddUser(User* user)
97 Membership*& memb = userlist[user];
101 memb = new Membership(user, this);
105 void Channel::DelUser(User* user)
107 UserMembIter it = userlist.find(user);
108 if (it != userlist.end())
112 void Channel::CheckDestroy()
114 if (!userlist.empty())
118 FIRST_MOD_RESULT(OnChannelPreDelete, res, (this));
119 if (res == MOD_RES_DENY)
122 chan_hash::iterator iter = ServerInstance->chanlist->find(this->name);
123 /* kill the record */
124 if (iter != ServerInstance->chanlist->end())
126 FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
127 ServerInstance->chanlist->erase(iter);
131 ServerInstance->GlobalCulls.AddItem(this);
134 void Channel::DelUser(const UserMembIter& membiter)
136 Membership* memb = membiter->second;
139 userlist.erase(membiter);
141 // If this channel became empty then it should be removed
145 Membership* Channel::GetUser(User* user)
147 UserMembIter i = userlist.find(user);
148 if (i == userlist.end())
153 void Channel::SetDefaultModes()
155 ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "SetDefaultModes %s",
156 ServerInstance->Config->DefaultModes.c_str());
157 irc::spacesepstream list(ServerInstance->Config->DefaultModes);
159 std::string parameter;
161 list.GetToken(modeseq);
163 for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
165 ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
168 if (mode->GetNumParams(true))
169 list.GetToken(parameter);
173 mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
179 * add a channel to a user, creating the record for it if needed and linking
180 * it to the user record
182 Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, const std::string& key)
184 if (user->registered != REG_ALL)
186 ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "Attempted to join unregistered user " + user->uuid + " to channel " + cname);
191 * We don't restrict the number of channels that remote users or users that are override-joining may be in.
192 * We restrict local users to MaxChans channels.
193 * We restrict local operators to OperMaxChans channels.
194 * This is a lot more logical than how it was formerly. -- w00t
198 if (user->HasPrivPermission("channels/high-join-limit"))
200 if (user->chans.size() >= ServerInstance->Config->OperMaxChans)
202 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cname.c_str());
208 unsigned int maxchans = user->GetClass()->maxchans;
210 maxchans = ServerInstance->Config->MaxChans;
211 if (user->chans.size() >= maxchans)
213 user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cname.c_str());
219 // Crop channel name if it's too long
220 if (cname.length() > ServerInstance->Config->Limits.ChanMax)
221 cname.resize(ServerInstance->Config->Limits.ChanMax);
223 Channel* chan = ServerInstance->FindChan(cname);
224 bool created_by_local = (chan == NULL); // Flag that will be passed to modules in the OnUserJoin() hook later
225 std::string privs; // Prefix mode(letter)s to give to the joining user
231 if (override == false)
233 // Ask the modules whether they're ok with the join, pass NULL as Channel* as the channel is yet to be created
234 ModResult MOD_RESULT;
235 FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, NULL, cname, privs, key));
236 if (MOD_RESULT == MOD_RES_DENY)
237 return NULL; // A module wasn't happy with the join, abort
240 chan = new Channel(cname, ServerInstance->Time());
241 // Set the default modes on the channel (<options:defaultmodes>)
242 chan->SetDefaultModes();
246 /* Already on the channel */
247 if (chan->HasUser(user))
250 if (override == false)
252 ModResult MOD_RESULT;
253 FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, chan, cname, privs, key));
255 // A module explicitly denied the join and (hopefully) generated a message
256 // describing the situation, so we may stop here without sending anything
257 if (MOD_RESULT == MOD_RES_DENY)
260 // If no module returned MOD_RES_DENY or MOD_RES_ALLOW (which is the case
261 // most of the time) then proceed to check channel modes +k, +i, +l and bans,
263 // If a module explicitly allowed the join (by returning MOD_RES_ALLOW),
264 // then this entire section is skipped
265 if (MOD_RESULT == MOD_RES_PASSTHRU)
267 std::string ckey = chan->GetModeParameter('k');
268 bool invited = user->IsInvited(chan);
269 bool can_bypass = ServerInstance->Config->InvBypassModes && invited;
273 FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, chan, key));
274 if (!MOD_RESULT.check((ckey == key) || can_bypass))
276 // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
277 user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), chan->name.c_str());
282 if (chan->IsModeSet('i'))
284 FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, chan));
285 if (!MOD_RESULT.check(invited))
287 user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), chan->name.c_str());
292 std::string limit = chan->GetModeParameter('l');
295 FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, chan));
296 if (!MOD_RESULT.check((chan->GetUserCounter() < atol(limit.c_str()) || can_bypass)))
298 user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), chan->name.c_str());
303 if (chan->IsBanned(user) && !can_bypass)
305 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), chan->name.c_str());
310 * If the user has invites for this channel, remove them now
311 * after a successful join so they don't build up.
315 user->RemoveInvite(chan);
321 // We figured that this join is allowed and also created the
322 // channel if it didn't exist before, now do the actual join
323 chan->ForceJoin(user, &privs, false, created_by_local);
327 void Channel::ForceJoin(User* user, const std::string* privs, bool bursting, bool created_by_local)
331 ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "Attempted to join server user " + user->uuid + " to channel " + this->name);
335 Membership* memb = this->AddUser(user);
337 return; // Already on the channel
339 user->chans.insert(this);
343 // If the user was granted prefix modes (in the OnUserPreJoin hook, or he's a
344 // remote user and his own server set the modes), then set them internally now
345 memb->modes = *privs;
346 for (std::string::const_iterator i = privs->begin(); i != privs->end(); ++i)
348 ModeHandler* mh = ServerInstance->Modes->FindMode(*i, MODETYPE_CHANNEL);
351 std::string nick = user->nick;
352 /* Set, and make sure that the mode handler knows this mode was now set */
353 this->SetPrefix(user, mh->GetModeChar(), true);
354 mh->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, nick, true);
359 // Tell modules about this join, they have the chance now to populate except_list with users we won't send the JOIN (and possibly MODE) to
361 FOREACH_MOD(I_OnUserJoin,OnUserJoin(memb, bursting, created_by_local, except_list));
363 this->WriteAllExcept(user, false, 0, except_list, "JOIN :%s", this->name.c_str());
365 /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
366 if ((GetUserCounter() > 1) && (!memb->modes.empty()))
368 std::string ms = memb->modes;
369 for(unsigned int i=0; i < memb->modes.length(); i++)
370 ms.append(" ").append(user->nick);
372 except_list.insert(user);
373 this->WriteAllExcept(user, !ServerInstance->Config->CycleHostsFromUser, 0, except_list, "MODE %s +%s", this->name.c_str(), ms.c_str());
380 user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), this->name.c_str(), this->topic.c_str());
381 user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), this->name.c_str(), this->setby.c_str(), (unsigned long)this->topicset);
383 this->UserList(user);
386 FOREACH_MOD(I_OnPostJoin,OnPostJoin(memb));
389 bool Channel::IsBanned(User* user)
392 FIRST_MOD_RESULT(OnCheckChannelBan, result, (user, this));
394 if (result != MOD_RES_PASSTHRU)
395 return (result == MOD_RES_DENY);
397 ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
398 const ListModeBase::ModeList* bans = banlm->GetList(this);
401 for (ListModeBase::ModeList::const_iterator it = bans->begin(); it != bans->end(); it++)
403 if (CheckBan(user, it->mask))
410 bool Channel::CheckBan(User* user, const std::string& mask)
413 FIRST_MOD_RESULT(OnCheckBan, result, (user, this, mask));
414 if (result != MOD_RES_PASSTHRU)
415 return (result == MOD_RES_DENY);
417 // extbans were handled above, if this is one it obviously didn't match
418 if ((mask.length() <= 2) || (mask[1] == ':'))
421 std::string::size_type at = mask.find('@');
422 if (at == std::string::npos)
425 const std::string nickIdent = user->nick + "!" + user->ident;
426 std::string prefix = mask.substr(0, at);
427 if (InspIRCd::Match(nickIdent, prefix, NULL))
429 std::string suffix = mask.substr(at + 1);
430 if (InspIRCd::Match(user->host, suffix, NULL) ||
431 InspIRCd::Match(user->dhost, suffix, NULL) ||
432 InspIRCd::MatchCIDR(user->GetIPString(), suffix, NULL))
438 ModResult Channel::GetExtBanStatus(User *user, char type)
441 FIRST_MOD_RESULT(OnExtBanCheck, rv, (user, this, type));
442 if (rv != MOD_RES_PASSTHRU)
445 ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
446 const ListModeBase::ModeList* bans = banlm->GetList(this);
450 for (ListModeBase::ModeList::const_iterator it = bans->begin(); it != bans->end(); ++it)
452 if (CheckBan(user, it->mask))
456 return MOD_RES_PASSTHRU;
460 * Remove a channel from a users record, remove the reference to the Membership object
461 * from the channel and destroy it.
463 void Channel::PartUser(User *user, std::string &reason)
465 UserMembIter membiter = userlist.find(user);
467 if (membiter != userlist.end())
469 Membership* memb = membiter->second;
471 FOREACH_MOD(I_OnUserPart,OnUserPart(memb, reason, except_list));
473 WriteAllExcept(user, false, 0, except_list, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
475 // Remove this channel from the user's chanlist
476 user->chans.erase(this);
477 // Remove the Membership from this channel's userlist and destroy it
478 this->DelUser(membiter);
482 void Channel::KickUser(User* src, User* victim, const std::string& reason, Membership* srcmemb)
484 UserMembIter victimiter = userlist.find(victim);
485 Membership* memb = ((victimiter != userlist.end()) ? victimiter->second : NULL);
489 src->WriteNumeric(ERR_USERNOTINCHANNEL, "%s %s %s :They are not on that channel",src->nick.c_str(), victim->nick.c_str(), this->name.c_str());
493 // Do the following checks only if the KICK is done by a local user;
494 // each server enforces its own rules.
497 // Modules are allowed to explicitly allow or deny kicks done by local users
499 FIRST_MOD_RESULT(OnUserPreKick, res, (src,memb,reason));
500 if (res == MOD_RES_DENY)
503 if (res == MOD_RES_PASSTHRU)
506 srcmemb = GetUser(src);
507 unsigned int them = srcmemb ? srcmemb->getRank() : 0;
508 unsigned int req = HALFOP_VALUE;
509 for (std::string::size_type i = 0; i < memb->modes.length(); i++)
511 ModeHandler* mh = ServerInstance->Modes->FindMode(memb->modes[i], MODETYPE_CHANNEL);
512 if (mh && mh->GetLevelRequired() > req)
513 req = mh->GetLevelRequired();
518 src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",
519 src->nick.c_str(), this->name.c_str(), req > HALFOP_VALUE ? "" : "half-");
526 FOREACH_MOD(I_OnUserKick,OnUserKick(src, memb, reason, except_list));
528 WriteAllExcept(src, false, 0, except_list, "KICK %s %s :%s", name.c_str(), victim->nick.c_str(), reason.c_str());
530 victim->chans.erase(this);
531 this->DelUser(victimiter);
534 void Channel::WriteChannel(User* user, const char* text, ...)
536 std::string textbuffer;
537 VAFORMAT(textbuffer, text, text);
538 this->WriteChannel(user, textbuffer);
541 void Channel::WriteChannel(User* user, const std::string &text)
543 const std::string message = ":" + user->GetFullHost() + " " + text;
545 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
547 if (IS_LOCAL(i->first))
548 i->first->Write(message);
552 void Channel::WriteChannelWithServ(const std::string& ServName, const char* text, ...)
554 std::string textbuffer;
555 VAFORMAT(textbuffer, text, text);
556 this->WriteChannelWithServ(ServName, textbuffer);
559 void Channel::WriteChannelWithServ(const std::string& ServName, const std::string &text)
561 const std::string message = ":" + (ServName.empty() ? ServerInstance->Config->ServerName : ServName) + " " + text;
563 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
565 if (IS_LOCAL(i->first))
566 i->first->Write(message);
570 /* write formatted text from a source user to all users on a channel except
571 * for the sender (for privmsg etc) */
572 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...)
574 std::string textbuffer;
575 VAFORMAT(textbuffer, text, text);
576 this->WriteAllExceptSender(user, serversource, status, textbuffer);
579 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...)
581 std::string textbuffer;
582 VAFORMAT(textbuffer, text, text);
583 textbuffer = ":" + (serversource ? ServerInstance->Config->ServerName : user->GetFullHost()) + " " + textbuffer;
584 this->RawWriteAllExcept(user, serversource, status, except_list, textbuffer);
587 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
589 const std::string message = ":" + (serversource ? ServerInstance->Config->ServerName : user->GetFullHost()) + " " + text;
590 this->RawWriteAllExcept(user, serversource, status, except_list, message);
593 void Channel::RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &out)
595 unsigned int minrank = 0;
598 ModeHandler* mh = ServerInstance->Modes->FindPrefix(status);
600 minrank = mh->GetPrefixRank();
602 for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
604 if (IS_LOCAL(i->first) && (except_list.find(i->first) == except_list.end()))
606 /* User doesn't have the status we're after */
607 if (minrank && i->second->getRank() < minrank)
610 i->first->Write(out);
615 void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text)
618 except_list.insert(user);
619 this->WriteAllExcept(user, serversource, status, except_list, std::string(text));
622 const char* Channel::ChanModes(bool showkey)
624 static std::string scratch;
629 /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
630 for(int n = 0; n < 64; n++)
634 scratch.push_back(n + 65);
635 if (n == 'k' - 65 && !showkey)
641 const std::string param = this->GetModeParameter(n + 65);
652 return scratch.c_str();
655 /* compile a userlist of a channel into a string, each nick seperated by
656 * spaces and op, voice etc status shown as @ and +, and send it to 'user'
658 void Channel::UserList(User *user)
660 if (this->IsModeSet('s') && !this->HasUser(user) && !user->HasPrivPermission("channels/auspex"))
662 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
666 std::string list = user->nick;
668 list.push_back(this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=');
670 list.append(this->name).append(" :");
671 std::string::size_type pos = list.size();
673 bool has_one = false;
675 /* Improvement by Brain - this doesnt change in value, so why was it inside
678 bool has_user = this->HasUser(user);
680 std::string prefixlist;
682 for (UserMembIter i = userlist.begin(); i != userlist.end(); ++i)
684 if (i->first->quitting)
686 if ((!has_user) && (i->first->IsModeSet('i')))
689 * user is +i, and source not on the channel, does not show
695 prefixlist = this->GetPrefixChar(i->first);
696 nick = i->first->nick;
698 FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->second, prefixlist, nick));
700 /* Nick was nuked, a module wants us to skip it */
704 if (list.size() + prefixlist.length() + nick.length() + 1 > 480)
706 /* list overflowed into multiple numerics */
707 user->WriteNumeric(RPL_NAMREPLY, list);
709 // Erase all nicks, keep the constant part
714 list.append(prefixlist).append(nick).push_back(' ');
719 /* if whats left in the list isnt empty, send it */
722 user->WriteNumeric(RPL_NAMREPLY, list);
725 user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
728 /* returns the status character for a given user on a channel, e.g. @ for op,
729 * % for halfop etc. If the user has several modes set, the highest mode
730 * the user has must be returned.
732 const char* Channel::GetPrefixChar(User *user)
734 static char pf[2] = {0, 0};
736 unsigned int bestrank = 0;
738 UserMembIter m = userlist.find(user);
739 if (m != userlist.end())
741 for(unsigned int i=0; i < m->second->modes.length(); i++)
743 char mchar = m->second->modes[i];
744 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
745 if (mh && mh->GetPrefixRank() > bestrank && mh->GetPrefix())
747 bestrank = mh->GetPrefixRank();
748 pf[0] = mh->GetPrefix();
755 unsigned int Membership::getRank()
757 char mchar = modes.c_str()[0];
761 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
763 rv = mh->GetPrefixRank();
768 const char* Channel::GetAllPrefixChars(User* user)
770 static char prefix[64];
773 UserMembIter m = userlist.find(user);
774 if (m != userlist.end())
776 for(unsigned int i=0; i < m->second->modes.length(); i++)
778 char mchar = m->second->modes[i];
779 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
780 if (mh && mh->GetPrefix())
781 prefix[ctr++] = mh->GetPrefix();
789 unsigned int Channel::GetPrefixValue(User* user)
791 UserMembIter m = userlist.find(user);
792 if (m == userlist.end())
794 return m->second->getRank();
797 bool Channel::SetPrefix(User* user, char prefix, bool adding)
799 ModeHandler* delta_mh = ServerInstance->Modes->FindMode(prefix, MODETYPE_CHANNEL);
802 UserMembIter m = userlist.find(user);
803 if (m == userlist.end())
805 for(unsigned int i=0; i < m->second->modes.length(); i++)
807 char mchar = m->second->modes[i];
808 ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
809 if (mh && mh->GetPrefixRank() <= delta_mh->GetPrefixRank())
812 m->second->modes.substr(0,i) +
813 (adding ? std::string(1, prefix) : "") +
814 m->second->modes.substr(mchar == prefix ? i+1 : i);
815 return adding != (mchar == prefix);
819 m->second->modes += std::string(1, prefix);
823 void Invitation::Create(Channel* c, LocalUser* u, time_t timeout)
825 if ((timeout != 0) && (ServerInstance->Time() >= timeout))
826 // Expired, don't bother
829 ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create chan=%s user=%s", c->name.c_str(), u->uuid.c_str());
831 Invitation* inv = Invitation::Find(c, u, false);
834 if ((inv->expiry == 0) || (inv->expiry > timeout))
836 inv->expiry = timeout;
837 ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create changed expiry in existing invitation %p", (void*) inv);
841 inv = new Invitation(c, u, timeout);
842 c->invites.push_back(inv);
843 u->invites.push_back(inv);
844 ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create created new invitation %p", (void*) inv);
848 Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired)
850 ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find chan=%s user=%s check_expired=%d", c ? c->name.c_str() : "NULL", u ? u->uuid.c_str() : "NULL", check_expired);
851 if (!u || u->invites.empty())
854 InviteList locallist;
855 locallist.swap(u->invites);
857 Invitation* result = NULL;
858 for (InviteList::iterator i = locallist.begin(); i != locallist.end(); )
860 Invitation* inv = *i;
861 if ((check_expired) && (inv->expiry != 0) && (inv->expiry <= ServerInstance->Time()))
863 /* Expired invite, remove it. */
864 std::string expiration = ServerInstance->TimeString(inv->expiry);
865 ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find ecountered expired entry: %p expired %s", (void*) inv, expiration.c_str());
866 i = locallist.erase(i);
872 /* Is it what we're searching for? */
882 locallist.swap(u->invites);
883 ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find result=%p", (void*) result);
887 Invitation::~Invitation()
889 // Remove this entry from both lists
890 InviteList::iterator it = std::find(chan->invites.begin(), chan->invites.end(), this);
891 if (it != chan->invites.end())
892 chan->invites.erase(it);
893 it = std::find(user->invites.begin(), user->invites.end(), this);
894 if (it != user->invites.end())
895 user->invites.erase(it);
898 void InviteBase::ClearInvites()
900 ServerInstance->Logs->Log("INVITEBASE", LOG_DEBUG, "InviteBase::ClearInvites %p", (void*) this);
901 InviteList locallist;
902 locallist.swap(invites);
903 for (InviteList::const_iterator i = locallist.begin(); i != locallist.end(); ++i)