]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/inspircd.cpp
More test suite stuff
[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         this->Logs->CloseLogs();
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::SetSignals()
182 {
183 #ifndef WIN32
184         signal(SIGALRM, SIG_IGN);
185         signal(SIGHUP, InspIRCd::SetSignal);
186         signal(SIGPIPE, SIG_IGN);
187         signal(SIGCHLD, SIG_IGN);
188 #endif
189         signal(SIGTERM, InspIRCd::SetSignal);
190 }
191
192 void InspIRCd::QuickExit(int status)
193 {
194         exit(0);
195 }
196
197 bool InspIRCd::DaemonSeed()
198 {
199 #ifdef WINDOWS
200         printf_c("InspIRCd Process ID: \033[1;32m%lu\033[0m\n", GetCurrentProcessId());
201         return true;
202 #else
203         signal(SIGTERM, InspIRCd::QuickExit);
204
205         int childpid;
206         if ((childpid = fork ()) < 0)
207                 return false;
208         else if (childpid > 0)
209         {
210                 /* We wait here for the child process to kill us,
211                  * so that the shell prompt doesnt come back over
212                  * the output.
213                  * Sending a kill with a signal of 0 just checks
214                  * if the child pid is still around. If theyre not,
215                  * they threw an error and we should give up.
216                  */
217                 while (kill(childpid, 0) != -1)
218                         sleep(1);
219                 exit(0);
220         }
221         setsid ();
222         umask (007);
223         printf("InspIRCd Process ID: \033[1;32m%lu\033[0m\n",(unsigned long)getpid());
224
225         signal(SIGTERM, InspIRCd::SetSignal);
226
227         rlimit rl;
228         if (getrlimit(RLIMIT_CORE, &rl) == -1)
229         {
230                 this->Log(DEFAULT,"Failed to getrlimit()!");
231                 return false;
232         }
233         else
234         {
235                 rl.rlim_cur = rl.rlim_max;
236                 if (setrlimit(RLIMIT_CORE, &rl) == -1)
237                         this->Log(DEFAULT,"setrlimit() failed, cannot increase coredump size.");
238         }
239
240         return true;
241 #endif
242 }
243
244 void InspIRCd::WritePID(const std::string &filename)
245 {
246         std::string fname = (filename.empty() ? "inspircd.pid" : filename);
247         if (*(fname.begin()) != '/')
248         {
249                 std::string::size_type pos;
250                 std::string confpath = this->ConfigFileName;
251                 if ((pos = confpath.rfind("/")) != std::string::npos)
252                 {
253                         /* Leaves us with just the path */
254                         fname = confpath.substr(0, pos) + std::string("/") + fname;
255                 }
256         }
257         std::ofstream outfile(fname.c_str());
258         if (outfile.is_open())
259         {
260                 outfile << getpid();
261                 outfile.close();
262         }
263         else
264         {
265                 printf("Failed to write PID-file '%s', exiting.\n",fname.c_str());
266                 this->Log(DEFAULT,"Failed to write PID-file '%s', exiting.",fname.c_str());
267                 Exit(EXIT_STATUS_PID);
268         }
269 }
270
271 InspIRCd::InspIRCd(int argc, char** argv)
272         : GlobalCulls(this),
273
274          /* Functor initialisation. Note that the ordering here is very important. */
275          HandleProcessUser(this),
276          HandleIsNick(this),
277          HandleIsIdent(this),
278          HandleFindDescriptor(this),
279          HandleFloodQuitUser(this),
280
281          /* Functor pointer initialisation. Must match the order of the list above */
282          ProcessUser(&HandleProcessUser),
283          IsNick(&HandleIsNick),
284          IsIdent(&HandleIsIdent),
285          FindDescriptor(&HandleFindDescriptor),
286          FloodQuitUser(&HandleFloodQuitUser)
287
288 {
289
290         int found_ports = 0;
291         FailedPortList pl;
292         int do_version = 0, do_nofork = 0, do_debug = 0,
293             do_nolog = 0, do_root = 0, do_testsuite = 0;    /* flag variables */
294         char c = 0;
295
296         memset(&server, 0, sizeof(server));
297         memset(&client, 0, sizeof(client));
298
299         // This must be created first, so other parts of Insp can use it while starting up
300         this->Logs = new LogManager(this);
301
302         SocketEngineFactory* SEF = new SocketEngineFactory();
303         SE = SEF->Create(this);
304         delete SEF;
305
306         this->s_signal = 0;
307         
308         // Create base manager classes early, so nothing breaks
309         this->Users = new UserManager(this);
310         
311         this->Users->unregistered_count = 0;
312
313         this->Users->clientlist = new user_hash();
314         this->Users->uuidlist = new user_hash();
315         this->chanlist = new chan_hash();
316
317         this->Res = NULL;
318
319         this->Config = new ServerConfig(this);
320         this->SNO = new SnomaskManager(this);
321         this->BanCache = new BanCacheManager(this);
322         this->Modules = new ModuleManager(this);
323         this->stats = new serverstats();
324         this->Timers = new TimerManager(this);
325         this->Parser = new CommandParser(this);
326         this->XLines = new XLineManager(this);
327
328         this->Config->argv = argv;
329         this->Config->argc = argc;
330
331         if (chdir(Config->GetFullProgDir().c_str()))
332         {
333                 printf("Unable to change to my directory: %s\nAborted.", strerror(errno));
334                 exit(0);
335         }
336
337         this->Config->opertypes.clear();
338         this->Config->operclass.clear();
339
340         this->TIME = this->OLDTIME = this->startup_time = time(NULL);
341         this->time_delta = 0;
342         srand(this->TIME);
343
344         *this->LogFileName = 0;
345         strlcpy(this->ConfigFileName, CONFIG_FILE, MAXBUF);
346
347         struct option longopts[] =
348         {
349                 { "nofork",     no_argument,            &do_nofork,     1       },
350                 { "logfile",    required_argument,      NULL,           'f'     },
351                 { "config",     required_argument,      NULL,           'c'     },
352                 { "debug",      no_argument,            &do_debug,      1       },
353                 { "nolog",      no_argument,            &do_nolog,      1       },
354                 { "runasroot",  no_argument,            &do_root,       1       },
355                 { "version",    no_argument,            &do_version,    1       },
356                 { "testsuite",  no_argument,            &do_testsuite,  1       },
357                 { 0, 0, 0, 0 }
358         };
359
360         while ((c = getopt_long_only(argc, argv, ":f:", longopts, NULL)) != -1)
361         {
362                 switch (c)
363                 {
364                         case 'f':
365                                 /* Log filename was set */
366                                 strlcpy(LogFileName, optarg, MAXBUF);
367                         break;
368                         case 'c':
369                                 /* Config filename was set */
370                                 strlcpy(ConfigFileName, optarg, MAXBUF);
371                         break;
372                         case 0:
373                                 /* getopt_long_only() set an int variable, just keep going */
374                         break;
375                         default:
376                                 /* Unknown parameter! DANGER, INTRUDER.... err.... yeah. */
377                                 printf("Usage: %s [--nofork] [--nolog] [--debug] [--logfile <filename>]\n\
378                                                   [--runasroot] [--version] [--config <config>] [--testsuite]\n", argv[0]);
379                                 Exit(EXIT_STATUS_ARGV);
380                         break;
381                 }
382         }
383
384         if (do_version)
385         {
386                 printf("\n%s r%s\n", VERSION, REVISION);
387                 Exit(EXIT_STATUS_NOERROR);
388         }
389
390 #ifdef WIN32
391
392         // Handle forking
393         if(!do_nofork)
394         {
395                 DWORD ExitCode = WindowsForkStart(this);
396                 if(ExitCode)
397                         exit(ExitCode);
398         }
399
400         // Set up winsock
401         WSADATA wsadata;
402         WSAStartup(MAKEWORD(2,0), &wsadata);
403         ChangeWindowsSpecificPointers(this);
404 #endif
405         strlcpy(Config->MyExecutable,argv[0],MAXBUF);
406
407         /* Set the finished argument values */
408         Config->nofork = do_nofork;
409         Config->forcedebug = do_debug;
410         Config->writelog = !do_nolog;
411         Config->TestSuite = do_testsuite;
412
413         if (!this->OpenLog(argv, argc))
414         {
415                 printf("ERROR: Could not open logfile %s: %s\n\n", Config->logpath.c_str(), strerror(errno));
416                 Exit(EXIT_STATUS_LOG);
417         }
418
419         if (!ServerConfig::FileExists(this->ConfigFileName))
420         {
421                 printf("ERROR: Cannot open config file: %s\nExiting...\n", this->ConfigFileName);
422                 this->Log(DEFAULT,"Unable to open config file %s", this->ConfigFileName);
423                 Exit(EXIT_STATUS_CONFIG);
424         }
425
426         printf_c("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
427         printf_c("(C) InspIRCd Development Team.\033[0m\n\n");
428         printf_c("Developers:\n");
429         printf_c("\t\033[1;32mBrain, FrostyCoolSlug, w00t, Om, Special\n");
430         printf_c("\t\033[1;32mpippijn, peavey, aquanight, fez\033[0m\n\n");
431         printf_c("Others:\t\t\t\033[1;32mSee /INFO Output\033[0m\n");
432
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                         Logs->Log("STARTUP", 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                 Logs->Log("STARTUP", DEFAULT,"ERROR: I couldn't bind any ports! Something else is bound to those ports!");
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                         Logs->Log("STARTUP", 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                         Logs->Log("STARTUP", 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         Logs->Log("STARTUP", 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         /* See if we're supposed to be running the test suite rather than entering the mainloop */
610         if (Config->TestSuite)
611         {
612                 TestSuite* ts = new TestSuite(this);
613                 delete ts;
614                 Exit(0);
615         }
616
617         while (true)
618         {
619 #ifndef WIN32
620                 static rusage ru;
621 #else
622                 static time_t uptime;
623                 static struct tm * stime;
624                 static char window_title[100];
625 #endif
626
627                 /* time() seems to be a pretty expensive syscall, so avoid calling it too much.
628                  * Once per loop iteration is pleanty.
629                  */
630                 OLDTIME = TIME;
631                 TIME = time(NULL);
632
633                 /* Run background module timers every few seconds
634                  * (the docs say modules shouldnt rely on accurate
635                  * timing using this event, so we dont have to
636                  * time this exactly).
637                  */
638                 if (TIME != OLDTIME)
639                 {
640                         if (TIME < OLDTIME)
641                         {
642                                 SNO->WriteToSnoMask('A', "\002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME));
643                         }
644
645                         if ((TIME % 3600) == 0)
646                         {
647                                 this->RehashUsersAndChans();
648                                 FOREACH_MOD_I(this, I_OnGarbageCollect, OnGarbageCollect());
649                         }
650
651                         Timers->TickTimers(TIME);
652                         this->DoBackgroundUserStuff();
653
654                         if ((TIME % 5) == 0)
655                         {
656                                 FOREACH_MOD_I(this,I_OnBackgroundTimer,OnBackgroundTimer(TIME));
657                                 SNO->FlushSnotices();
658                         }
659 #ifndef WIN32
660                         /* Same change as in cmd_stats.cpp, use RUSAGE_SELF rather than '0' -- Om */
661                         if (!getrusage(RUSAGE_SELF, &ru))
662                         {
663                                 gettimeofday(&this->stats->LastSampled, NULL);
664                                 this->stats->LastCPU = ru.ru_utime;
665                         }
666 #else
667                         WindowsIPC->Check();    
668 #endif
669                 }
670
671                 /* Call the socket engine to wait on the active
672                  * file descriptors. The socket engine has everything's
673                  * descriptors in its list... dns, modules, users,
674                  * servers... so its nice and easy, just one call.
675                  * This will cause any read or write events to be
676                  * dispatched to their handlers.
677                  */
678                 this->SE->DispatchEvents();
679
680                 /* if any users were quit, take them out */
681                 this->GlobalCulls.Apply();
682
683                 /* If any inspsockets closed, remove them */
684                 this->BufferedSocketCull();
685
686                 if (this->s_signal)
687                 {
688                         this->SignalHandler(s_signal);
689                         this->s_signal = 0;
690                 }
691         }
692
693         return 0;
694 }
695
696 void InspIRCd::BufferedSocketCull()
697 {
698         for (std::map<BufferedSocket*,BufferedSocket*>::iterator x = SocketCull.begin(); x != SocketCull.end(); ++x)
699         {
700                 Log(DEBUG,"Cull socket");
701                 SE->DelFd(x->second);
702                 x->second->Close();
703                 delete x->second;
704         }
705         SocketCull.clear();
706 }
707
708 /**********************************************************************************/
709
710 /**
711  * An ircd in five lines! bwahahaha. ahahahahaha. ahahah *cough*.
712  */
713
714 int main(int argc, char ** argv)
715 {
716         SI = new InspIRCd(argc, argv);
717         mysig = &SI->s_signal;
718         SI->Run();
719         delete SI;
720         return 0;
721 }
722
723 /* this returns true when all modules are satisfied that the user should be allowed onto the irc server
724  * (until this returns true, a user will block in the waiting state, waiting to connect up to the
725  * registration timeout maximum seconds)
726  */
727 bool InspIRCd::AllModulesReportReady(User* user)
728 {
729         for (EventHandlerIter i = Modules->EventHandlers[I_OnCheckReady].begin(); i != Modules->EventHandlers[I_OnCheckReady].end(); ++i)
730         {
731                 int res = (*i)->OnCheckReady(user);
732                 if (!res)
733                         return false;
734         }
735
736         return true;
737 }
738
739 time_t InspIRCd::Time(bool delta)
740 {
741         if (delta)
742                 return TIME + time_delta;
743         return TIME;
744 }
745
746 int InspIRCd::SetTimeDelta(int delta)
747 {
748         int old = time_delta;
749         time_delta = delta;
750         this->Log(DEBUG, "Time delta set to %d (was %d)", time_delta, old);
751         return old;
752 }
753
754 int InspIRCd::GetTimeDelta()
755 {
756         return time_delta;
757 }
758
759 void InspIRCd::SetSignal(int signal)
760 {
761         *mysig = signal;
762 }