]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/membership.h
Add an oper only parameter to Simple{Channel,User}ModeHandler.
[user/henk/code/inspircd.git] / include / membership.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2012-2014 Attila Molnar <attilamolnar@hush.com>
5  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
6  *
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.
10  *
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
14  * details.
15  *
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/>.
18  */
19
20
21 #pragma once
22
23 #include "convto.h"
24
25 /**
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).
31  */
32 class CoreExport Membership : public Extensible, public insp::intrusive_list_node<Membership>
33 {
34  public:
35         /** Type of the Membership id
36          */
37         typedef uint64_t Id;
38
39         /** User on the channel
40          */
41         User* const user;
42
43         /** Channel the user is on
44          */
45         Channel* const chan;
46
47         /** List of prefix mode letters this member has,
48          * sorted by prefix rank, highest first
49          */
50         std::string modes;
51
52         /** Id of this Membership, set by the protocol module, other components should never read or
53          * write this field.
54          */
55         Id id;
56
57         /** Converts a string to a Membership::Id
58          * @param str The string to convert
59          * @return Raw value of type Membership::Id
60          */
61         static Id IdFromString(const std::string& str)
62         {
63                 return ConvToNum<Id>(str);
64         }
65
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.
70          */
71         Membership(User* u, Channel* c) : user(u), chan(c) {}
72
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
76          */
77         bool HasMode(const PrefixMode* pm) const
78         {
79                 return (modes.find(pm->GetModeChar()) != std::string::npos);
80         }
81
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
86          */
87         unsigned int getRank();
88
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
96          */
97         bool SetPrefix(PrefixMode* mh, bool adding);
98
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().
105          */
106         char GetPrefixChar() const;
107
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.
112          */
113         std::string GetAllPrefixChars() const;
114
115         /** Sends a server notice to this user in the context of this channel.
116          * @param text The contents of the message to send.
117          */
118         void WriteNotice(const std::string& text) const;
119 };