diff --git a/include/services.h b/include/services.h index 3a7ff65c2..47e9b8940 100644 --- a/include/services.h +++ b/include/services.h @@ -374,12 +374,22 @@ template class CoreExport Service : public Base Service(Module *o, const Anope::string &n) : owner(o), name(n) { - if (Service::services.find(n) != Service::services.end()) - throw ModuleException("Service with name " + n + " already exists"); - Service::services[n] = static_cast(this); + this->Register(); } virtual ~Service() + { + this->Unregister(); + } + + void Register() + { + if (Service::services.find(this->name) != Service::services.end()) + throw ModuleException("Service with name " + this->name + " already exists"); + Service::services[this->name] = static_cast(this); + } + + void Unregister() { Service::services.erase(this->name); }