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");
133 log(DEBUG,"Write: Normal");
135 char textbuffer[MAXBUF],tb[MAXBUF];
136 va_start (argsPtr, text);
137 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
139 int bytes = snprintf(tb,MAXBUF,"%s\r\n",textbuffer);
141 if (fd_ref_table[sock])
143 if (Config->GetIOHook(fd_ref_table[sock]->port))
145 log(DEBUG,"Write: IO Hooked");
146 Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
150 fd_ref_table[sock]->AddWriteBuf(tb);
152 ServerInstance->stats->statsSent += bytes;
154 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
157 /* write a server formatted numeric response to a single socket */
159 void WriteServ(int sock, char* text, ...)
165 log(DEFAULT,"*** BUG *** WriteServ was given an invalid parameter");
168 log(DEBUG,"WriteServ: normal");
170 va_start (argsPtr, text);
171 char textbuffer[MAXBUF],tb[MAXBUF];
172 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
174 int bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,textbuffer);
176 if (fd_ref_table[sock])
178 if (Config->GetIOHook(fd_ref_table[sock]->port))
180 log(DEBUG,"WriteServ: IO Hooked");
181 Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
185 fd_ref_table[sock]->AddWriteBuf(tb);
187 ServerInstance->stats->statsSent += bytes;
189 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
192 /* write text from an originating user to originating user */
194 void WriteFrom(int sock, userrec *user,char* text, ...)
198 if ((!text) || (!user))
200 log(DEFAULT,"*** BUG *** WriteFrom was given an invalid parameter");
203 log(DEBUG,"WriteFrom: normal");
205 va_start (argsPtr, text);
206 char textbuffer[MAXBUF],tb[MAXBUF];
207 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
209 int bytes = snprintf(tb,MAXBUF,":%s!%s@%s %s\r\n",user->nick,user->ident,user->dhost,textbuffer);
211 if (fd_ref_table[sock])
213 if (Config->GetIOHook(fd_ref_table[sock]->port))
215 log(DEBUG,"WriteFrom: IO hooked");
216 Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
220 fd_ref_table[sock]->AddWriteBuf(tb);
222 ServerInstance->stats->statsSent += bytes;
224 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
227 /* write text to an destination user from a source user (e.g. user privmsg) */
229 void WriteTo(userrec *source, userrec *dest,char *data, ...)
231 if ((!dest) || (!data))
233 log(DEFAULT,"*** BUG *** WriteTo was given an invalid parameter");
236 if (dest->fd == FD_MAGIC_NUMBER)
238 char textbuffer[MAXBUF],tb[MAXBUF];
240 va_start (argsPtr, data);
241 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
245 // if no source given send it from the server.
248 WriteServ(dest->fd,":%s %s",Config->ServerName,textbuffer);
252 WriteFrom(dest->fd,source,"%s",textbuffer);
256 /* write formatted text from a source user to all users on a channel
257 * including the sender (NOT for privmsg, notice etc!) */
259 void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...)
261 if ((!Ptr) || (!user) || (!text))
263 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
266 char textbuffer[MAXBUF];
268 va_start (argsPtr, text);
269 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
272 std::vector<char*> *ulist = Ptr->GetUsers();
273 unsigned int x = ulist->size();
274 for (unsigned int j = 0; j < x; j++)
276 char* o = (*ulist)[j];
277 userrec* otheruser = (userrec*)o;
278 if (otheruser->fd != FD_MAGIC_NUMBER)
279 WriteTo(user,otheruser,"%s",textbuffer);
283 /* write formatted text from a source user to all users on a channel
284 * including the sender (NOT for privmsg, notice etc!) doesnt send to
285 * users on remote servers */
287 void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...)
289 if ((!Ptr) || (!text))
291 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
294 char textbuffer[MAXBUF];
296 va_start (argsPtr, text);
297 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
300 std::vector<char*> *ulist = Ptr->GetUsers();
301 unsigned int x = ulist->size();
302 for (unsigned int j = 0; j < x; j++)
304 char* o = (*ulist)[j];
305 userrec* otheruser = (userrec*)o;
306 if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser->fd != -1) && (otheruser != user))
310 WriteServ(otheruser->fd,"%s",textbuffer);
314 WriteTo(user,otheruser,"%s",textbuffer);
320 void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
322 if ((!Ptr) || (!text))
324 log(DEFAULT,"*** BUG *** WriteChannelWithServ was given an invalid parameter");
327 char textbuffer[MAXBUF];
329 va_start (argsPtr, text);
330 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
334 std::vector<char*> *ulist = Ptr->GetUsers();
335 unsigned int x = ulist->size();
336 for (unsigned int j = 0; j < x; j++)
338 char* o = (*ulist)[j];
339 userrec* otheruser = (userrec*)o;
340 if (otheruser->fd != FD_MAGIC_NUMBER)
341 WriteServ(otheruser->fd,"%s",textbuffer);
345 /* write formatted text from a source user to all users on a channel except
346 * for the sender (for privmsg etc) */
348 void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...)
350 if ((!Ptr) || (!user) || (!text))
352 log(DEFAULT,"*** BUG *** ChanExceptSender was given an invalid parameter");
355 char textbuffer[MAXBUF];
357 va_start (argsPtr, text);
358 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
361 std::vector<char*> *ulist = Ptr->GetUsers();
362 unsigned int x = ulist->size();
363 for (unsigned int j = 0; j < x; j++)
365 char* o = (*ulist)[j];
366 userrec* otheruser = (userrec*)o;
367 if ((otheruser->fd != FD_MAGIC_NUMBER) && (user != otheruser))
368 WriteFrom(otheruser->fd,user,"%s",textbuffer);
372 std::string GetServerDescription(char* servername)
374 std::string description = "";
375 FOREACH_MOD OnGetServerDescription(servername,description);
376 if (description != "")
382 return Config->ServerDesc; // not a remote server that can be found, it must be me.
386 /* write a formatted string to all users who share at least one common
387 * channel, including the source user e.g. for use in NICK */
389 void WriteCommon(userrec *u, char* text, ...)
393 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
397 if (u->registered != 7) {
398 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
402 char textbuffer[MAXBUF];
404 va_start (argsPtr, text);
405 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
408 // FIX: Stops a message going to the same person more than once
409 memset(&already_sent,0,MAXCLIENTS);
411 bool sent_to_at_least_one = false;
413 unsigned int y = u->chans.size();
414 for (unsigned int i = 0; i < y; i++)
416 if (u->chans[i].channel)
418 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
419 unsigned int x = ulist->size();
420 for (unsigned int j = 0; j < x; j++)
422 char* o = (*ulist)[j];
423 userrec* otheruser = (userrec*)o;
424 if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
426 already_sent[otheruser->fd] = 1;
427 WriteFrom(otheruser->fd,u,"%s",textbuffer);
428 sent_to_at_least_one = true;
433 // if the user was not in any channels, no users will receive the text. Make sure the user
434 // receives their OWN message for WriteCommon
435 if (!sent_to_at_least_one)
437 WriteFrom(u->fd,u,"%s",textbuffer);
441 /* write a formatted string to all users who share at least one common
442 * channel, NOT including the source user e.g. for use in QUIT */
444 void WriteCommonExcept(userrec *u, char* text, ...)
448 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
452 if (u->registered != 7) {
453 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
457 char textbuffer[MAXBUF];
459 va_start (argsPtr, text);
460 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
463 memset(&already_sent,0,MAXCLIENTS);
465 unsigned int y = u->chans.size();
466 for (unsigned int i = 0; i < y; i++)
468 if (u->chans[i].channel)
470 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
471 unsigned int x = ulist->size();
472 for (unsigned int j = 0; j < x; j++)
474 char* o = (*ulist)[j];
475 userrec* otheruser = (userrec*)o;
478 if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
480 already_sent[otheruser->fd] = 1;
481 WriteFrom(otheruser->fd,u,"%s",textbuffer);
489 void WriteOpers(char* text, ...)
493 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
497 char textbuffer[MAXBUF];
499 va_start (argsPtr, text);
500 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
503 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
506 if ((a) && (a->fd != FD_MAGIC_NUMBER))
508 if (strchr(a->modes,'s'))
510 // send server notices to all with +s
511 WriteServ(a->fd,"NOTICE %s :%s",a->nick,textbuffer);
517 void ServerNoticeAll(char* text, ...)
522 char textbuffer[MAXBUF];
524 va_start (argsPtr, text);
525 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
528 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
530 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
532 WriteServ(i->second->fd,"NOTICE $%s :%s",Config->ServerName,textbuffer);
537 void ServerPrivmsgAll(char* text, ...)
542 char textbuffer[MAXBUF];
544 va_start (argsPtr, text);
545 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
548 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
550 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
552 WriteServ(i->second->fd,"PRIVMSG $%s :%s",Config->ServerName,textbuffer);
557 void WriteMode(const char* modes, int flags, const char* text, ...)
559 if ((!text) || (!modes) || (!flags))
561 log(DEFAULT,"*** BUG *** WriteMode was given an invalid parameter");
565 char textbuffer[MAXBUF];
567 va_start (argsPtr, text);
568 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
570 int modelen = strlen(modes);
572 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
574 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
576 bool send_to_user = false;
581 for (int n = 0; n < modelen; n++)
583 if (!hasumode(i->second,modes[n]))
585 send_to_user = false;
590 else if (flags == WM_OR)
592 send_to_user = false;
593 for (int n = 0; n < modelen; n++)
595 if (hasumode(i->second,modes[n]))
605 WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,textbuffer);
611 void NoticeAll(userrec *source, bool local_only, char* text, ...)
613 if ((!text) || (!source))
615 log(DEFAULT,"*** BUG *** NoticeAll was given an invalid parameter");
619 char textbuffer[MAXBUF];
621 va_start (argsPtr, text);
622 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
625 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
627 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
629 WriteFrom(i->second->fd,source,"NOTICE $* :%s",textbuffer);
636 void WriteWallOps(userrec *source, bool local_only, char* text, ...)
638 if ((!text) || (!source))
640 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
644 char textbuffer[MAXBUF];
646 va_start (argsPtr, text);
647 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
650 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
652 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
654 if (strchr(i->second->modes,'w'))
656 WriteTo(source,i->second,"WALLOPS :%s",textbuffer);
662 /* convert a string to lowercase. Note following special circumstances
663 * taken from RFC 1459. Many "official" server branches still hold to this
664 * rule so i will too;
666 * Because of IRC's scandanavian origin, the characters {}| are
667 * considered to be the lower case equivalents of the characters []\,
668 * respectively. This is a critical issue when determining the
669 * equivalence of two nicknames.
672 void strlower(char *n)
676 for (char* t = n; *t; t++)
677 *t = lowermap[(unsigned)*t];
681 /* Find a user record by nickname and return a pointer to it */
683 userrec* Find(std::string nick)
685 user_hash::iterator iter = clientlist.find(nick);
687 if (iter == clientlist.end())
688 /* Couldn't find it */
694 /* find a channel record by channel name and return a pointer to it */
696 chanrec* FindChan(const char* chan)
700 log(DEFAULT,"*** BUG *** Findchan was given an invalid parameter");
704 chan_hash::iterator iter = chanlist.find(chan);
706 if (iter == chanlist.end())
707 /* Couldn't find it */
714 long GetMaxBans(char* name)
717 for (int count = 0; count < Config->ConfValueEnum("banlist",&Config->config_f); count++)
719 Config->ConfValue("banlist","chan",count,CM,&Config->config_f);
722 Config->ConfValue("banlist","limit",count,CM,&Config->config_f);
729 void purge_empty_chans(userrec* u)
734 // firstly decrement the count on each channel
735 for (unsigned int f = 0; f < u->chans.size(); f++)
737 if (u->chans[f].channel)
739 u->chans[f].channel->DelUser((char*)u);
743 for (unsigned int i = 0; i < u->chans.size(); i++)
745 if (u->chans[i].channel)
747 if (!usercount(u->chans[i].channel))
749 chan_hash::iterator i2 = chanlist.find(u->chans[i].channel->name);
750 /* kill the record */
751 if (i2 != chanlist.end())
753 log(DEBUG,"del_channel: destroyed: %s",i2->second->name);
758 u->chans[i].channel = NULL;
763 log(DEBUG,"skipped purge for %s",u->chans[i].channel->name);
767 log(DEBUG,"completed channel purge, killed %lu",(unsigned long)purge);
773 char* chanmodes(chanrec *chan)
775 static char scratch[MAXBUF];
776 static char sparam[MAXBUF];
777 char* offset = scratch;
781 log(DEFAULT,"*** BUG *** chanmodes was given an invalid parameter");
788 if (chan->binarymodes & CM_NOEXTERNAL)
790 if (chan->binarymodes & CM_TOPICLOCK)
796 if (chan->binarymodes & CM_INVITEONLY)
798 if (chan->binarymodes & CM_MODERATED)
800 if (chan->binarymodes & CM_SECRET)
802 if (chan->binarymodes & CM_PRIVATE)
805 snprintf(sparam,MAXBUF," %s",chan->key);
809 sprintf(foo," %lu",(unsigned long)chan->limit);
810 strlcat(sparam,foo,MAXBUF);
812 if (*chan->custom_modes)
814 for (char* t = chan->custom_modes; *t; t++)
816 for (int z = 0; chan->custom_modes[z]; z++)
818 std::string extparam = chan->GetModeParameter(chan->custom_modes[z]);
821 strlcat(sparam," ",MAXBUF);
822 strlcat(sparam,extparam.c_str(),MAXBUF);
826 /* Null terminate scratch */
828 strlcat(scratch,sparam,MAXMODES);
833 /* compile a userlist of a channel into a string, each nick seperated by
834 * spaces and op, voice etc status shown as @ and + */
836 void userlist(userrec *user,chanrec *c)
840 log(DEFAULT,"*** BUG *** userlist was given an invalid parameter");
844 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
846 std::vector<char*> *ulist = c->GetUsers();
847 for (unsigned int i = 0; i < ulist->size(); i++)
849 char* o = (*ulist)[i];
850 userrec* otheruser = (userrec*)o;
851 if ((!has_channel(user,c)) && (strchr(otheruser->modes,'i')))
853 /* user is +i, and source not on the channel, does not show
854 * nick in NAMES list */
857 strlcat(list,cmode(otheruser,c),MAXBUF);
858 strlcat(list,otheruser->nick,MAXBUF);
859 strlcat(list," ",MAXBUF);
860 if (strlen(list)>(480-NICKMAX))
862 /* list overflowed into
863 * multiple numerics */
864 WriteServ(user->fd,"%s",list);
865 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
868 /* if whats left in the list isnt empty, send it */
869 if (list[strlen(list)-1] != ':')
871 WriteServ(user->fd,"%s",list);
875 /* return a count of the users on a specific channel accounting for
876 * invisible users who won't increase the count. e.g. for /LIST */
878 int usercount_i(chanrec *c)
884 log(DEFAULT,"*** BUG *** usercount_i was given an invalid parameter");
888 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
892 if (has_channel(i->second,c))
894 if (isnick(i->second->nick))
896 if ((!has_channel(i->second,c)) && (strchr(i->second->modes,'i')))
898 /* user is +i, and source not on the channel, does not show
899 * nick in NAMES list */
907 log(DEBUG,"usercount_i: %s %lu",c->name,(unsigned long)count);
912 int usercount(chanrec *c)
916 log(DEFAULT,"*** BUG *** usercount was given an invalid parameter");
919 int count = c->GetUserCounter();
920 log(DEBUG,"usercount: %s %lu",c->name,(unsigned long)count);
925 // looks up a users password for their connection class (<ALLOW>/<DENY> tags)
927 char* Passwd(userrec *user)
929 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
931 if ((i->type == CC_ALLOW) && match(user->host,i->host))
939 bool IsDenied(userrec *user)
941 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
943 if ((i->type == CC_DENY) && match(user->host,i->host))
954 /* sends out an error notice to all connected clients (not to be used
957 void send_error(char *s)
959 log(DEBUG,"send_error: %s",s);
960 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
962 if (IS_LOCAL(i->second))
964 if (i->second->registered == 7)
966 WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,s);
970 // fix - unregistered connections receive ERROR, not NOTICE
971 Write(i->second->fd,"ERROR :%s",s);
977 void Error(int status)
979 signal (SIGALRM, SIG_IGN);
980 signal (SIGPIPE, SIG_IGN);
981 signal (SIGTERM, SIG_IGN);
982 signal (SIGABRT, SIG_IGN);
983 signal (SIGSEGV, SIG_IGN);
984 signal (SIGURG, SIG_IGN);
985 signal (SIGKILL, SIG_IGN);
986 log(DEFAULT,"*** fell down a pothole in the road to perfection ***");
987 send_error("Error! Segmentation fault! save meeeeeeeeeeeeee *splat!*");
991 // this function counts all users connected, wether they are registered or NOT.
994 return clientlist.size();
997 // this counts only registered users, so that the percentages in /MAP don't mess up when users are sitting in an unregistered state
998 int registered_usercount(void)
1001 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1003 if (i->second->registered == 7) c++;
1008 int usercount_invisible(void)
1011 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1013 if ((isnick(i->second->nick)) && (strchr(i->second->modes,'i'))) c++;
1018 int usercount_opers(void)
1021 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1023 if ((isnick(i->second->nick)) && (strchr(i->second->modes,'o'))) c++;
1028 int usercount_unknown(void)
1032 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1034 if ((i->second->fd > -1) && (i->second->registered != 7))
1040 long chancount(void)
1042 return chanlist.size();
1048 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1050 if ((isnick(i->second->nick)) && (i->second->fd > -1)) c++;
1055 void ShowMOTD(userrec *user)
1057 static char mbuf[MAXBUF];
1058 static char crud[MAXBUF];
1059 std::string WholeMOTD = "";
1060 if (!Config->MOTD.size())
1062 WriteServ(user->fd,"422 %s :Message of the day file is missing.",user->nick);
1065 snprintf(crud,MAXBUF,":%s 372 %s :- ", Config->ServerName, user->nick);
1066 snprintf(mbuf,MAXBUF,":%s 375 %s :- %s message of the day\r\n", Config->ServerName, user->nick, Config->ServerName);
1067 WholeMOTD = WholeMOTD + mbuf;
1068 for (unsigned int i = 0; i < Config->MOTD.size(); i++)
1069 WholeMOTD = WholeMOTD + std::string(crud) + Config->MOTD[i].c_str() + std::string("\r\n");
1070 snprintf(mbuf,MAXBUF,":%s 376 %s :End of message of the day.\r\n", Config->ServerName, user->nick);
1071 WholeMOTD = WholeMOTD + mbuf;
1072 // only one write operation
1073 if (Config->GetIOHook(user->port))
1075 Config->GetIOHook(user->port)->OnRawSocketWrite(user->fd,(char*)WholeMOTD.c_str(),WholeMOTD.length());
1079 user->AddWriteBuf(WholeMOTD);
1081 ServerInstance->stats->statsSent += WholeMOTD.length();
1084 void ShowRULES(userrec *user)
1086 if (!Config->RULES.size())
1088 WriteServ(user->fd,"NOTICE %s :Rules file is missing.",user->nick);
1091 WriteServ(user->fd,"NOTICE %s :%s rules",user->nick,Config->ServerName);
1092 for (unsigned int i = 0; i < Config->RULES.size(); i++)
1093 WriteServ(user->fd,"NOTICE %s :%s",user->nick,Config->RULES[i].c_str());
1094 WriteServ(user->fd,"NOTICE %s :End of %s rules.",user->nick,Config->ServerName);
1097 // this returns 1 when all modules are satisfied that the user should be allowed onto the irc server
1098 // (until this returns true, a user will block in the waiting state, waiting to connect up to the
1099 // registration timeout maximum seconds)
1100 bool AllModulesReportReady(userrec* user)
1102 for (int i = 0; i <= MODCOUNT; i++)
1104 int res = modules[i]->OnCheckReady(user);
1111 bool DirValid(char* dirandfile)
1114 char buffer[MAXBUF], otherdir[MAXBUF];
1115 strlcpy(work,dirandfile,MAXBUF);
1116 int p = strlen(work);
1117 // we just want the dir
1127 // Get the current working directory
1128 if( getcwd( buffer, MAXBUF ) == NULL )
1131 if( getcwd( otherdir, MAXBUF ) == NULL )
1134 if (strlen(otherdir) >= strlen(work))
1136 otherdir[strlen(work)] = '\0';
1137 if (!strcmp(otherdir,work))
1146 std::string GetFullProgDir(char** argv, int argc)
1149 char buffer[MAXBUF], otherdir[MAXBUF];
1150 strlcpy(work,argv[0],MAXBUF);
1151 int p = strlen(work);
1152 // we just want the dir
1162 // Get the current working directory
1163 if( getcwd( buffer, MAXBUF ) == NULL )
1166 if( getcwd( otherdir, MAXBUF ) == NULL )