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>
58 #include "inspstring.h"
60 #include "helperfuncs.h"
62 #include "socketengine.h"
63 #include "inspircd_se_config.h"
64 #include "userprocess.h"
67 #include "command_parse.h"
69 InspIRCd* ServerInstance;
71 extern ModuleList modules;
72 extern FactoryList factory;
74 std::vector<InspSocket*> module_sockets;
75 std::vector<userrec*> local_users;
78 extern char LOG_FILE[MAXBUF];
82 insp_sockaddr client, server;
85 extern InspSocket* socket_ref[MAX_DESCRIPTORS];
86 time_t TIME = time(NULL), OLDTIME = time(NULL);
88 // This table references users by file descriptor.
89 // its an array to make it VERY fast, as all lookups are referenced
90 // by an integer, meaning there is no need for a scan/search operation.
91 userrec* fd_ref_table[MAX_DESCRIPTORS];
92 Server* MyServer = new Server;
93 ServerConfig *Config = new ServerConfig;
96 servernamelist servernames;
99 void AddServerName(const std::string &servername)
101 log(DEBUG,"Adding server name: %s",servername.c_str());
103 if(find(servernames.begin(), servernames.end(), servername) == servernames.end())
104 servernames.push_back(servername); /* Wasn't already there. */
107 const char* FindServerNamePtr(const std::string &servername)
109 servernamelist::iterator iter = find(servernames.begin(), servernames.end(), servername);
111 if(iter == servernames.end())
113 AddServerName(servername);
114 iter = --servernames.end();
117 return iter->c_str();
120 bool FindServerName(const std::string &servername)
122 return (find(servernames.begin(), servernames.end(), servername) != servernames.end());
125 void Exit(int status)
127 if (Config->log_file)
128 fclose(Config->log_file);
129 send_error("Server shutdown.");
133 void InspIRCd::Start()
135 printf("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
136 printf("(C) ChatSpike Development team.\033[0m\n\n");
137 printf("Developers:\t\t\033[1;32mBrain, FrostyCoolSlug, w00t, Om, Special\033[0m\n");
138 printf("Others:\t\t\t\033[1;32mSee /INFO Output\033[0m\n");
139 printf("Name concept:\t\t\033[1;32mLord_Zathras\033[0m\n\n");
142 void Killed(int status)
144 if (Config->log_file)
145 fclose(Config->log_file);
146 send_error("Server terminated.");
150 void Rehash(int status)
152 WriteOpers("Rehashing config file %s due to SIGHUP",CleanFilename(CONFIG_FILE));
153 fclose(Config->log_file);
155 Config->Read(false,NULL);
156 FOREACH_MOD(I_OnRehash,OnRehash(""));
159 void InspIRCd::SetSignals()
161 signal (SIGALRM, SIG_IGN);
162 signal (SIGHUP, Rehash);
163 signal (SIGPIPE, SIG_IGN);
164 signal (SIGTERM, Exit);
165 signal (SIGSEGV, Error);
168 bool InspIRCd::DaemonSeed()
171 if ((childpid = fork ()) < 0)
173 else if (childpid > 0)
175 /* We wait a few seconds here, so that the shell prompt doesnt come back over the output */
181 printf("InspIRCd Process ID: \033[1;32m%lu\033[0m\n",(unsigned long)getpid());
184 if (getrlimit(RLIMIT_CORE, &rl) == -1)
186 log(DEFAULT,"Failed to getrlimit()!");
191 rl.rlim_cur = rl.rlim_max;
192 if (setrlimit(RLIMIT_CORE, &rl) == -1)
193 log(DEFAULT,"setrlimit() failed, cannot increase coredump size.");
199 void InspIRCd::WritePID(const std::string &filename)
201 std::ofstream outfile(filename.c_str());
202 if (outfile.is_open())
209 printf("Failed to write PID-file '%s', exiting.\n",filename.c_str());
210 log(DEFAULT,"Failed to write PID-file '%s', exiting.",filename.c_str());
215 std::string InspIRCd::GetRevision()
220 void InspIRCd::MakeLowerMap()
222 // initialize the lowercase mapping table
223 for (unsigned int cn = 0; cn < 256; cn++)
225 // lowercase the uppercase chars
226 for (unsigned int cn = 65; cn < 91; cn++)
227 lowermap[cn] = tolower(cn);
228 // now replace the specific chars for scandanavian comparison
229 lowermap[(unsigned)'['] = '{';
230 lowermap[(unsigned)']'] = '}';
231 lowermap[(unsigned)'\\'] = '|';
234 InspIRCd::InspIRCd(int argc, char** argv)
237 module_sockets.clear();
238 this->startup_time = time(NULL);
240 log(DEBUG,"*** InspIRCd starting up!");
241 if (!FileExists(CONFIG_FILE))
243 printf("ERROR: Cannot open config file: %s\nExiting...\n",CONFIG_FILE);
244 log(DEFAULT,"main: no config");
245 printf("ERROR: Your config file is missing, this IRCd will self destruct in 10 seconds!\n");
250 for (int i = 1; i < argc; i++)
252 if (!strcmp(argv[i],"-nofork"))
254 Config->nofork = true;
256 else if(!strcmp(argv[i],"-debug"))
258 Config->forcedebug = true;
260 else if(!strcmp(argv[i],"-nolog"))
262 Config->writelog = false;
264 else if (!strcmp(argv[i],"-wait"))
268 else if (!strcmp(argv[i],"-nolimit"))
270 printf("WARNING: The `-nolimit' option is deprecated, and now on by default. This behaviour may change in the future.\n");
272 else if (!strcmp(argv[i],"-logfile"))
276 strlcpy(LOG_FILE,argv[i+1],MAXBUF);
277 printf("LOG: Setting logfile to %s\n",LOG_FILE);
281 printf("ERROR: The -logfile parameter must be followed by a log file name and path.\n");
288 strlcpy(Config->MyExecutable,argv[0],MAXBUF);
290 this->MakeLowerMap();
293 this->stats = new serverstats();
294 this->Parser = new CommandParser();
295 Config->ClearStack();
296 Config->Read(true,NULL);
298 this->ModeGrok = new ModeParser();
299 AddServerName(Config->ServerName);
301 InitializeDisabledCommands(Config->DisabledCommands, this);
302 stats->BoundPortCount = BindPorts(true);
304 for(int t = 0; t < 255; t++)
305 Config->global_implementation[t] = 0;
307 memset(&Config->implement_lists,0,sizeof(Config->implement_lists));
313 if (!this->DaemonSeed())
315 printf("ERROR: could not go into daemon mode. Shutting down.\n");
320 /* Because of limitations in kqueue on freebsd, we must fork BEFORE we
321 * initialize the socket engine.
323 SocketEngineFactory* SEF = new SocketEngineFactory();
327 /* We must load the modules AFTER initializing the socket engine, now */
332 std::string InspIRCd::GetVersionString()
334 char versiondata[MAXBUF];
335 char dnsengine[] = "singlethread-object";
336 if (*Config->CustomVersion)
338 snprintf(versiondata,MAXBUF,"%s %s :%s",VERSION,Config->ServerName,Config->CustomVersion);
342 snprintf(versiondata,MAXBUF,"%s %s :%s [FLAGS=%lu,%s,%s]",VERSION,Config->ServerName,SYSTEM,(unsigned long)OPTIMISATION,SE->GetName().c_str(),dnsengine);
347 char* InspIRCd::ModuleError()
352 void InspIRCd::EraseFactory(int j)
355 for (std::vector<ircd_module*>::iterator t = factory.begin(); t != factory.end(); t++)
360 factory.push_back(NULL);
367 void InspIRCd::EraseModule(int j)
370 for (std::vector<Module*>::iterator m = modules.begin(); m!= modules.end(); m++)
376 modules.push_back(NULL);
382 for (std::vector<std::string>::iterator v = Config->module_names.begin(); v != Config->module_names.end(); v++)
386 Config->module_names.erase(v);
394 void InspIRCd::MoveTo(std::string modulename,int slot)
396 unsigned int v2 = 256;
397 for (unsigned int v = 0; v < Config->module_names.size(); v++)
399 if (Config->module_names[v] == modulename)
401 // found an instance, swap it with the item at MODCOUNT
406 if ((v2 != (unsigned int)slot) && (v2 < 256))
408 // Swap the module names over
409 Config->module_names[v2] = Config->module_names[slot];
410 Config->module_names[slot] = modulename;
411 // now swap the module factories
412 ircd_module* temp = factory[v2];
413 factory[v2] = factory[slot];
414 factory[slot] = temp;
415 // now swap the module objects
416 Module* temp_module = modules[v2];
417 modules[v2] = modules[slot];
418 modules[slot] = temp_module;
419 // now swap the implement lists (we dont
420 // need to swap the global or recount it)
421 for (int n = 0; n < 255; n++)
423 char x = Config->implement_lists[v2][n];
424 Config->implement_lists[v2][n] = Config->implement_lists[slot][n];
425 Config->implement_lists[slot][n] = x;
430 log(DEBUG,"Move of %s to slot failed!",modulename.c_str());
434 void InspIRCd::MoveAfter(std::string modulename, std::string after)
436 for (unsigned int v = 0; v < Config->module_names.size(); v++)
438 if (Config->module_names[v] == after)
440 MoveTo(modulename, v);
446 void InspIRCd::MoveBefore(std::string modulename, std::string before)
448 for (unsigned int v = 0; v < Config->module_names.size(); v++)
450 if (Config->module_names[v] == before)
454 MoveTo(modulename, v-1);
458 MoveTo(modulename, v);
465 void InspIRCd::MoveToFirst(std::string modulename)
467 MoveTo(modulename,0);
470 void InspIRCd::MoveToLast(std::string modulename)
472 MoveTo(modulename,MODCOUNT);
475 void InspIRCd::BuildISupport()
477 // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
479 v << "WALLCHOPS WALLVOICES MODES=" << MAXMODES << " CHANTYPES=# PREFIX=(ohv)@%+ MAP MAXCHANNELS=" << MAXCHANS << " MAXBANS=60 VBANLIST NICKLEN=" << NICKMAX-1;
480 v << " CASEMAPPING=rfc1459 STATUSMSG=@%+ CHARSET=ascii TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=" << Config->MaxTargets << " AWAYLEN=";
481 v << MAXAWAY << " CHANMODES=b,k,l,psmnti FNC NETWORK=" << Config->Network << " MAXPARA=32";
482 Config->data005 = v.str();
483 FOREACH_MOD(I_On005Numeric,On005Numeric(Config->data005));
486 bool InspIRCd::UnloadModule(const char* filename)
488 std::string filename_str = filename;
489 for (unsigned int j = 0; j != Config->module_names.size(); j++)
491 if (Config->module_names[j] == filename_str)
493 if (modules[j]->GetVersion().Flags & VF_STATIC)
495 log(DEFAULT,"Failed to unload STATIC module %s",filename);
496 snprintf(MODERR,MAXBUF,"Module not unloadable (marked static)");
499 /* Give the module a chance to tidy out all its metadata */
500 for (chan_hash::iterator c = chanlist.begin(); c != chanlist.end(); c++)
502 modules[j]->OnCleanup(TYPE_CHANNEL,c->second);
504 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
506 modules[j]->OnCleanup(TYPE_USER,u->second);
509 FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(modules[j],Config->module_names[j]));
511 for(int t = 0; t < 255; t++)
513 Config->global_implementation[t] -= Config->implement_lists[j][t];
516 /* We have to renumber implement_lists after unload because the module numbers change!
518 for(int j2 = j; j2 < 254; j2++)
520 for(int t = 0; t < 255; t++)
522 Config->implement_lists[j2][t] = Config->implement_lists[j2+1][t];
527 log(DEBUG,"Deleting module...");
528 this->EraseModule(j);
529 log(DEBUG,"Erasing module entry...");
530 this->EraseFactory(j);
531 log(DEBUG,"Removing dependent commands...");
532 Parser->RemoveCommands(filename);
533 log(DEFAULT,"Module %s unloaded",filename);
539 log(DEFAULT,"Module %s is not loaded, cannot unload it!",filename);
540 snprintf(MODERR,MAXBUF,"Module not loaded");
544 bool InspIRCd::LoadModule(const char* filename)
546 char modfile[MAXBUF];
548 strlcpy(modfile,filename,MAXBUF);
550 snprintf(modfile,MAXBUF,"%s/%s",Config->ModPath,filename);
552 std::string filename_str = filename;
555 if (!DirValid(modfile))
557 log(DEFAULT,"Module %s is not within the modules directory.",modfile);
558 snprintf(MODERR,MAXBUF,"Module %s is not within the modules directory.",modfile);
563 log(DEBUG,"Loading module: %s",modfile);
565 if (FileExists(modfile))
568 for (unsigned int j = 0; j < Config->module_names.size(); j++)
570 if (Config->module_names[j] == filename_str)
572 log(DEFAULT,"Module %s is already loaded, cannot load a module twice!",modfile);
573 snprintf(MODERR,MAXBUF,"Module already loaded");
577 ircd_module* a = new ircd_module(modfile);
578 factory[MODCOUNT+1] = a;
579 if (factory[MODCOUNT+1]->LastError())
581 log(DEFAULT,"Unable to load %s: %s",modfile,factory[MODCOUNT+1]->LastError());
582 snprintf(MODERR,MAXBUF,"Loader/Linker error: %s",factory[MODCOUNT+1]->LastError());
587 if (factory[MODCOUNT+1]->factory)
589 Module* m = factory[MODCOUNT+1]->factory->CreateModule(MyServer);
590 modules[MODCOUNT+1] = m;
591 /* save the module and the module's classfactory, if
592 * this isnt done, random crashes can occur :/ */
593 Config->module_names.push_back(filename);
595 char* x = &Config->implement_lists[MODCOUNT+1][0];
596 for(int t = 0; t < 255; t++)
599 modules[MODCOUNT+1]->Implements(x);
601 for(int t = 0; t < 255; t++)
602 Config->global_implementation[t] += Config->implement_lists[MODCOUNT+1][t];
606 log(DEFAULT,"Unable to load %s",modfile);
607 snprintf(MODERR,MAXBUF,"Factory function failed!");
611 catch (ModuleException& modexcept)
613 log(DEFAULT,"Unable to load %s: ",modfile,modexcept.GetReason());
614 snprintf(MODERR,MAXBUF,"Factory function threw an exception: %s",modexcept.GetReason());
621 log(DEFAULT,"InspIRCd: startup: Module Not Found %s",modfile);
622 snprintf(MODERR,MAXBUF,"Module file could not be found");
627 FOREACH_MOD(I_OnLoadModule,OnLoadModule(modules[MODCOUNT],filename_str));
628 // now work out which modules, if any, want to move to the back of the queue,
629 // and if they do, move them there.
630 std::vector<std::string> put_to_back;
631 std::vector<std::string> put_to_front;
632 std::map<std::string,std::string> put_before;
633 std::map<std::string,std::string> put_after;
634 for (unsigned int j = 0; j < Config->module_names.size(); j++)
636 if (modules[j]->Prioritize() == PRIORITY_LAST)
638 put_to_back.push_back(Config->module_names[j]);
640 else if (modules[j]->Prioritize() == PRIORITY_FIRST)
642 put_to_front.push_back(Config->module_names[j]);
644 else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_BEFORE)
646 put_before[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
648 else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_AFTER)
650 put_after[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
653 for (unsigned int j = 0; j < put_to_back.size(); j++)
655 MoveToLast(put_to_back[j]);
657 for (unsigned int j = 0; j < put_to_front.size(); j++)
659 MoveToFirst(put_to_front[j]);
661 for (std::map<std::string,std::string>::iterator j = put_before.begin(); j != put_before.end(); j++)
663 MoveBefore(j->first,j->second);
665 for (std::map<std::string,std::string>::iterator j = put_after.begin(); j != put_after.end(); j++)
667 MoveAfter(j->first,j->second);
673 void InspIRCd::DoOneIteration(bool process_module_sockets)
675 int activefds[MAX_DESCRIPTORS];
679 InspSocket* s = NULL;
680 InspSocket* s_del = NULL;
681 unsigned int numberactive;
682 insp_sockaddr sock_us; // our port number
683 socklen_t uslen; // length of our port number
685 /* time() seems to be a pretty expensive syscall, so avoid calling it too much.
686 * Once per loop iteration is pleanty.
691 /* Run background module timers every few seconds
692 * (the docs say modules shouldnt rely on accurate
693 * timing using this event, so we dont have to
694 * time this exactly).
696 if (((TIME % 5) == 0) && (!expire_run))
699 if (process_module_sockets)
701 /* Fix by brain - the addition of DoOneIteration means that this
702 * can end up getting called recursively in the following pattern:
704 * m_spanningtree DoPingChecks
705 * (server pings out and is squit)
706 * (squit causes call to DoOneIteration)
707 * DoOneIteration enters here
708 * calls DoBackground timer
709 * enters m_spanningtree DoPingChecks... see step 1.
711 * This should do the job and fix the bug.
713 FOREACH_MOD(I_OnBackgroundTimer,OnBackgroundTimer(TIME));
715 TickMissedTimers(TIME);
719 else if ((TIME % 5) == 1)
724 if (iterations++ == 15)
727 DoBackgroundUserStuff(TIME);
730 /* Once a second, do the background processing */
734 WriteOpers("*** \002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME));
735 if ((TIME % 3600) == 0)
737 MaintainWhoWas(TIME);
741 /* Process timeouts on module sockets each time around
742 * the loop. There shouldnt be many module sockets, at
743 * most, 20 or so, so this won't be much of a performance
746 if (process_module_sockets)
747 DoSocketTimeouts(TIME);
751 /* Call the socket engine to wait on the active
752 * file descriptors. The socket engine has everything's
753 * descriptors in its list... dns, modules, users,
754 * servers... so its nice and easy, just one call.
756 if (!(numberactive = SE->Wait(activefds)))
760 * Now process each of the fd's. For users, we have a fast
761 * lookup table which can find a user by file descriptor, so
762 * processing them by fd isnt expensive. If we have a lot of
763 * listening ports or module sockets though, things could get
766 log(DEBUG,"There are %d fd's to process.",numberactive);
768 for (unsigned int activefd = 0; activefd < numberactive; activefd++)
770 int socket_type = SE->GetType(activefds[activefd]);
775 log(DEBUG,"Type: X_ESTAB_CLIENT: fd=%d",activefds[activefd]);
776 cu = fd_ref_table[activefds[activefd]];
784 log(DEBUG,"Type: X_ESTAB_MODULE: fd=%d",activefds[activefd]);
786 if (!process_module_sockets)
789 /* Process module-owned sockets.
790 * Modules are encouraged to inherit their sockets from
791 * InspSocket so we can process them neatly like this.
793 s = socket_ref[activefds[activefd]];
795 if ((s) && (!s->Poll()))
797 log(DEBUG,"Socket poll returned false, close and bail");
798 SE->DelFd(s->GetFd());
799 socket_ref[activefds[activefd]] = NULL;
800 for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
803 if ((s_del) && (s_del->GetFd() == activefds[activefd]))
805 module_sockets.erase(a);
814 log(DEBUG,"WTF, X_ESTAB_MODULE for nonexistent InspSocket, removed!");
815 SE->DelFd(s->GetFd());
820 /* Handles instances of the Resolver class,
821 * a simple class extended by modules for
822 * nonblocking resolving of addresses.
825 dns_deal_with_classes(activefds[activefd]);
830 log(DEBUG,"Type: X_LISTEN_MODULE: fd=%d",activefds[activefd]);
832 /* It's a listener */
833 uslen = sizeof(sock_us);
834 length = sizeof(client);
835 incomingSockfd = accept (activefds[activefd],(struct sockaddr*)&client,&length);
837 if ((incomingSockfd > -1) && (!getsockname(incomingSockfd,(sockaddr*)&sock_us,&uslen)))
840 in_port = ntohs(sock_us.sin6_port);
842 in_port = ntohs(sock_us.sin_port);
844 log(DEBUG,"Accepted socket %d",incomingSockfd);
845 /* Years and years ago, we used to resolve here
846 * using gethostbyaddr(). That is sucky and we
847 * don't do that any more...
849 NonBlocking(incomingSockfd);
850 if (Config->GetIOHook(in_port))
855 Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, insp_ntoa(client.sin6_addr), in_port);
857 Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, insp_ntoa(client.sin_addr), in_port);
860 catch (ModuleException& modexcept)
862 log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
865 stats->statsAccept++;
867 AddClient(incomingSockfd, in_port, false, client.sin6_addr);
869 AddClient(incomingSockfd, in_port, false, client.sin_addr);
871 log(DEBUG,"Adding client on port %lu fd=%lu",(unsigned long)in_port,(unsigned long)incomingSockfd);
875 log(DEBUG,"Accept failed on fd %lu: %s",(unsigned long)incomingSockfd,strerror(errno));
876 shutdown(incomingSockfd,2);
877 close(incomingSockfd);
878 stats->statsRefused++;
883 /* Something went wrong if we're in here.
884 * In fact, so wrong, im not quite sure
885 * what we would do, so for now, its going
886 * to safely do bugger all.
888 log(DEBUG,"Type: X_WHAT_THE_FUCK_BBQ: fd=%d",activefds[activefd]);
889 SE->DelFd(activefds[activefd]);
897 /* Until THIS point, ServerInstance == NULL */
901 LoadAllModules(this);
903 /* Just in case no modules were loaded - fix for bug #101 */
904 this->BuildISupport();
906 printf("\nInspIRCd is now running!\n");
915 /* Add the listening sockets used for client inbound connections
916 * to the socket engine
918 for (unsigned long count = 0; count < stats->BoundPortCount; count++)
919 SE->AddFd(Config->openSockfd[count],true,X_LISTEN);
921 this->WritePID(Config->PID);
923 /* main loop, this never returns */
929 DoOneIteration(true);
931 /* This is never reached -- we hope! */
935 /**********************************************************************************/
938 * An ircd in four lines! bwahahaha. ahahahahaha. ahahah *cough*.
941 int main(int argc, char** argv)
943 /* TEST SUITE FOR TOKENSTREAM
947 * String: 'PRIVMSG #test FOO BAR'
948 * Token 0 = 'PRIVMSG'
952 * String: 'PRIVMSG #test :FOO BAR BAZ'
953 * Token 0 = 'PRIVMSG'
955 * Token 2 = 'FOO BAR BAZ'
956 * String: ':PRIVMSG #test :FOO BAR BAZ'
957 * Token 0 = ':PRIVMSG'
959 * Token 0 = 'AAAAAAA'
963 std::string a = "PRIVMSG #test FOO BAR";
964 printf("String: '%s'\n",a.c_str());
965 irc::tokenstream test(a);
966 printf("Token 0 = '%s'\n",test.GetToken().c_str());
967 printf("Token 1 = '%s'\n",test.GetToken().c_str());
968 printf("Token 2 = '%s'\n",test.GetToken().c_str());
969 printf("Token 3 = '%s'\n",test.GetToken().c_str());
970 printf("Token 4 = '%s'\n",test.GetToken().c_str());
972 std::string b = "PRIVMSG #test :FOO BAR BAZ";
973 printf("String: '%s'\n",b.c_str());
974 irc::tokenstream test2(b);
975 printf("Token 0 = '%s'\n",test2.GetToken().c_str());
976 printf("Token 1 = '%s'\n",test2.GetToken().c_str());
977 printf("Token 2 = '%s'\n",test2.GetToken().c_str());
978 printf("Token 3 = '%s'\n",test2.GetToken().c_str());
980 std::string c = ":PRIVMSG #test :FOO BAR BAZ";
981 printf("String: '%s'\n",c.c_str());
982 irc::tokenstream test3(c);
983 printf("Token 0 = '%s'\n",test3.GetToken().c_str());
986 printf("String: '%s'\n",c.c_str());
987 irc::tokenstream test4(c);
988 printf("Token 0 = '%s'\n",test4.GetToken().c_str());
989 printf("Token 1 = '%s'\n",test4.GetToken().c_str());
992 printf("String: '%s'\n",c.c_str());
993 irc::tokenstream test5(c);
994 printf("Token 0 = '%s'\n",test5.GetToken().c_str());
1000 ServerInstance = new InspIRCd(argc, argv);
1001 ServerInstance->Run();
1002 DELETE(ServerInstance);
1004 catch (std::bad_alloc)
1006 log(DEFAULT,"You are out of memory! (got exception std::bad_alloc!)");
1007 send_error("**** OUT OF MEMORY **** We're gonna need a bigger boat!");
1008 printf("Out of memory! (got exception std::bad_alloc!");