X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmembership.h;h=05d6b3796fb1ac72e44a035117d927077b4878f0;hb=7770cd985405c7630e9149fc08c314ec824a9c75;hp=44eaf1eb6c2d39f404b8c144b6b047ec40c7c722;hpb=f71e6bf9cb41811f18864f5d4eecb26e29d03f25;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/membership.h b/include/membership.h index 44eaf1eb6..05d6b3796 100644 --- a/include/membership.h +++ b/include/membership.h @@ -20,18 +20,70 @@ #pragma once -class CoreExport Membership : public Extensible, public intrusive_list_node +uint64_t ConvToUInt64(const std::string& in); + +/** + * 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 ConvToUInt64(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) {} + + /** Returns true if this member has a given prefix mode set + * @param m The prefix mode letter to check + * @return True if the member has the prefix mode set, false otherwise + */ inline bool hasMode(char m) const { return modes.find(m) != 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(); /** Add a prefix character to a user. @@ -60,42 +112,3 @@ class CoreExport Membership : public Extensible, public intrusive_list_node -class InviteBase -{ - protected: - intrusive_list invites; - - public: - void ClearInvites(); - - friend class Invitation; -}; - -class CoreExport Invitation : public intrusive_list_node, public intrusive_list_node -{ - Invitation(Channel* c, LocalUser* u, time_t timeout) : user(u), chan(c), expiry(timeout) {} - - public: - LocalUser* const user; - Channel* const chan; - time_t expiry; - - ~Invitation(); - static void Create(Channel* c, LocalUser* u, time_t timeout); - static Invitation* Find(Channel* c, LocalUser* u, bool check_expired = true); -}; - -typedef intrusive_list InviteList; - -template -inline void InviteBase::ClearInvites() -{ - for (typename intrusive_list::iterator i = invites.begin(); i != invites.end(); ) - { - Invitation* inv = *i; - ++i; - delete inv; - } -}