X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmembership.h;h=1bac0cf95e90563825e89d998a7f1284d7b53625;hb=c05f81cac83e80c7727594e3929e0709eccca689;hp=458c7efc4b7575872f9be21de1881bd5faafa1a0;hpb=228c2b2e582c7d64a7c6f564561322c7d3d168c4;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/membership.h b/include/membership.h index 458c7efc4..1bac0cf95 100644 --- a/include/membership.h +++ b/include/membership.h @@ -1,40 +1,122 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://wiki.inspircd.org/Credits + * Copyright (C) 2013-2014, 2016 Attila Molnar + * Copyright (C) 2013, 2017-2018 Sadie Powell + * Copyright (C) 2012 Robby + * Copyright (C) 2010 Craig Edwards + * Copyright (C) 2009 Daniel De Graaf * - * This program is free but copyrighted software; see - * the file COPYING for details. + * 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. * - * --------------------------------------------------- + * 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 . */ -#ifndef __MEMBERSHIP_H__ -#define __MEMBERSHIP_H__ -class User; -class Channel; +#pragma once + +#include "convto.h" -struct CoreExport Membership : public Extensible +/** + * 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). + */ +class CoreExport Membership : public Extensible, public insp::intrusive_list_node { + public: + /** Type of the Membership id + */ + typedef uint64_t Id; + + /** User on the channel + */ User* const user; + + /** Channel the user is on + */ Channel* const chan; - // mode list, sorted by prefix rank, higest first + + /** List of prefix mode letters this member has, + * sorted by prefix rank, highest first + */ std::string modes; + + /** 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) + { + return ConvToNum(str); + } + + /** 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. + */ Membership(User* u, Channel* c) : user(u), chan(c) {} - inline bool hasMode(char m) const + + /** Check if this member has a given prefix mode set + * @param pm Prefix mode to check + * @return True if the member has the prefix mode set, false otherwise + */ + bool HasMode(const PrefixMode* pm) const { - return modes.find(m) != std::string::npos; + return (modes.find(pm->GetModeChar()) != std::string::npos); } + + /** 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 + */ unsigned int getRank(); -}; -CoreExport typedef std::map UserMembList; -CoreExport typedef UserMembList::iterator UserMembIter; -CoreExport typedef UserMembList::const_iterator UserMembCIter; + /** 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 + */ + bool SetPrefix(PrefixMode* mh, bool adding); -CoreExport typedef std::set CUList; + /** 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; -#endif + /** 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. + */ + std::string GetAllPrefixChars() const; + + /** 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; +};