summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/base.cpp10
-rw-r--r--src/command_parse.cpp6
-rw-r--r--src/mode.cpp6
-rw-r--r--src/modules.cpp45
4 files changed, 43 insertions, 24 deletions
diff --git a/src/base.cpp b/src/base.cpp
index 496b23ef5..0ff3fbe4c 100644
--- a/src/base.cpp
+++ b/src/base.cpp
@@ -95,6 +95,10 @@ ServiceProvider::~ServiceProvider()
{
}
+void ServiceProvider::RegisterService()
+{
+}
+
ExtensionItem::ExtensionItem(const std::string& Key, ExtensibleType exttype, Module* mod)
: ServiceProvider(mod, Key, SERVICE_METADATA)
, type(exttype)
@@ -140,6 +144,12 @@ void* ExtensionItem::unset_raw(Extensible* container)
return rv;
}
+void ExtensionItem::RegisterService()
+{
+ if (!ServerInstance->Extensions.Register(this))
+ throw ModuleException("Extension already exists: " + name);
+}
+
bool ExtensionManager::Register(ExtensionItem* item)
{
return types.insert(std::make_pair(item->name, item)).second;
diff --git a/src/command_parse.cpp b/src/command_parse.cpp
index 7998d9cc3..c123353b0 100644
--- a/src/command_parse.cpp
+++ b/src/command_parse.cpp
@@ -379,6 +379,12 @@ Command::~Command()
ServerInstance->Parser.RemoveCommand(this);
}
+void Command::RegisterService()
+{
+ if (!ServerInstance->Parser.AddCommand(this))
+ throw ModuleException("Command already exists: " + name);
+}
+
void CommandParser::ProcessBuffer(std::string &buffer,LocalUser *user)
{
if (buffer.empty())
diff --git a/src/mode.cpp b/src/mode.cpp
index 671b5d854..6038f6f5b 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -90,6 +90,12 @@ bool ModeHandler::ResolveModeConflict(std::string& theirs, const std::string& ou
return (theirs < ours);
}
+void ModeHandler::RegisterService()
+{
+ ServerInstance->Modes.AddMode(this);
+ ServerInstance->Modules.AddReferent((GetModeType() == MODETYPE_CHANNEL ? "mode/" : "umode/") + name, this);
+}
+
ModeAction SimpleUserModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
{
/* We're either trying to add a mode we already have or
diff --git a/src/modules.cpp b/src/modules.cpp
index 79a71652c..d77221c39 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -528,22 +528,6 @@ void ModuleManager::AddService(ServiceProvider& item)
{
switch (item.service)
{
- case SERVICE_COMMAND:
- if (!ServerInstance->Parser.AddCommand(static_cast<Command*>(&item)))
- throw ModuleException("Command "+std::string(item.name)+" already exists.");
- return;
- case SERVICE_MODE:
- {
- ModeHandler* mh = static_cast<ModeHandler*>(&item);
- ServerInstance->Modes->AddMode(mh);
- DataProviders.insert(std::make_pair((mh->GetModeType() == MODETYPE_CHANNEL ? "mode/" : "umode/") + item.name, &item));
- dynamic_reference_base::reset_all();
- return;
- }
- case SERVICE_METADATA:
- if (!ServerInstance->Extensions.Register(static_cast<ExtensionItem*>(&item)))
- throw ModuleException("Extension " + std::string(item.name) + " already exists.");
- return;
case SERVICE_DATA:
case SERVICE_IOHOOK:
{
@@ -561,7 +545,7 @@ void ModuleManager::AddService(ServiceProvider& item)
return;
}
default:
- throw ModuleException("Cannot add unknown service type");
+ item.RegisterService();
}
}
@@ -576,13 +560,7 @@ void ModuleManager::DelService(ServiceProvider& item)
case SERVICE_DATA:
case SERVICE_IOHOOK:
{
- for(std::multimap<std::string, ServiceProvider*>::iterator i = DataProviders.begin(); i != DataProviders.end(); )
- {
- std::multimap<std::string, ServiceProvider*>::iterator curr = i++;
- if (curr->second == &item)
- DataProviders.erase(curr);
- }
- dynamic_reference_base::reset_all();
+ DelReferent(&item);
return;
}
default:
@@ -674,3 +652,22 @@ Module* ModuleManager::Find(const std::string &name)
else
return modfind->second;
}
+
+void ModuleManager::AddReferent(const std::string& name, ServiceProvider* service)
+{
+ DataProviders.insert(std::make_pair(name, service));
+ dynamic_reference_base::reset_all();
+}
+
+void ModuleManager::DelReferent(ServiceProvider* service)
+{
+ for (std::multimap<std::string, ServiceProvider*>::iterator i = DataProviders.begin(); i != DataProviders.end(); )
+ {
+ ServiceProvider* curr = i->second;
+ if (curr == service)
+ DataProviders.erase(i++);
+ else
+ ++i;
+ }
+ dynamic_reference_base::reset_all();
+}