summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/modules/cap.h28
-rw-r--r--src/modules/m_cap.cpp2
2 files changed, 30 insertions, 0 deletions
diff --git a/include/modules/cap.h b/include/modules/cap.h
index 9ff5faca9..e6f9340e8 100644
--- a/include/modules/cap.h
+++ b/include/modules/cap.h
@@ -285,4 +285,32 @@ namespace Cap
return NULL;
}
};
+
+ /** Reference to a cap. The cap may be provided by another module.
+ */
+ class Reference
+ {
+ dynamic_reference_nocheck<Capability> 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;
+ }
+ };
}
diff --git a/src/modules/m_cap.cpp b/src/modules/m_cap.cpp
index c01377f46..3e9c37a34 100644
--- a/src/modules/m_cap.cpp
+++ b/src/modules/m_cap.cpp
@@ -170,6 +170,7 @@ class Cap::ManagerImpl : public Cap::Manager, public ReloadModule::EventListener
cap->bit = AllocateBit();
cap->extitem = &capext;
caps.insert(std::make_pair(cap->GetName(), cap));
+ ServerInstance->Modules.AddReferent("cap/" + cap->GetName(), cap);
FOREACH_MOD_CUSTOM(evprov, Cap::EventListener, OnCapAddDel, (cap, true));
}
@@ -193,6 +194,7 @@ class Cap::ManagerImpl : public Cap::Manager, public ReloadModule::EventListener
cap->set(user, false);
}
+ ServerInstance->Modules.DelReferent(cap);
cap->Unregister();
caps.erase(cap->GetName());
}