mirror of
https://github.com/anope/anope.git
synced 2026-06-26 12:56:39 +02:00
addModule + delModule compressed into constructor/destructor.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1615 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
@@ -35,6 +35,32 @@ Module::Module(const std::string &mname, const std::string &creator)
|
||||
{
|
||||
this->lang[i].argc = 0;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
ModuleHash *current = NULL;
|
||||
ModuleHash *newHash = NULL;
|
||||
ModuleHash *lastHash = NULL;
|
||||
|
||||
index = CMD_HASH(this->name);
|
||||
|
||||
for (current = MODULE_HASH[index]; current; current = current->next) {
|
||||
if (this->name ==current->name)
|
||||
throw CoreException("Module already exists!");
|
||||
lastHash = current;
|
||||
}
|
||||
|
||||
if ((newHash = (ModuleHash *)malloc(sizeof(ModuleHash))) == NULL) {
|
||||
fatal("Out of memory");
|
||||
}
|
||||
this->created = time(NULL);
|
||||
newHash->next = NULL;
|
||||
newHash->name = sstrdup(this->name.c_str());
|
||||
newHash->m = this;
|
||||
|
||||
if (lastHash == NULL)
|
||||
MODULE_HASH[index] = newHash;
|
||||
else
|
||||
lastHash->next = newHash;
|
||||
}
|
||||
|
||||
Module::~Module()
|
||||
@@ -157,7 +183,25 @@ Module::~Module()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
ModuleHash *lastHash = NULL;
|
||||
ModuleHash *mhash = NULL;
|
||||
|
||||
index = CMD_HASH(this->name);
|
||||
|
||||
for (mhash = MODULE_HASH[index]; mhash; mhash = mhash->next) {
|
||||
if (this->name == mhash->name) {
|
||||
if (!lastHash) {
|
||||
MODULE_HASH[index] = mhash->next;
|
||||
} else {
|
||||
lastHash->next = mhash->next;
|
||||
}
|
||||
free(mhash->name);
|
||||
free(mhash);
|
||||
}
|
||||
lastHash = mhash;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user