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