1
0
mirror of https://github.com/anope/anope.git synced 2026-07-06 15:53:13 +02:00

Automatically destruct messages when modules are unloaded

This commit is contained in:
Adam
2010-10-04 16:38:25 -04:00
parent cf98cd3e06
commit ab5ebc2245
11 changed files with 142 additions and 312 deletions
-8
View File
@@ -14,11 +14,6 @@
Uplink *uplink_server;
extern void moduleAddMsgs();
extern void moduleAddIRCDMsgs();
/*************************************************************************/
void introduce_user(const Anope::string &user)
{
/* Watch out for infinite loops... */
@@ -379,9 +374,6 @@ void Init(int ac, char **av)
throw FatalException(ex.GetReason());
}
/* Add Core MSG handles */
moduleAddMsgs();
#ifndef _WIN32
if (!nofork)
{
+4 -7
View File
@@ -304,10 +304,7 @@ int m_whois(const Anope::string &source, const Anope::string &who)
return MOD_CONT;
}
/* *INDENT-OFF* */
void moduleAddMsgs()
{
Anope::AddMessage("STATS", m_stats);
Anope::AddMessage("TIME", m_time);
Anope::AddMessage("VERSION", m_version);
}
Message message_stats("STATS", m_stats);
Message message_time("TIME", m_time);
Message message_verssion("VERSION", m_version);
+12 -27
View File
@@ -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