]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/inspircd.cpp
InspSocket -> BufferedSocket. Paves the way for a SimpleSocket class which ident...
[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         this->next_call = this->TIME + 3;
342         srand(this->TIME);
343
344         *this->LogFileName = 0;
345         strlcpy(this->ConfigFileName, CONFIG_FILE, MAXBUF);
346
347         struct option longopts[] =
348         {
349                 { "nofork",     no_argument,            &do_nofork,     1       },
350                 { "logfile",    required_argument,      NULL,           'f'     },
351                 { "config",     required_argument,      NULL,           'c'     },
352                 { "debug",      no_argument,            &do_debug,      1       },
353                 { "nolog",      no_argument,            &do_nolog,      1       },
354                 { "runasroot",  no_argument,            &do_root,       1       },
355                 { "version",    no_argument,            &do_version,    1       },
356                 { 0, 0, 0, 0 }
357         };
358
359         while ((c = getopt_long_only(argc, argv, ":f:", longopts, NULL)) != -1)
360         {
361                 switch (c)
362                 {
363                         case 'f':
364                                 /* Log filename was set */
365                                 strlcpy(LogFileName, optarg, MAXBUF);
366                         break;
367                         case 'c':
368                                 /* Config filename was set */
369                                 strlcpy(ConfigFileName, optarg, MAXBUF);
370                         break;
371                         case 0:
372                                 /* getopt_long_only() set an int variable, just keep going */
373                         break;
374                         default:
375                                 /* Unknown parameter! DANGER, INTRUDER.... err.... yeah. */
376                                 printf("Usage: %s [--nofork] [--nolog] [--debug] [--logfile <filename>] [--runasroot] [--version] [--config <config>]\n", argv[0]);
377                                 Exit(EXIT_STATUS_ARGV);
378                         break;
379                 }
380         }
381
382         if (do_version)
383         {
384                 printf("\n%s r%s\n", VERSION, REVISION);
385                 Exit(EXIT_STATUS_NOERROR);
386         }
387
388 #ifdef WIN32
389
390         // Handle forking
391         if(!do_nofork)
392         {
393                 DWORD ExitCode = WindowsForkStart(this);
394                 if(ExitCode)
395                         exit(ExitCode);
396         }
397
398         // Set up winsock
399         WSADATA wsadata;
400         WSAStartup(MAKEWORD(2,0), &wsadata);
401
402         ChangeWindowsSpecificPointers(this);
403 #endif
404         strlcpy(Config->MyExecutable,argv[0],MAXBUF);
405
406         if (!this->OpenLog(argv, argc))
407         {
408                 printf("ERROR: Could not open logfile %s: %s\n\n", Config->logpath.c_str(), strerror(errno));
409                 Exit(EXIT_STATUS_LOG);
410         }
411
412         if (!ServerConfig::FileExists(this->ConfigFileName))
413         {
414                 printf("ERROR: Cannot open config file: %s\nExiting...\n", this->ConfigFileName);
415                 this->Log(DEFAULT,"Unable to open config file %s", this->ConfigFileName);
416                 Exit(EXIT_STATUS_CONFIG);
417         }
418
419         printf_c("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
420         printf_c("(C) InspIRCd Development Team.\033[0m\n\n");
421         printf_c("Developers:\t\t\033[1;32mBrain, FrostyCoolSlug, w00t, Om, Special, pippijn, peavey, Burlex\033[0m\n");
422         printf_c("Others:\t\t\t\033[1;32mSee /INFO Output\033[0m\n");
423
424         /* Set the finished argument values */
425         Config->nofork = do_nofork;
426         Config->forcedebug = do_debug;
427         Config->writelog = !do_nolog;
428
429         this->Modules = new ModuleManager(this);
430         this->stats = new serverstats();
431         this->Timers = new TimerManager(this);
432         this->Parser = new CommandParser(this);
433         this->XLines = new XLineManager(this);
434         
435         Config->ClearStack();
436         Config->Read(true, NULL);
437         
438         this->Modules->modules.resize(255);
439         this->Modules->handles.resize(255);
440
441         /*
442          * Initialise SID/UID.
443          * For an explanation as to exactly how this works, and why it works this way, see GetUID().
444          *   -- w00t
445          */
446         /* Generate SID */
447         size_t sid = 0;
448         if (Config->sid)
449         {
450                 sid = Config->sid;
451         }
452         else
453         {
454                 for (const char* x = Config->ServerName; *x; ++x)
455                         sid = 5 * sid + *x;
456                 for (const char* y = Config->ServerDesc; *y; ++y)
457                         sid = 5 * sid + *y;
458                 sid = sid % 999;
459
460                 Config->sid = sid;
461         }
462
463         this->InitialiseUID();
464
465         /* set up fake client */
466         this->FakeClient = new User(this);
467         this->FakeClient->SetFd(FD_MAGIC_NUMBER);
468
469         if (!do_root)
470                 this->CheckRoot();
471         else
472         {
473                 printf("* WARNING * WARNING * WARNING * WARNING * WARNING * \n\n");
474                 printf("YOU ARE RUNNING INSPIRCD AS ROOT. THIS IS UNSUPPORTED\n");
475                 printf("AND IF YOU ARE HACKED, CRACKED, SPINDLED OR MUTILATED\n");
476                 printf("OR ANYTHING ELSE UNEXPECTED HAPPENS TO YOU OR YOUR\n");
477                 printf("SERVER, THEN IT IS YOUR OWN FAULT. IF YOU DID NOT MEAN\n");
478                 printf("TO START INSPIRCD AS ROOT, HIT CTRL+C NOW AND RESTART\n");
479                 printf("THE PROGRAM AS A NORMAL USER. YOU HAVE BEEN WARNED!\n");
480                 printf("\nInspIRCd starting in 20 seconds, ctrl+c to abort...\n");
481                 sleep(20);
482         }
483
484         this->SetSignals();
485
486         if (!Config->nofork)
487         {
488                 if (!this->DaemonSeed())
489                 {
490                         printf("ERROR: could not go into daemon mode. Shutting down.\n");
491                         Log(DEFAULT,"ERROR: could not go into daemon mode. Shutting down.");
492                         Exit(EXIT_STATUS_FORK);
493                 }
494         }
495
496         SE->RecoverFromFork();
497
498         this->Modes = new ModeParser(this);
499         this->AddServerName(Config->ServerName);
500         CheckDie();
501         int bounditems = BindPorts(true, found_ports, pl);
502
503         for(int t = 0; t < 255; t++)
504                 Config->global_implementation[t] = 0;
505
506         memset(&Config->implement_lists,0,sizeof(Config->implement_lists));
507
508         printf("\n");
509
510         this->Res = new DNS(this);
511
512         this->Modules->LoadAll();
513         
514         /* Just in case no modules were loaded - fix for bug #101 */
515         this->BuildISupport();
516         InitializeDisabledCommands(Config->DisabledCommands, this);
517
518         if ((Config->ports.size() == 0) && (found_ports > 0))
519         {
520                 printf("\nERROR: I couldn't bind any ports! Are you sure you didn't start InspIRCd twice?\n");
521                 Log(DEFAULT,"ERROR: I couldn't bind any ports! Are you sure you didn't start InspIRCd twice?");
522                 Exit(EXIT_STATUS_BIND);
523         }
524
525         if (Config->ports.size() != (unsigned int)found_ports)
526         {
527                 printf("\nWARNING: Not all your client ports could be bound --\nstarting anyway with %d of %d client ports bound.\n\n", bounditems, found_ports);
528                 printf("The following port(s) failed to bind:\n");
529                 int j = 1;
530                 for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
531                 {
532                         printf("%d.\tIP: %s\tPort: %lu\n", j, i->first.empty() ? "<all>" : i->first.c_str(), (unsigned long)i->second);
533                 }
534         }
535 #ifndef WINDOWS
536         if (!Config->nofork)
537         {
538                 if (kill(getppid(), SIGTERM) == -1)
539                 {
540                         printf("Error killing parent process: %s\n",strerror(errno));
541                         Log(DEFAULT,"Error killing parent process: %s",strerror(errno));
542                 }
543         }
544
545         if (isatty(0) && isatty(1) && isatty(2))
546         {
547                 /* We didn't start from a TTY, we must have started from a background process -
548                  * e.g. we are restarting, or being launched by cron. Dont kill parent, and dont
549                  * close stdin/stdout
550                  */
551                 if (!do_nofork)
552                 {
553                         fclose(stdin);
554                         fclose(stderr);
555                         fclose(stdout);
556                 }
557                 else
558                 {
559                         Log(DEFAULT,"Keeping pseudo-tty open as we are running in the foreground.");
560                 }
561         }
562 #else
563         WindowsIPC = new IPC(this);
564         if(!Config->nofork)
565         {
566                 WindowsForkKillOwner(this);
567                 FreeConsole();
568         }
569 #endif
570
571         printf("\nInspIRCd is now running!\n");
572         Log(DEFAULT,"Startup complete.");
573
574         this->WritePID(Config->PID);
575 }
576
577 /* moved to a function, as UID generation can call this also */
578 void InspIRCd::InitialiseUID()
579 {
580         int i;
581         size_t sid = Config->sid;
582
583         current_uid[0] = sid / 100 + 48;
584         current_uid[1] = ((sid / 10) % 10) + 48;
585         current_uid[2] = sid % 10 + 48;
586
587         /* Initialise UID */
588         for(i = 3; i < UUID_LENGTH - 1; i++)
589                 current_uid[i] = 'A';
590 }
591
592 int InspIRCd::Run()
593 {
594         while (true)
595         {
596 #ifndef WIN32
597                 static rusage ru;
598 #else
599                 static time_t uptime;
600                 static struct tm * stime;
601                 static char window_title[100];
602 #endif
603
604                 /* time() seems to be a pretty expensive syscall, so avoid calling it too much.
605                  * Once per loop iteration is pleanty.
606                  */
607                 OLDTIME = TIME;
608                 TIME = time(NULL);
609
610                 /* Run background module timers every few seconds
611                  * (the docs say modules shouldnt rely on accurate
612                  * timing using this event, so we dont have to
613                  * time this exactly).
614                  */
615                 if (TIME != OLDTIME)
616                 {
617                         if (TIME < OLDTIME)
618                                 WriteOpers("*** \002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME));
619                         if ((TIME % 3600) == 0)
620                         {
621                                 this->RehashUsersAndChans();
622                                 FOREACH_MOD_I(this, I_OnGarbageCollect, OnGarbageCollect());
623                         }
624                         Timers->TickTimers(TIME);
625                         this->DoBackgroundUserStuff(TIME);
626
627                         if ((TIME % 5) == 0)
628                         {
629                                 XLines->expire_lines();
630                                 FOREACH_MOD_I(this,I_OnBackgroundTimer,OnBackgroundTimer(TIME));
631                                 Timers->TickMissedTimers(TIME);
632                         }
633 #ifndef WIN32
634                         /* Same change as in cmd_stats.cpp, use RUSAGE_SELF rather than '0' -- Om */
635                         if (!getrusage(RUSAGE_SELF, &ru))
636                         {
637                                 gettimeofday(&this->stats->LastSampled, NULL);
638                                 this->stats->LastCPU = ru.ru_utime;
639                         }
640 #else
641                         WindowsIPC->Check();
642         
643                         if(Config->nofork)
644                         {
645                                 uptime = Time() - startup_time;
646                                 stime = gmtime(&uptime);
647                                 snprintf(window_title, 100, "InspIRCd - %u clients, %u accepted connections - Up %u days, %.2u:%.2u:%.2u",
648                                         LocalUserCount(), stats->statsAccept, stime->tm_yday, stime->tm_hour, stime->tm_min, stime->tm_sec);
649                                 SetConsoleTitle(window_title);
650                         }
651 #endif
652                 }
653
654                 /* Call the socket engine to wait on the active
655                  * file descriptors. The socket engine has everything's
656                  * descriptors in its list... dns, modules, users,
657                  * servers... so its nice and easy, just one call.
658                  * This will cause any read or write events to be
659                  * dispatched to their handlers.
660                  */
661                 this->SE->DispatchEvents();
662
663                 /* if any users was quit, take them out */
664                 this->GlobalCulls.Apply();
665
666                 /* If any inspsockets closed, remove them */
667                 this->BufferedSocketCull();
668
669                 if (this->s_signal)
670                 {
671                         this->SignalHandler(s_signal);
672                         this->s_signal = 0;
673                 }
674         }
675
676         return 0;
677 }
678
679 void InspIRCd::BufferedSocketCull()
680 {
681         for (std::map<BufferedSocket*,BufferedSocket*>::iterator x = SocketCull.begin(); x != SocketCull.end(); ++x)
682         {
683                 SE->DelFd(x->second);
684                 x->second->Close();
685                 delete x->second;
686         }
687         SocketCull.clear();
688 }
689
690 /**********************************************************************************/
691
692 /**
693  * An ircd in four lines! bwahahaha. ahahahahaha. ahahah *cough*.
694  */
695
696 int ircd(int argc, char ** argv)
697 {
698         SI = new InspIRCd(argc, argv);
699         mysig = &SI->s_signal;
700         SI->Run();
701         delete SI;
702         return 0;
703 }
704
705 #ifdef WINDOWS
706
707 int main(int argc, char ** argv)
708 {
709         ircd(argc,argv);
710         return 0;
711 }
712
713 #else
714 int main(int argc, char** argv)
715 {
716         return ircd(argc,argv);
717 }
718 #endif
719
720 /* this returns true when all modules are satisfied that the user should be allowed onto the irc server
721  * (until this returns true, a user will block in the waiting state, waiting to connect up to the
722  * registration timeout maximum seconds)
723  */
724 bool InspIRCd::AllModulesReportReady(User* user)
725 {
726         if (!Config->global_implementation[I_OnCheckReady])
727                 return true;
728
729         for (int i = 0; i <= this->Modules->GetCount(); i++)
730         {
731                 if (Config->implement_lists[i][I_OnCheckReady])
732                 {
733                         int res = this->Modules->modules[i]->OnCheckReady(user);
734                         if (!res)
735                                 return false;
736                 }
737         }
738         return true;
739 }
740
741 time_t InspIRCd::Time(bool delta)
742 {
743         if (delta)
744                 return TIME + time_delta;
745         return TIME;
746 }
747
748 int InspIRCd::SetTimeDelta(int delta)
749 {
750         int old = time_delta;
751         time_delta = delta;
752         this->Log(DEBUG, "Time delta set to %d (was %d)", time_delta, old);
753         return old;
754 }
755
756 void InspIRCd::AddLocalClone(User* user)
757 {
758         clonemap::iterator x = local_clones.find(user->GetIPString());
759         if (x != local_clones.end())
760                 x->second++;
761         else
762                 local_clones[user->GetIPString()] = 1;
763 }
764
765 void InspIRCd::AddGlobalClone(User* user)
766 {
767         clonemap::iterator y = global_clones.find(user->GetIPString());
768         if (y != global_clones.end())
769                 y->second++;
770         else
771                 global_clones[user->GetIPString()] = 1;
772 }
773
774 int InspIRCd::GetTimeDelta()
775 {
776         return time_delta;
777 }
778
779 void InspIRCd::SetSignal(int signal)
780 {
781         *mysig = signal;
782 }