From c770c47e18121e93bcdd06b1ab5f161440ffcfe2 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 31 Jul 2010 21:37:45 -0400 Subject: Don't dynamically allocate commands in modules anymore, instead made them members of modules. This means the commands are automatically destructed when the module is unloaded. Cleans up some old ugly code. --- src/command.cpp | 10 +++++++- src/module.cpp | 75 --------------------------------------------------------- src/modules.cpp | 1 - 3 files changed, 9 insertions(+), 77 deletions(-) (limited to 'src') diff --git a/src/command.cpp b/src/command.cpp index de9842d78..93c1f978c 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -16,6 +16,8 @@ Command::Command(const Anope::string &sname, size_t min_params, size_t max_param Command::~Command() { + if (this->module) + this->module->DelCommand(this->service, this); } CommandReturn Command::Execute(User *u, const std::vector &) @@ -39,7 +41,13 @@ bool Command::AddSubcommand(Command *c) return false; } -bool Command::DelSubcommand(const Anope::string &cname) +bool Command::DelSubcommand(Command *c) { return false; } + +Command *Command::FindSubcommand(const Anope::string &name) +{ + return NULL; +} + diff --git a/src/module.cpp b/src/module.cpp index 97cf717de..aa46a6f63 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -40,81 +40,6 @@ Module::~Module() /* Clear any active callbacks this module has */ ModuleManager::ClearCallBacks(this); - /** - * ok, im going to walk every hash looking for commands we own, now, not exactly elegant or efficiant :) - **/ - if (HostServ) - { - for (CommandMap::iterator it = HostServ->Commands.begin(), it_end = HostServ->Commands.end(); it != it_end; ) - { - Command *c = it->second; - ++it; - - if (c->module == this) - this->DelCommand(HostServ, c); - } - } - - if (BotServ) - { - for (CommandMap::iterator it = BotServ->Commands.begin(), it_end = BotServ->Commands.end(); it != it_end; ) - { - Command *c = it->second; - ++it; - - if (c->module == this) - this->DelCommand(BotServ, c); - } - } - - if (MemoServ) - { - for (CommandMap::iterator it = MemoServ->Commands.begin(), it_end = MemoServ->Commands.end(); it != it_end; ) - { - Command *c = it->second; - ++it; - - if (c->module == this) - this->DelCommand(MemoServ, c); - } - } - - if (NickServ) - { - for (CommandMap::iterator it = NickServ->Commands.begin(), it_end = NickServ->Commands.end(); it != it_end; ) - { - Command *c = it->second; - ++it; - - if (c->module == this) - this->DelCommand(NickServ, c); - } - } - - if (ChanServ) - { - for (CommandMap::iterator it = ChanServ->Commands.begin(), it_end = ChanServ->Commands.end(); it != it_end; ) - { - Command *c = it->second; - ++it; - - if (c->module == this) - this->DelCommand(ChanServ, c); - } - } - - if (OperServ) - { - for (CommandMap::iterator it = OperServ->Commands.begin(), it_end = OperServ->Commands.end(); it != it_end; ) - { - Command *c = it->second; - ++it; - - if (c->module == this) - this->DelCommand(OperServ, c); - } - } - std::list::iterator it = std::find(Modules.begin(), Modules.end(), this); if (it != Modules.end()) Modules.erase(it); diff --git a/src/modules.cpp b/src/modules.cpp index 26401351d..5cd9b6b69 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -185,7 +185,6 @@ int Module::AddCommand(BotInfo *bi, Command *c) if (it.second != true) { Alog() << "Error creating command " << c->name << ". Command already exists!"; - delete c; return MOD_ERR_EXISTS; } -- cgit