]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Initialise SSL session pointer to NULL to prevent a potentially unsafe comparison...
[user/henk/code/inspircd.git] / src / inspircd.cpp
index 1d8ce762517fd4aed0f873c2ac2503d63efbb67b..463f9d82fdcbc130a85131d0005c4aa61c79b84f 100644 (file)
 #include "caller.h"
 #include "testsuite.h"
 
-using irc::sockets::insp_ntoa;
-using irc::sockets::insp_inaddr;
-using irc::sockets::insp_sockaddr;
-
 InspIRCd* SI = NULL;
 int* mysig = NULL;
 
@@ -77,6 +73,10 @@ const char* ExitCodes[] =
                "Couldn't load module on startup", /* 13 */
                "Could not create windows forked process", /* 14 */
                "Received SIGTERM", /* 15 */
+               "Bad command handler loaded", /* 16 */
+               "RegisterServiceCtrlHandler failed", /* 17 */
+               "UpdateSCMStatus failed", /* 18 */
+               "CreateEvent failed" /* 19 */
 };
 
 void InspIRCd::Cleanup()
@@ -454,6 +454,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
        ThreadEngineFactory* tef = new ThreadEngineFactory();
        this->Threads = tef->Create(this);
        delete tef;
+       this->Mutexes = new MutexFactory(this);
 
        /* Default implementation does nothing */
        this->PI = new ProtocolInterface(this);
@@ -621,7 +622,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
        /* During startup we don't actually initialize this
         * in the thread engine.
         */
-       this->ConfigThread = new ConfigReaderThread(this, true, NULL);
+       this->ConfigThread = new ConfigReaderThread(this, true, "");
        ConfigThread->Run();
        delete ConfigThread;
        this->ConfigThread = NULL;
@@ -719,6 +720,8 @@ InspIRCd::InspIRCd(int argc, char** argv)
                WindowsForkKillOwner(this);
                FreeConsole();
        }
+       /* Set win32 service as running, if we are running as a service */
+       SetServiceRunning();
 #endif
 
        Logs->Log("STARTUP", DEFAULT, "Startup complete as '%s'[%s], %d max open sockets", Config->ServerName,Config->GetSID().c_str(), SE->GetMaxFds());
@@ -771,7 +774,8 @@ int InspIRCd::Run()
                        this->Res->Rehash();
                        this->ResetMaxBans();
                        InitializeDisabledCommands(Config->DisabledCommands, this);
-                       FOREACH_MOD_I(this, I_OnRehash, OnRehash(Config->RehashUser, Config->RehashParameter));
+                       User* user = !Config->RehashUserUID.empty() ? FindNick(Config->RehashUserUID) : NULL;
+                       FOREACH_MOD_I(this, I_OnRehash, OnRehash(user, Config->RehashParameter));
                        this->BuildISupport();
                }
 
@@ -788,11 +792,12 @@ int InspIRCd::Run()
                 */
                if (TIME != OLDTIME)
                {
-                       if (TIME < OLDTIME)
+                       /* Allow a buffer of two seconds drift on this so that ntpdate etc dont harass admins */
+                       if (TIME < OLDTIME - 2)
                        {
                                SNO->WriteToSnoMask('d', "\002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %lu secs.", (unsigned long)OLDTIME-TIME);
                        }
-                       else if (TIME != OLDTIME + 1)
+                       else if (TIME > OLDTIME + 2)
                        {
                                SNO->WriteToSnoMask('d', "\002EH?!\002 -- Time is jumping FORWARDS! Clock skipped %lu secs.", (unsigned long)TIME - OLDTIME);
                        }
@@ -866,15 +871,6 @@ void InspIRCd::BufferedSocketCull()
  * An ircd in five lines! bwahahaha. ahahahahaha. ahahah *cough*.
  */
 
-int main(int argc, char ** argv)
-{
-       SI = new InspIRCd(argc, argv);
-       mysig = &SI->s_signal;
-       SI->Run();
-       delete SI;
-       return 0;
-}
-
 /* this returns true when all modules are satisfied that the user should be allowed onto the irc server
  * (until this returns true, a user will block in the waiting state, waiting to connect up to the
  * registration timeout maximum seconds)
@@ -898,3 +894,18 @@ void InspIRCd::SetSignal(int signal)
 {
        *mysig = signal;
 }
+
+/* On posix systems, the flow of the program starts right here, with
+ * ENTRYPOINT being a #define that defines main(). On Windows, ENTRYPOINT
+ * defines smain() and the real main() is in the service code under
+ * win32service.cpp. This allows the service control manager to control
+ * the process where we are running as a windows service.
+ */
+ENTRYPOINT
+{
+       SI = new InspIRCd(argc, argv);
+       mysig = &SI->s_signal;
+       SI->Run();
+       delete SI;
+       return 0;
+}