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