]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules.cpp
Implement feature in bug #395 reported by stealth, and tidy up a bit
[user/henk/code/inspircd.git] / src / modules.cpp
index f0ef1f383e467c57191c968225617a70cc6bcddf..28d746323eb2cb2f6871dff97945616e2edb47de 100644 (file)
@@ -200,6 +200,131 @@ void              Module::OnGarbageCollect() { }
 void           Module::OnBufferFlushed(userrec* user) { }
 
 
+char* InspIRCd::ModuleError()
+{
+       return MODERR;
+}
+
+void InspIRCd::EraseFactory(int j)
+{
+       int v = 0;
+       for (std::vector<ircd_module*>::iterator t = factory.begin(); t != factory.end(); t++)
+       {
+               if (v == j)
+               {
+                       delete *t;
+                       factory.erase(t);
+                       factory.push_back(NULL);
+                       return;
+               }
+               v++;
+       }
+}
+
+void InspIRCd::EraseModule(int j)
+{
+       int v1 = 0;
+       for (ModuleList::iterator m = modules.begin(); m!= modules.end(); m++)
+       {
+               if (v1 == j)
+               {
+                       DELETE(*m);
+                       modules.erase(m);
+                       modules.push_back(NULL);
+                       break;
+               }
+               v1++;
+       }
+       int v2 = 0;
+       for (std::vector<std::string>::iterator v = Config->module_names.begin(); v != Config->module_names.end(); v++)
+       {
+               if (v2 == j)
+               {
+                       Config->module_names.erase(v);
+                       break;
+               }
+               v2++;
+       }
+
+}
+
+void InspIRCd::MoveTo(std::string modulename,int slot)
+{
+       unsigned int v2 = 256;
+       for (unsigned int v = 0; v < Config->module_names.size(); v++)
+       {
+               if (Config->module_names[v] == modulename)
+               {
+                       // found an instance, swap it with the item at the end
+                       v2 = v;
+                       break;
+               }
+       }
+       if ((v2 != (unsigned int)slot) && (v2 < 256))
+       {
+               // Swap the module names over
+               Config->module_names[v2] = Config->module_names[slot];
+               Config->module_names[slot] = modulename;
+               // now swap the module factories
+               ircd_module* temp = factory[v2];
+               factory[v2] = factory[slot];
+               factory[slot] = temp;
+               // now swap the module objects
+               Module* temp_module = modules[v2];
+               modules[v2] = modules[slot];
+               modules[slot] = temp_module;
+               // now swap the implement lists (we dont
+               // need to swap the global or recount it)
+               for (int n = 0; n < 255; n++)
+               {
+                       char x = Config->implement_lists[v2][n];
+                       Config->implement_lists[v2][n] = Config->implement_lists[slot][n];
+                       Config->implement_lists[slot][n] = x;
+               }
+       }
+}
+
+void InspIRCd::MoveAfter(std::string modulename, std::string after)
+{
+       for (unsigned int v = 0; v < Config->module_names.size(); v++)
+       {
+               if (Config->module_names[v] == after)
+               {
+                       MoveTo(modulename, v);
+                       return;
+               }
+       }
+}
+
+void InspIRCd::MoveBefore(std::string modulename, std::string before)
+{
+       for (unsigned int v = 0; v < Config->module_names.size(); v++)
+       {
+               if (Config->module_names[v] == before)
+               {
+                       if (v > 0)
+                       {
+                               MoveTo(modulename, v-1);
+                       }
+                       else
+                       {
+                               MoveTo(modulename, v);
+                       }
+                       return;
+               }
+       }
+}
+
+void InspIRCd::MoveToFirst(std::string modulename)
+{
+       MoveTo(modulename,0);
+}
+
+void InspIRCd::MoveToLast(std::string modulename)
+{
+       MoveTo(modulename,this->GetModuleCount());
+}
+
 bool InspIRCd::UnloadModule(const char* filename)
 {
        std::string filename_str = filename;
@@ -567,15 +692,6 @@ const std::string& InspIRCd::GetModuleName(Module* m)
        return nothing; /* As above */
 }
 
-void InspIRCd::RehashServer()
-{
-       this->WriteOpers("*** Rehashing config file");
-       this->RehashUsersAndChans();
-       this->Config->Read(false,NULL);
-       this->ResetMaxBans();
-       this->Res->Rehash();
-}
-
 /* This is ugly, yes, but hash_map's arent designed to be
  * addressed in this manner, and this is a bit of a kludge.
  * Luckily its a specialist function and rarely used by
@@ -639,9 +755,9 @@ void InspIRCd::DumpText(userrec* User, const std::string &LinePrefix, stringstre
        User->WriteServ(CompleteLine);
 }
 
-userrec* InspIRCd::FindDescriptor(int socket)
+userrec* FindDescriptorHandler::Call(int socket)
 {
-       return reinterpret_cast<userrec*>(this->SE->GetRef(socket));
+       return reinterpret_cast<userrec*>(Server->SE->GetRef(socket));
 }
 
 bool InspIRCd::AddMode(ModeHandler* mh, const unsigned char mode)