2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2012-2014 Attila Molnar <attilamolnar@hush.com>
5 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * Represents a member of a channel.
25 * A Membership object is created when a user joins a channel, and destroyed when a user leaves
26 * (via kick, part or quit) a channel.
27 * All prefix modes a member has is tracked by this object. Moreover, Memberships are Extensibles
28 * meaning modules can add arbitrary data to them using extensions (see m_delaymsg for an example).
30 class CoreExport Membership : public Extensible, public intrusive_list_node<Membership>
33 /** User on the channel
37 /** Channel the user is on
41 /** List of prefix mode letters this member has,
42 * sorted by prefix rank, highest first
46 /** Constructor, sets the user and chan fields to the parameters, does NOT update any bookkeeping
47 * information in the User or the Channel.
48 * Call Channel::JoinUser() or ForceJoin() to make a user join a channel instead of constructing
49 * Membership objects directly.
51 Membership(User* u, Channel* c) : user(u), chan(c) {}
53 /** Returns true if this member has a given prefix mode set
54 * @param m The prefix mode letter to check
55 * @return True if the member has the prefix mode set, false otherwise
57 inline bool hasMode(char m) const
59 return modes.find(m) != std::string::npos;
62 /** Returns the rank of this member.
63 * The rank of a member is defined as the rank given by the 'strongest' prefix mode a
64 * member has. See the PrefixMode class description for more info.
65 * @return The rank of the member
67 unsigned int getRank();
69 /** Add a prefix character to a user.
70 * Only the core should call this method, usually from
71 * within the mode parser or when the first user joins
72 * the channel (to grant the default privs to them)
73 * @param mh The mode handler of the prefix mode to associate
74 * @param adding True if adding the prefix, false when removing
75 * @return True if a change was made
77 bool SetPrefix(PrefixMode* mh, bool adding);
79 /** Get the highest prefix this user has on the channel
80 * @return A character containing the highest prefix.
81 * If the user has no prefix, 0 is returned. If the user has multiple prefixes,
82 * the highest is returned. If you do not recognise the prefix character you
83 * can get, you can deal with it in a 'proportional' manner compared to known
84 * prefixes, using GetPrefixValue().
86 char GetPrefixChar() const;
88 /** Return all prefix chars this member has.
89 * @return A list of all prefix characters. The prefixes will always
90 * be in rank order, greatest first, as certain IRC clients require
91 * this when multiple prefixes are used names lists.
93 const char* GetAllPrefixChars() const;
100 /** List of pending Invitations
102 intrusive_list<Invitation, T> invites;
105 /** Remove and destruct all pending invitations this user or channel has.
106 * Must be called before the object is destroyed, also called when the TS of the channel is lowered.
110 friend class Invitation;
114 * The Invitation class contains all data about a pending invitation.
115 * Invitation objects are referenced from the user and the channel they belong to.
117 class CoreExport Invitation : public intrusive_list_node<Invitation, Channel>, public intrusive_list_node<Invitation, LocalUser>
119 /** Constructs an Invitation, only called by Create()
120 * @param c Channel the user is invited to
121 * @param u User being invited
122 * @param timeout Expiration time for this Invitation
124 Invitation(Channel* c, LocalUser* u, time_t timeout) : user(u), chan(c), expiry(timeout) {}
127 /** User the invitation is for
129 LocalUser* const user;
131 /** Channel where the user is invited to
135 /** Timestamp when this Invitation expires or 0 if it doesn't expire.
136 * Invitation::Create() can update this field; see that for more info.
141 * Removes references to this Invitation from the associated user and channel.
145 /** Create or extend an Invitation.
146 * When a user is invited to join a channel either a new Invitation object is created or
147 * or the expiration timestamp is updated if there is already a pending Invitation for
148 * the given (user, channel) pair and the new expiration time is further than the current.
149 * @param c Target channel
150 * @param u Target user
151 * @param timeout Timestamp when the invite should expire, 0 for no expiration
153 static void Create(Channel* c, LocalUser* u, time_t timeout);
155 /** Finds the Invitation object for the given channel/user pair.
156 * @param c Target channel, can be NULL to remove expired entries
157 * @param u Target user, cannot be NULL
158 * @param check_expired Pass true to remove all expired invites found while searching, false
159 * to return with an Invitation even if it's expired
160 * @return Invitation object for the given (channel, user) pair if it exists, NULL otherwise
162 static Invitation* Find(Channel* c, LocalUser* u, bool check_expired = true);
165 typedef intrusive_list<Invitation, LocalUser> InviteList;
168 inline void InviteBase<T>::ClearInvites()
170 for (typename intrusive_list<Invitation, T>::iterator i = invites.begin(); i != invites.end(); )
172 Invitation* inv = *i;
173 // Destructing the Invitation invalidates the iterator, so move it now