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