summaryrefslogtreecommitdiff
path: root/src/module.cpp
diff options
context:
space:
mode:
authorRobin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864>2008-11-09 19:03:56 +0000
committerRobin Burchell w00t@inspircd.org <Robin Burchell w00t@inspircd.org@5417fbe8-f217-4b02-8779-1006273d7864>2008-11-09 19:03:56 +0000
commit649a12c07ffd4340594486d31fa703fb78103222 (patch)
tree66b354a55523a12b8ad9c732f78c4df30fc0a8cd /src/module.cpp
parent65fd49d3628dd8d3bde8f70b58ac458785a261d7 (diff)
addModule + delModule compressed into constructor/destructor.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1615 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/module.cpp')
-rw-r--r--src/module.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/module.cpp b/src/module.cpp
index 3f9aabaed..08d1a1cf0 100644
--- a/src/module.cpp
+++ b/src/module.cpp
@@ -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;
}
}