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 void log(int level,char *text, ...)
69 if (level < Config->LogLevel)
71 char textbuffer[MAXBUF];
72 timeinfo = localtime(&TIME);
77 va_start (argsPtr, text);
78 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
80 strlcpy(b,asctime(timeinfo),MAXBUF);
81 b[24] = ':'; // we know this is the end of the time string
83 fprintf(Config->log_file,"%s %s\n",b,textbuffer);
86 // nofork enabled? display it on terminal too
87 printf("%s %s\n",b,textbuffer);
92 void readfile(file_cache &F, const char* fname)
97 log(DEBUG,"readfile: loading %s",fname);
99 file = fopen(fname,"r");
104 fgets(linebuf,sizeof(linebuf),file);
105 linebuf[strlen(linebuf)-1]='\0';
112 F.push_back(linebuf);
119 log(DEBUG,"readfile: failed to load file: %s",fname);
121 log(DEBUG,"readfile: loaded %s, %lu lines",fname,(unsigned long)F.size());
124 void Write(int sock,char *text, ...)
130 log(DEFAULT,"*** BUG *** Write was given an invalid parameter");
134 char textbuffer[MAXBUF],tb[MAXBUF];
135 va_start (argsPtr, text);
136 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
138 int bytes = snprintf(tb,MAXBUF,"%s\r\n",textbuffer);
140 if (fd_ref_table[sock])
142 if (Config->GetIOHook(fd_ref_table[sock]->port))
144 Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
148 fd_ref_table[sock]->AddWriteBuf(tb);
150 ServerInstance->stats->statsSent += bytes;
152 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
155 /* write a server formatted numeric response to a single socket */
157 void WriteServ(int sock, char* text, ...)
163 log(DEFAULT,"*** BUG *** WriteServ was given an invalid parameter");
167 va_start (argsPtr, text);
168 char textbuffer[MAXBUF],tb[MAXBUF];
169 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
171 int bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,textbuffer);
173 if (fd_ref_table[sock])
175 if (Config->GetIOHook(fd_ref_table[sock]->port))
177 Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
181 fd_ref_table[sock]->AddWriteBuf(tb);
183 ServerInstance->stats->statsSent += bytes;
185 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
188 /* write text from an originating user to originating user */
190 void WriteFrom(int sock, userrec *user,char* text, ...)
194 if ((!text) || (!user))
196 log(DEFAULT,"*** BUG *** WriteFrom was given an invalid parameter");
200 va_start (argsPtr, text);
201 char textbuffer[MAXBUF],tb[MAXBUF];
202 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
204 int bytes = snprintf(tb,MAXBUF,":%s!%s@%s %s\r\n",user->nick,user->ident,user->dhost,textbuffer);
206 if (fd_ref_table[sock])
208 if (Config->GetIOHook(fd_ref_table[sock]->port))
210 Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
214 fd_ref_table[sock]->AddWriteBuf(tb);
216 ServerInstance->stats->statsSent += bytes;
218 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
221 /* write text to an destination user from a source user (e.g. user privmsg) */
223 void WriteTo(userrec *source, userrec *dest,char *data, ...)
225 if ((!dest) || (!data))
227 log(DEFAULT,"*** BUG *** WriteTo was given an invalid parameter");
230 if (dest->fd == FD_MAGIC_NUMBER)
232 char textbuffer[MAXBUF],tb[MAXBUF];
234 va_start (argsPtr, data);
235 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
239 // if no source given send it from the server.
242 WriteServ(dest->fd,":%s %s",Config->ServerName,textbuffer);
246 WriteFrom(dest->fd,source,"%s",textbuffer);
250 /* write formatted text from a source user to all users on a channel
251 * including the sender (NOT for privmsg, notice etc!) */
253 void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...)
255 if ((!Ptr) || (!user) || (!text))
257 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
260 char textbuffer[MAXBUF];
262 va_start (argsPtr, text);
263 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
266 std::vector<char*> *ulist = Ptr->GetUsers();
267 unsigned int x = ulist->size();
268 for (unsigned int j = 0; j < x; j++)
270 char* o = (*ulist)[j];
271 userrec* otheruser = (userrec*)o;
272 if (otheruser->fd != FD_MAGIC_NUMBER)
273 WriteTo(user,otheruser,"%s",textbuffer);
277 /* write formatted text from a source user to all users on a channel
278 * including the sender (NOT for privmsg, notice etc!) doesnt send to
279 * users on remote servers */
281 void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...)
283 if ((!Ptr) || (!text))
285 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
288 char textbuffer[MAXBUF];
290 va_start (argsPtr, text);
291 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
294 std::vector<char*> *ulist = Ptr->GetUsers();
295 unsigned int x = ulist->size();
296 for (unsigned int j = 0; j < x; j++)
298 char* o = (*ulist)[j];
299 userrec* otheruser = (userrec*)o;
300 if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser->fd != -1) && (otheruser != user))
304 WriteServ(otheruser->fd,"%s",textbuffer);
308 WriteTo(user,otheruser,"%s",textbuffer);
314 void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
316 if ((!Ptr) || (!text))
318 log(DEFAULT,"*** BUG *** WriteChannelWithServ was given an invalid parameter");
321 char textbuffer[MAXBUF];
323 va_start (argsPtr, text);
324 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
328 std::vector<char*> *ulist = Ptr->GetUsers();
329 unsigned int x = ulist->size();
330 for (unsigned int j = 0; j < x; j++)
332 char* o = (*ulist)[j];
333 userrec* otheruser = (userrec*)o;
334 if (otheruser->fd != FD_MAGIC_NUMBER)
335 WriteServ(otheruser->fd,"%s",textbuffer);
339 /* write formatted text from a source user to all users on a channel except
340 * for the sender (for privmsg etc) */
342 void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...)
344 if ((!Ptr) || (!user) || (!text))
346 log(DEFAULT,"*** BUG *** ChanExceptSender was given an invalid parameter");
349 char textbuffer[MAXBUF];
351 va_start (argsPtr, text);
352 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
355 std::vector<char*> *ulist = Ptr->GetUsers();
356 unsigned int x = ulist->size();
357 for (unsigned int j = 0; j < x; j++)
359 char* o = (*ulist)[j];
360 userrec* otheruser = (userrec*)o;
361 if ((otheruser->fd != FD_MAGIC_NUMBER) && (user != otheruser))
362 WriteFrom(otheruser->fd,user,"%s",textbuffer);
366 std::string GetServerDescription(char* servername)
368 std::string description = "";
369 FOREACH_MOD OnGetServerDescription(servername,description);
370 if (description != "")
376 return Config->ServerDesc; // not a remote server that can be found, it must be me.
380 /* write a formatted string to all users who share at least one common
381 * channel, including the source user e.g. for use in NICK */
383 void WriteCommon(userrec *u, char* text, ...)
387 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
391 if (u->registered != 7) {
392 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
396 char textbuffer[MAXBUF];
398 va_start (argsPtr, text);
399 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
402 // FIX: Stops a message going to the same person more than once
403 memset(&already_sent,0,MAXCLIENTS);
405 bool sent_to_at_least_one = false;
407 unsigned int y = u->chans.size();
408 for (unsigned int i = 0; i < y; i++)
410 if (u->chans[i].channel)
412 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
413 unsigned int x = ulist->size();
414 for (unsigned int j = 0; j < x; j++)
416 char* o = (*ulist)[j];
417 userrec* otheruser = (userrec*)o;
418 if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
420 already_sent[otheruser->fd] = 1;
421 WriteFrom(otheruser->fd,u,"%s",textbuffer);
422 sent_to_at_least_one = true;
427 // if the user was not in any channels, no users will receive the text. Make sure the user
428 // receives their OWN message for WriteCommon
429 if (!sent_to_at_least_one)
431 WriteFrom(u->fd,u,"%s",textbuffer);
435 /* write a formatted string to all users who share at least one common
436 * channel, NOT including the source user e.g. for use in QUIT */
438 void WriteCommonExcept(userrec *u, char* text, ...)
442 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
446 if (u->registered != 7) {
447 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
451 char textbuffer[MAXBUF];
453 va_start (argsPtr, text);
454 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
457 memset(&already_sent,0,MAXCLIENTS);
459 unsigned int y = u->chans.size();
460 for (unsigned int i = 0; i < y; i++)
462 if (u->chans[i].channel)
464 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
465 unsigned int x = ulist->size();
466 for (unsigned int j = 0; j < x; j++)
468 char* o = (*ulist)[j];
469 userrec* otheruser = (userrec*)o;
472 if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
474 already_sent[otheruser->fd] = 1;
475 WriteFrom(otheruser->fd,u,"%s",textbuffer);
483 void WriteOpers(char* text, ...)
487 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
491 char textbuffer[MAXBUF];
493 va_start (argsPtr, text);
494 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
497 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
500 if ((a) && (a->fd != FD_MAGIC_NUMBER))
502 if (strchr(a->modes,'s'))
504 // send server notices to all with +s
505 WriteServ(a->fd,"NOTICE %s :%s",a->nick,textbuffer);
511 void ServerNoticeAll(char* text, ...)
516 char textbuffer[MAXBUF];
518 va_start (argsPtr, text);
519 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
522 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
524 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
526 WriteServ(i->second->fd,"NOTICE $%s :%s",Config->ServerName,textbuffer);
531 void ServerPrivmsgAll(char* text, ...)
536 char textbuffer[MAXBUF];
538 va_start (argsPtr, text);
539 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
542 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
544 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
546 WriteServ(i->second->fd,"PRIVMSG $%s :%s",Config->ServerName,textbuffer);
551 void WriteMode(const char* modes, int flags, const char* text, ...)
553 if ((!text) || (!modes) || (!flags))
555 log(DEFAULT,"*** BUG *** WriteMode was given an invalid parameter");
559 char textbuffer[MAXBUF];
561 va_start (argsPtr, text);
562 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
564 int modelen = strlen(modes);
566 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
568 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
570 bool send_to_user = false;
575 for (int n = 0; n < modelen; n++)
577 if (!hasumode(i->second,modes[n]))
579 send_to_user = false;
584 else if (flags == WM_OR)
586 send_to_user = false;
587 for (int n = 0; n < modelen; n++)
589 if (hasumode(i->second,modes[n]))
599 WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,textbuffer);
605 void NoticeAll(userrec *source, bool local_only, char* text, ...)
607 if ((!text) || (!source))
609 log(DEFAULT,"*** BUG *** NoticeAll was given an invalid parameter");
613 char textbuffer[MAXBUF];
615 va_start (argsPtr, text);
616 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
619 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
621 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
623 WriteFrom(i->second->fd,source,"NOTICE $* :%s",textbuffer);
630 void WriteWallOps(userrec *source, bool local_only, char* text, ...)
632 if ((!text) || (!source))
634 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
638 char textbuffer[MAXBUF];
640 va_start (argsPtr, text);
641 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
644 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
646 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
648 if (strchr(i->second->modes,'w'))
650 WriteTo(source,i->second,"WALLOPS :%s",textbuffer);
656 /* convert a string to lowercase. Note following special circumstances
657 * taken from RFC 1459. Many "official" server branches still hold to this
658 * rule so i will too;
660 * Because of IRC's scandanavian origin, the characters {}| are
661 * considered to be the lower case equivalents of the characters []\,
662 * respectively. This is a critical issue when determining the
663 * equivalence of two nicknames.
666 void strlower(char *n)
670 for (char* t = n; *t; t++)
671 *t = lowermap[(unsigned)*t];
675 /* Find a user record by nickname and return a pointer to it */
677 userrec* Find(std::string nick)
679 user_hash::iterator iter = clientlist.find(nick);
681 if (iter == clientlist.end())
682 /* Couldn't find it */
688 /* find a channel record by channel name and return a pointer to it */
690 chanrec* FindChan(const char* chan)
694 log(DEFAULT,"*** BUG *** Findchan was given an invalid parameter");
698 chan_hash::iterator iter = chanlist.find(chan);
700 if (iter == chanlist.end())
701 /* Couldn't find it */
708 long GetMaxBans(char* name)
711 for (int count = 0; count < Config->ConfValueEnum("banlist",&Config->config_f); count++)
713 Config->ConfValue("banlist","chan",count,CM,&Config->config_f);
716 Config->ConfValue("banlist","limit",count,CM,&Config->config_f);
723 void purge_empty_chans(userrec* u)
728 // firstly decrement the count on each channel
729 for (unsigned int f = 0; f < u->chans.size(); f++)
731 if (u->chans[f].channel)
733 u->chans[f].channel->DelUser((char*)u);
737 for (unsigned int i = 0; i < u->chans.size(); i++)
739 if (u->chans[i].channel)
741 if (!usercount(u->chans[i].channel))
743 chan_hash::iterator i2 = chanlist.find(u->chans[i].channel->name);
744 /* kill the record */
745 if (i2 != chanlist.end())
747 log(DEBUG,"del_channel: destroyed: %s",i2->second->name);
752 u->chans[i].channel = NULL;
757 log(DEBUG,"skipped purge for %s",u->chans[i].channel->name);
761 log(DEBUG,"completed channel purge, killed %lu",(unsigned long)purge);
767 char* chanmodes(chanrec *chan)
769 static char scratch[MAXBUF];
770 static char sparam[MAXBUF];
771 char* offset = scratch;
775 log(DEFAULT,"*** BUG *** chanmodes was given an invalid parameter");
782 if (chan->binarymodes & CM_NOEXTERNAL)
784 if (chan->binarymodes & CM_TOPICLOCK)
790 if (chan->binarymodes & CM_INVITEONLY)
792 if (chan->binarymodes & CM_MODERATED)
794 if (chan->binarymodes & CM_SECRET)
796 if (chan->binarymodes & CM_PRIVATE)
799 snprintf(sparam,MAXBUF," %s",chan->key);
803 sprintf(foo," %lu",(unsigned long)chan->limit);
804 strlcat(sparam,foo,MAXBUF);
806 if (*chan->custom_modes)
808 for (char* t = chan->custom_modes; *t; t++)
810 for (int z = 0; chan->custom_modes[z]; z++)
812 std::string extparam = chan->GetModeParameter(chan->custom_modes[z]);
815 strlcat(sparam," ",MAXBUF);
816 strlcat(sparam,extparam.c_str(),MAXBUF);
820 /* Null terminate scratch */
822 strlcat(scratch,sparam,MAXMODES);
827 /* compile a userlist of a channel into a string, each nick seperated by
828 * spaces and op, voice etc status shown as @ and + */
830 void userlist(userrec *user,chanrec *c)
834 log(DEFAULT,"*** BUG *** userlist was given an invalid parameter");
838 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
840 std::vector<char*> *ulist = c->GetUsers();
841 for (unsigned int i = 0; i < ulist->size(); i++)
843 char* o = (*ulist)[i];
844 userrec* otheruser = (userrec*)o;
845 if ((!has_channel(user,c)) && (strchr(otheruser->modes,'i')))
847 /* user is +i, and source not on the channel, does not show
848 * nick in NAMES list */
851 strlcat(list,cmode(otheruser,c),MAXBUF);
852 strlcat(list,otheruser->nick,MAXBUF);
853 strlcat(list," ",MAXBUF);
854 if (strlen(list)>(480-NICKMAX))
856 /* list overflowed into
857 * multiple numerics */
858 WriteServ(user->fd,"%s",list);
859 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
862 /* if whats left in the list isnt empty, send it */
863 if (list[strlen(list)-1] != ':')
865 WriteServ(user->fd,"%s",list);
869 /* return a count of the users on a specific channel accounting for
870 * invisible users who won't increase the count. e.g. for /LIST */
872 int usercount_i(chanrec *c)
878 log(DEFAULT,"*** BUG *** usercount_i was given an invalid parameter");
882 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
886 if (has_channel(i->second,c))
888 if (isnick(i->second->nick))
890 if ((!has_channel(i->second,c)) && (strchr(i->second->modes,'i')))
892 /* user is +i, and source not on the channel, does not show
893 * nick in NAMES list */
901 log(DEBUG,"usercount_i: %s %lu",c->name,(unsigned long)count);
906 int usercount(chanrec *c)
910 log(DEFAULT,"*** BUG *** usercount was given an invalid parameter");
913 int count = c->GetUserCounter();
914 log(DEBUG,"usercount: %s %lu",c->name,(unsigned long)count);
919 // looks up a users password for their connection class (<ALLOW>/<DENY> tags)
921 char* Passwd(userrec *user)
923 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
925 if ((i->type == CC_ALLOW) && match(user->host,i->host))
933 bool IsDenied(userrec *user)
935 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
937 if ((i->type == CC_DENY) && match(user->host,i->host))
948 /* sends out an error notice to all connected clients (not to be used
951 void send_error(char *s)
953 log(DEBUG,"send_error: %s",s);
954 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
956 if (IS_LOCAL(i->second))
958 if (i->second->registered == 7)
960 WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,s);
964 // fix - unregistered connections receive ERROR, not NOTICE
965 Write(i->second->fd,"ERROR :%s",s);
971 void Error(int status)
973 signal (SIGALRM, SIG_IGN);
974 signal (SIGPIPE, SIG_IGN);
975 signal (SIGTERM, SIG_IGN);
976 signal (SIGABRT, SIG_IGN);
977 signal (SIGSEGV, SIG_IGN);
978 signal (SIGURG, SIG_IGN);
979 signal (SIGKILL, SIG_IGN);
980 log(DEFAULT,"*** fell down a pothole in the road to perfection ***");
981 send_error("Error! Segmentation fault! save meeeeeeeeeeeeee *splat!*");
985 // this function counts all users connected, wether they are registered or NOT.
988 return clientlist.size();
991 // this counts only registered users, so that the percentages in /MAP don't mess up when users are sitting in an unregistered state
992 int registered_usercount(void)
995 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
997 if (i->second->registered == 7) c++;
1002 int usercount_invisible(void)
1005 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1007 if ((isnick(i->second->nick)) && (strchr(i->second->modes,'i'))) c++;
1012 int usercount_opers(void)
1015 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1017 if ((isnick(i->second->nick)) && (strchr(i->second->modes,'o'))) c++;
1022 int usercount_unknown(void)
1026 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1028 if ((i->second->fd > -1) && (i->second->registered != 7))
1034 long chancount(void)
1036 return chanlist.size();
1042 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1044 if ((isnick(i->second->nick)) && (i->second->fd > -1)) c++;
1049 void ShowMOTD(userrec *user)
1051 static char mbuf[MAXBUF];
1052 static char crud[MAXBUF];
1053 std::string WholeMOTD = "";
1054 if (!Config->MOTD.size())
1056 WriteServ(user->fd,"422 %s :Message of the day file is missing.",user->nick);
1059 snprintf(crud,MAXBUF,":%s 372 %s :- ", Config->ServerName, user->nick);
1060 snprintf(mbuf,MAXBUF,":%s 375 %s :- %s message of the day\r\n", Config->ServerName, user->nick, Config->ServerName);
1061 WholeMOTD = WholeMOTD + mbuf;
1062 for (unsigned int i = 0; i < Config->MOTD.size(); i++)
1063 WholeMOTD = WholeMOTD + std::string(crud) + Config->MOTD[i].c_str() + std::string("\r\n");
1064 snprintf(mbuf,MAXBUF,":%s 376 %s :End of message of the day.\r\n", Config->ServerName, user->nick);
1065 WholeMOTD = WholeMOTD + mbuf;
1066 // only one write operation
1067 if (Config->GetIOHook(user->port))
1069 Config->GetIOHook(user->port)->OnRawSocketWrite(user->fd,(char*)WholeMOTD.c_str(),WholeMOTD.length());
1073 user->AddWriteBuf(WholeMOTD);
1075 ServerInstance->stats->statsSent += WholeMOTD.length();
1078 void ShowRULES(userrec *user)
1080 if (!Config->RULES.size())
1082 WriteServ(user->fd,"NOTICE %s :Rules file is missing.",user->nick);
1085 WriteServ(user->fd,"NOTICE %s :%s rules",user->nick,Config->ServerName);
1086 for (unsigned int i = 0; i < Config->RULES.size(); i++)
1087 WriteServ(user->fd,"NOTICE %s :%s",user->nick,Config->RULES[i].c_str());
1088 WriteServ(user->fd,"NOTICE %s :End of %s rules.",user->nick,Config->ServerName);
1091 // this returns 1 when all modules are satisfied that the user should be allowed onto the irc server
1092 // (until this returns true, a user will block in the waiting state, waiting to connect up to the
1093 // registration timeout maximum seconds)
1094 bool AllModulesReportReady(userrec* user)
1096 for (int i = 0; i <= MODCOUNT; i++)
1098 int res = modules[i]->OnCheckReady(user);
1105 bool DirValid(char* dirandfile)
1108 char buffer[MAXBUF], otherdir[MAXBUF];
1109 strlcpy(work,dirandfile,MAXBUF);
1110 int p = strlen(work);
1111 // we just want the dir
1121 // Get the current working directory
1122 if( getcwd( buffer, MAXBUF ) == NULL )
1125 if( getcwd( otherdir, MAXBUF ) == NULL )
1128 if (strlen(otherdir) >= strlen(work))
1130 otherdir[strlen(work)] = '\0';
1131 if (!strcmp(otherdir,work))
1140 std::string GetFullProgDir(char** argv, int argc)
1143 char buffer[MAXBUF], otherdir[MAXBUF];
1144 strlcpy(work,argv[0],MAXBUF);
1145 int p = strlen(work);
1146 // we just want the dir
1156 // Get the current working directory
1157 if( getcwd( buffer, MAXBUF ) == NULL )
1160 if( getcwd( otherdir, MAXBUF ) == NULL )