summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/modules.h9
-rw-r--r--src/modules.cpp11
2 files changed, 16 insertions, 4 deletions
diff --git a/include/modules.h b/include/modules.h
index ac90d60e7..3e5ace3f4 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -288,7 +288,7 @@ class CoreExport dynamic_reference_base : public interfacebase
std::string name;
void resolve();
protected:
- DataProvider* value;
+ ServiceProvider* value;
public:
ModuleRef creator;
dynamic_reference_base(Module* Creator, const std::string& Name);
@@ -343,6 +343,13 @@ class dynamic_reference_nocheck : public dynamic_reference_base
}
};
+class ModeReference : public dynamic_reference_nocheck<ModeHandler>
+{
+ public:
+ ModeReference(Module* mod, const std::string& modename)
+ : dynamic_reference_nocheck<ModeHandler>(mod, "mode/" + modename) {}
+};
+
/** Priority types which can be used by Module::Prioritize()
*/
enum Priority { PRIORITY_FIRST, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER };
diff --git a/src/modules.cpp b/src/modules.cpp
index b09639b2e..1194e8358 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -368,10 +368,10 @@ void ModuleManager::DoSafeUnload(Module* mod)
ModeHandler* mh;
mh = ServerInstance->Modes->FindMode(m, MODETYPE_USER);
if (mh && mh->creator == mod)
- ServerInstance->Modes->DelMode(mh);
+ this->DelService(*mh);
mh = ServerInstance->Modes->FindMode(m, MODETYPE_CHANNEL);
if (mh && mh->creator == mod)
- ServerInstance->Modes->DelMode(mh);
+ this->DelService(*mh);
}
for(std::multimap<std::string, ServiceProvider*>::iterator i = DataProviders.begin(); i != DataProviders.end(); )
{
@@ -436,6 +436,8 @@ void ModuleManager::AddService(ServiceProvider& item)
case SERVICE_MODE:
if (!ServerInstance->Modes->AddMode(static_cast<ModeHandler*>(&item)))
throw ModuleException("Mode "+std::string(item.name)+" already exists.");
+ DataProviders.insert(std::make_pair("mode/" + item.name, &item));
+ dynamic_reference_base::reset_all();
return;
case SERVICE_METADATA:
if (!ServerInstance->Extensions.Register(static_cast<ExtensionItem*>(&item)))
@@ -444,6 +446,9 @@ void ModuleManager::AddService(ServiceProvider& item)
case SERVICE_DATA:
case SERVICE_IOHOOK:
{
+ if (item.name.substr(0, 5) == "mode/")
+ throw ModuleException("The \"mode/\" service name prefix is reserved.");
+
DataProviders.insert(std::make_pair(item.name, &item));
std::string::size_type slash = item.name.find('/');
if (slash != std::string::npos)
@@ -466,7 +471,7 @@ void ModuleManager::DelService(ServiceProvider& item)
case SERVICE_MODE:
if (!ServerInstance->Modes->DelMode(static_cast<ModeHandler*>(&item)))
throw ModuleException("Mode "+std::string(item.name)+" does not exist.");
- return;
+ // Fall through
case SERVICE_DATA:
case SERVICE_IOHOOK:
{