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;
56 extern char lowermap[255];
57 static char list[MAXBUF];
58 extern userrec* fd_ref_table[65536];
59 extern serverstats* stats;
60 static char already_sent[65536];
61 extern std::vector<userrec*> all_opers;
62 extern user_hash clientlist;
63 extern chan_hash chanlist;
64 extern command_table cmdlist;
65 extern Module* IOHookModule;
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),MAXBUF);
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(int sock,char *text, ...)
132 log(DEFAULT,"*** BUG *** Write was given an invalid parameter");
136 char textbuffer[MAXBUF],tb[MAXBUF];
137 va_start (argsPtr, text);
138 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
140 int bytes = snprintf(tb,MAXBUF,"%s\r\n",textbuffer);
142 if (fd_ref_table[sock])
146 IOHookModule->OnRawSocketWrite(sock,tb,bytes);
150 fd_ref_table[sock]->AddWriteBuf(tb);
152 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");
169 va_start (argsPtr, text);
170 char textbuffer[MAXBUF],tb[MAXBUF];
171 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
173 int bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,textbuffer);
175 if (fd_ref_table[sock])
179 IOHookModule->OnRawSocketWrite(sock,tb,bytes);
183 fd_ref_table[sock]->AddWriteBuf(tb);
185 stats->statsSent += bytes;
187 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
190 /* write text from an originating user to originating user */
192 void WriteFrom(int sock, userrec *user,char* text, ...)
196 if ((!text) || (!user))
198 log(DEFAULT,"*** BUG *** WriteFrom was given an invalid parameter");
202 va_start (argsPtr, text);
203 char textbuffer[MAXBUF],tb[MAXBUF];
204 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
206 int bytes = snprintf(tb,MAXBUF,":%s!%s@%s %s\r\n",user->nick,user->ident,user->dhost,textbuffer);
208 if (fd_ref_table[sock])
212 IOHookModule->OnRawSocketWrite(sock,tb,bytes);
216 fd_ref_table[sock]->AddWriteBuf(tb);
218 stats->statsSent += bytes;
220 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
223 /* write text to an destination user from a source user (e.g. user privmsg) */
225 void WriteTo(userrec *source, userrec *dest,char *data, ...)
227 if ((!dest) || (!data))
229 log(DEFAULT,"*** BUG *** WriteTo was given an invalid parameter");
232 if (dest->fd == FD_MAGIC_NUMBER)
234 char textbuffer[MAXBUF],tb[MAXBUF];
236 va_start (argsPtr, data);
237 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
241 // if no source given send it from the server.
244 WriteServ(dest->fd,":%s %s",Config->ServerName,textbuffer);
248 WriteFrom(dest->fd,source,"%s",textbuffer);
252 /* write formatted text from a source user to all users on a channel
253 * including the sender (NOT for privmsg, notice etc!) */
255 void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...)
257 if ((!Ptr) || (!user) || (!text))
259 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
262 char textbuffer[MAXBUF];
264 va_start (argsPtr, text);
265 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
268 std::vector<char*> *ulist = Ptr->GetUsers();
269 unsigned int x = ulist->size();
270 for (unsigned int j = 0; j < x; j++)
272 char* o = (*ulist)[j];
273 userrec* otheruser = (userrec*)o;
274 if (otheruser->fd != FD_MAGIC_NUMBER)
275 WriteTo(user,otheruser,"%s",textbuffer);
279 /* write formatted text from a source user to all users on a channel
280 * including the sender (NOT for privmsg, notice etc!) doesnt send to
281 * users on remote servers */
283 void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...)
285 if ((!Ptr) || (!text))
287 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
290 char textbuffer[MAXBUF];
292 va_start (argsPtr, text);
293 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
296 std::vector<char*> *ulist = Ptr->GetUsers();
297 unsigned int x = ulist->size();
298 for (unsigned int j = 0; j < x; j++)
300 char* o = (*ulist)[j];
301 userrec* otheruser = (userrec*)o;
302 if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser->fd != -1) && (otheruser != user))
306 WriteServ(otheruser->fd,"%s",textbuffer);
310 WriteTo(user,otheruser,"%s",textbuffer);
316 void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
318 if ((!Ptr) || (!text))
320 log(DEFAULT,"*** BUG *** WriteChannelWithServ was given an invalid parameter");
323 char textbuffer[MAXBUF];
325 va_start (argsPtr, text);
326 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
330 std::vector<char*> *ulist = Ptr->GetUsers();
331 unsigned int x = ulist->size();
332 for (unsigned int j = 0; j < x; j++)
334 char* o = (*ulist)[j];
335 userrec* otheruser = (userrec*)o;
336 if (otheruser->fd != FD_MAGIC_NUMBER)
337 WriteServ(otheruser->fd,"%s",textbuffer);
341 /* write formatted text from a source user to all users on a channel except
342 * for the sender (for privmsg etc) */
344 void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...)
346 if ((!Ptr) || (!user) || (!text))
348 log(DEFAULT,"*** BUG *** ChanExceptSender was given an invalid parameter");
351 char textbuffer[MAXBUF];
353 va_start (argsPtr, text);
354 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
357 std::vector<char*> *ulist = Ptr->GetUsers();
358 unsigned int x = ulist->size();
359 for (unsigned int j = 0; j < x; j++)
361 char* o = (*ulist)[j];
362 userrec* otheruser = (userrec*)o;
363 if ((otheruser->fd != FD_MAGIC_NUMBER) && (user != otheruser))
364 WriteFrom(otheruser->fd,user,"%s",textbuffer);
368 std::string GetServerDescription(char* servername)
370 std::string description = "";
371 FOREACH_MOD OnGetServerDescription(servername,description);
372 if (description != "")
378 return Config->ServerDesc; // not a remote server that can be found, it must be me.
382 /* write a formatted string to all users who share at least one common
383 * channel, including the source user e.g. for use in NICK */
385 void WriteCommon(userrec *u, char* text, ...)
389 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
393 if (u->registered != 7) {
394 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
398 char textbuffer[MAXBUF];
400 va_start (argsPtr, text);
401 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
404 // FIX: Stops a message going to the same person more than once
405 memset(&already_sent,0,MAXCLIENTS);
407 bool sent_to_at_least_one = false;
409 unsigned int y = u->chans.size();
410 for (unsigned int i = 0; i < y; i++)
412 if (u->chans[i].channel)
414 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
415 unsigned int x = ulist->size();
416 for (unsigned int j = 0; j < x; j++)
418 char* o = (*ulist)[j];
419 userrec* otheruser = (userrec*)o;
420 if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
422 already_sent[otheruser->fd] = 1;
423 WriteFrom(otheruser->fd,u,"%s",textbuffer);
424 sent_to_at_least_one = true;
429 // if the user was not in any channels, no users will receive the text. Make sure the user
430 // receives their OWN message for WriteCommon
431 if (!sent_to_at_least_one)
433 WriteFrom(u->fd,u,"%s",textbuffer);
437 /* write a formatted string to all users who share at least one common
438 * channel, NOT including the source user e.g. for use in QUIT */
440 void WriteCommonExcept(userrec *u, char* text, ...)
444 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
448 if (u->registered != 7) {
449 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
453 char textbuffer[MAXBUF];
455 va_start (argsPtr, text);
456 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
459 memset(&already_sent,0,MAXCLIENTS);
461 unsigned int y = u->chans.size();
462 for (unsigned int i = 0; i < y; i++)
464 if (u->chans[i].channel)
466 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
467 unsigned int x = ulist->size();
468 for (unsigned int j = 0; j < x; j++)
470 char* o = (*ulist)[j];
471 userrec* otheruser = (userrec*)o;
474 if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
476 already_sent[otheruser->fd] = 1;
477 WriteFrom(otheruser->fd,u,"%s",textbuffer);
485 void WriteOpers(char* text, ...)
489 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
493 char textbuffer[MAXBUF];
495 va_start (argsPtr, text);
496 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
499 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
502 if ((a) && (a->fd != FD_MAGIC_NUMBER))
504 if (strchr(a->modes,'s'))
506 // send server notices to all with +s
507 WriteServ(a->fd,"NOTICE %s :%s",a->nick,textbuffer);
513 void ServerNoticeAll(char* text, ...)
518 char textbuffer[MAXBUF];
520 va_start (argsPtr, text);
521 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
524 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
526 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
528 WriteServ(i->second->fd,"NOTICE $%s :%s",Config->ServerName,textbuffer);
533 void ServerPrivmsgAll(char* text, ...)
538 char textbuffer[MAXBUF];
540 va_start (argsPtr, text);
541 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
544 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
546 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
548 WriteServ(i->second->fd,"PRIVMSG $%s :%s",Config->ServerName,textbuffer);
553 void WriteMode(const char* modes, int flags, const char* text, ...)
555 if ((!text) || (!modes) || (!flags))
557 log(DEFAULT,"*** BUG *** WriteMode was given an invalid parameter");
561 char textbuffer[MAXBUF];
563 va_start (argsPtr, text);
564 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
566 int modelen = strlen(modes);
568 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
570 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
572 bool send_to_user = false;
577 for (int n = 0; n < modelen; n++)
579 if (!hasumode(i->second,modes[n]))
581 send_to_user = false;
586 else if (flags == WM_OR)
588 send_to_user = false;
589 for (int n = 0; n < modelen; n++)
591 if (hasumode(i->second,modes[n]))
601 WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,textbuffer);
607 void NoticeAll(userrec *source, bool local_only, char* text, ...)
609 if ((!text) || (!source))
611 log(DEFAULT,"*** BUG *** NoticeAll was given an invalid parameter");
615 char textbuffer[MAXBUF];
617 va_start (argsPtr, text);
618 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
621 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
623 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
625 WriteFrom(i->second->fd,source,"NOTICE $* :%s",textbuffer);
632 void WriteWallOps(userrec *source, bool local_only, char* text, ...)
634 if ((!text) || (!source))
636 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
640 char textbuffer[MAXBUF];
642 va_start (argsPtr, text);
643 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
646 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
648 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
650 if (strchr(i->second->modes,'w'))
652 WriteTo(source,i->second,"WALLOPS :%s",textbuffer);
658 /* convert a string to lowercase. Note following special circumstances
659 * taken from RFC 1459. Many "official" server branches still hold to this
660 * rule so i will too;
662 * Because of IRC's scandanavian origin, the characters {}| are
663 * considered to be the lower case equivalents of the characters []\,
664 * respectively. This is a critical issue when determining the
665 * equivalence of two nicknames.
668 void strlower(char *n)
672 for (char* t = n; *t; t++)
673 *t = lowermap[(unsigned)*t];
677 /* Find a user record by nickname and return a pointer to it */
679 userrec* Find(std::string nick)
681 user_hash::iterator iter = clientlist.find(nick);
683 if (iter == clientlist.end())
684 /* Couldn't find it */
690 /* find a channel record by channel name and return a pointer to it */
692 chanrec* FindChan(const char* chan)
696 log(DEFAULT,"*** BUG *** Findchan was given an invalid parameter");
700 chan_hash::iterator iter = chanlist.find(chan);
702 if (iter == chanlist.end())
703 /* Couldn't find it */
710 long GetMaxBans(char* name)
713 for (int count = 0; count < Config->ConfValueEnum("banlist",&Config->config_f); count++)
715 Config->ConfValue("banlist","chan",count,CM,&Config->config_f);
718 Config->ConfValue("banlist","limit",count,CM,&Config->config_f);
725 void purge_empty_chans(userrec* u)
730 // firstly decrement the count on each channel
731 for (unsigned int f = 0; f < u->chans.size(); f++)
733 if (u->chans[f].channel)
735 u->chans[f].channel->DelUser((char*)u);
739 for (unsigned int i = 0; i < u->chans.size(); i++)
741 if (u->chans[i].channel)
743 if (!usercount(u->chans[i].channel))
745 chan_hash::iterator i2 = chanlist.find(u->chans[i].channel->name);
746 /* kill the record */
747 if (i2 != chanlist.end())
749 log(DEBUG,"del_channel: destroyed: %s",i2->second->name);
754 u->chans[i].channel = NULL;
759 log(DEBUG,"skipped purge for %s",u->chans[i].channel->name);
763 log(DEBUG,"completed channel purge, killed %lu",(unsigned long)purge);
769 char* chanmodes(chanrec *chan)
771 static char scratch[MAXBUF];
772 static char sparam[MAXBUF];
773 char* offset = scratch;
777 log(DEFAULT,"*** BUG *** chanmodes was given an invalid parameter");
784 if (chan->binarymodes & CM_NOEXTERNAL)
786 if (chan->binarymodes & CM_TOPICLOCK)
792 if (chan->binarymodes & CM_INVITEONLY)
794 if (chan->binarymodes & CM_MODERATED)
796 if (chan->binarymodes & CM_SECRET)
798 if (chan->binarymodes & CM_PRIVATE)
801 snprintf(sparam,MAXBUF," %s",chan->key);
805 sprintf(foo," %lu",(unsigned long)chan->limit);
806 strlcat(sparam,foo,MAXBUF);
808 if (*chan->custom_modes)
810 for (char* t = chan->custom_modes; *t; t++)
812 for (int z = 0; chan->custom_modes[z]; z++)
814 std::string extparam = chan->GetModeParameter(chan->custom_modes[z]);
817 strlcat(sparam," ",MAXBUF);
818 strlcat(sparam,extparam.c_str(),MAXBUF);
822 /* Null terminate scratch */
824 strlcat(scratch,sparam,MAXMODES);
829 /* compile a userlist of a channel into a string, each nick seperated by
830 * spaces and op, voice etc status shown as @ and + */
832 void userlist(userrec *user,chanrec *c)
836 log(DEFAULT,"*** BUG *** userlist was given an invalid parameter");
840 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
842 std::vector<char*> *ulist = c->GetUsers();
843 for (unsigned int i = 0; i < ulist->size(); i++)
845 char* o = (*ulist)[i];
846 userrec* otheruser = (userrec*)o;
847 if ((!has_channel(user,c)) && (strchr(otheruser->modes,'i')))
849 /* user is +i, and source not on the channel, does not show
850 * nick in NAMES list */
853 strlcat(list,cmode(otheruser,c),MAXBUF);
854 strlcat(list,otheruser->nick,MAXBUF);
855 strlcat(list," ",MAXBUF);
856 if (strlen(list)>(480-NICKMAX))
858 /* list overflowed into
859 * multiple numerics */
860 WriteServ(user->fd,"%s",list);
861 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
864 /* if whats left in the list isnt empty, send it */
865 if (list[strlen(list)-1] != ':')
867 WriteServ(user->fd,"%s",list);
871 /* return a count of the users on a specific channel accounting for
872 * invisible users who won't increase the count. e.g. for /LIST */
874 int usercount_i(chanrec *c)
880 log(DEFAULT,"*** BUG *** usercount_i was given an invalid parameter");
884 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
888 if (has_channel(i->second,c))
890 if (isnick(i->second->nick))
892 if ((!has_channel(i->second,c)) && (strchr(i->second->modes,'i')))
894 /* user is +i, and source not on the channel, does not show
895 * nick in NAMES list */
903 log(DEBUG,"usercount_i: %s %lu",c->name,(unsigned long)count);
908 int usercount(chanrec *c)
912 log(DEFAULT,"*** BUG *** usercount was given an invalid parameter");
915 int count = c->GetUserCounter();
916 log(DEBUG,"usercount: %s %lu",c->name,(unsigned long)count);
921 // looks up a users password for their connection class (<ALLOW>/<DENY> tags)
923 char* Passwd(userrec *user)
925 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
927 if ((i->type == CC_ALLOW) && match(user->host,i->host))
935 bool IsDenied(userrec *user)
937 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
939 if ((i->type == CC_DENY) && match(user->host,i->host))
950 /* sends out an error notice to all connected clients (not to be used
953 void send_error(char *s)
955 log(DEBUG,"send_error: %s",s);
956 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
958 if (IS_LOCAL(i->second))
960 if (i->second->registered == 7)
962 WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,s);
966 // fix - unregistered connections receive ERROR, not NOTICE
967 Write(i->second->fd,"ERROR :%s",s);
973 void Error(int status)
975 signal (SIGALRM, SIG_IGN);
976 signal (SIGPIPE, SIG_IGN);
977 signal (SIGTERM, SIG_IGN);
978 signal (SIGABRT, SIG_IGN);
979 signal (SIGSEGV, SIG_IGN);
980 signal (SIGURG, SIG_IGN);
981 signal (SIGKILL, SIG_IGN);
982 log(DEFAULT,"*** fell down a pothole in the road to perfection ***");
983 send_error("Error! Segmentation fault! save meeeeeeeeeeeeee *splat!*");
987 // this function counts all users connected, wether they are registered or NOT.
990 return clientlist.size();
993 // this counts only registered users, so that the percentages in /MAP don't mess up when users are sitting in an unregistered state
994 int registered_usercount(void)
997 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
999 if (i->second->registered == 7) c++;
1004 int usercount_invisible(void)
1007 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1009 if ((isnick(i->second->nick)) && (strchr(i->second->modes,'i'))) c++;
1014 int usercount_opers(void)
1017 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1019 if ((isnick(i->second->nick)) && (strchr(i->second->modes,'o'))) c++;
1024 int usercount_unknown(void)
1028 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1030 if ((i->second->fd > -1) && (i->second->registered != 7))
1036 long chancount(void)
1038 return chanlist.size();
1044 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1046 if ((isnick(i->second->nick)) && (i->second->fd > -1)) c++;
1051 void ShowMOTD(userrec *user)
1053 static char mbuf[MAXBUF];
1054 static char crud[MAXBUF];
1055 std::string WholeMOTD = "";
1056 if (!Config->MOTD.size())
1058 WriteServ(user->fd,"422 %s :Message of the day file is missing.",user->nick);
1061 snprintf(crud,MAXBUF,":%s 372 %s :- ", Config->ServerName, user->nick);
1062 snprintf(mbuf,MAXBUF,":%s 375 %s :- %s message of the day\r\n", Config->ServerName, user->nick, Config->ServerName);
1063 WholeMOTD = WholeMOTD + mbuf;
1064 for (unsigned int i = 0; i < Config->MOTD.size(); i++)
1065 WholeMOTD = WholeMOTD + std::string(crud) + Config->MOTD[i].c_str() + std::string("\r\n");
1066 snprintf(mbuf,MAXBUF,":%s 376 %s :End of message of the day.\r\n", Config->ServerName, user->nick);
1067 WholeMOTD = WholeMOTD + mbuf;
1068 // only one write operation
1071 IOHookModule->OnRawSocketWrite(user->fd,(char*)WholeMOTD.c_str(),WholeMOTD.length());
1075 user->AddWriteBuf(WholeMOTD);
1077 stats->statsSent += WholeMOTD.length();
1080 void ShowRULES(userrec *user)
1082 if (!Config->RULES.size())
1084 WriteServ(user->fd,"NOTICE %s :Rules file is missing.",user->nick);
1087 WriteServ(user->fd,"NOTICE %s :%s rules",user->nick,Config->ServerName);
1088 for (unsigned int i = 0; i < Config->RULES.size(); i++)
1089 WriteServ(user->fd,"NOTICE %s :%s",user->nick,Config->RULES[i].c_str());
1090 WriteServ(user->fd,"NOTICE %s :End of %s rules.",user->nick,Config->ServerName);
1093 // this returns 1 when all modules are satisfied that the user should be allowed onto the irc server
1094 // (until this returns true, a user will block in the waiting state, waiting to connect up to the
1095 // registration timeout maximum seconds)
1096 bool AllModulesReportReady(userrec* user)
1098 for (int i = 0; i <= MODCOUNT; i++)
1100 int res = modules[i]->OnCheckReady(user);
1107 void createcommand(char* cmd, handlerfunc f, char flags, int minparams,char* source)
1110 /* create the command and push it onto the table */
1111 strlcpy(comm.command,cmd,MAXBUF);
1112 strlcpy(comm.source,source,MAXBUF);
1113 comm.handler_function = f;
1114 comm.flags_needed = flags;
1115 comm.min_params = minparams;
1117 comm.total_bytes = 0;
1118 cmdlist.push_back(comm);
1119 log(DEBUG,"Added command %s (%lu parameters)",cmd,(unsigned long)minparams);
1123 void SetupCommandTable(void)
1125 createcommand("USER",handle_user,0,4,"<core>");
1126 createcommand("NICK",handle_nick,0,1,"<core>");
1127 createcommand("QUIT",handle_quit,0,0,"<core>");
1128 createcommand("VERSION",handle_version,0,0,"<core>");
1129 createcommand("PING",handle_ping,0,1,"<core>");
1130 createcommand("PONG",handle_pong,0,1,"<core>");
1131 createcommand("ADMIN",handle_admin,0,0,"<core>");
1132 createcommand("PRIVMSG",handle_privmsg,0,2,"<core>");
1133 createcommand("INFO",handle_info,0,0,"<core>");
1134 createcommand("TIME",handle_time,0,0,"<core>");
1135 createcommand("WHOIS",handle_whois,0,1,"<core>");
1136 createcommand("WALLOPS",handle_wallops,'o',1,"<core>");
1137 createcommand("NOTICE",handle_notice,0,2,"<core>");
1138 createcommand("JOIN",handle_join,0,1,"<core>");
1139 createcommand("NAMES",handle_names,0,0,"<core>");
1140 createcommand("PART",handle_part,0,1,"<core>");
1141 createcommand("KICK",handle_kick,0,2,"<core>");
1142 createcommand("MODE",handle_mode,0,1,"<core>");
1143 createcommand("TOPIC",handle_topic,0,1,"<core>");
1144 createcommand("WHO",handle_who,0,1,"<core>");
1145 createcommand("MOTD",handle_motd,0,0,"<core>");
1146 createcommand("RULES",handle_rules,0,0,"<core>");
1147 createcommand("OPER",handle_oper,0,2,"<core>");
1148 createcommand("LIST",handle_list,0,0,"<core>");
1149 createcommand("DIE",handle_die,'o',1,"<core>");
1150 createcommand("RESTART",handle_restart,'o',1,"<core>");
1151 createcommand("KILL",handle_kill,'o',2,"<core>");
1152 createcommand("REHASH",handle_rehash,'o',0,"<core>");
1153 createcommand("LUSERS",handle_lusers,0,0,"<core>");
1154 createcommand("STATS",handle_stats,0,1,"<core>");
1155 createcommand("USERHOST",handle_userhost,0,1,"<core>");
1156 createcommand("AWAY",handle_away,0,0,"<core>");
1157 createcommand("ISON",handle_ison,0,0,"<core>");
1158 createcommand("SUMMON",handle_summon,0,0,"<core>");
1159 createcommand("USERS",handle_users,0,0,"<core>");
1160 createcommand("INVITE",handle_invite,0,0,"<core>");
1161 createcommand("PASS",handle_pass,0,1,"<core>");
1162 createcommand("TRACE",handle_trace,'o',0,"<core>");
1163 createcommand("WHOWAS",handle_whowas,0,1,"<core>");
1164 createcommand("CONNECT",handle_connect,'o',1,"<core>");
1165 createcommand("SQUIT",handle_squit,'o',0,"<core>");
1166 createcommand("MODULES",handle_modules,0,0,"<core>");
1167 createcommand("LINKS",handle_links,0,0,"<core>");
1168 createcommand("MAP",handle_map,0,0,"<core>");
1169 createcommand("KLINE",handle_kline,'o',1,"<core>");
1170 createcommand("GLINE",handle_gline,'o',1,"<core>");
1171 createcommand("ZLINE",handle_zline,'o',1,"<core>");
1172 createcommand("QLINE",handle_qline,'o',1,"<core>");
1173 createcommand("ELINE",handle_eline,'o',1,"<core>");
1174 createcommand("LOADMODULE",handle_loadmodule,'o',1,"<core>");
1175 createcommand("UNLOADMODULE",handle_unloadmodule,'o',1,"<core>");
1176 createcommand("SERVER",handle_server,0,0,"<core>");
1177 createcommand("COMMANDS",handle_commands,0,0,"<core>");
1180 bool DirValid(char* dirandfile)
1183 char buffer[MAXBUF], otherdir[MAXBUF];
1184 strlcpy(work,dirandfile,MAXBUF);
1185 int p = strlen(work);
1186 // we just want the dir
1196 // Get the current working directory
1197 if( getcwd( buffer, MAXBUF ) == NULL )
1200 if( getcwd( otherdir, MAXBUF ) == NULL )
1203 if (strlen(otherdir) >= strlen(work))
1205 otherdir[strlen(work)] = '\0';
1206 if (!strcmp(otherdir,work))
1215 std::string GetFullProgDir(char** argv, int argc)
1218 char buffer[MAXBUF], otherdir[MAXBUF];
1219 strlcpy(work,argv[0],MAXBUF);
1220 int p = strlen(work);
1221 // we just want the dir
1231 // Get the current working directory
1232 if( getcwd( buffer, MAXBUF ) == NULL )
1235 if( getcwd( otherdir, MAXBUF ) == NULL )