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/>.
26 * Represents a member of a channel.
27 * A Membership object is created when a user joins a channel, and destroyed when a user leaves
28 * (via kick, part or quit) a channel.
29 * All prefix modes a member has is tracked by this object. Moreover, Memberships are Extensibles
30 * meaning modules can add arbitrary data to them using extensions (see m_delaymsg for an example).
32 class CoreExport Membership : public Extensible, public insp::intrusive_list_node<Membership>
35 /** Type of the Membership id
39 /** User on the channel
43 /** Channel the user is on
47 /** List of prefix mode letters this member has,
48 * sorted by prefix rank, highest first
52 /** Id of this Membership, set by the protocol module, other components should never read or
57 /** Converts a string to a Membership::Id
58 * @param str The string to convert
59 * @return Raw value of type Membership::Id
61 static Id IdFromString(const std::string& str)
63 return ConvToNum<Id>(str);
66 /** Constructor, sets the user and chan fields to the parameters, does NOT update any bookkeeping
67 * information in the User or the Channel.
68 * Call Channel::JoinUser() or ForceJoin() to make a user join a channel instead of constructing
69 * Membership objects directly.
71 Membership(User* u, Channel* c) : user(u), chan(c) {}
73 /** Check if this member has a given prefix mode set
74 * @param pm Prefix mode to check
75 * @return True if the member has the prefix mode set, false otherwise
77 bool HasMode(const PrefixMode* pm) const
79 return (modes.find(pm->GetModeChar()) != std::string::npos);
82 /** Returns the rank of this member.
83 * The rank of a member is defined as the rank given by the 'strongest' prefix mode a
84 * member has. See the PrefixMode class description for more info.
85 * @return The rank of the member
87 unsigned int getRank();
89 /** Add a prefix character to a user.
90 * Only the core should call this method, usually from
91 * within the mode parser or when the first user joins
92 * the channel (to grant the default privs to them)
93 * @param mh The mode handler of the prefix mode to associate
94 * @param adding True if adding the prefix, false when removing
95 * @return True if a change was made
97 bool SetPrefix(PrefixMode* mh, bool adding);
99 /** Get the highest prefix this user has on the channel
100 * @return A character containing the highest prefix.
101 * If the user has no prefix, 0 is returned. If the user has multiple prefixes,
102 * the highest is returned. If you do not recognise the prefix character you
103 * can get, you can deal with it in a 'proportional' manner compared to known
104 * prefixes, using GetPrefixValue().
106 char GetPrefixChar() const;
108 /** Return all prefix chars this member has.
109 * @return A list of all prefix characters. The prefixes will always
110 * be in rank order, greatest first, as certain IRC clients require
111 * this when multiple prefixes are used names lists.
113 std::string GetAllPrefixChars() const;
115 /** Sends a server notice to this user in the context of this channel.
116 * @param text The contents of the message to send.
118 void WriteNotice(const std::string& text) const;