X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=include%2Fmodules%2Fcap.h;h=8299d14aeae7634eb6553266c09f1f7492714b22;hb=124c17e14134a4999afc1a5e981ab7c75b3694b9;hp=6f91f5aeefbb6575029c2109654eccb14c281f05;hpb=302053cf8f5378da7f23e5d2f68a24c9d2325351;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules/cap.h b/include/modules/cap.h index 6f91f5aee..8299d14ae 100644 --- a/include/modules/cap.h +++ b/include/modules/cap.h @@ -28,7 +28,14 @@ namespace Cap static const unsigned int MAX_VALUE_LENGTH = 100; typedef intptr_t Ext; - typedef LocalIntExt ExtItem; + class ExtItem : public LocalIntExt + { + public: + ExtItem(Module* mod); + std::string serialize(SerializeFormat format, const Extensible* container, void* item) const CXX11_OVERRIDE; + void unserialize(SerializeFormat format, Extensible* container, const std::string& value) CXX11_OVERRIDE; + }; + class Capability; enum Protocol @@ -190,7 +197,7 @@ namespace Cap if (!IsRegistered()) return false; Ext caps = extitem->get(user); - return (caps & GetMask()); + return ((caps & GetMask()) != 0); } /** Turn the capability on/off for a user. If the cap is not registered this method has no effect. @@ -278,4 +285,32 @@ namespace Cap return NULL; } }; + + /** Reference to a cap. The cap may be provided by another module. + */ + class Reference + { + dynamic_reference_nocheck ref; + + public: + /** Constructor, initializes the capability reference + * @param mod Module creating this object + * @param Name Raw name of the cap as used in the protocol (CAP LS, etc.) + */ + Reference(Module* mod, const std::string& Name) + : ref(mod, "cap/" + Name) + { + } + + /** Check whether a user has the referenced capability turned on. + * @param user User to check + * @return True if the user is using the referenced capability, false otherwise + */ + bool get(LocalUser* user) + { + if (ref) + return ref->get(user); + return false; + } + }; }