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