1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
19 #include "inspircd_config.h"
21 #include "inspircd_io.h"
24 #include <sys/errno.h>
28 #include <ext/hash_map>
36 #include "connection.h"
47 #include "inspstring.h"
48 #include "helperfuncs.h"
53 extern std::vector<Module*> modules;
54 extern ServerConfig *Config;
55 extern InspIRCd* ServerInstance;
57 extern char lowermap[255];
58 static char list[MAXBUF];
59 extern userrec* fd_ref_table[65536];
60 static char already_sent[65536];
61 extern std::vector<userrec*> all_opers;
62 extern user_hash clientlist;
63 extern chan_hash chanlist;
65 extern std::vector<userrec*> local_users;
67 void log(int level,char *text, ...)
71 if (level < Config->LogLevel)
73 char textbuffer[MAXBUF];
74 timeinfo = localtime(&TIME);
79 va_start (argsPtr, text);
80 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
82 strlcpy(b,asctime(timeinfo),26);
83 b[24] = ':'; // we know this is the end of the time string
85 fprintf(Config->log_file,"%s %s\n",b,textbuffer);
88 // nofork enabled? display it on terminal too
89 printf("%s %s\n",b,textbuffer);
94 void readfile(file_cache &F, const char* fname)
99 log(DEBUG,"readfile: loading %s",fname);
101 file = fopen(fname,"r");
106 fgets(linebuf,sizeof(linebuf),file);
107 linebuf[strlen(linebuf)-1]='\0';
114 F.push_back(linebuf);
121 log(DEBUG,"readfile: failed to load file: %s",fname);
123 log(DEBUG,"readfile: loaded %s, %lu lines",fname,(unsigned long)F.size());
126 void Write_NoFormat(int sock,char *text)
128 if ((sock < 0) || (!text))
132 int bytes = snprintf(tb,MAXBUF,"%s\r\n",text);
134 if (fd_ref_table[sock])
136 if (Config->GetIOHook(fd_ref_table[sock]->port))
138 Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
142 fd_ref_table[sock]->AddWriteBuf(tb);
144 ServerInstance->stats->statsSent += bytes;
146 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
149 void Write(int sock,char *text, ...)
155 log(DEFAULT,"*** BUG *** Write was given an invalid parameter");
159 char textbuffer[MAXBUF],tb[MAXBUF];
160 va_start (argsPtr, text);
161 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
163 int bytes = snprintf(tb,MAXBUF,"%s\r\n",textbuffer);
165 if (fd_ref_table[sock])
167 if (Config->GetIOHook(fd_ref_table[sock]->port))
169 Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
173 fd_ref_table[sock]->AddWriteBuf(tb);
175 ServerInstance->stats->statsSent += bytes;
177 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
180 void WriteServ_NoFormat(int sock, char* text)
182 if ((sock < 0) || (!text))
185 int bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,text);
187 if (fd_ref_table[sock])
189 if (Config->GetIOHook(fd_ref_table[sock]->port))
191 Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
195 fd_ref_table[sock]->AddWriteBuf(tb);
197 ServerInstance->stats->statsSent += bytes;
199 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
202 /* write a server formatted numeric response to a single socket */
204 void WriteServ(int sock, char* text, ...)
210 log(DEFAULT,"*** BUG *** WriteServ was given an invalid parameter");
214 va_start (argsPtr, text);
215 char textbuffer[MAXBUF],tb[MAXBUF];
216 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
218 int bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,textbuffer);
220 if (fd_ref_table[sock])
222 if (Config->GetIOHook(fd_ref_table[sock]->port))
224 Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
228 fd_ref_table[sock]->AddWriteBuf(tb);
230 ServerInstance->stats->statsSent += bytes;
232 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
235 void WriteFrom_NoFormat(int sock, userrec *user,char* text)
237 if ((sock < 0) || (!text) || (!user))
240 int bytes = snprintf(tb,MAXBUF,":%s!%s@%s %s\r\n",user->nick,user->ident,user->dhost,text);
242 if (fd_ref_table[sock])
244 if (Config->GetIOHook(fd_ref_table[sock]->port))
246 Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
250 fd_ref_table[sock]->AddWriteBuf(tb);
252 ServerInstance->stats->statsSent += bytes;
254 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
257 /* write text from an originating user to originating user */
259 void WriteFrom(int sock, userrec *user,char* text, ...)
263 if ((!text) || (!user))
265 log(DEFAULT,"*** BUG *** WriteFrom was given an invalid parameter");
269 va_start (argsPtr, text);
270 char textbuffer[MAXBUF],tb[MAXBUF];
271 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
273 int bytes = snprintf(tb,MAXBUF,":%s!%s@%s %s\r\n",user->nick,user->ident,user->dhost,textbuffer);
275 if (fd_ref_table[sock])
277 if (Config->GetIOHook(fd_ref_table[sock]->port))
279 Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
283 fd_ref_table[sock]->AddWriteBuf(tb);
285 ServerInstance->stats->statsSent += bytes;
287 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
290 /* write text to an destination user from a source user (e.g. user privmsg) */
292 void WriteTo(userrec *source, userrec *dest,char *data, ...)
294 if ((!dest) || (!data))
296 log(DEFAULT,"*** BUG *** WriteTo was given an invalid parameter");
301 char textbuffer[MAXBUF],tb[MAXBUF];
303 va_start (argsPtr, data);
304 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
308 // if no source given send it from the server.
311 WriteServ(dest->fd,":%s %s",Config->ServerName,textbuffer);
315 WriteFrom_NoFormat(dest->fd,source,textbuffer);
319 void WriteTo_NoFormat(userrec *source, userrec *dest,char *data)
321 if ((!dest) || (!data))
325 WriteServ(dest->fd,":%s %s",Config->ServerName,data);
329 WriteFrom_NoFormat(dest->fd,source,data);
333 /* write formatted text from a source user to all users on a channel
334 * including the sender (NOT for privmsg, notice etc!) */
336 void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...)
338 if ((!Ptr) || (!user) || (!text))
340 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
343 char textbuffer[MAXBUF];
345 va_start (argsPtr, text);
346 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
349 std::vector<char*> *ulist = Ptr->GetUsers();
350 unsigned int x = ulist->size();
351 for (unsigned int j = 0; j < x; j++)
353 char* o = (*ulist)[j];
354 userrec* otheruser = (userrec*)o;
355 if (otheruser->fd != FD_MAGIC_NUMBER)
356 WriteTo_NoFormat(user,otheruser,textbuffer);
360 /* write formatted text from a source user to all users on a channel
361 * including the sender (NOT for privmsg, notice etc!) doesnt send to
362 * users on remote servers */
364 void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...)
366 if ((!Ptr) || (!text))
368 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
371 char textbuffer[MAXBUF];
373 va_start (argsPtr, text);
374 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
377 std::vector<char*> *ulist = Ptr->GetUsers();
378 unsigned int x = ulist->size();
379 for (unsigned int j = 0; j < x; j++)
381 char* o = (*ulist)[j];
382 userrec* otheruser = (userrec*)o;
383 if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser->fd != -1) && (otheruser != user))
387 WriteServ_NoFormat(otheruser->fd,textbuffer);
391 WriteTo_NoFormat(user,otheruser,textbuffer);
397 void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
399 if ((!Ptr) || (!text))
401 log(DEFAULT,"*** BUG *** WriteChannelWithServ was given an invalid parameter");
404 char textbuffer[MAXBUF];
406 va_start (argsPtr, text);
407 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
411 std::vector<char*> *ulist = Ptr->GetUsers();
412 unsigned int x = ulist->size();
413 for (unsigned int j = 0; j < x; j++)
415 char* o = (*ulist)[j];
416 userrec* otheruser = (userrec*)o;
417 if (IS_LOCAL(otheruser))
418 WriteServ_NoFormat(otheruser->fd,textbuffer);
422 /* write formatted text from a source user to all users on a channel except
423 * for the sender (for privmsg etc) */
425 void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...)
427 if ((!Ptr) || (!user) || (!text))
429 log(DEFAULT,"*** BUG *** ChanExceptSender was given an invalid parameter");
432 char textbuffer[MAXBUF];
434 va_start (argsPtr, text);
435 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
438 std::vector<char*> *ulist = Ptr->GetUsers();
439 unsigned int x = ulist->size();
440 for (unsigned int j = 0; j < x; j++)
442 char* o = (*ulist)[j];
443 userrec* otheruser = (userrec*)o;
444 if ((IS_LOCAL(otheruser)) && (user != otheruser))
445 WriteFrom_NoFormat(otheruser->fd,user,textbuffer);
449 std::string GetServerDescription(char* servername)
451 std::string description = "";
452 FOREACH_MOD(I_OnGetServerDescription,OnGetServerDescription(servername,description));
453 if (description != "")
459 return Config->ServerDesc; // not a remote server that can be found, it must be me.
463 /* write a formatted string to all users who share at least one common
464 * channel, including the source user e.g. for use in NICK */
466 void WriteCommon(userrec *u, char* text, ...)
470 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
474 if (u->registered != 7) {
475 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
479 char textbuffer[MAXBUF];
481 va_start (argsPtr, text);
482 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
485 // FIX: Stops a message going to the same person more than once
486 memset(&already_sent,0,MAX_DESCRIPTORS);
488 bool sent_to_at_least_one = false;
490 unsigned int y = u->chans.size();
491 for (unsigned int i = 0; i < y; i++)
493 if (u->chans[i].channel)
495 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
496 unsigned int x = ulist->size();
497 for (unsigned int j = 0; j < x; j++)
499 char* o = (*ulist)[j];
500 userrec* otheruser = (userrec*)o;
501 if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
503 already_sent[otheruser->fd] = 1;
504 WriteFrom_NoFormat(otheruser->fd,u,textbuffer);
505 sent_to_at_least_one = true;
510 // if the user was not in any channels, no users will receive the text. Make sure the user
511 // receives their OWN message for WriteCommon
512 if (!sent_to_at_least_one)
514 WriteFrom(u->fd,u,"%s",textbuffer);
518 /* write a formatted string to all users who share at least one common
519 * channel, NOT including the source user e.g. for use in QUIT */
521 void WriteCommonExcept(userrec *u, char* text, ...)
525 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
529 if (u->registered != 7) {
530 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
534 char textbuffer[MAXBUF];
536 va_start (argsPtr, text);
537 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
540 memset(&already_sent,0,MAX_DESCRIPTORS);
542 unsigned int y = u->chans.size();
543 for (unsigned int i = 0; i < y; i++)
545 if (u->chans[i].channel)
547 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
548 unsigned int x = ulist->size();
549 for (unsigned int j = 0; j < x; j++)
551 char* o = (*ulist)[j];
552 userrec* otheruser = (userrec*)o;
555 if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
557 already_sent[otheruser->fd] = 1;
558 WriteFrom_NoFormat(otheruser->fd,u,textbuffer);
566 void WriteOpers(char* text, ...)
570 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
574 char textbuffer[MAXBUF];
576 va_start (argsPtr, text);
577 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
580 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
585 if (strchr(a->modes,'s'))
587 // send server notices to all with +s
588 WriteServ(a->fd,"NOTICE %s :%s",a->nick,textbuffer);
594 void ServerNoticeAll(char* text, ...)
599 char textbuffer[MAXBUF];
601 va_start (argsPtr, text);
602 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
605 for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
607 userrec* t = (userrec*)(*i);
608 WriteServ(t->fd,"NOTICE $%s :%s",Config->ServerName,textbuffer);
612 void ServerPrivmsgAll(char* text, ...)
617 char textbuffer[MAXBUF];
619 va_start (argsPtr, text);
620 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
623 for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
625 userrec* t = (userrec*)(*i);
626 WriteServ(t->fd,"PRIVMSG $%s :%s",Config->ServerName,textbuffer);
630 void WriteMode(const char* modes, int flags, const char* text, ...)
632 if ((!text) || (!modes) || (!flags))
634 log(DEFAULT,"*** BUG *** WriteMode was given an invalid parameter");
638 char textbuffer[MAXBUF];
640 va_start (argsPtr, text);
641 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
643 int modelen = strlen(modes);
645 for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
647 userrec* t = (userrec*)(*i);
648 bool send_to_user = false;
652 for (int n = 0; n < modelen; n++)
654 if (!hasumode(t,modes[n]))
656 send_to_user = false;
661 else if (flags == WM_OR)
663 send_to_user = false;
664 for (int n = 0; n < modelen; n++)
666 if (hasumode(t,modes[n]))
675 WriteServ(t->fd,"NOTICE %s :%s",t->nick,textbuffer);
680 void NoticeAll(userrec *source, bool local_only, char* text, ...)
682 if ((!text) || (!source))
684 log(DEFAULT,"*** BUG *** NoticeAll was given an invalid parameter");
688 char textbuffer[MAXBUF];
690 va_start (argsPtr, text);
691 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
694 for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
696 userrec* t = (userrec*)(*i);
697 WriteFrom(t->fd,source,"NOTICE $* :%s",textbuffer);
703 void WriteWallOps(userrec *source, bool local_only, char* text, ...)
705 if ((!text) || (!source))
707 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
711 char textbuffer[MAXBUF];
713 va_start (argsPtr, text);
714 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
717 for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
719 userrec* t = (userrec*)(*i);
720 if ((IS_LOCAL(t)) && (strchr(t->modes,'w')))
722 WriteTo(source,t,"WALLOPS :%s",textbuffer);
727 /* convert a string to lowercase. Note following special circumstances
728 * taken from RFC 1459. Many "official" server branches still hold to this
729 * rule so i will too;
731 * Because of IRC's scandanavian origin, the characters {}| are
732 * considered to be the lower case equivalents of the characters []\,
733 * respectively. This is a critical issue when determining the
734 * equivalence of two nicknames.
737 void strlower(char *n)
741 for (char* t = n; *t; t++)
742 *t = lowermap[(unsigned)*t];
746 /* Find a user record by nickname and return a pointer to it */
748 userrec* Find(std::string nick)
750 user_hash::iterator iter = clientlist.find(nick);
752 if (iter == clientlist.end())
753 /* Couldn't find it */
759 /* find a channel record by channel name and return a pointer to it */
761 chanrec* FindChan(const char* chan)
765 log(DEFAULT,"*** BUG *** Findchan was given an invalid parameter");
769 chan_hash::iterator iter = chanlist.find(chan);
771 if (iter == chanlist.end())
772 /* Couldn't find it */
779 long GetMaxBans(char* name)
782 for (int count = 0; count < Config->ConfValueEnum("banlist",&Config->config_f); count++)
784 Config->ConfValue("banlist","chan",count,CM,&Config->config_f);
787 Config->ConfValue("banlist","limit",count,CM,&Config->config_f);
794 void purge_empty_chans(userrec* u)
799 // firstly decrement the count on each channel
800 for (unsigned int f = 0; f < u->chans.size(); f++)
802 if (u->chans[f].channel)
804 u->chans[f].channel->DelUser((char*)u);
808 for (unsigned int i = 0; i < u->chans.size(); i++)
810 if (u->chans[i].channel)
812 if (!usercount(u->chans[i].channel))
814 chan_hash::iterator i2 = chanlist.find(u->chans[i].channel->name);
815 /* kill the record */
816 if (i2 != chanlist.end())
818 log(DEBUG,"del_channel: destroyed: %s",i2->second->name);
823 u->chans[i].channel = NULL;
828 log(DEBUG,"skipped purge for %s",u->chans[i].channel->name);
832 log(DEBUG,"completed channel purge, killed %lu",(unsigned long)purge);
838 char* chanmodes(chanrec *chan)
840 static char scratch[MAXBUF];
841 static char sparam[MAXBUF];
842 char* offset = scratch;
846 log(DEFAULT,"*** BUG *** chanmodes was given an invalid parameter");
853 if (chan->binarymodes & CM_NOEXTERNAL)
855 if (chan->binarymodes & CM_TOPICLOCK)
861 if (chan->binarymodes & CM_INVITEONLY)
863 if (chan->binarymodes & CM_MODERATED)
865 if (chan->binarymodes & CM_SECRET)
867 if (chan->binarymodes & CM_PRIVATE)
870 snprintf(sparam,MAXBUF," %s",chan->key);
874 sprintf(foo," %lu",(unsigned long)chan->limit);
875 strlcat(sparam,foo,MAXBUF);
877 if (*chan->custom_modes)
879 for (char* t = chan->custom_modes; *t; t++)
881 for (int z = 0; chan->custom_modes[z]; z++)
883 std::string extparam = chan->GetModeParameter(chan->custom_modes[z]);
886 strlcat(sparam," ",MAXBUF);
887 strlcat(sparam,extparam.c_str(),MAXBUF);
891 /* Null terminate scratch */
893 strlcat(scratch,sparam,MAXMODES);
898 /* compile a userlist of a channel into a string, each nick seperated by
899 * spaces and op, voice etc status shown as @ and + */
901 void userlist(userrec *user,chanrec *c)
905 log(DEFAULT,"*** BUG *** userlist was given an invalid parameter");
909 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
911 std::vector<char*> *ulist = c->GetUsers();
912 for (unsigned int i = 0; i < ulist->size(); i++)
914 char* o = (*ulist)[i];
915 userrec* otheruser = (userrec*)o;
916 if ((!has_channel(user,c)) && (strchr(otheruser->modes,'i')))
918 /* user is +i, and source not on the channel, does not show
919 * nick in NAMES list */
922 strlcat(list,cmode(otheruser,c),MAXBUF);
923 strlcat(list,otheruser->nick,MAXBUF);
924 strlcat(list," ",MAXBUF);
925 if (strlen(list)>(480-NICKMAX))
927 /* list overflowed into
928 * multiple numerics */
929 WriteServ(user->fd,"%s",list);
930 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
933 /* if whats left in the list isnt empty, send it */
934 if (list[strlen(list)-1] != ':')
936 WriteServ(user->fd,"%s",list);
940 /* return a count of the users on a specific channel accounting for
941 * invisible users who won't increase the count. e.g. for /LIST */
943 int usercount_i(chanrec *c)
949 log(DEFAULT,"*** BUG *** usercount_i was given an invalid parameter");
953 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
955 if (has_channel(i->second,c))
957 if (i->second->registered == 7)
959 if ((!has_channel(i->second,c)) && (strchr(i->second->modes,'i')))
961 /* user is +i, and source not on the channel, does not show
962 * nick in NAMES list */
969 log(DEBUG,"usercount_i: %s %lu",c->name,(unsigned long)count);
974 int usercount(chanrec *c)
976 return (c ? c->GetUserCounter() : 0);
980 // looks up a users password for their connection class (<ALLOW>/<DENY> tags)
982 char* Passwd(userrec *user)
984 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
986 if ((i->type == CC_ALLOW) && match(user->host,i->host.c_str()))
988 return (char*)i->pass.c_str();
994 bool IsDenied(userrec *user)
996 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
998 if ((i->type == CC_DENY) && match(user->host,i->host.c_str()))
1009 /* sends out an error notice to all connected clients (not to be used
1012 void send_error(char *s)
1014 log(DEBUG,"send_error: %s",s);
1015 for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
1017 userrec* t = (userrec*)(*i);
1018 if (t->registered == 7)
1020 WriteServ(t->fd,"NOTICE %s :%s",t->nick,s);
1024 // fix - unregistered connections receive ERROR, not NOTICE
1025 Write(t->fd,"ERROR :%s",s);
1030 void Error(int status)
1032 signal (SIGALRM, SIG_IGN);
1033 signal (SIGPIPE, SIG_IGN);
1034 signal (SIGTERM, SIG_IGN);
1035 signal (SIGABRT, SIG_IGN);
1036 signal (SIGSEGV, SIG_IGN);
1037 signal (SIGURG, SIG_IGN);
1038 signal (SIGKILL, SIG_IGN);
1039 log(DEFAULT,"*** fell down a pothole in the road to perfection ***");
1040 send_error("Error! Segmentation fault! save meeeeeeeeeeeeee *splat!*");
1044 // this function counts all users connected, wether they are registered or NOT.
1047 return clientlist.size();
1050 // this counts only registered users, so that the percentages in /MAP don't mess up when users are sitting in an unregistered state
1051 int registered_usercount(void)
1054 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1056 if (i->second->registered == 7) c++;
1061 int usercount_invisible(void)
1064 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1066 if ((i->second->registered == 7) && (strchr(i->second->modes,'i'))) c++;
1071 int usercount_opers(void)
1073 return all_opers.size();
1076 int usercount_unknown(void)
1079 for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
1081 userrec* t = (userrec*)(*i);
1082 if (t->registered != 7)
1088 long chancount(void)
1090 return chanlist.size();
1096 for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
1098 userrec* t = (userrec*)(*i);
1099 if (t->registered == 7) c++;
1104 void ShowMOTD(userrec *user)
1106 static char mbuf[MAXBUF];
1107 static char crud[MAXBUF];
1108 std::string WholeMOTD = "";
1109 if (!Config->MOTD.size())
1111 WriteServ(user->fd,"422 %s :Message of the day file is missing.",user->nick);
1114 snprintf(crud,MAXBUF,":%s 372 %s :- ", Config->ServerName, user->nick);
1115 snprintf(mbuf,MAXBUF,":%s 375 %s :- %s message of the day\r\n", Config->ServerName, user->nick, Config->ServerName);
1116 WholeMOTD = WholeMOTD + mbuf;
1117 for (unsigned int i = 0; i < Config->MOTD.size(); i++)
1118 WholeMOTD = WholeMOTD + std::string(crud) + Config->MOTD[i].c_str() + std::string("\r\n");
1119 snprintf(mbuf,MAXBUF,":%s 376 %s :End of message of the day.\r\n", Config->ServerName, user->nick);
1120 WholeMOTD = WholeMOTD + mbuf;
1121 // only one write operation
1122 if (Config->GetIOHook(user->port))
1124 Config->GetIOHook(user->port)->OnRawSocketWrite(user->fd,(char*)WholeMOTD.c_str(),WholeMOTD.length());
1128 user->AddWriteBuf(WholeMOTD);
1130 ServerInstance->stats->statsSent += WholeMOTD.length();
1133 void ShowRULES(userrec *user)
1135 if (!Config->RULES.size())
1137 WriteServ(user->fd,"NOTICE %s :Rules file is missing.",user->nick);
1140 WriteServ(user->fd,"NOTICE %s :%s rules",user->nick,Config->ServerName);
1141 for (unsigned int i = 0; i < Config->RULES.size(); i++)
1142 WriteServ(user->fd,"NOTICE %s :%s",user->nick,Config->RULES[i].c_str());
1143 WriteServ(user->fd,"NOTICE %s :End of %s rules.",user->nick,Config->ServerName);
1146 // this returns 1 when all modules are satisfied that the user should be allowed onto the irc server
1147 // (until this returns true, a user will block in the waiting state, waiting to connect up to the
1148 // registration timeout maximum seconds)
1149 bool AllModulesReportReady(userrec* user)
1151 if (!Config->global_implementation[I_OnCheckReady])
1153 for (int i = 0; i <= MODCOUNT; i++)
1155 if (Config->implement_lists[i][I_OnCheckReady])
1157 int res = modules[i]->OnCheckReady(user);
1165 bool DirValid(char* dirandfile)
1168 char buffer[MAXBUF], otherdir[MAXBUF];
1169 strlcpy(work,dirandfile,MAXBUF);
1170 int p = strlen(work);
1171 // we just want the dir
1181 // Get the current working directory
1182 if( getcwd( buffer, MAXBUF ) == NULL )
1185 if( getcwd( otherdir, MAXBUF ) == NULL )
1188 if (strlen(otherdir) >= strlen(work))
1190 otherdir[strlen(work)] = '\0';
1191 if (!strcmp(otherdir,work))
1200 std::string GetFullProgDir(char** argv, int argc)
1203 char buffer[MAXBUF], otherdir[MAXBUF];
1204 strlcpy(work,argv[0],MAXBUF);
1205 int p = strlen(work);
1206 // we just want the dir
1216 // Get the current working directory
1217 if( getcwd( buffer, MAXBUF ) == NULL )
1220 if( getcwd( otherdir, MAXBUF ) == NULL )