summaryrefslogtreecommitdiff
path: root/src/modules.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2010-10-04 16:38:25 -0400
committerAdam <Adam@anope.org>2010-10-04 16:38:25 -0400
commitab5ebc224516abfe424f2e631eed2dc314c32ab9 (patch)
tree116b0af44cd0b3d45e3fbf9715264f4c34c9439a /src/modules.cpp
parentcf98cd3e06e4de0f9902824b0ef8239e947c5b6a (diff)
Automatically destruct messages when modules are unloaded
Diffstat (limited to 'src/modules.cpp')
-rw-r--r--src/modules.cpp39
1 files changed, 12 insertions, 27 deletions
diff --git a/src/modules.cpp b/src/modules.cpp
index 902b940db..0f6771c3a 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -87,49 +87,34 @@ Module *FindModule(const Anope::string &name)
return NULL;
}
-/** Add a message to Anope
- * @param name The message name as sent by the IRCd
- * @param func A callback function that will be called when this message is received
- * @return The new message object
+/** Message constructor, adds the message to Anope
+ * @param n The message name
+ * @param f A callback function
*/
-Message *Anope::AddMessage(const Anope::string &name, bool (*func)(const Anope::string &source, const std::vector<Anope::string> &params))
+Message::Message(const Anope::string &n, bool (*f)(const Anope::string &, const std::vector<Anope::string> &)) : name(n), func(f)
{
- Message *m = new Message();
-
- m->name = name;
- m->func = func;
-
- MessageMap.insert(std::make_pair(m->name, m));
-
- return m;
+ MessageMap.insert(std::make_pair(this->name, this));
}
-/** Deletes a message from Anope
- * XXX Im not sure what will happen if this function is called indirectly from a message function pointed to by this message and there
- * is more than one hook for this message.. must check
- * @param m The message
- * @return true if the message was found and deleted, else false
+/** Message destructor
*/
-bool Anope::DelMessage(Message *m)
+Message::~Message()
{
- message_map::iterator it = MessageMap.find(m->name);
+ message_map::iterator it = MessageMap.find(this->name);
if (it == MessageMap.end())
- return false;
+ return;
- message_map::iterator upper = MessageMap.upper_bound(m->name);
+ message_map::iterator upper = MessageMap.upper_bound(this->name);
for (; it != upper; ++it)
{
- if (it->second == m)
+ if (it->second == this)
{
- delete m;
MessageMap.erase(it);
- return true;
+ break;
}
}
-
- return false;
}
/** Find message in the message table