2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013-2014, 2016 Attila Molnar <attilamolnar@hush.com>
5 * Copyright (C) 2013, 2017-2018 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
8 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10 * This file is part of InspIRCd. InspIRCd is free software: you can
11 * redistribute it and/or modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation, version 2.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 * Represents a member of a channel.
30 * A Membership object is created when a user joins a channel, and destroyed when a user leaves
31 * (via kick, part or quit) a channel.
32 * All prefix modes a member has is tracked by this object. Moreover, Memberships are Extensibles
33 * meaning modules can add arbitrary data to them using extensions (see m_delaymsg for an example).
35 class CoreExport Membership : public Extensible, public insp::intrusive_list_node<Membership>
38 /** Type of the Membership id
42 /** User on the channel
46 /** Channel the user is on
50 /** List of prefix mode letters this member has,
51 * sorted by prefix rank, highest first
55 /** Id of this Membership, set by the protocol module, other components should never read or
60 /** Converts a string to a Membership::Id
61 * @param str The string to convert
62 * @return Raw value of type Membership::Id
64 static Id IdFromString(const std::string& str)
66 return ConvToNum<Id>(str);
69 /** Constructor, sets the user and chan fields to the parameters, does NOT update any bookkeeping
70 * information in the User or the Channel.
71 * Call Channel::JoinUser() or ForceJoin() to make a user join a channel instead of constructing
72 * Membership objects directly.
74 Membership(User* u, Channel* c) : user(u), chan(c) {}
76 /** Check if this member has a given prefix mode set
77 * @param pm Prefix mode to check
78 * @return True if the member has the prefix mode set, false otherwise
80 bool HasMode(const PrefixMode* pm) const
82 return (modes.find(pm->GetModeChar()) != std::string::npos);
85 /** Returns the rank of this member.
86 * The rank of a member is defined as the rank given by the 'strongest' prefix mode a
87 * member has. See the PrefixMode class description for more info.
88 * @return The rank of the member
90 unsigned int getRank();
92 /** Add a prefix character to a user.
93 * Only the core should call this method, usually from
94 * within the mode parser or when the first user joins
95 * the channel (to grant the default privs to them)
96 * @param mh The mode handler of the prefix mode to associate
97 * @param adding True if adding the prefix, false when removing
98 * @return True if a change was made
100 bool SetPrefix(PrefixMode* mh, bool adding);
102 /** Get the highest prefix this user has on the channel
103 * @return A character containing the highest prefix.
104 * If the user has no prefix, 0 is returned. If the user has multiple prefixes,
105 * the highest is returned. If you do not recognise the prefix character you
106 * can get, you can deal with it in a 'proportional' manner compared to known
107 * prefixes, using GetPrefixValue().
109 char GetPrefixChar() const;
111 /** Return all prefix chars this member has.
112 * @return A list of all prefix characters. The prefixes will always
113 * be in rank order, greatest first, as certain IRC clients require
114 * this when multiple prefixes are used names lists.
116 std::string GetAllPrefixChars() const;
118 /** Sends a server notice to this user in the context of this channel.
119 * @param text The contents of the message to send.
121 void WriteNotice(const std::string& text) const;