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