]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Add newlines to the end :) (\n)
[user/henk/code/inspircd.git] / src / inspircd.cpp
index aaad2746ada3a7206134ebaad5a5e6371e5f1556..ee5d0a2bc2d8507b76a39a857bd77e136f4c933f 100644 (file)
@@ -13,6 +13,7 @@
 
 /* $Install: src/inspircd $(BINPATH) */
 
+
 #include "inspircd.h"
 #include <signal.h>
 
@@ -276,15 +277,29 @@ void InspIRCd::WritePID(const std::string &filename)
 InspIRCd::InspIRCd(int argc, char** argv)
        : GlobalCulls(this),
 
-        /* Functor initialisation. Note that the ordering here is very important. */
+        /* Functor initialisation. Note that the ordering here is very important. 
+         *
+         * THIS MUST MATCH ORDER OF DECLARATION OF THE HandleWhateverFunc classes
+         * within class InspIRCd.
+         */
         HandleProcessUser(this),
         HandleIsNick(this),
         HandleIsIdent(this),
         HandleFindDescriptor(this),
         HandleFloodQuitUser(this),
-
-        /* Functor pointer initialisation. Must match the order of the list above */
+        HandleIsChannel(this),
+        HandleIsSID(this),
+        HandleRehash(this),
+
+        /* Functor pointer initialisation. Must match the order of the list above
+         *
+         * THIS MUST MATCH THE ORDER OF DECLARATION OF THE FUNCTORS, e.g. the methods
+         * themselves within the class.
+         */
         ProcessUser(&HandleProcessUser),
+        IsChannel(&HandleIsChannel),
+        IsSID(&HandleIsSID),
+        Rehash(&HandleRehash),
         IsNick(&HandleIsNick),
         IsIdent(&HandleIsIdent),
         FindDescriptor(&HandleFindDescriptor),
@@ -308,11 +323,13 @@ InspIRCd::InspIRCd(int argc, char** argv)
        SE = SEF->Create(this);
        delete SEF;
 
-
        ThreadEngineFactory* tef = new ThreadEngineFactory();
        this->Threads = tef->Create(this);
        delete tef;
 
+       /* Default implementation does nothing */
+       this->PI = new ProtocolInterface(this);
+
        this->s_signal = 0;
        
        // Create base manager classes early, so nothing breaks
@@ -446,13 +463,6 @@ InspIRCd::InspIRCd(int argc, char** argv)
 
        this->Modes = new ModeParser(this);
 
-       /* 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);
-
        if (!do_root)
                this->CheckRoot();
        else
@@ -499,10 +509,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
         * For an explanation as to exactly how this works, and why it works this way, see GetUID().
         *   -- w00t
         */
-       if (*Config->sid)
-       {
-       }
-       else
+       if (!*Config->sid)
        {
                // Generate one
                size_t sid = 0;
@@ -518,18 +525,14 @@ InspIRCd::InspIRCd(int argc, char** argv)
                Config->sid[2] = (char)(sid % 10 + 48);
        }
 
-       this->InitialiseUID();
-
        /* set up fake client again this time with the correct uid */
-       delete FakeClient;
-       this->FakeClient = new User(this);
+       this->FakeClient = new User(this, "#INVALID");
        this->FakeClient->SetFd(FD_MAGIC_NUMBER);
 
        // Get XLine to do it's thing.
        this->XLines->CheckELines();
        this->XLines->ApplyLines();
 
-
        CheckDie();
        int bounditems = BindPorts(true, found_ports, pl);
 
@@ -552,12 +555,16 @@ InspIRCd::InspIRCd(int argc, char** argv)
        {
                printf("\nWARNING: Not all your client ports could be bound --\nstarting anyway with %d of %d client ports bound.\n\n", bounditems, found_ports);
                printf("The following port(s) failed to bind:\n");
+               printf("Hint: Try using an IP instead of blank or *\n\n");
                int j = 1;
                for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
                {
                        printf("%d.\tIP: %s\tPort: %lu\n", j, i->first.empty() ? "<all>" : i->first.c_str(), (unsigned long)i->second);
                }
        }
