1 /* ---------------------------------------------------------------------
3 * +------------------------------------+
4 * | Inspire Internet Relay Chat Daemon |
5 * +------------------------------------+
7 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
9 * <brain@chatspike.net>
10 * <Craig@chatspike.net>
12 * Written by Craig Edwards, Craig McLure, and others.
13 * This program is free but copyrighted software; you can redistribute
14 * it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * ---------------------------------------------------------------------
31 #include "inspircd_config.h"
33 #include "configreader.h"
35 #include <sys/errno.h>
36 #include <sys/ioctl.h>
57 #include "inspstring.h"
58 #include "helperfuncs.h"
60 #include "socketengine.h"
61 #include "inspircd_se_config.h"
62 #include "userprocess.h"
65 #include "command_parse.h"
67 using irc::sockets::BindPorts;
68 using irc::sockets::NonBlocking;
69 using irc::sockets::insp_ntoa;
70 using irc::sockets::insp_inaddr;
71 using irc::sockets::insp_sockaddr;
73 InspIRCd* ServerInstance = NULL;
75 extern ModuleList modules;
76 extern FactoryList factory;
79 extern char LOG_FILE[MAXBUF];
83 insp_sockaddr client, server;
86 time_t TIME = time(NULL), OLDTIME = time(NULL);
88 Server* MyServer = new Server;
91 void InspIRCd::AddServerName(const std::string &servername)
93 log(DEBUG,"Adding server name: %s",servername.c_str());
95 if(find(servernames.begin(), servernames.end(), servername) == servernames.end())
96 servernames.push_back(servername); /* Wasn't already there. */
99 const char* InspIRCd::FindServerNamePtr(const std::string &servername)
101 servernamelist::iterator iter = find(servernames.begin(), servernames.end(), servername);
103 if(iter == servernames.end())
105 AddServerName(servername);
106 iter = --servernames.end();
109 return iter->c_str();
112 bool InspIRCd::FindServerName(const std::string &servername)
114 return (find(servernames.begin(), servernames.end(), servername) != servernames.end());
117 void InspIRCd::Exit(int status)
119 if (ServerInstance->Config->log_file)
120 fclose(ServerInstance->Config->log_file);
121 ServerInstance->SendError("Server shutdown.");
125 void InspIRCd::Start()
127 printf("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
128 printf("(C) ChatSpike Development team.\033[0m\n\n");
129 printf("Developers:\t\t\033[1;32mBrain, FrostyCoolSlug, w00t, Om, Special\033[0m\n");
130 printf("Others:\t\t\t\033[1;32mSee /INFO Output\033[0m\n");
131 printf("Name concept:\t\t\033[1;32mLord_Zathras\033[0m\n\n");
134 void InspIRCd::Rehash(int status)
136 ServerInstance->WriteOpers("Rehashing config file %s due to SIGHUP",ServerConfig::CleanFilename(CONFIG_FILE));
137 fclose(ServerInstance->Config->log_file);
138 ServerInstance->OpenLog(NULL,0);
139 ServerInstance->Config->Read(false,NULL);
140 FOREACH_MOD(I_OnRehash,OnRehash(""));
143 void InspIRCd::SetSignals(bool SEGVHandler)
145 signal (SIGALRM, SIG_IGN);
146 signal (SIGHUP, InspIRCd::Rehash);
147 signal (SIGPIPE, SIG_IGN);
148 signal (SIGTERM, InspIRCd::Exit);
150 signal (SIGSEGV, InspIRCd::Error);
153 bool InspIRCd::DaemonSeed()
156 if ((childpid = fork ()) < 0)
158 else if (childpid > 0)
160 /* We wait a few seconds here, so that the shell prompt doesnt come back over the output */
166 printf("InspIRCd Process ID: \033[1;32m%lu\033[0m\n",(unsigned long)getpid());
169 if (getrlimit(RLIMIT_CORE, &rl) == -1)
171 log(DEFAULT,"Failed to getrlimit()!");
176 rl.rlim_cur = rl.rlim_max;
177 if (setrlimit(RLIMIT_CORE, &rl) == -1)
178 log(DEFAULT,"setrlimit() failed, cannot increase coredump size.");
184 void InspIRCd::WritePID(const std::string &filename)
186 std::ofstream outfile(filename.c_str());
187 if (outfile.is_open())
194 printf("Failed to write PID-file '%s', exiting.\n",filename.c_str());
195 log(DEFAULT,"Failed to write PID-file '%s', exiting.",filename.c_str());
200 std::string InspIRCd::GetRevision()
205 void InspIRCd::MakeLowerMap()
207 // initialize the lowercase mapping table
208 for (unsigned int cn = 0; cn < 256; cn++)
210 // lowercase the uppercase chars
211 for (unsigned int cn = 65; cn < 91; cn++)
212 lowermap[cn] = tolower(cn);
213 // now replace the specific chars for scandanavian comparison
214 lowermap[(unsigned)'['] = '{';
215 lowermap[(unsigned)']'] = '}';
216 lowermap[(unsigned)'\\'] = '|';
219 InspIRCd::InspIRCd(int argc, char** argv)
221 bool SEGVHandler = false;
222 ServerInstance = this;
223 this->Config = new ServerConfig(this);
225 this->module_sockets.clear();
226 this->startup_time = time(NULL);
228 log(DEBUG,"*** InspIRCd starting up!");
229 if (!ServerConfig::FileExists(CONFIG_FILE))
231 printf("ERROR: Cannot open config file: %s\nExiting...\n",CONFIG_FILE);
232 log(DEFAULT,"main: no config");
233 printf("ERROR: Your config file is missing, this IRCd will self destruct in 10 seconds!\n");
238 for (int i = 1; i < argc; i++)
240 if (!strcmp(argv[i],"-nofork"))
242 Config->nofork = true;
244 else if(!strcmp(argv[i],"-debug"))
246 Config->forcedebug = true;
248 else if(!strcmp(argv[i],"-nolog"))
250 Config->writelog = false;
252 else if (!strcmp(argv[i],"-wait"))
256 else if (!strcmp(argv[i],"-nolimit"))
258 printf("WARNING: The `-nolimit' option is deprecated, and now on by default. This behaviour may change in the future.\n");
260 else if (!strcmp(argv[i],"-notraceback"))
264 else if (!strcmp(argv[i],"-logfile"))
268 strlcpy(LOG_FILE,argv[i+1],MAXBUF);
269 printf("LOG: Setting logfile to %s\n",LOG_FILE);
273 printf("ERROR: The -logfile parameter must be followed by a log file name and path.\n");
280 printf("Usage: %s [-nofork] [-nolog] [-debug] [-wait] [-nolimit] [-notraceback] [-logfile <filename>]\n",argv[0]);
286 strlcpy(Config->MyExecutable,argv[0],MAXBUF);
288 this->MakeLowerMap();
291 this->stats = new serverstats();
292 this->Parser = new CommandParser();
293 this->Timers = new TimerManager();
294 Config->ClearStack();
295 Config->Read(true, NULL);
297 this->ModeGrok = new ModeParser();
298 this->AddServerName(Config->ServerName);
300 InitializeDisabledCommands(Config->DisabledCommands, this);
301 stats->BoundPortCount = BindPorts(true);
303 for(int t = 0; t < 255; t++)
304 Config->global_implementation[t] = 0;
306 memset(&Config->implement_lists,0,sizeof(Config->implement_lists));
309 this->SetSignals(SEGVHandler);
312 if (!this->DaemonSeed())
314 printf("ERROR: could not go into daemon mode. Shutting down.\n");
319 /* Because of limitations in kqueue on freebsd, we must fork BEFORE we
320 * initialize the socket engine.
322 SocketEngineFactory* SEF = new SocketEngineFactory();
326 /* We must load the modules AFTER initializing the socket engine, now */
331 std::string InspIRCd::GetVersionString()
333 char versiondata[MAXBUF];
334 char dnsengine[] = "singlethread-object";
335 if (*Config->CustomVersion)
337 snprintf(versiondata,MAXBUF,"%s %s :%s",VERSION,Config->ServerName,Config->CustomVersion);
341 snprintf(versiondata,MAXBUF,"%s %s :%s [FLAGS=%lu,%s,%s]",VERSION,Config->ServerName,SYSTEM,(unsigned long)OPTIMISATION,SE->GetName().c_str(),dnsengine);
346 char* InspIRCd::ModuleError()
351 void InspIRCd::EraseFactory(int j)
354 for (std::vector<ircd_module*>::iterator t = factory.begin(); t != factory.end(); t++)
359 factory.push_back(NULL);
366 void InspIRCd::EraseModule(int j)
369 for (std::vector<Module*>::iterator m = modules.begin(); m!= modules.end(); m++)
375 modules.push_back(NULL);
381 for (std::vector<std::string>::iterator v = Config->module_names.begin(); v != Config->module_names.end(); v++)
385 Config->module_names.erase(v);
393 void InspIRCd::MoveTo(std::string modulename,int slot)
395 unsigned int v2 = 256;
396 for (unsigned int v = 0; v < Config->module_names.size(); v++)
398 if (Config->module_names[v] == modulename)
400 // found an instance, swap it with the item at MODCOUNT
405 if ((v2 != (unsigned int)slot) && (v2 < 256))
407 // Swap the module names over
408 Config->module_names[v2] = Config->module_names[slot];
409 Config->module_names[slot] = modulename;
410 // now swap the module factories
411 ircd_module* temp = factory[v2];
412 factory[v2] = factory[slot];
413 factory[slot] = temp;
414 // now swap the module objects
415 Module* temp_module = modules[v2];
416 modules[v2] = modules[slot];
417 modules[slot] = temp_module;
418 // now swap the implement lists (we dont
419 // need to swap the global or recount it)
420 for (int n = 0; n < 255; n++)
422 char x = Config->implement_lists[v2][n];
423 Config->implement_lists[v2][n] = Config->implement_lists[slot][n];
424 Config->implement_lists[slot][n] = x;
429 log(DEBUG,"Move of %s to slot failed!",modulename.c_str());
433 void InspIRCd::MoveAfter(std::string modulename, std::string after)
435 for (unsigned int v = 0; v < Config->module_names.size(); v++)
437 if (Config->module_names[v] == after)
439 MoveTo(modulename, v);
445 void InspIRCd::MoveBefore(std::string modulename, std::string before)
447 for (unsigned int v = 0; v < Config->module_names.size(); v++)
449 if (Config->module_names[v] == before)
453 MoveTo(modulename, v-1);
457 MoveTo(modulename, v);
464 void InspIRCd::MoveToFirst(std::string modulename)
466 MoveTo(modulename,0);
469 void InspIRCd::MoveToLast(std::string modulename)
471 MoveTo(modulename,MODCOUNT);
474 void InspIRCd::BuildISupport()
476 // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
478 v << "WALLCHOPS WALLVOICES MODES=" << MAXMODES << " CHANTYPES=# PREFIX=(ohv)@%+ MAP MAXCHANNELS=" << MAXCHANS << " MAXBANS=60 VBANLIST NICKLEN=" << NICKMAX-1;
479 v << " CASEMAPPING=rfc1459 STATUSMSG=@%+ CHARSET=ascii TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=" << Config->MaxTargets << " AWAYLEN=";
480 v << MAXAWAY << " CHANMODES=b,k,l,psmnti FNC NETWORK=" << Config->Network << " MAXPARA=32";
481 Config->data005 = v.str();
482 FOREACH_MOD(I_On005Numeric,On005Numeric(Config->data005));
485 bool InspIRCd::UnloadModule(const char* filename)
487 std::string filename_str = filename;
488 for (unsigned int j = 0; j != Config->module_names.size(); j++)
490 if (Config->module_names[j] == filename_str)
492 if (modules[j]->GetVersion().Flags & VF_STATIC)
494 log(DEFAULT,"Failed to unload STATIC module %s",filename);
495 snprintf(MODERR,MAXBUF,"Module not unloadable (marked static)");
498 /* Give the module a chance to tidy out all its metadata */
499 for (chan_hash::iterator c = this->chanlist.begin(); c != this->chanlist.end(); c++)
501 modules[j]->OnCleanup(TYPE_CHANNEL,c->second);
503 for (user_hash::iterator u = this->clientlist.begin(); u != this->clientlist.end(); u++)
505 modules[j]->OnCleanup(TYPE_USER,u->second);
508 FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(modules[j],Config->module_names[j]));
510 for(int t = 0; t < 255; t++)
512 Config->global_implementation[t] -= Config->implement_lists[j][t];
515 /* We have to renumber implement_lists after unload because the module numbers change!
517 for(int j2 = j; j2 < 254; j2++)
519 for(int t = 0; t < 255; t++)
521 Config->implement_lists[j2][t] = Config->implement_lists[j2+1][t];
526 log(DEBUG,"Removing dependent commands...");
527 Parser->RemoveCommands(filename);
528 log(DEBUG,"Deleting module...");
529 this->EraseModule(j);
530 log(DEBUG,"Erasing module entry...");
531 this->EraseFactory(j);
532 log(DEFAULT,"Module %s unloaded",filename);
538 log(DEFAULT,"Module %s is not loaded, cannot unload it!",filename);
539 snprintf(MODERR,MAXBUF,"Module not loaded");
543 bool InspIRCd::LoadModule(const char* filename)
545 char modfile[MAXBUF];
547 strlcpy(modfile,filename,MAXBUF);
549 snprintf(modfile,MAXBUF,"%s/%s",Config->ModPath,filename);
551 std::string filename_str = filename;
554 if (!ServerConfig::DirValid(modfile))
556 log(DEFAULT,"Module %s is not within the modules directory.",modfile);
557 snprintf(MODERR,MAXBUF,"Module %s is not within the modules directory.",modfile);
562 log(DEBUG,"Loading module: %s",modfile);
564 if (ServerConfig::FileExists(modfile))
567 for (unsigned int j = 0; j < Config->module_names.size(); j++)
569 if (Config->module_names[j] == filename_str)
571 log(DEFAULT,"Module %s is already loaded, cannot load a module twice!",modfile);
572 snprintf(MODERR,MAXBUF,"Module already loaded");
578 ircd_module* a = new ircd_module(modfile);
579 factory[MODCOUNT+1] = a;
580 if (factory[MODCOUNT+1]->LastError())
582 log(DEFAULT,"Unable to load %s: %s",modfile,factory[MODCOUNT+1]->LastError());
583 snprintf(MODERR,MAXBUF,"Loader/Linker error: %s",factory[MODCOUNT+1]->LastError());
586 if ((long)factory[MODCOUNT+1]->factory != -1)
588 Module* m = factory[MODCOUNT+1]->factory->CreateModule(MyServer);
589 modules[MODCOUNT+1] = m;
590 /* save the module and the module's classfactory, if
591 * this isnt done, random crashes can occur :/ */
592 Config->module_names.push_back(filename);
594 char* x = &Config->implement_lists[MODCOUNT+1][0];
595 for(int t = 0; t < 255; t++)
598 modules[MODCOUNT+1]->Implements(x);
600 for(int t = 0; t < 255; t++)
601 Config->global_implementation[t] += Config->implement_lists[MODCOUNT+1][t];
605 log(DEFAULT,"Unable to load %s",modfile);
606 snprintf(MODERR,MAXBUF,"Factory function failed: Probably missing init_module() entrypoint.");
610 catch (ModuleException& modexcept)
612 log(DEFAULT,"Unable to load %s: ",modfile,modexcept.GetReason());
613 snprintf(MODERR,MAXBUF,"Factory function threw an exception: %s",modexcept.GetReason());
620 log(DEFAULT,"InspIRCd: startup: Module Not Found %s",modfile);
621 snprintf(MODERR,MAXBUF,"Module file could not be found");
626 FOREACH_MOD(I_OnLoadModule,OnLoadModule(modules[MODCOUNT],filename_str));
627 // now work out which modules, if any, want to move to the back of the queue,
628 // and if they do, move them there.
629 std::vector<std::string> put_to_back;
630 std::vector<std::string> put_to_front;
631 std::map<std::string,std::string> put_before;
632 std::map<std::string,std::string> put_after;
633 for (unsigned int j = 0; j < Config->module_names.size(); j++)
635 if (modules[j]->Prioritize() == PRIORITY_LAST)
637 put_to_back.push_back(Config->module_names[j]);
639 else if (modules[j]->Prioritize() == PRIORITY_FIRST)
641 put_to_front.push_back(Config->module_names[j]);
643 else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_BEFORE)
645 put_before[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
647 else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_AFTER)
649 put_after[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
652 for (unsigned int j = 0; j < put_to_back.size(); j++)
654 MoveToLast(put_to_back[j]);
656 for (unsigned int j = 0; j < put_to_front.size(); j++)
658 MoveToFirst(put_to_front[j]);
660 for (std::map<std::string,std::string>::iterator j = put_before.begin(); j != put_before.end(); j++)
662 MoveBefore(j->first,j->second);
664 for (std::map<std::string,std::string>::iterator j = put_after.begin(); j != put_after.end(); j++)
666 MoveAfter(j->first,j->second);
672 void InspIRCd::DoOneIteration(bool process_module_sockets)
674 int activefds[MAX_DESCRIPTORS];
678 InspSocket* s = NULL;
679 InspSocket* s_del = NULL;
680 unsigned int numberactive;
681 insp_sockaddr sock_us; // our port number
682 socklen_t uslen; // length of our port number
684 /* time() seems to be a pretty expensive syscall, so avoid calling it too much.
685 * Once per loop iteration is pleanty.
690 /* Run background module timers every few seconds
691 * (the docs say modules shouldnt rely on accurate
692 * timing using this event, so we dont have to
693 * time this exactly).
695 if (((TIME % 5) == 0) && (!expire_run))
698 if (process_module_sockets)
700 FOREACH_MOD(I_OnBackgroundTimer,OnBackgroundTimer(TIME));
702 Timers->TickMissedTimers(TIME);
706 else if ((TIME % 5) == 1)
711 if (iterations++ == 15)
714 this->DoBackgroundUserStuff(TIME);
717 /* Once a second, do the background processing */
721 WriteOpers("*** \002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME));
722 if ((TIME % 3600) == 0)
724 irc::whowas::MaintainWhoWas(TIME);
728 /* Process timeouts on module sockets each time around
729 * the loop. There shouldnt be many module sockets, at
730 * most, 20 or so, so this won't be much of a performance
733 if (process_module_sockets)
734 this->DoSocketTimeouts(TIME);
736 Timers->TickTimers(TIME);
738 /* Call the socket engine to wait on the active
739 * file descriptors. The socket engine has everything's
740 * descriptors in its list... dns, modules, users,
741 * servers... so its nice and easy, just one call.
743 if (!(numberactive = SE->Wait(activefds)))
747 * Now process each of the fd's. For users, we have a fast
748 * lookup table which can find a user by file descriptor, so
749 * processing them by fd isnt expensive. If we have a lot of
750 * listening ports or module sockets though, things could get
753 log(DEBUG,"There are %d fd's to process.",numberactive);
755 for (unsigned int activefd = 0; activefd < numberactive; activefd++)
757 int socket_type = SE->GetType(activefds[activefd]);
762 log(DEBUG,"Type: X_ESTAB_CLIENT: fd=%d",activefds[activefd]);
763 cu = this->fd_ref_table[activefds[activefd]];
765 this->ProcessUser(cu);
771 log(DEBUG,"Type: X_ESTAB_MODULE: fd=%d",activefds[activefd]);
773 if (!process_module_sockets)
776 /* Process module-owned sockets.
777 * Modules are encouraged to inherit their sockets from
778 * InspSocket so we can process them neatly like this.
780 s = this->socket_ref[activefds[activefd]];
782 if ((s) && (!s->Poll()))
784 log(DEBUG,"Socket poll returned false, close and bail");
785 SE->DelFd(s->GetFd());
786 this->socket_ref[activefds[activefd]] = NULL;
787 for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
790 if ((s_del) && (s_del->GetFd() == activefds[activefd]))
792 module_sockets.erase(a);
801 log(DEBUG,"WTF, X_ESTAB_MODULE for nonexistent InspSocket, removed!");
802 SE->DelFd(s->GetFd());
807 /* Handles instances of the Resolver class,
808 * a simple class extended by modules and the core for
809 * nonblocking resolving of addresses.
811 this->Res->MarshallReads(activefds[activefd]);
816 log(DEBUG,"Type: X_LISTEN: fd=%d",activefds[activefd]);
818 /* It's a listener */
819 uslen = sizeof(sock_us);
820 length = sizeof(client);
821 incomingSockfd = accept (activefds[activefd],(struct sockaddr*)&client,&length);
823 if ((incomingSockfd > -1) && (!getsockname(incomingSockfd,(sockaddr*)&sock_us,&uslen)))
826 in_port = ntohs(sock_us.sin6_port);
828 in_port = ntohs(sock_us.sin_port);
830 log(DEBUG,"Accepted socket %d",incomingSockfd);
831 /* Years and years ago, we used to resolve here
832 * using gethostbyaddr(). That is sucky and we
833 * don't do that any more...
835 NonBlocking(incomingSockfd);
836 if (Config->GetIOHook(in_port))
841 Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, insp_ntoa(client.sin6_addr), in_port);
843 Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, insp_ntoa(client.sin_addr), in_port);
846 catch (ModuleException& modexcept)
848 log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
851 stats->statsAccept++;
853 log(DEBUG,"Add ipv6 client");
854 userrec::AddClient(this, incomingSockfd, in_port, false, client.sin6_addr);
856 log(DEBUG,"Add ipv4 client");
857 userrec::AddClient(this, incomingSockfd, in_port, false, client.sin_addr);
859 log(DEBUG,"Adding client on port %d fd=%d",in_port,incomingSockfd);
863 log(DEBUG,"Accept failed on fd %d: %s",incomingSockfd,strerror(errno));
864 shutdown(incomingSockfd,2);
865 close(incomingSockfd);
866 stats->statsRefused++;
871 /* Something went wrong if we're in here.
872 * In fact, so wrong, im not quite sure
873 * what we would do, so for now, its going
874 * to safely do bugger all.
876 log(DEBUG,"Type: X_WHAT_THE_FUCK_BBQ: fd=%d",activefds[activefd]);
877 SE->DelFd(activefds[activefd]);
883 bool InspIRCd::IsIdent(const char* n)
888 for (char* i = (char*)n; *i; i++)
890 if ((*i >= 'A') && (*i <= '}'))
894 if (((*i >= '0') && (*i <= '9')) || (*i == '-') || (*i == '.'))
904 bool InspIRCd::IsNick(const char* n)
910 for (char* i = (char*)n; *i; i++, p++)
912 /* "A"-"}" can occur anywhere in a nickname */
913 if ((*i >= 'A') && (*i <= '}'))
917 /* "0"-"9", "-" can occur anywhere BUT the first char of a nickname */
918 if ((((*i >= '0') && (*i <= '9')) || (*i == '-')) && (i > n))
922 /* invalid character! abort */
925 return (p < NICKMAX - 1);
930 this->Res = new DNS(this);
932 log(DEBUG,"RES: %08x",this->Res);
934 this->LoadAllModules();
936 /* Just in case no modules were loaded - fix for bug #101 */
937 this->BuildISupport();
939 if (!stats->BoundPortCount)
941 printf("\nI couldn't bind any ports! Are you sure you didn't start InspIRCd twice?\n");
945 /* Add the listening sockets used for client inbound connections
946 * to the socket engine
948 log(DEBUG,"%d listeners",stats->BoundPortCount);
949 for (unsigned long count = 0; count < stats->BoundPortCount; count++)
951 log(DEBUG,"Add listener: %d",Config->openSockfd[count]);
952 if (!SE->AddFd(Config->openSockfd[count],true,X_LISTEN))
954 printf("\nEH? Could not add listener to socketengine. You screwed up, aborting.\n");
966 printf("\nInspIRCd is now running!\n");
968 this->WritePID(Config->PID);
970 /* main loop, this never returns */
976 DoOneIteration(true);
978 /* This is never reached -- we hope! */
982 /**********************************************************************************/
985 * An ircd in four lines! bwahahaha. ahahahahaha. ahahah *cough*.
988 int main(int argc, char** argv)
990 /* This is a MatchCIDR() test suite -
991 printf("Should be 0: %d\n",MatchCIDR("127.0.0.1","1.2.3.4/8"));
992 printf("Should be 1: %d\n",MatchCIDR("127.0.0.1","127.0.0.0/8"));
993 printf("Should be 1: %d\n",MatchCIDR("127.0.0.1","127.0.0.0/18"));
994 printf("Should be 0: %d\n",MatchCIDR("3ffe::0","2fc9::0/16"));
995 printf("Should be 1: %d\n",MatchCIDR("3ffe:1:3::0", "3ffe:1::0/32"));
1002 ServerInstance = new InspIRCd(argc, argv);
1003 ServerInstance->Run();
1004 DELETE(ServerInstance);
1006 catch (std::bad_alloc&)
1008 log(SPARSE,"You are out of memory! (got exception std::bad_alloc!)");
1009 ServerInstance->SendError("**** OUT OF MEMORY **** We're gonna need a bigger boat!");
1014 log(SPARSE,"Uncaught exception, aborting.");
1015 ServerInstance->SendError("Server terminating due to uncaught exception.");
1020 /* this returns true when all modules are satisfied that the user should be allowed onto the irc server
1021 * (until this returns true, a user will block in the waiting state, waiting to connect up to the
1022 * registration timeout maximum seconds)
1024 bool InspIRCd::AllModulesReportReady(userrec* user)
1026 if (!Config->global_implementation[I_OnCheckReady])
1029 for (int i = 0; i <= MODCOUNT; i++)
1031 if (Config->implement_lists[i][I_OnCheckReady])
1033 int res = modules[i]->OnCheckReady(user);