]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/inspircd.cpp
New logging implementation. Also write messages about InspIRCd::Log() being deprecate...
[user/henk/code/inspircd.git] / src / inspircd.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* $Install: src/inspircd $(BINPATH) */
15
16 #include "inspircd.h"
17 #include <signal.h>
18
19 #ifndef WIN32
20         #include <dirent.h>
21         #include <unistd.h>
22         #include <sys/resource.h>
23         #include <dlfcn.h>
24         #include <getopt.h>
25
26         /* Some systems don't define RUSAGE_SELF. This should fix them. */
27         #ifndef RUSAGE_SELF
28                 #define RUSAGE_SELF 0
29         #endif
30 #endif
31
32 #include <fstream>
33 #include "xline.h"
34 #include "bancache.h"
35 #include "socketengine.h"
36 #include "inspircd_se_config.h"
37 #include "socket.h"
38 #include "command_parse.h"
39 #include "exitcodes.h"
40 #include "caller.h"
41
42 using irc::sockets::insp_ntoa;
43 using irc::sockets::insp_inaddr;
44 using irc::sockets::insp_sockaddr;
45
46 InspIRCd* SI = NULL;
47 int* mysig = NULL;
48
49
50 /* Burlex: Moved from exitcodes.h -- due to duplicate symbols */
51 const char* ExitCodes[] =
52 {
53                 "No error", /* 0 */
54                 "DIE command", /* 1 */
55                 "execv() failed", /* 2 */
56                 "Internal error", /* 3 */
57                 "Config file error", /* 4 */
58                 "Logfile error", /* 5 */
59                 "POSIX fork failed", /* 6 */
60                 "Bad commandline parameters", /* 7 */
61                 "No ports could be bound", /* 8 */
62                 "Can't write PID file", /* 9 */
63                 "SocketEngine could not initialize", /* 10 */
64                 "Refusing to start up as root", /* 11 */
65                 "Found a <die> tag!", /* 12 */
66                 "Couldn't load module on startup", /* 13 */
67                 "Could not create windows forked process", /* 14 */
68                 "Received SIGTERM", /* 15 */
69 };
70
71 void InspIRCd::Cleanup()
72 {
73         if (Config)
74         {
75                 for (unsigned int i = 0; i < Config->ports.size(); i++)
76                 {
77                         /* This calls the constructor and closes the listening socket */
78                         delete Config->ports[i];
79                 }
80
81                 Config->ports.clear();
82         }
83
84         /* Close all client sockets, or the new process inherits them */
85         for (std::vector<User*>::const_iterator i = this->Users->local_users.begin(); i != this->Users->local_users.end(); i++)
86         {
87                 (*i)->SetWriteError("Server shutdown");
88                 (*i)->CloseSocket();
89         }
90
91         /* We do this more than once, so that any service providers get a
92          * chance to be unhooked by the modules using them, but then get
93          * a chance to be removed themsleves.
94          */
95         for (int tries = 0; tries < 3; tries++)
96         {
97                 std::vector<std::string> module_names = Modules->GetAllModuleNames(0);
98                 for (std::vector<std::string>::iterator k = module_names.begin(); k != module_names.end(); ++k)
99                 {
100                         /* Unload all modules, so they get a chance to clean up their listeners */
101                         this->Modules->Unload(k->c_str());
102                 }
103         }
104
105         /* Close logging */
106         // XXX we need to add a method to terminate all logstreams.
107
108         /* Cleanup Server Names */
109         for(servernamelist::iterator itr = servernames.begin(); itr != servernames.end(); ++itr)
110                 delete (*itr);
111
112
113 }
114
115 void InspIRCd::Restart(const std::string &reason)
116 {
117         /* SendError flushes each client's queue,
118          * regardless of writeability state
119          */
120         this->SendError(reason);
121
122         this->Cleanup();
123
124         /* Figure out our filename (if theyve renamed it, we're boned) */
125         std::string me;
126
127 #ifdef WINDOWS
128         char module[MAX_PATH];
129         if (GetModuleFileName(NULL, module, MAX_PATH))
130                 me = module;
131 #else
132         me = Config->MyDir + "/inspircd";
133 #endif
134
135         if (execv(me.c_str(), Config->argv) == -1)
136         {
137                 /* Will raise a SIGABRT if not trapped */
138                 throw CoreException(std::string("Failed to execv()! error: ") + strerror(errno));
139         }
140 }
141
142 void InspIRCd::ResetMaxBans()
143 {
144         for (chan_hash::const_iterator i = chanlist->begin(); i != chanlist->end(); i++)
145                 i->second->ResetMaxBans();
146 }
147
148 /** Because hash_map doesnt free its buckets when we delete items (this is a 'feature')
149  * we must occasionally rehash the hash (yes really).
150  * We do this by copying the entries from the old hash to a new hash, causing all
151  * empty buckets to be weeded out of the hash. We dont do this on a timer, as its
152  * very expensive, so instead we do it when the user types /REHASH and expects a
153  * short delay anyway.
154  */
155 void InspIRCd::RehashUsersAndChans()
156 {
157         user_hash* old_users = this->Users->clientlist;
158         user_hash* old_uuid  = this->Users->uuidlist;
159         chan_hash* old_chans = this->chanlist;
160
161         this->Users->clientlist = new user_hash();
162         this->Users->uuidlist = new user_hash();
163         this->chanlist = new chan_hash();
164
165         for (user_hash::const_iterator n = old_users->begin(); n != old_users->end(); n++)
166                 this->Users->clientlist->insert(*n);
167
168         delete old_users;
169
170         for (user_hash::const_iterator n = old_uuid->begin(); n != old_uuid->end(); n++)
171                 this->Users->uuidlist->insert(*n);
172
173         delete old_uuid;
174
175         for (chan_hash::const_iterator n = old_chans->begin(); n != old_chans->end(); n++)
176                 this->chanlist->insert(*n);
177
178         delete old_chans;
179 }
180
181 void InspIRCd::CloseLog()
182 {
183         // XXX add a method to terminate all logstreams.
184 }
185
186 void InspIRCd::SetSignals()
187 {
188 #ifndef WIN32
189         signal(SIGALRM, SIG_IGN);
190         signal(SIGHUP, InspIRCd::SetSignal);
191         signal(SIGPIPE, SIG_IGN);
192         signal(SIGCHLD, SIG_IGN);
193 #endif
194         signal(SIGTERM, InspIRCd::SetSignal);
195 }
196
197 void InspIRCd::QuickExit(int status)
198 {
199         exit(0);
200 }
201
202 bool InspIRCd::DaemonSeed()
203 {
204 #ifdef WINDOWS
205         printf_c("InspIRCd Process ID: \033[1;32m%lu\033[0m\n", GetCurrentProcessId());
206         return true;
207 #else
208         signal(SIGTERM, InspIRCd::QuickExit);
209
210         int childpid;
211         if ((childpid = fork ()) < 0)
212                 return false;
213         else if (childpid > 0)
214         {
215                 /* We wait here for the child process to kill us,
216                  * so that the shell prompt doesnt come back over
217                  * the output.
218                  * Sending a kill with a signal of 0 just checks
219                  * if the child pid is still around. If theyre not,
220                  * they threw an error and we should give up.
221                  */
222                 while (kill(childpid, 0) != -1)
223                         sleep(1);
224                 exit(0);
225         }
226         setsid ();
227         umask (007);
228         printf("InspIRCd Process ID: \033[1;32m%lu\033[0m\n",(unsigned long)getpid());
229
230         signal(SIGTERM, InspIRCd::SetSignal);
231
232         rlimit rl;
233         if (getrlimit(RLIMIT_CORE, &rl) == -1)
234         {
235                 this->Log(DEFAULT,"Failed to getrlimit()!");
236                 return false;
237         }
238         else
239         {
240                 rl.rlim_cur = rl.rlim_max;
241                 if (setrlimit(RLIMIT_CORE, &rl) == -1)
242                         this->Log(DEFAULT,"setrlimit() failed, cannot increase coredump size.");
243         }
244
245         return true;
246 #endif
247 }
248
249 void InspIRCd::WritePID(const std::string &filename)
250 {
251         std::string fname = (filename.empty() ? "inspircd.pid" : filename);
252         if (*(fname.begin()) != '/')
253         {
254                 std::string::size_type pos;
255                 std::string confpath = this->ConfigFileName;
256                 if ((pos = confpath.rfind("/")) != std::string::npos)
257                 {
258                         /* Leaves us with just the path */
259                         fname = confpath.substr(0, pos) + std::string("/") + fname;
260                 }
261         }
262         std::ofstream outfile(fname.c_str());
263         if (outfile.is_open())
264         {
265                 outfile << getpid();
266                 outfile.close();
267         }
268         else
269         {
270                 printf("Failed to write PID-file '%s', exiting.\n",fname.c_str());
271                 this->Log(DEFAULT,"Failed to write PID-file '%s', exiting.",fname.c_str());
272                 Exit(EXIT_STATUS_PID);
273         }
274 }
275
276 InspIRCd::InspIRCd(int argc, char** argv)
277         : GlobalCulls(this),
278
279          /* Functor initialisation. Note that the ordering here is very important. */
280          HandleProcessUser(this),
281          HandleIsNick(this),
282          HandleIsIdent(this),
283          HandleFindDescriptor(this),
284          HandleFloodQuitUser(this),
285
286          /* Functor pointer initialisation. Must match the order of the list above */
287          ProcessUser(&HandleProcessUser),
288          IsNick(&HandleIsNick),
289          IsIdent(&HandleIsIdent),
290          FindDescriptor(&HandleFindDescriptor),
291          FloodQuitUser(&HandleFloodQuitUser)
292
293 {
294
295         int found_ports = 0;
296         FailedPortList pl;
297         int do_version = 0, do_nofork = 0, do_debug = 0, do_nolog = 0, do_root = 0;    /* flag variables */
298         char c = 0;
299
300         memset(&server, 0, sizeof(server));
301         memset(&client, 0, sizeof(client));
302
303         // This must be created first, so other parts of Insp can use it while starting up
304         this->Logs = new LogManager(this);
305
306         SocketEngineFactory* SEF = new SocketEngineFactory();
307         SE = SEF->Create(this);
308         delete SEF;
309
310         this->s_signal = 0;
311         
312         // Create base manager classes early, so nothing breaks
313         this->Users = new UserManager(this);
314         
315         this->Users->unregistered_count = 0;
316
317         this->Users->clientlist = new user_hash();
318         this->Users->uuidlist = new user_hash();
319         this->chanlist = new chan_hash();
320
321         this->Res = NULL;
322
323         this->Config = new ServerConfig(this);
324         this->SNO = new SnomaskManager(this);
325         this->BanCache = new BanCacheManager(this);
326         this->Modules = new ModuleManager(this);
327         this->stats = new serverstats();
328         this->Timers = new TimerManager(this);
329         this->Parser = new CommandParser(this);
330         this->XLines = new XLineManager(this);
331
332         this->Config->argv = argv;
333         this->Config->argc = argc;
334
335         if (chdir(Config->GetFullProgDir().c_str()))
336         {
337                 printf("Unable to change to my directory: %s\nAborted.", strerror(errno));
338                 exit(0);
339         }
340
341         this->Config->opertypes.clear();
342         this->Config->operclass.clear();
343
344         this->TIME = this->OLDTIME = this->startup_time = time(NULL);
345         this->time_delta = 0;
346         srand(this->TIME);
347
348         *this->LogFileName = 0;
349         strlcpy(this->ConfigFileName, CONFIG_FILE, MAXBUF);
350
351         struct option longopts[] =
352         {
353                 { "nofork",     no_argument,            &do_nofork,     1       },
354                 { "logfile",    required_argument,      NULL,           'f'     },
355                 { "config",     required_argument,      NULL,           'c'     },
356                 { "debug",      no_argument,            &do_debug,      1       },
357                 { "nolog",      no_argument,            &do_nolog,      1       },
358                 { "runasroot",  no_argument,            &do_root,       1       },
359                 { "version",    no_argument,            &do_version,    1       },
360                 { 0, 0, 0, 0 }
361         };
362
363         while ((c = getopt_long_only(argc, argv, ":f:", longopts, NULL)) != -1)
364         {
365                 switch (c)
366                 {
367                         case 'f':
368                                 /* Log filename was set */
369                                 strlcpy(LogFileName, optarg, MAXBUF);
370                         break;
371                         case 'c':
372                                 /* Config filename was set */
373                                 strlcpy(ConfigFileName, optarg, MAXBUF);
374                         break;
375                         case 0:
376                                 /* getopt_long_only() set an int variable, just keep going */
377                         break;
378                         default:
379                                 /* Unknown parameter! DANGER, INTRUDER.... err.... yeah. */
380                                 printf("Usage: %s [--nofork] [--nolog] [--debug] [--logfile <filename>] [--runasroot] [--version] [--config <config>]\n", argv[0]);
381                                 Exit(EXIT_STATUS_ARGV);
382                         break;
383                 }
384         }
385
386         if (do_version)
387         {
388                 printf("\n%s r%s\n", VERSION, REVISION);
389                 Exit(EXIT_STATUS_NOERROR);
390         }
391
392 #ifdef WIN32
393
394         // Handle forking
395         if(!do_nofork)
396         {
397                 DWORD ExitCode = WindowsForkStart(this);
398                 if(ExitCode)
399                         exit(ExitCode);
400         }
401
402         // Set up winsock
403         WSADATA wsadata;
404         WSAStartup(MAKEWORD(2,0), &wsadata);
405         ChangeWindowsSpecificPointers(this);
406 #endif
407         strlcpy(Config->MyExecutable,argv[0],MAXBUF);
408
409         if (!this->OpenLog(argv, argc))
410         {
411                 printf("ERROR: Could not open logfile %s: %s\n\n", Config->logpath.c_str(), strerror(errno));
412                 Exit(EXIT_STATUS_LOG);
413         }
414
415         if (!ServerConfig::FileExists(this->ConfigFileName))
416         {
417                 printf("ERROR: Cannot open config file: %s\nExiting...\n", this->ConfigFileName);
418                 this->Log(DEFAULT,"Unable to open config file %s", this->ConfigFileName);
419                 Exit(EXIT_STATUS_CONFIG);
420         }
421
422         printf_c("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
423         printf_c("(C) InspIRCd Development Team.\033[0m\n\n");
424         printf_c("Developers:\n");
425         printf_c("\t\033[1;32mBrain, FrostyCoolSlug, w00t, Om, Special\n");
426         printf_c("\t\033[1;32mpippijn, peavey, aquanight, fez\033[0m\n\n");
427         printf_c("Others:\t\t\t\033[1;32mSee /INFO Output\033[0m\n");
428
429         /* Set the finished argument values */
430         Config->nofork = do_nofork;
431         Config->forcedebug = do_debug;
432         Config->writelog = !do_nolog;   
433         Config->ClearStack();
434
435         this->Modes = new ModeParser(this);
436
437         /* set up fake client (uid is incorrect at this point,
438          * until after config is read. we set up the user again
439          * at that point 
440          */
441         this->FakeClient = new User(this);
442         this->FakeClient->SetFd(FD_MAGIC_NUMBER);
443
444         if (!do_root)
445                 this->CheckRoot();
446         else
447         {
448                 printf("* WARNING * WARNING * WARNING * WARNING * WARNING * \n\n");
449                 printf("YOU ARE RUNNING INSPIRCD AS ROOT. THIS IS UNSUPPORTED\n");
450                 printf("AND IF YOU ARE HACKED, CRACKED, SPINDLED OR MUTILATED\n");
451                 printf("OR ANYTHING ELSE UNEXPECTED HAPPENS TO YOU OR YOUR\n");
452                 printf("SERVER, THEN IT IS YOUR OWN FAULT. IF YOU DID NOT MEAN\n");
453                 printf("TO START INSPIRCD AS ROOT, HIT CTRL+C NOW AND RESTART\n");
454                 printf("THE PROGRAM AS A NORMAL USER. YOU HAVE BEEN WARNED!\n");
455                 printf("\nInspIRCd starting in 20 seconds, ctrl+c to abort...\n");
456                 sleep(20);
457         }
458
459         this->SetSignals();
460
461         if (!Config->nofork)
462         {
463                 if (!this->DaemonSeed())
464                 {
465                         printf("ERROR: could not go into daemon mode. Shutting down.\n");
466                         Log(DEFAULT,"ERROR: could not go into daemon mode. Shutting down.");
467                         Exit(EXIT_STATUS_FORK);
468                 }
469         }
470
471         SE->RecoverFromFork();
472
473         /* Read config, pass 0. At the end if this pass,
474          * the Config->IncludeFiles is populated, we call
475          * Config->StartDownloads to initialize the downlaods of all
476          * these files.
477          */
478         Config->Read(true, NULL, 0);
479         Config->DoDownloads();
480         /* We have all the files we can get, initiate pass 1 */
481         Config->Read(true, NULL, 1);
482
483         this->AddServerName(Config->ServerName);
484
485         /*
486          * Initialise SID/UID.
487          * For an explanation as to exactly how this works, and why it works this way, see GetUID().
488          *   -- w00t
489          */
490         if (*Config->sid)
491         {
492         }
493         else
494         {
495                 // Generate one
496                 size_t sid = 0;
497
498                 for (const char* x = Config->ServerName; *x; ++x)
499                         sid = 5 * sid + *x;
500                 for (const char* y = Config->ServerDesc; *y; ++y)
501                         sid = 5 * sid + *y;
502                 sid = sid % 999;
503
504                 Config->sid[0] = (char)(sid / 100 + 48);
505                 Config->sid[1] = (char)(((sid / 10) % 10) + 48);
506                 Config->sid[2] = (char)(sid % 10 + 48);
507         }
508
509         this->InitialiseUID();
510
511         /* set up fake client again this time with the correct uid */
512         delete FakeClient;
513         this->FakeClient = new User(this);
514         this->FakeClient->SetFd(FD_MAGIC_NUMBER);
515
516         // Get XLine to do it's thing.
517         this->XLines->CheckELines();
518         this->XLines->ApplyLines();
519
520
521         CheckDie();
522         int bounditems = BindPorts(true, found_ports, pl);
523
524         printf("\n");
525
526         /*this->Modules->LoadAll();*/
527         
528         /* Just in case no modules were loaded - fix for bug #101 */
529         this->BuildISupport();
530         InitializeDisabledCommands(Config->DisabledCommands, this);
531
532         if ((Config->ports.size() == 0) && (found_ports > 0))
533         {
534                 printf("\nERROR: I couldn't bind any ports! Are you sure you didn't start InspIRCd twice?\n");
535                 Log(DEFAULT,"ERROR: I couldn't bind any ports! Are you sure you didn't start InspIRCd twice?");
536                 Exit(EXIT_STATUS_BIND);
537         }
538
539         if (Config->ports.size() != (unsigned int)found_ports)
540         {
541                 printf("\nWARNING: Not all your client ports could be bound --\nstarting anyway with %d of %d client ports bound.\n\n", bounditems, found_ports);
542                 printf("The following port(s) failed to bind:\n");
543                 int j = 1;
544                 for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
545                 {
546                         printf("%d.\tIP: %s\tPort: %lu\n", j, i->first.empty() ? "<all>" : i->first.c_str(), (unsigned long)i->second);
547                 }
548         }
549 #ifndef WINDOWS
550         if (!Config->nofork)
551         {
552                 if (kill(getppid(), SIGTERM) == -1)
553                 {
554                         printf("Error killing parent process: %s\n",strerror(errno));
555                         Log(DEFAULT,"Error killing parent process: %s",strerror(errno));
556                 }
557         }
558
559         if (isatty(0) && isatty(1) && isatty(2))
560         {
561                 /* We didn't start from a TTY, we must have started from a background process -
562                  * e.g. we are restarting, or being launched by cron. Dont kill parent, and dont
563                  * close stdin/stdout
564                  */
565                 if (!do_nofork)
566                 {
567                         fclose(stdin);
568                         fclose(stderr);
569                         fclose(stdout);
570                 }
571                 else
572                 {
573                         Log(DEFAULT,"Keeping pseudo-tty open as we are running in the foreground.");
574                 }
575         }
576 #else
577         WindowsIPC = new IPC(this);
578         if(!Config->nofork)
579         {
580                 WindowsForkKillOwner(this);
581                 FreeConsole();
582         }
583 #endif
584
585         printf("\nInspIRCd is now running as '%s'[%s]\n", Config->ServerName,Config->GetSID().c_str());
586         Log(DEFAULT,"Startup complete as '%s'[%s]", Config->ServerName,Config->GetSID().c_str());
587
588         this->WritePID(Config->PID);
589 }
590
591 /* moved to a function, as UID generation can call this also */
592 void InspIRCd::InitialiseUID()
593 {
594         int i = 3;
595
596         current_uid[0] = Config->sid[0];
597         current_uid[1] = Config->sid[1];
598         current_uid[2] = Config->sid[2];
599
600         /* Initialise UID */
601         for(i = 3; i < UUID_LENGTH - 1; i++)
602                 current_uid[i] = 'A';
603
604         current_uid[UUID_LENGTH] = '\0';
605 }
606
607 int InspIRCd::Run()
608 {
609         while (true)
610         {
611 #ifndef WIN32
612                 static rusage ru;
613 #else
614                 static time_t uptime;
615                 static struct tm * stime;
616                 static char window_title[100];
617 #endif
618
619                 /* time() seems to be a pretty expensive syscall, so avoid calling it too much.
620                  * Once per loop iteration is pleanty.
621                  */
622                 OLDTIME = TIME;
623                 TIME = time(NULL);
624
625                 /* Run background module timers every few seconds
626                  * (the docs say modules shouldnt rely on accurate
627                  * timing using this event, so we dont have to
628                  * time this exactly).
629                  */
630                 if (TIME != OLDTIME)
631                 {
632                         if (TIME < OLDTIME)
633                         {
634                                 SNO->WriteToSnoMask('A', "\002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME));
635                         }
636
637                         if ((TIME % 3600) == 0)
638                         {
639                                 this->RehashUsersAndChans();
640                                 FOREACH_MOD_I(this, I_OnGarbageCollect, OnGarbageCollect());
641                         }
642
643                         Timers->TickTimers(TIME);
644                         this->DoBackgroundUserStuff();
645
646                         if ((TIME % 5) == 0)
647                         {
648                                 FOREACH_MOD_I(this,I_OnBackgroundTimer,OnBackgroundTimer(TIME));
649                                 SNO->FlushSnotices();
650                         }
651 #ifndef WIN32
652                         /* Same change as in cmd_stats.cpp, use RUSAGE_SELF rather than '0' -- Om */
653                         if (!getrusage(RUSAGE_SELF, &ru))
654                         {
655                                 gettimeofday(&this->stats->LastSampled, NULL);
656                                 this->stats->LastCPU = ru.ru_utime;
657                         }
658 #else
659                         WindowsIPC->Check();    
660 #endif
661                 }
662
663                 /* Call the socket engine to wait on the active
664                  * file descriptors. The socket engine has everything's
665                  * descriptors in its list... dns, modules, users,
666                  * servers... so its nice and easy, just one call.
667                  * This will cause any read or write events to be
668                  * dispatched to their handlers.
669                  */
670                 this->SE->DispatchEvents();
671
672                 /* if any users were quit, take them out */
673                 this->GlobalCulls.Apply();
674
675                 /* If any inspsockets closed, remove them */
676                 this->BufferedSocketCull();
677
678                 if (this->s_signal)
679                 {
680                         this->SignalHandler(s_signal);
681                         this->s_signal = 0;
682                 }
683         }
684
685         return 0;
686 }
687
688 void InspIRCd::BufferedSocketCull()
689 {
690         for (std::map<BufferedSocket*,BufferedSocket*>::iterator x = SocketCull.begin(); x != SocketCull.end(); ++x)
691         {
692                 Log(DEBUG,"Cull socket");
693                 SE->DelFd(x->second);
694                 x->second->Close();
695                 delete x->second;
696         }
697         SocketCull.clear();
698 }
699
700 /**********************************************************************************/
701
702 /**
703  * An ircd in five lines! bwahahaha. ahahahahaha. ahahah *cough*.
704  */
705
706 int main(int argc, char ** argv)
707 {
708         SI = new InspIRCd(argc, argv);
709         mysig = &SI->s_signal;
710         SI->Run();
711         delete SI;
712         return 0;
713 }
714
715 /* this returns true when all modules are satisfied that the user should be allowed onto the irc server
716  * (until this returns true, a user will block in the waiting state, waiting to connect up to the
717  * registration timeout maximum seconds)
718  */
719 bool InspIRCd::AllModulesReportReady(User* user)
720 {
721         for (EventHandlerIter i = Modules->EventHandlers[I_OnCheckReady].begin(); i != Modules->EventHandlers[I_OnCheckReady].end(); ++i)
722         {
723                 int res = (*i)->OnCheckReady(user);
724                 if (!res)
725                         return false;
726         }
727
728         return true;
729 }
730
731 time_t InspIRCd::Time(bool delta)
732 {
733         if (delta)
734                 return TIME + time_delta;
735         return TIME;
736 }
737
738 int InspIRCd::SetTimeDelta(int delta)
739 {
740         int old = time_delta;
741         time_delta = delta;
742         this->Log(DEBUG, "Time delta set to %d (was %d)", time_delta, old);
743         return old;
744 }
745
746 int InspIRCd::GetTimeDelta()
747 {
748         return time_delta;
749 }
750
751 void InspIRCd::SetSignal(int signal)
752 {
753         *mysig = signal;
754 }