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); if (!ServerInstance->Modes->AddMode(mh)) throw ModuleException("Mode "+std::string(item.name)+" already exists."); 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: { if ((item.name.substr(0, 5) == "mode/") || (item.name.substr(0, 6) == "umode/")) throw ModuleException("The \"mode/\" and the \"umode\" service name prefixes are reserved."); DataProviders.insert(std::make_pair(item.name, &item)); std::string::size_type slash = item.name.find('/'); if (slash != std::string::npos) { DataProviders.insert(std::make_pair(item.name.substr(0, slash), &item)); DataProviders.insert(std::make_pair(item.name.substr(slash + 1), &item)); } dynamic_reference_base::reset_all(); return; } default: throw ModuleException("Cannot add unknown service type"); } }