1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "configreader.h"
23 #include "socketengine.h"
24 #include "inspircd_se_config.h"
27 #include "command_parse.h"
30 using irc::sockets::NonBlocking;
31 using irc::sockets::Blocking;
32 using irc::sockets::insp_ntoa;
33 using irc::sockets::insp_inaddr;
34 using irc::sockets::insp_sockaddr;
38 void InspIRCd::AddServerName(const std::string &servername)
40 this->Log(DEBUG,"Adding server name: %s",servername.c_str());
42 if(find(servernames.begin(), servernames.end(), servername) == servernames.end())
43 servernames.push_back(servername); /* Wasn't already there. */
46 const char* InspIRCd::FindServerNamePtr(const std::string &servername)
48 servernamelist::iterator iter = find(servernames.begin(), servernames.end(), servername);
50 if(iter == servernames.end())
52 AddServerName(servername);
53 iter = --servernames.end();
59 bool InspIRCd::FindServerName(const std::string &servername)
61 return (find(servernames.begin(), servernames.end(), servername) != servernames.end());
64 void InspIRCd::Exit(int status)
68 SI->SendError("Exiting with status " + ConvToStr(status));
75 void InspIRCd::Cleanup()
77 std::vector<std::string> mymodnames;
78 int MyModCount = this->GetModuleCount();
80 for (unsigned int i = 0; i < stats->BoundPortCount; i++)
81 /* This calls the constructor and closes the listening socket */
82 delete Config->openSockfd[i];
84 /* We do this more than once, so that any service providers get a
85 * chance to be unhooked by the modules using them, but then get
86 * a chance to be removed themsleves.
88 for (int tries = 0; tries < 3; tries++)
90 MyModCount = this->GetModuleCount();
93 /* Unload all modules, so they get a chance to clean up their listeners */
94 for (int j = 0; j <= MyModCount; j++)
95 mymodnames.push_back(Config->module_names[j]);
97 for (int k = 0; k <= MyModCount; k++)
98 this->UnloadModule(mymodnames[k].c_str());
101 /* Close all client sockets, or the new process inherits them */
102 for (std::vector<userrec*>::const_iterator i = this->local_users.begin(); i != this->local_users.end(); i++)
106 this->Logger->Close();
109 void InspIRCd::Restart(const std::string &reason)
111 /* SendError flushes each client's queue,
112 * regardless of writeability state
114 this->SendError(reason);
118 /* Figure out our filename (if theyve renamed it, we're boned) */
119 std::string me = Config->MyDir + "/inspircd";
121 if (execv(me.c_str(), Config->argv) == -1)
123 /* Will raise a SIGABRT if not trapped */
124 throw CoreException(std::string("Failed to execv()! error: ") + strerror(errno));
128 void InspIRCd::Start()
130 printf("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
131 printf("(C) InspIRCd Development Team.\033[0m\n\n");
132 printf("Developers:\t\t\033[1;32mBrain, FrostyCoolSlug, w00t, Om, Special, pippijn, peavey\033[0m\n");
133 printf("Others:\t\t\t\033[1;32mSee /INFO Output\033[0m\n");
136 void InspIRCd::Rehash(int status)
138 SI->WriteOpers("Rehashing config file %s due to SIGHUP",ServerConfig::CleanFilename(CONFIG_FILE));
139 fclose(SI->Config->log_file);
141 SI->Config->Read(false,NULL);
142 FOREACH_MOD_I(SI,I_OnRehash,OnRehash(""));
145 void InspIRCd::SetSignals()
147 signal(SIGALRM, SIG_IGN);
148 signal(SIGHUP, InspIRCd::Rehash);
149 signal(SIGPIPE, SIG_IGN);
150 signal(SIGTERM, InspIRCd::Exit);
151 signal(SIGCHLD, SIG_IGN);
154 bool InspIRCd::DaemonSeed()
157 if ((childpid = fork ()) < 0)
159 else if (childpid > 0)
161 /* We wait here for the child process to kill us,
162 * so that the shell prompt doesnt come back over
164 * Sending a kill with a signal of 0 just checks
165 * if the child pid is still around. If theyre not,
166 * they threw an error and we should give up.
168 while (kill(childpid, 0) != -1)
174 printf("InspIRCd Process ID: \033[1;32m%lu\033[0m\n",(unsigned long)getpid());
177 if (getrlimit(RLIMIT_CORE, &rl) == -1)
179 this->Log(DEFAULT,"Failed to getrlimit()!");
184 rl.rlim_cur = rl.rlim_max;
185 if (setrlimit(RLIMIT_CORE, &rl) == -1)
186 this->Log(DEFAULT,"setrlimit() failed, cannot increase coredump size.");
192 void InspIRCd::WritePID(const std::string &filename)
194 std::string fname = (filename.empty() ? "inspircd.pid" : filename);
195 if (*(fname.begin()) != '/')
197 std::string::size_type pos;
198 std::string confpath = CONFIG_FILE;
199 if ((pos = confpath.find("/inspircd.conf")) != std::string::npos)
201 /* Leaves us with just the path */
202 fname = confpath.substr(0, pos) + std::string("/") + fname;
205 std::ofstream outfile(fname.c_str());
206 if (outfile.is_open())
213 printf("Failed to write PID-file '%s', exiting.\n",fname.c_str());
214 this->Log(DEFAULT,"Failed to write PID-file '%s', exiting.",fname.c_str());
219 std::string InspIRCd::GetRevision()
224 InspIRCd::InspIRCd(int argc, char** argv)
225 : ModCount(-1), duration_m(60), duration_h(60*60), duration_d(60*60*24), duration_w(60*60*24*7), duration_y(60*60*24*365)
233 this->Config = new ServerConfig(this);
234 this->Config->opertypes.clear();
235 this->Config->operclass.clear();
236 this->SNO = new SnomaskManager(this);
238 this->TIME = this->OLDTIME = this->startup_time = time(NULL);
239 this->time_delta = 0;
240 this->next_call = this->TIME + 3;
242 this->Log(DEBUG,"*** InspIRCd starting up!");
243 if (!ServerConfig::FileExists(CONFIG_FILE))
245 printf("ERROR: Cannot open config file: %s\nExiting...\n",CONFIG_FILE);
246 this->Log(DEFAULT,"main: no config");
247 printf("ERROR: Your config file is missing, this IRCd will self destruct in 10 seconds!\n");
250 *this->LogFileName = 0;
252 for (int i = 1; i < argc; i++)
254 if (!strcmp(argv[i],"-nofork"))
256 Config->nofork = true;
258 else if(!strcmp(argv[i],"-debug"))
260 Config->forcedebug = true;
262 else if(!strcmp(argv[i],"-nolog"))
264 Config->writelog = false;
266 else if (!strcmp(argv[i],"-wait"))
270 else if (!strcmp(argv[i],"-logfile"))
274 strlcpy(LogFileName,argv[i+1],MAXBUF);
275 printf("LOG: Setting logfile to %s\n",LogFileName);
279 printf("ERROR: The -logfile parameter must be followed by a log file name and path.\n");
286 printf("Usage: %s [-nofork] [-nolog] [-debug] [-wait] [-logfile <filename>]\n",argv[0]);
292 strlcpy(Config->MyExecutable,argv[0],MAXBUF);
294 this->OpenLog(argv, argc);
295 this->stats = new serverstats();
296 this->Parser = new CommandParser(this);
297 this->Timers = new TimerManager();
298 this->XLines = new XLineManager(this);
299 Config->ClearStack();
300 Config->Read(true, NULL);
302 this->Modes = new ModeParser(this);
303 this->AddServerName(Config->ServerName);
305 InitializeDisabledCommands(Config->DisabledCommands, this);
306 stats->BoundPortCount = BindPorts(true, found_ports, pl);
308 for(int t = 0; t < 255; t++)
309 Config->global_implementation[t] = 0;
311 memset(&Config->implement_lists,0,sizeof(Config->implement_lists));
317 if (!this->DaemonSeed())
319 printf("ERROR: could not go into daemon mode. Shutting down.\n");
324 /* Because of limitations in kqueue on freebsd, we must fork BEFORE we
325 * initialize the socket engine.
327 SocketEngineFactory* SEF = new SocketEngineFactory();
328 SE = SEF->Create(this);
331 this->Res = new DNS(this);
333 this->LoadAllModules();
334 /* Just in case no modules were loaded - fix for bug #101 */
335 this->BuildISupport();
337 if ((stats->BoundPortCount == 0) && (found_ports > 0))
339 printf("\nERROR: I couldn't bind any ports! Are you sure you didn't start InspIRCd twice?\n");
343 if (stats->BoundPortCount != (unsigned int)found_ports)
345 printf("\nWARNING: Not all your client ports could be bound --\nstarting anyway with %ld of %d client ports bound.\n\n", stats->BoundPortCount, found_ports);
346 printf("The following port%s failed to bind:\n", found_ports - stats->BoundPortCount != 1 ? "s" : "");
348 for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
350 printf("%d.\tIP: %s\tPort: %lu\n", j, i->first.empty() ? "<all>" : i->first.c_str(), (unsigned long)i->second);
354 /* Add the listening sockets used for client inbound connections
355 * to the socket engine
357 this->Log(DEBUG,"%d listeners",stats->BoundPortCount);
358 for (unsigned long count = 0; count < stats->BoundPortCount; count++)
360 this->Log(DEBUG,"Add listener: %d",Config->openSockfd[count]->GetFd());
361 if (!SE->AddFd(Config->openSockfd[count]))
363 printf("\nEH? Could not add listener to socketengine. You screwed up, aborting.\n");
370 if (kill(getppid(), SIGTERM) == -1)
371 printf("Error killing parent process: %s\n",strerror(errno));
377 printf("\nInspIRCd is now running!\n");
379 this->WritePID(Config->PID);
382 std::string InspIRCd::GetVersionString()
384 char versiondata[MAXBUF];
385 char dnsengine[] = "singlethread-object";
386 if (*Config->CustomVersion)
388 snprintf(versiondata,MAXBUF,"%s %s :%s",VERSION,Config->ServerName,Config->CustomVersion);
392 snprintf(versiondata,MAXBUF,"%s %s :%s [FLAGS=%lu,%s,%s]",VERSION,Config->ServerName,SYSTEM,(unsigned long)OPTIMISATION,SE->GetName().c_str(),dnsengine);
397 char* InspIRCd::ModuleError()
402 void InspIRCd::EraseFactory(int j)
405 for (std::vector<ircd_module*>::iterator t = factory.begin(); t != factory.end(); t++)
411 factory.push_back(NULL);
418 void InspIRCd::EraseModule(int j)
421 for (ModuleList::iterator m = modules.begin(); m!= modules.end(); m++)
427 modules.push_back(NULL);
433 for (std::vector<std::string>::iterator v = Config->module_names.begin(); v != Config->module_names.end(); v++)
437 Config->module_names.erase(v);
445 void InspIRCd::MoveTo(std::string modulename,int slot)
447 unsigned int v2 = 256;
448 for (unsigned int v = 0; v < Config->module_names.size(); v++)
450 if (Config->module_names[v] == modulename)
452 // found an instance, swap it with the item at the end
457 if ((v2 != (unsigned int)slot) && (v2 < 256))
459 // Swap the module names over
460 Config->module_names[v2] = Config->module_names[slot];
461 Config->module_names[slot] = modulename;
462 // now swap the module factories
463 ircd_module* temp = factory[v2];
464 factory[v2] = factory[slot];
465 factory[slot] = temp;
466 // now swap the module objects
467 Module* temp_module = modules[v2];
468 modules[v2] = modules[slot];
469 modules[slot] = temp_module;
470 // now swap the implement lists (we dont
471 // need to swap the global or recount it)
472 for (int n = 0; n < 255; n++)
474 char x = Config->implement_lists[v2][n];
475 Config->implement_lists[v2][n] = Config->implement_lists[slot][n];
476 Config->implement_lists[slot][n] = x;
481 this->Log(DEBUG,"Move of %s to slot failed!",modulename.c_str());
485 void InspIRCd::MoveAfter(std::string modulename, std::string after)
487 for (unsigned int v = 0; v < Config->module_names.size(); v++)
489 if (Config->module_names[v] == after)
491 MoveTo(modulename, v);
497 void InspIRCd::MoveBefore(std::string modulename, std::string before)
499 for (unsigned int v = 0; v < Config->module_names.size(); v++)
501 if (Config->module_names[v] == before)
505 MoveTo(modulename, v-1);
509 MoveTo(modulename, v);
516 void InspIRCd::MoveToFirst(std::string modulename)
518 MoveTo(modulename,0);
521 void InspIRCd::MoveToLast(std::string modulename)
523 MoveTo(modulename,this->GetModuleCount());
526 void InspIRCd::BuildISupport()
528 // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
530 v << "WALLCHOPS WALLVOICES MODES=" << MAXMODES << " CHANTYPES=# PREFIX=" << this->Modes->BuildPrefixes() << " MAP MAXCHANNELS=" << MAXCHANS << " MAXBANS=60 VBANLIST NICKLEN=" << NICKMAX-1;
531 v << " CASEMAPPING=rfc1459 STATUSMSG=@%+ CHARSET=ascii TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=" << Config->MaxTargets << " AWAYLEN=";
532 v << MAXAWAY << " CHANMODES=" << this->Modes->ChanModes() << " FNC NETWORK=" << Config->Network << " MAXPARA=32";
533 Config->data005 = v.str();
534 FOREACH_MOD_I(this,I_On005Numeric,On005Numeric(Config->data005));
538 bool InspIRCd::UnloadModule(const char* filename)
540 std::string filename_str = filename;
541 for (unsigned int j = 0; j != Config->module_names.size(); j++)
543 if (Config->module_names[j] == filename_str)
545 if (modules[j]->GetVersion().Flags & VF_STATIC)
547 this->Log(DEFAULT,"Failed to unload STATIC module %s",filename);
548 snprintf(MODERR,MAXBUF,"Module not unloadable (marked static)");
551 std::pair<int,std::string> intercount = GetInterfaceInstanceCount(modules[j]);
552 if (intercount.first > 0)
554 this->Log(DEFAULT,"Failed to unload module %s, being used by %d other(s) via interface '%s'",filename, intercount.first, intercount.second.c_str());
555 snprintf(MODERR,MAXBUF,"Module not unloadable (Still in use by %d other module%s which %s using its interface '%s') -- unload dependent modules first!",
557 intercount.first > 1 ? "s" : "",
558 intercount.first > 1 ? "are" : "is",
559 intercount.second.c_str());
562 /* Give the module a chance to tidy out all its metadata */
563 for (chan_hash::iterator c = this->chanlist.begin(); c != this->chanlist.end(); c++)
565 modules[j]->OnCleanup(TYPE_CHANNEL,c->second);
567 for (user_hash::iterator u = this->clientlist.begin(); u != this->clientlist.end(); u++)
569 modules[j]->OnCleanup(TYPE_USER,u->second);
572 /* Tidy up any dangling resolvers */
573 this->Res->CleanResolvers(modules[j]);
575 FOREACH_MOD_I(this,I_OnUnloadModule,OnUnloadModule(modules[j],Config->module_names[j]));
577 for(int t = 0; t < 255; t++)
579 Config->global_implementation[t] -= Config->implement_lists[j][t];
582 /* We have to renumber implement_lists after unload because the module numbers change!
584 for(int j2 = j; j2 < 254; j2++)
586 for(int t = 0; t < 255; t++)
588 Config->implement_lists[j2][t] = Config->implement_lists[j2+1][t];
593 Parser->RemoveCommands(filename);
594 this->EraseModule(j);
595 this->EraseFactory(j);
596 this->Log(DEFAULT,"Module %s unloaded",filename);
602 this->Log(DEFAULT,"Module %s is not loaded, cannot unload it!",filename);
603 snprintf(MODERR,MAXBUF,"Module not loaded");
607 bool InspIRCd::LoadModule(const char* filename)
609 /* Do we have a glob pattern in the filename?
610 * The user wants to load multiple modules which
613 if (strchr(filename,'*') || (strchr(filename,'?')))
616 DIR* library = opendir(Config->ModPath);
619 /* Try and locate and load all modules matching the pattern */
620 dirent* entry = NULL;
621 while ((entry = readdir(library)))
623 if (this->MatchText(entry->d_name, filename))
625 if (!this->LoadModule(entry->d_name))
631 /* Loadmodule will now return false if any one of the modules failed
632 * to load (but wont abort when it encounters a bad one) and when 1 or
633 * more modules were actually loaded.
635 return (n_match > 0);
638 char modfile[MAXBUF];
639 snprintf(modfile,MAXBUF,"%s/%s",Config->ModPath,filename);
640 std::string filename_str = filename;
642 if (!ServerConfig::DirValid(modfile))
644 this->Log(DEFAULT,"Module %s is not within the modules directory.",modfile);
645 snprintf(MODERR,MAXBUF,"Module %s is not within the modules directory.",modfile);
648 this->Log(DEBUG,"Loading module: %s",modfile);
650 if (ServerConfig::FileExists(modfile))
653 for (unsigned int j = 0; j < Config->module_names.size(); j++)
655 if (Config->module_names[j] == filename_str)
657 this->Log(DEFAULT,"Module %s is already loaded, cannot load a module twice!",modfile);
658 snprintf(MODERR,MAXBUF,"Module already loaded");
664 ircd_module* a = new ircd_module(this, modfile);
665 factory[this->ModCount+1] = a;
666 if (factory[this->ModCount+1]->LastError())
668 this->Log(DEFAULT,"Unable to load %s: %s",modfile,factory[this->ModCount+1]->LastError());
669 snprintf(MODERR,MAXBUF,"Loader/Linker error: %s",factory[this->ModCount+1]->LastError());
672 if ((long)factory[this->ModCount+1]->factory != -1)
674 Module* m = factory[this->ModCount+1]->factory->CreateModule(this);
676 Version v = m->GetVersion();
678 if (v.API != API_VERSION)
682 this->Log(DEFAULT,"Unable to load %s: Incorrect module API version: %d (our version: %d)",modfile,v.API,API_VERSION);
683 snprintf(MODERR,MAXBUF,"Loader/Linker error: Incorrect module API version: %d (our version: %d)",v.API,API_VERSION);
688 this->Log(DEFAULT,"New module introduced: %s (API version %d, Module version %d.%d.%d.%d)%s", filename, v.API, v.Major, v.Minor, v.Revision, v.Build, (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]"));
691 modules[this->ModCount+1] = m;
692 /* save the module and the module's classfactory, if
693 * this isnt done, random crashes can occur :/ */
694 Config->module_names.push_back(filename);
696 char* x = &Config->implement_lists[this->ModCount+1][0];
697 for(int t = 0; t < 255; t++)
700 modules[this->ModCount+1]->Implements(x);
702 for(int t = 0; t < 255; t++)
703 Config->global_implementation[t] += Config->implement_lists[this->ModCount+1][t];
707 this->Log(DEFAULT,"Unable to load %s",modfile);
708 snprintf(MODERR,MAXBUF,"Factory function failed: Probably missing init_module() entrypoint.");
712 catch (CoreException& modexcept)
714 this->Log(DEFAULT,"Unable to load %s: ",modfile,modexcept.GetReason());
715 snprintf(MODERR,MAXBUF,"Factory function of %s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
721 this->Log(DEFAULT,"InspIRCd: startup: Module Not Found %s",modfile);
722 snprintf(MODERR,MAXBUF,"Module file could not be found");
726 FOREACH_MOD_I(this,I_OnLoadModule,OnLoadModule(modules[this->ModCount],filename_str));
727 // now work out which modules, if any, want to move to the back of the queue,
728 // and if they do, move them there.
729 std::vector<std::string> put_to_back;
730 std::vector<std::string> put_to_front;
731 std::map<std::string,std::string> put_before;
732 std::map<std::string,std::string> put_after;
733 for (unsigned int j = 0; j < Config->module_names.size(); j++)
735 if (modules[j]->Prioritize() == PRIORITY_LAST)
736 put_to_back.push_back(Config->module_names[j]);
737 else if (modules[j]->Prioritize() == PRIORITY_FIRST)
738 put_to_front.push_back(Config->module_names[j]);
739 else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_BEFORE)
740 put_before[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
741 else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_AFTER)
742 put_after[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8];
744 for (unsigned int j = 0; j < put_to_back.size(); j++)
745 MoveToLast(put_to_back[j]);
746 for (unsigned int j = 0; j < put_to_front.size(); j++)
747 MoveToFirst(put_to_front[j]);
748 for (std::map<std::string,std::string>::iterator j = put_before.begin(); j != put_before.end(); j++)
749 MoveBefore(j->first,j->second);
750 for (std::map<std::string,std::string>::iterator j = put_after.begin(); j != put_after.end(); j++)
751 MoveAfter(j->first,j->second);
756 void InspIRCd::DoOneIteration(bool process_module_sockets)
760 /* time() seems to be a pretty expensive syscall, so avoid calling it too much.
761 * Once per loop iteration is pleanty.
766 /* Run background module timers every few seconds
767 * (the docs say modules shouldnt rely on accurate
768 * timing using this event, so we dont have to
769 * time this exactly).
774 WriteOpers("*** \002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME));
775 if ((TIME % 3600) == 0)
777 irc::whowas::MaintainWhoWas(this, TIME);
779 Timers->TickTimers(TIME);
780 this->DoBackgroundUserStuff(TIME);
784 XLines->expire_lines();
785 FOREACH_MOD_I(this,I_OnBackgroundTimer,OnBackgroundTimer(TIME));
786 Timers->TickMissedTimers(TIME);
789 if (!getrusage(0, &ru))
791 gettimeofday(&this->stats->LastSampled, NULL);
792 this->stats->LastCPU = ru.ru_utime;
796 /* Call the socket engine to wait on the active
797 * file descriptors. The socket engine has everything's
798 * descriptors in its list... dns, modules, users,
799 * servers... so its nice and easy, just one call.
800 * This will cause any read or write events to be
801 * dispatched to their handlers.
803 SE->DispatchEvents();
806 bool InspIRCd::IsIdent(const char* n)
811 for (char* i = (char*)n; *i; i++)
813 if ((*i >= 'A') && (*i <= '}'))
817 if (((*i >= '0') && (*i <= '9')) || (*i == '-') || (*i == '.'))
831 DoOneIteration(true);
833 /* This is never reached -- we hope! */
837 /**********************************************************************************/
840 * An ircd in four lines! bwahahaha. ahahahahaha. ahahah *cough*.
843 int main(int argc, char** argv)
845 SI = new InspIRCd(argc, argv);
851 /* this returns true when all modules are satisfied that the user should be allowed onto the irc server
852 * (until this returns true, a user will block in the waiting state, waiting to connect up to the
853 * registration timeout maximum seconds)
855 bool InspIRCd::AllModulesReportReady(userrec* user)
857 if (!Config->global_implementation[I_OnCheckReady])
860 for (int i = 0; i <= this->GetModuleCount(); i++)
862 if (Config->implement_lists[i][I_OnCheckReady])
864 int res = modules[i]->OnCheckReady(user);
872 int InspIRCd::GetModuleCount()
874 return this->ModCount;
877 time_t InspIRCd::Time(bool delta)
880 return TIME + time_delta;
884 int InspIRCd::SetTimeDelta(int delta)
886 int old = time_delta;
888 this->Log(DEBUG, "Time delta set to %d (was %d)", time_delta, old);
892 void InspIRCd::AddLocalClone(userrec* user)
894 clonemap::iterator x = local_clones.find(user->GetIPString());
895 if (x != local_clones.end())
898 local_clones[user->GetIPString()] = 1;
901 void InspIRCd::AddGlobalClone(userrec* user)
903 clonemap::iterator y = global_clones.find(user->GetIPString());
904 if (y != global_clones.end())
907 global_clones[user->GetIPString()] = 1;
910 int InspIRCd::GetTimeDelta()
915 bool FileLogger::Readable()
920 void FileLogger::HandleEvent(EventType et, int errornum)
922 this->WriteLogLine("");
923 ServerInstance->SE->DelFd(this);
926 void FileLogger::WriteLogLine(const std::string &line)
933 int written = fprintf(log,"%s",buffer.c_str());
934 if ((written >= 0) && (written < (int)buffer.length()))
936 buffer.erase(0, buffer.length());
937 ServerInstance->SE->AddFd(this);
939 else if (written == -1)
942 ServerInstance->SE->AddFd(this);
946 /* Wrote the whole buffer, and no need for write callback */
956 void FileLogger::Close()
960 int flags = fcntl(fileno(log), F_GETFL, 0);
961 fcntl(fileno(log), F_SETFL, flags ^ O_NONBLOCK);
963 fprintf(log,"%s",buffer.c_str());
968 ServerInstance->SE->DelFd(this);
971 FileLogger::FileLogger(InspIRCd* Instance, FILE* logfile) : ServerInstance(Instance), log(logfile), writeops(0)
973 irc::sockets::NonBlocking(fileno(log));
974 this->SetFd(fileno(log));
978 FileLogger::~FileLogger()