]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Provide a facility for modules to flag a config file completed
[user/henk/code/inspircd.git] / src / inspircd.cpp
index f671c9545f1069e63904ce591a9bd56e73e5124c..12a9bf756612fe80febb17afc00e4bdb831fe46e 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <fstream>
 #include "xline.h"
+#include "bancache.h"
 #include "socketengine.h"
 #include "inspircd_se_config.h"
 #include "socket.h"
@@ -69,9 +70,6 @@ const char* ExitCodes[] =
 
 void InspIRCd::Cleanup()
 {
-       std::vector<std::string> mymodnames;
-       int MyModCount = this->Modules->GetCount();
-
        if (Config)
        {
                for (unsigned int i = 0; i < Config->ports.size(); i++)
@@ -96,19 +94,12 @@ void InspIRCd::Cleanup()
         */
        for (int tries = 0; tries < 3; tries++)
        {
-               MyModCount = this->Modules->GetCount();
-               mymodnames.clear();
-
-               if (MyModCount)
+               std::vector<std::string> module_names = Modules->GetAllModuleNames(0);
+               for (std::vector<std::string>::iterator k = module_names.begin(); k != module_names.end(); ++k)
                {
                        /* Unload all modules, so they get a chance to clean up their listeners */
-                       for (int j = 0; j <= MyModCount; j++)
-                               mymodnames.push_back(Config->module_names[j]);
-
-                       for (int k = 0; k <= MyModCount; k++)
-                               this->Modules->Unload(mymodnames[k].c_str());
+                       this->Modules->Unload(k->c_str());
                }
-
        }
 
        /* Close logging */
@@ -324,7 +315,15 @@ InspIRCd::InspIRCd(int argc, char** argv)
        this->uuidlist = new user_hash();
        this->chanlist = new chan_hash();
 
+
        this->Config = new ServerConfig(this);
+       this->SNO = new SnomaskManager(this);
+       this->BanCache = new BanCacheManager(this);
+       this->Modules = new ModuleManager(this);
+       this->stats = new serverstats();
+       this->Timers = new TimerManager(this);
+       this->Parser = new CommandParser(this);
+       this->XLines = new XLineManager(this);
 
        this->Config->argv = argv;
        this->Config->argc = argc;
@@ -337,7 +336,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
 
        this->Config->opertypes.clear();
        this->Config->operclass.clear();
-       this->SNO = new SnomaskManager(this);
+
        this->TIME = this->OLDTIME = this->startup_time = time(NULL);
        this->time_delta = 0;
        srand(this->TIME);
@@ -425,49 +424,15 @@ InspIRCd::InspIRCd(int argc, char** argv)
        /* Set the finished argument values */
        Config->nofork = do_nofork;
        Config->forcedebug = do_debug;
-       Config->writelog = !do_nolog;
-
-       this->Modules = new ModuleManager(this);
-       this->stats = new serverstats();
-       this->Timers = new TimerManager(this);
-       this->Parser = new CommandParser(this);
-       this->XLines = new XLineManager(this);
-       
+       Config->writelog = !do_nolog;   
        Config->ClearStack();
-       Config->Read(true, NULL);
-
-       // Get XLine to do it's thing.
-       this->XLines->CheckELines(this->XLines->lookup_lines['E']);
-       this->XLines->ApplyLines();
-       
-       this->Modules->modules.resize(255);
-       this->Modules->handles.resize(255);
-
-       /*
-        * Initialise SID/UID.
-        * For an explanation as to exactly how this works, and why it works this way, see GetUID().
-        *   -- w00t
-        */
-       /* Generate SID */
-       size_t sid = 0;
-       if (Config->sid)
-       {
-               sid = Config->sid;
-       }
-       else
-       {
-               for (const char* x = Config->ServerName; *x; ++x)
-                       sid = 5 * sid + *x;
-               for (const char* y = Config->ServerDesc; *y; ++y)
-                       sid = 5 * sid + *y;
-               sid = sid % 999;
-
-               Config->sid = sid;
-       }
 
-       this->InitialiseUID();
+       this->Modes = new ModeParser(this);
 
-       /* set up fake client */
+       /* set up fake client (uid is incorrect at this point,
+         * until after config is read. we set up the user again
+         * at that point 
+         */
        this->FakeClient = new User(this);
        this->FakeClient->SetFd(FD_MAGIC_NUMBER);
 
@@ -500,21 +465,88 @@ InspIRCd::InspIRCd(int argc, char** argv)
 
        SE->RecoverFromFork();
 
-       this->Modes = new ModeParser(this);
-       this->AddServerName(Config->ServerName);
-       CheckDie();
-       int bounditems = BindPorts(true, found_ports, pl);
+       this->Res = new DNS(this);
 
-       for(int t = 0; t < 255; t++)
-               Config->global_implementation[t] = 0;
+       /* Read config, pass 0. At the end if this pass,
+        * the Config->IncludeFiles is populated, we call
+        * Config->StartDownloads to initialize the downlaods of all
+        * these files.
+        */
+        Config->Read(true, NULL, 0);
+       Config->StartDownloads();
+       
+       /* Now the downloads are started, we monitor them for completion.
+        * On completion, we call Read again with pass = 1.
+        * NOTE: We really should add a timeout here
+        */
 
-       memset(&Config->implement_lists,0,sizeof(Config->implement_lists));
+       while (Config->Downloading())
+       {
+               SE->DispatchEvents();
+               this->BufferedSocketCull();
+       }
 
        printf("\n");
 
-       this->Res = new DNS(this);
+       if (Config->FileErrors)
+       {
+               /* One or more file download/access errors, do not
+                * proceed to second pass
+                */
+               for (std::map<std::string, std::istream*>::iterator x = Config->IncludedFiles.begin(); x != Config->IncludedFiles.end(); ++x)
+               {
+                       if (!x->second)
+                               printf("ERROR: Failed to access the file: %s.\n", x->first.c_str());
+               }
+               printf("Initialisation of configuration failed.\n");
+               Exit(EXIT_STATUS_CONFIG);
+       }
+
+       /* We have all the files we can get, initiate pass 1 */
+       Config->Read(true, NULL, 1);
+
+        this->AddServerName(Config->ServerName);
+
+        /* set up fake client again this time with the correct uid */
+        delete FakeClient;
+        this->FakeClient = new User(this);
+        this->FakeClient->SetFd(FD_MAGIC_NUMBER);
+
+        /*
+         * Initialise SID/UID.
+         * For an explanation as to exactly how this works, and why it works this way, see GetUID().
+         *   -- w00t
+         */
+        /* Generate SID */
+        size_t sid = 0;
+        if (Config->sid)
+        {
+                sid = Config->sid;
+        }
+        else
+        {
+                for (const char* x = Config->ServerName; *x; ++x)
+                        sid = 5 * sid + *x;
+                for (const char* y = Config->ServerDesc; *y; ++y)
+                        sid = 5 * sid + *y;
+                sid = sid % 999;
+
+                Config->sid = sid;
+        }
+
+        this->InitialiseUID();
+
+        // Get XLine to do it's thing.
+        this->XLines->CheckELines();
+        this->XLines->ApplyLines();
+
+
+       CheckDie();
+       int bounditems = BindPorts(true, found_ports, pl);
+
+       printf("\n");
 
-       this->Modules->LoadAll();
+       /*this->Modules->LoadAll();*/
        
        /* Just in case no modules were loaded - fix for bug #101 */
        this->BuildISupport();
@@ -635,7 +667,6 @@ int InspIRCd::Run()
 
                        if ((TIME % 5) == 0)
                        {
-                               XLines->expire_lines();
                                FOREACH_MOD_I(this,I_OnBackgroundTimer,OnBackgroundTimer(TIME));
                                Timers->TickMissedTimers(TIME);
                        }
@@ -717,18 +748,13 @@ int main(int argc, char ** argv)
  */
 bool InspIRCd::AllModulesReportReady(User* user)
 {
-       if (!Config->global_implementation[I_OnCheckReady])
-               return true;
-
-       for (int i = 0; i <= this->Modules->GetCount(); i++)
+       for (EventHandlerIter i = Modules->EventHandlers[I_OnCheckReady].begin(); i != Modules->EventHandlers[I_OnCheckReady].end(); ++i)
        {
-               if (Config->implement_lists[i][I_OnCheckReady])
-               {
-                       int res = this->Modules->modules[i]->OnCheckReady(user);
-                       if (!res)
-                               return false;
-               }
+               int res = (*i)->OnCheckReady(user);
+               if (!res)
+                       return false;
        }
+
        return true;
 }