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