2012-04-19 20:58:29 +02:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
2009-09-13 20:30:47 +00:00
|
|
|
*
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2013-2014, 2016 Attila Molnar <attilamolnar@hush.com>
|
|
|
|
* Copyright (C) 2013, 2017-2018 Sadie Powell <sadie@witchery.services>
|
|
|
|
* Copyright (C) 2012 Robby <robby@chatbelgie.be>
|
|
|
|
* Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
|
2012-04-19 20:58:29 +02:00
|
|
|
* Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
|
2009-09-13 20:30:47 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This file is part of InspIRCd. InspIRCd is free software: you can
|
|
|
|
* redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.
|
2009-09-13 20:30:47 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-09-13 20:30:47 +00:00
|
|
|
*/
|
|
|
|
|
2012-04-19 20:58:29 +02:00
|
|
|
|
2013-04-02 20:12:15 +01:00
|
|
|
#pragma once
|
2009-09-13 20:30:47 +00:00
|
|
|
|
2017-11-17 00:02:03 +00:00
|
|
|
#include "convto.h"
|
2014-06-11 14:04:00 +02:00
|
|
|
|
2014-05-06 15:13:30 +02:00
|
|
|
/**
|
|
|
|
* Represents a member of a channel.
|
|
|
|
* A Membership object is created when a user joins a channel, and destroyed when a user leaves
|
|
|
|
* (via kick, part or quit) a channel.
|
|
|
|
* All prefix modes a member has is tracked by this object. Moreover, Memberships are Extensibles
|
|
|
|
* meaning modules can add arbitrary data to them using extensions (see m_delaymsg for an example).
|
|
|
|
*/
|
2021-12-20 20:00:03 +00:00
|
|
|
class CoreExport Membership final
|
|
|
|
: public Extensible
|
|
|
|
, public insp::intrusive_list_node<Membership>
|
2009-09-13 20:30:47 +00:00
|
|
|
{
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2014-06-11 14:04:00 +02:00
|
|
|
/** Type of the Membership id
|
|
|
|
*/
|
|
|
|
typedef uint64_t Id;
|
|
|
|
|
2014-05-06 15:13:30 +02:00
|
|
|
/** User on the channel
|
|
|
|
*/
|
2009-09-13 20:30:47 +00:00
|
|
|
User* const user;
|
2014-05-06 15:13:30 +02:00
|
|
|
|
|
|
|
/** Channel the user is on
|
|
|
|
*/
|
2009-09-13 20:30:47 +00:00
|
|
|
Channel* const chan;
|
2014-05-06 15:13:30 +02:00
|
|
|
|
|
|
|
/** List of prefix mode letters this member has,
|
|
|
|
* sorted by prefix rank, highest first
|
|
|
|
*/
|
2022-05-17 13:02:58 +01:00
|
|
|
std::set<PrefixMode*, PrefixMode::Sorter> modes;
|
2014-05-06 15:13:30 +02:00
|
|
|
|
2014-06-11 14:04:00 +02:00
|
|
|
/** Id of this Membership, set by the protocol module, other components should never read or
|
|
|
|
* write this field.
|
|
|
|
*/
|
|
|
|
Id id;
|
|
|
|
|
|
|
|
/** Converts a string to a Membership::Id
|
|
|
|
* @param str The string to convert
|
|
|
|
* @return Raw value of type Membership::Id
|
|
|
|
*/
|
|
|
|
static Id IdFromString(const std::string& str)
|
|
|
|
{
|
2017-11-17 00:02:03 +00:00
|
|
|
return ConvToNum<Id>(str);
|
2014-06-11 14:04:00 +02:00
|
|
|
}
|
|
|
|
|
2014-05-06 15:13:30 +02:00
|
|
|
/** Constructor, sets the user and chan fields to the parameters, does NOT update any bookkeeping
|
|
|
|
* information in the User or the Channel.
|
|
|
|
* Call Channel::JoinUser() or ForceJoin() to make a user join a channel instead of constructing
|
|
|
|
* Membership objects directly.
|
|
|
|
*/
|
2022-01-31 02:04:43 +00:00
|
|
|
Membership(User* u, Channel* c)
|
|
|
|
: Extensible(ExtensionType::MEMBERSHIP)
|
|
|
|
, user(u)
|
|
|
|
, chan(c)
|
|
|
|
{
|
|
|
|
}
|
2014-05-06 15:13:30 +02:00
|
|
|
|
2016-08-30 16:19:31 +02:00
|
|
|
/** Check if this member has a given prefix mode set
|
|
|
|
* @param pm Prefix mode to check
|
2014-05-06 15:13:30 +02:00
|
|
|
* @return True if the member has the prefix mode set, false otherwise
|
|
|
|
*/
|
2016-08-30 16:19:31 +02:00
|
|
|
bool HasMode(const PrefixMode* pm) const
|
2009-09-13 20:30:47 +00:00
|
|
|
{
|
2022-05-17 13:02:58 +01:00
|
|
|
return std::find(modes.begin(), modes.end(), pm) != modes.end();
|
2009-09-13 20:30:47 +00:00
|
|
|
}
|
2014-05-06 15:13:30 +02:00
|
|
|
|
2022-05-17 13:02:58 +01:00
|
|
|
/** Returns the highest prefix mode for this membership or nullptr if no prefix mode is set. */
|
|
|
|
PrefixMode* GetMode() const { return modes.empty() ? nullptr : *modes.begin(); }
|
|
|
|
|
2014-05-06 15:13:30 +02:00
|
|
|
/** Returns the rank of this member.
|
|
|
|
* The rank of a member is defined as the rank given by the 'strongest' prefix mode a
|
|
|
|
* member has. See the PrefixMode class description for more info.
|
|
|
|
* @return The rank of the member
|
|
|
|
*/
|
2022-05-17 13:41:40 +01:00
|
|
|
ModeHandler::Rank GetRank() { return modes.empty() ? 0 : (*modes.begin())->GetPrefixRank(); }
|
2013-09-01 14:25:15 +02:00
|
|
|
|
|
|
|
/** Add a prefix character to a user.
|
|
|
|
* Only the core should call this method, usually from
|
|
|
|
* within the mode parser or when the first user joins
|
|
|
|
* the channel (to grant the default privs to them)
|
|
|
|
* @param mh The mode handler of the prefix mode to associate
|
|
|
|
* @param adding True if adding the prefix, false when removing
|
|
|
|
* @return True if a change was made
|
|
|
|
*/
|
2013-09-01 14:38:41 +02:00
|
|
|
bool SetPrefix(PrefixMode* mh, bool adding);
|
2014-02-14 12:15:00 +01:00
|
|
|
|
|
|
|
/** Get the highest prefix this user has on the channel
|
|
|
|
* @return A character containing the highest prefix.
|
|
|
|
* If the user has no prefix, 0 is returned. If the user has multiple prefixes,
|
|
|
|
* the highest is returned. If you do not recognise the prefix character you
|
|
|
|
* can get, you can deal with it in a 'proportional' manner compared to known
|
|
|
|
* prefixes, using GetPrefixValue().
|
|
|
|
*/
|
|
|
|
char GetPrefixChar() const;
|
2014-02-14 12:16:31 +01:00
|
|
|
|
2022-05-17 13:02:58 +01:00
|
|
|
/** Get the mode character of the highest prefix mode this user has on the channel or 0 if no prefix modes are set. */
|
|
|
|
char GetModeChar() const { return modes.empty() ? 0 : (*modes.begin())->GetModeChar(); }
|
|
|
|
|
2014-02-14 12:16:31 +01:00
|
|
|
/** Return all prefix chars this member has.
|
|
|
|
* @return A list of all prefix characters. The prefixes will always
|
|
|
|
* be in rank order, greatest first, as certain IRC clients require
|
|
|
|
* this when multiple prefixes are used names lists.
|
|
|
|
*/
|
2016-08-30 16:33:46 +02:00
|
|
|
std::string GetAllPrefixChars() const;
|
2018-01-03 16:24:19 +00:00
|
|
|
|
2022-05-17 13:02:58 +01:00
|
|
|
/** Returns all prefix modes this member has ordered descending by rank. */
|
|
|
|
std::string GetAllPrefixModes() const;
|
|
|
|
|
2018-01-03 16:24:19 +00:00
|
|
|
/** Sends a server notice to this user in the context of this channel.
|
|
|
|
* @param text The contents of the message to send.
|
|
|
|
*/
|
|
|
|
void WriteNotice(const std::string& text) const;
|
2009-09-13 20:30:47 +00:00
|
|
|
};
|