+
+       printf("\nInspIRCd is now running as '%s'[%s] with %d max open sockets\n", Config->ServerName,Config->GetSID().c_str(), SE->GetMaxFds());
+       
 #ifndef WINDOWS
        if (!Config->nofork)
        {
@@ -594,28 +601,11 @@ InspIRCd::InspIRCd(int argc, char** argv)
        }
 #endif
 
-       printf("\nInspIRCd is now running as '%s'[%s]\n", Config->ServerName,Config->GetSID().c_str());
-       Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s]", Config->ServerName,Config->GetSID().c_str());
+       Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName,Config->GetSID().c_str(), SE->GetMaxFds());
 
        this->WritePID(Config->PID);
 }
 
-/* moved to a function, as UID generation can call this also */
-void InspIRCd::InitialiseUID()
-{
-       int i = 3;
-
-       current_uid[0] = Config->sid[0];
-       current_uid[1] = Config->sid[1];
-       current_uid[2] = Config->sid[2];
-
-       /* Initialise UID */
-       for(i = 3; i < UUID_LENGTH - 1; i++)
-               current_uid[i] = 'A';
-
-       current_uid[UUID_LENGTH] = '\0';
-}
-
 int InspIRCd::Run()
 {
        /* See if we're supposed to be running the test suite rather than entering the mainloop */
@@ -636,6 +626,35 @@ int InspIRCd::Run()
                static char window_title[100];
 #endif
 
+               /* Check if there is a config thread which has finished executing but has not yet been freed */
+               if (this->ConfigThread && this->ConfigThread->GetExitFlag())
+               {
+                       /* Rehash has completed */
+                       this->Logs->Log("CONFIG",DEBUG,"Detected ConfigThread exiting, tidying up...");
+
+                       /* IMPORTANT: This delete may hang if you fuck up your thread syncronization.
+                        * It will hang waiting for the ConfigThread to 'join' to avoid race conditons,
+                        * until the other thread is completed.
+                        */
+                       delete ConfigThread;
+                       ConfigThread = NULL;
+
+                       /* These are currently not known to be threadsafe, so they are executed outside
+                        * of the thread. It would be pretty simple to move them to the thread Run method
+                        * once they are known threadsafe with all the correct mutexes in place.
+                        *
+                        * XXX: The order of these is IMPORTANT, do not reorder them without testing
+                        * thoroughly!!!
+                        */
+                       this->XLines->CheckELines();
+                       this->XLines->ApplyLines();
+                       this->Res->Rehash();
+                       this->ResetMaxBans();
+                       InitializeDisabledCommands(Config->DisabledCommands, this);
+                       FOREACH_MOD_I(this, I_OnRehash, OnRehash(Config->RehashUser, Config->RehashParameter));
+                       this->BuildISupport();
+               }
+
                /* time() seems to be a pretty expensive syscall, so avoid calling it too much.
                 * Once per loop iteration is pleanty.
                 */
@@ -651,7 +670,7 @@ int InspIRCd::Run()
                {
                        if (TIME < OLDTIME)
                        {
-                               SNO->WriteToSnoMask('A', "\002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME));
+                               SNO->WriteToSnoMask('A', "\002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %lu secs.", (unsigned long)OLDTIME-TIME);
                        }
 
                        if ((TIME % 3600) == 0)
@@ -740,11 +759,9 @@ bool InspIRCd::AllModulesReportReady(User* user)
 {
        for (EventHandlerIter i = Modules->EventHandlers[I_OnCheckReady].begin(); i != Modules->EventHandlers[I_OnCheckReady].end(); ++i)
        {
-               int res = (*i)->OnCheckReady(user);
-               if (!res)
+               if (!(*i)->OnCheckReady(user))
                        return false;
        }
-
        return true;
 }