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;
66 void log(int level,char *text, ...)
68 char textbuffer[MAXBUF];
72 if (level < Config->LogLevel)
76 timeinfo = localtime(&rawtime);
81 va_start (argsPtr, text);
82 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
84 strlcpy(b,asctime(timeinfo),MAXBUF);
85 b[24] = ':'; // we know this is the end of the time string
87 fprintf(Config->log_file,"%s %s\n",b,textbuffer);
90 // nofork enabled? display it on terminal too
91 printf("%s %s\n",b,textbuffer);
96 void readfile(file_cache &F, const char* fname)
101 log(DEBUG,"readfile: loading %s",fname);
103 file = fopen(fname,"r");
108 fgets(linebuf,sizeof(linebuf),file);
109 linebuf[strlen(linebuf)-1]='\0';
116 F.push_back(linebuf);
123 log(DEBUG,"readfile: failed to load file: %s",fname);
125 log(DEBUG,"readfile: loaded %s, %lu lines",fname,(unsigned long)F.size());
128 void Write(int sock,char *text, ...)
134 log(DEFAULT,"*** BUG *** Write was given an invalid parameter");
137 char textbuffer[MAXBUF];
141 va_start (argsPtr, text);
142 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
144 int bytes = snprintf(tb,MAXBUF,"%s\r\n",textbuffer);
146 if (fd_ref_table[sock])
149 FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes));
150 fd_ref_table[sock]->AddWriteBuf(tb);
151 stats->statsSent += bytes;
153 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
156 /* write a server formatted numeric response to a single socket */
158 void WriteServ(int sock, char* text, ...)
164 log(DEFAULT,"*** BUG *** WriteServ was given an invalid parameter");
167 char textbuffer[MAXBUF],tb[MAXBUF];
169 va_start (argsPtr, text);
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])
178 FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes));
179 fd_ref_table[sock]->AddWriteBuf(tb);
180 stats->statsSent += bytes;
182 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
185 /* write text from an originating user to originating user */
187 void WriteFrom(int sock, userrec *user,char* text, ...)
191 if ((!text) || (!user))
193 log(DEFAULT,"*** BUG *** WriteFrom was given an invalid parameter");
196 char textbuffer[MAXBUF],tb[MAXBUF];
198 va_start (argsPtr, text);
200 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
202 int bytes = snprintf(tb,MAXBUF,":%s!%s@%s %s\r\n",user->nick,user->ident,user->dhost,textbuffer);
204 if (fd_ref_table[sock])
207 FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes));
208 fd_ref_table[sock]->AddWriteBuf(tb);
209 stats->statsSent += bytes;
211 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
214 /* write text to an destination user from a source user (e.g. user privmsg) */
216 void WriteTo(userrec *source, userrec *dest,char *data, ...)
218 if ((!dest) || (!data))
220 log(DEFAULT,"*** BUG *** WriteTo was given an invalid parameter");
223 if (dest->fd == FD_MAGIC_NUMBER)
225 char textbuffer[MAXBUF],tb[MAXBUF];
227 va_start (argsPtr, data);
228 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
232 // if no source given send it from the server.
235 WriteServ(dest->fd,":%s %s",Config->ServerName,textbuffer);
239 WriteFrom(dest->fd,source,"%s",textbuffer);
243 /* write formatted text from a source user to all users on a channel
244 * including the sender (NOT for privmsg, notice etc!) */
246 void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...)
248 if ((!Ptr) || (!user) || (!text))
250 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
253 char textbuffer[MAXBUF];
255 va_start (argsPtr, text);
256 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
259 std::vector<char*> *ulist = Ptr->GetUsers();
260 for (unsigned int j = 0; j < ulist->size(); j++)
262 char* o = (*ulist)[j];
263 userrec* otheruser = (userrec*)o;
264 if (otheruser->fd != FD_MAGIC_NUMBER)
265 WriteTo(user,otheruser,"%s",textbuffer);
269 /* write formatted text from a source user to all users on a channel
270 * including the sender (NOT for privmsg, notice etc!) doesnt send to
271 * users on remote servers */
273 void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...)
275 if ((!Ptr) || (!text))
277 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
280 char textbuffer[MAXBUF];
282 va_start (argsPtr, text);
283 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
286 std::vector<char*> *ulist = Ptr->GetUsers();
287 for (unsigned int j = 0; j < ulist->size(); j++)
289 char* o = (*ulist)[j];
290 userrec* otheruser = (userrec*)o;
291 if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser->fd != -1) && (otheruser != user))
295 WriteServ(otheruser->fd,"%s",textbuffer);
299 WriteTo(user,otheruser,"%s",textbuffer);
305 void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
307 if ((!Ptr) || (!text))
309 log(DEFAULT,"*** BUG *** WriteChannelWithServ was given an invalid parameter");
312 char textbuffer[MAXBUF];
314 va_start (argsPtr, text);
315 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
319 std::vector<char*> *ulist = Ptr->GetUsers();
320 for (unsigned int j = 0; j < ulist->size(); j++)
322 char* o = (*ulist)[j];
323 userrec* otheruser = (userrec*)o;
324 if (otheruser->fd != FD_MAGIC_NUMBER)
325 WriteServ(otheruser->fd,"%s",textbuffer);
329 /* write formatted text from a source user to all users on a channel except
330 * for the sender (for privmsg etc) */
332 void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...)
334 if ((!Ptr) || (!user) || (!text))
336 log(DEFAULT,"*** BUG *** ChanExceptSender was given an invalid parameter");
339 char textbuffer[MAXBUF];
341 va_start (argsPtr, text);
342 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
345 std::vector<char*> *ulist = Ptr->GetUsers();
346 for (unsigned int j = 0; j < ulist->size(); j++)
348 char* o = (*ulist)[j];
349 userrec* otheruser = (userrec*)o;
350 if ((otheruser->fd != FD_MAGIC_NUMBER) && (user != otheruser))
351 WriteFrom(otheruser->fd,user,"%s",textbuffer);
355 std::string GetServerDescription(char* servername)
357 std::string description = "";
358 FOREACH_MOD OnGetServerDescription(servername,description);
359 if (description != "")
365 return Config->ServerDesc; // not a remote server that can be found, it must be me.
369 /* write a formatted string to all users who share at least one common
370 * channel, including the source user e.g. for use in NICK */
372 void WriteCommon(userrec *u, char* text, ...)
376 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
380 if (u->registered != 7) {
381 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
385 char textbuffer[MAXBUF];
387 va_start (argsPtr, text);
388 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
391 // FIX: Stops a message going to the same person more than once
392 memset(&already_sent,0,65536);
394 bool sent_to_at_least_one = false;
396 for (unsigned int i = 0; i < u->chans.size(); i++)
398 if (u->chans[i].channel)
400 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
401 for (unsigned int j = 0; j < ulist->size(); j++)
403 char* o = (*ulist)[j];
404 userrec* otheruser = (userrec*)o;
405 if ((otheruser->fd > 0) && (!already_sent[otheruser->fd]))
407 already_sent[otheruser->fd] = 1;
408 WriteFrom(otheruser->fd,u,"%s",textbuffer);
409 sent_to_at_least_one = true;
414 // if the user was not in any channels, no users will receive the text. Make sure the user
415 // receives their OWN message for WriteCommon
416 if (!sent_to_at_least_one)
418 WriteFrom(u->fd,u,"%s",textbuffer);
422 /* write a formatted string to all users who share at least one common
423 * channel, NOT including the source user e.g. for use in QUIT */
425 void WriteCommonExcept(userrec *u, char* text, ...)
429 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
433 if (u->registered != 7) {
434 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
438 char textbuffer[MAXBUF];
440 va_start (argsPtr, text);
441 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
444 memset(&already_sent,0,65536);
446 for (unsigned int i = 0; i < u->chans.size(); i++)
448 if (u->chans[i].channel)
450 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
451 for (unsigned int j = 0; j < ulist->size(); j++)
453 char* o = (*ulist)[j];
454 userrec* otheruser = (userrec*)o;
457 if ((otheruser->fd > 0) && (!already_sent[otheruser->fd]))
459 already_sent[otheruser->fd] = 1;
460 WriteFrom(otheruser->fd,u,"%s",textbuffer);
468 void WriteOpers(char* text, ...)
472 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
476 char textbuffer[MAXBUF];
478 va_start (argsPtr, text);
479 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
482 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
485 if ((a) && (a->fd != FD_MAGIC_NUMBER))
487 if (strchr(a->modes,'s'))
489 // send server notices to all with +s
490 WriteServ(a->fd,"NOTICE %s :%s",a->nick,textbuffer);
496 void ServerNoticeAll(char* text, ...)
501 char textbuffer[MAXBUF];
503 va_start (argsPtr, text);
504 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
507 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
509 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
511 WriteServ(i->second->fd,"NOTICE $%s :%s",Config->ServerName,textbuffer);
516 void ServerPrivmsgAll(char* text, ...)
521 char textbuffer[MAXBUF];
523 va_start (argsPtr, text);
524 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
527 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
529 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
531 WriteServ(i->second->fd,"PRIVMSG $%s :%s",Config->ServerName,textbuffer);
536 void WriteMode(const char* modes, int flags, const char* text, ...)
538 if ((!text) || (!modes) || (!flags))
540 log(DEFAULT,"*** BUG *** WriteMode was given an invalid parameter");
544 char textbuffer[MAXBUF];
546 va_start (argsPtr, text);
547 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
549 int modelen = strlen(modes);
551 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
553 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
555 bool send_to_user = false;
560 for (int n = 0; n < modelen; n++)
562 if (!hasumode(i->second,modes[n]))
564 send_to_user = false;
569 else if (flags == WM_OR)
571 send_to_user = false;
572 for (int n = 0; n < modelen; n++)
574 if (hasumode(i->second,modes[n]))
584 WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,textbuffer);
590 void NoticeAll(userrec *source, bool local_only, char* text, ...)
592 if ((!text) || (!source))
594 log(DEFAULT,"*** BUG *** NoticeAll was given an invalid parameter");
598 char textbuffer[MAXBUF];
600 va_start (argsPtr, text);
601 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
604 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
606 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
608 WriteFrom(i->second->fd,source,"NOTICE $* :%s",textbuffer);
615 void WriteWallOps(userrec *source, bool local_only, char* text, ...)
617 if ((!text) || (!source))
619 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
623 char textbuffer[MAXBUF];
625 va_start (argsPtr, text);
626 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
629 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
631 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
633 if (strchr(i->second->modes,'w'))
635 WriteTo(source,i->second,"WALLOPS :%s",textbuffer);
641 /* convert a string to lowercase. Note following special circumstances
642 * taken from RFC 1459. Many "official" server branches still hold to this
643 * rule so i will too;
645 * Because of IRC's scandanavian origin, the characters {}| are
646 * considered to be the lower case equivalents of the characters []\,
647 * respectively. This is a critical issue when determining the
648 * equivalence of two nicknames.
651 void strlower(char *n)
655 for (char* t = n; *t; t++)
656 *t = lowermap[(unsigned)*t];
660 /* Find a user record by nickname and return a pointer to it */
662 userrec* Find(std::string nick)
664 user_hash::iterator iter = clientlist.find(nick);
666 if (iter == clientlist.end())
667 /* Couldn't find it */
673 /* find a channel record by channel name and return a pointer to it */
675 chanrec* FindChan(const char* chan)
679 log(DEFAULT,"*** BUG *** Findchan was given an invalid parameter");
683 chan_hash::iterator iter = chanlist.find(chan);
685 if (iter == chanlist.end())
686 /* Couldn't find it */
693 long GetMaxBans(char* name)
696 for (int count = 0; count < Config->ConfValueEnum("banlist",&Config->config_f); count++)
698 Config->ConfValue("banlist","chan",count,CM,&Config->config_f);
701 Config->ConfValue("banlist","limit",count,CM,&Config->config_f);
708 void purge_empty_chans(userrec* u)
713 // firstly decrement the count on each channel
714 for (unsigned int f = 0; f < u->chans.size(); f++)
716 if (u->chans[f].channel)
718 u->chans[f].channel->DelUser((char*)u);
722 for (unsigned int i = 0; i < u->chans.size(); i++)
724 if (u->chans[i].channel)
726 if (!usercount(u->chans[i].channel))
728 chan_hash::iterator i2 = chanlist.find(u->chans[i].channel->name);
729 /* kill the record */
730 if (i2 != chanlist.end())
732 log(DEBUG,"del_channel: destroyed: %s",i2->second->name);
737 u->chans[i].channel = NULL;
742 log(DEBUG,"skipped purge for %s",u->chans[i].channel->name);
746 log(DEBUG,"completed channel purge, killed %lu",(unsigned long)purge);
752 char* chanmodes(chanrec *chan)
754 static char scratch[MAXBUF];
755 static char sparam[MAXBUF];
756 char* offset = scratch;
760 log(DEFAULT,"*** BUG *** chanmodes was given an invalid parameter");
767 if (chan->binarymodes & CM_NOEXTERNAL)
769 if (chan->binarymodes & CM_TOPICLOCK)
775 if (chan->binarymodes & CM_INVITEONLY)
777 if (chan->binarymodes & CM_MODERATED)
779 if (chan->binarymodes & CM_SECRET)
781 if (chan->binarymodes & CM_PRIVATE)
784 snprintf(sparam,MAXBUF," %s",chan->key);
788 sprintf(foo," %lu",(unsigned long)chan->limit);
789 strlcat(sparam,foo,MAXBUF);
791 if (*chan->custom_modes)
793 for (char* t = chan->custom_modes; *t; t++)
795 for (int z = 0; chan->custom_modes[z]; z++)
797 std::string extparam = chan->GetModeParameter(chan->custom_modes[z]);
800 strlcat(sparam," ",MAXBUF);
801 strlcat(sparam,extparam.c_str(),MAXBUF);
805 /* Null terminate scratch */
807 strlcat(scratch,sparam,MAXMODES);
812 /* compile a userlist of a channel into a string, each nick seperated by
813 * spaces and op, voice etc status shown as @ and + */
815 void userlist(userrec *user,chanrec *c)
819 log(DEFAULT,"*** BUG *** userlist was given an invalid parameter");
823 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
825 std::vector<char*> *ulist = c->GetUsers();
826 for (unsigned int i = 0; i < ulist->size(); i++)
828 char* o = (*ulist)[i];
829 userrec* otheruser = (userrec*)o;
830 if ((!has_channel(user,c)) && (strchr(otheruser->modes,'i')))
832 /* user is +i, and source not on the channel, does not show
833 * nick in NAMES list */
836 strlcat(list,cmode(otheruser,c),MAXBUF);
837 strlcat(list,otheruser->nick,MAXBUF);
838 strlcat(list," ",MAXBUF);
839 if (strlen(list)>(480-NICKMAX))
841 /* list overflowed into
842 * multiple numerics */
843 WriteServ(user->fd,"%s",list);
844 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
847 /* if whats left in the list isnt empty, send it */
848 if (list[strlen(list)-1] != ':')
850 WriteServ(user->fd,"%s",list);
854 /* return a count of the users on a specific channel accounting for
855 * invisible users who won't increase the count. e.g. for /LIST */
857 int usercount_i(chanrec *c)
863 log(DEFAULT,"*** BUG *** usercount_i was given an invalid parameter");
867 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
871 if (has_channel(i->second,c))
873 if (isnick(i->second->nick))
875 if ((!has_channel(i->second,c)) && (strchr(i->second->modes,'i')))
877 /* user is +i, and source not on the channel, does not show
878 * nick in NAMES list */
886 log(DEBUG,"usercount_i: %s %lu",c->name,(unsigned long)count);
891 int usercount(chanrec *c)
895 log(DEFAULT,"*** BUG *** usercount was given an invalid parameter");
898 int count = c->GetUserCounter();
899 log(DEBUG,"usercount: %s %lu",c->name,(unsigned long)count);
904 // looks up a users password for their connection class (<ALLOW>/<DENY> tags)
906 char* Passwd(userrec *user)
908 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
910 if ((i->type == CC_ALLOW) && match(user->host,i->host))
918 bool IsDenied(userrec *user)
920 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
922 if ((i->type == CC_DENY) && match(user->host,i->host))
933 /* sends out an error notice to all connected clients (not to be used
936 void send_error(char *s)
938 log(DEBUG,"send_error: %s",s);
939 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
941 if (IS_LOCAL(i->second))
943 if (i->second->registered == 7)
945 WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,s);
949 // fix - unregistered connections receive ERROR, not NOTICE
950 Write(i->second->fd,"ERROR :%s",s);
956 void Error(int status)
958 signal (SIGALRM, SIG_IGN);
959 signal (SIGPIPE, SIG_IGN);
960 signal (SIGTERM, SIG_IGN);
961 signal (SIGABRT, SIG_IGN);
962 signal (SIGSEGV, SIG_IGN);
963 signal (SIGURG, SIG_IGN);
964 signal (SIGKILL, SIG_IGN);
965 log(DEFAULT,"*** fell down a pothole in the road to perfection ***");
966 send_error("Error! Segmentation fault! save meeeeeeeeeeeeee *splat!*");
970 // this function counts all users connected, wether they are registered or NOT.
973 return clientlist.size();
976 // this counts only registered users, so that the percentages in /MAP don't mess up when users are sitting in an unregistered state
977 int registered_usercount(void)
980 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
982 if (i->second->registered == 7) c++;
987 int usercount_invisible(void)
990 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
992 if ((isnick(i->second->nick)) && (strchr(i->second->modes,'i'))) c++;
997 int usercount_opers(void)
1000 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1002 if ((isnick(i->second->nick)) && (strchr(i->second->modes,'o'))) c++;
1007 int usercount_unknown(void)
1011 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1013 if ((i->second->fd > -1) && (i->second->registered != 7))
1019 long chancount(void)
1021 return chanlist.size();
1027 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1029 if ((isnick(i->second->nick)) && (i->second->fd > -1)) c++;
1034 void ShowMOTD(userrec *user)
1036 static char mbuf[MAXBUF];
1037 static char crud[MAXBUF];
1038 std::string WholeMOTD = "";
1039 if (!Config->MOTD.size())
1041 WriteServ(user->fd,"422 %s :Message of the day file is missing.",user->nick);
1044 snprintf(crud,MAXBUF,":%s 372 %s :- ", Config->ServerName, user->nick);
1045 snprintf(mbuf,MAXBUF,":%s 375 %s :- %s message of the day\r\n", Config->ServerName, user->nick, Config->ServerName);
1046 WholeMOTD = WholeMOTD + mbuf;
1047 for (unsigned int i = 0; i < Config->MOTD.size(); i++)
1048 WholeMOTD = WholeMOTD + std::string(crud) + Config->MOTD[i].c_str() + std::string("\r\n");
1049 snprintf(mbuf,MAXBUF,":%s 376 %s :End of message of the day.\r\n", Config->ServerName, user->nick);
1050 WholeMOTD = WholeMOTD + mbuf;
1051 // only one write operation
1052 user->AddWriteBuf(WholeMOTD);
1053 stats->statsSent += WholeMOTD.length();
1056 void ShowRULES(userrec *user)
1058 if (!Config->RULES.size())
1060 WriteServ(user->fd,"NOTICE %s :Rules file is missing.",user->nick);
1063 WriteServ(user->fd,"NOTICE %s :%s rules",user->nick,Config->ServerName);
1064 for (unsigned int i = 0; i < Config->RULES.size(); i++)
1065 WriteServ(user->fd,"NOTICE %s :%s",user->nick,Config->RULES[i].c_str());
1066 WriteServ(user->fd,"NOTICE %s :End of %s rules.",user->nick,Config->ServerName);
1069 // this returns 1 when all modules are satisfied that the user should be allowed onto the irc server
1070 // (until this returns true, a user will block in the waiting state, waiting to connect up to the
1071 // registration timeout maximum seconds)
1072 bool AllModulesReportReady(userrec* user)
1074 for (int i = 0; i <= MODCOUNT; i++)
1076 int res = modules[i]->OnCheckReady(user);
1083 void createcommand(char* cmd, handlerfunc f, char flags, int minparams,char* source)
1086 /* create the command and push it onto the table */
1087 strlcpy(comm.command,cmd,MAXBUF);
1088 strlcpy(comm.source,source,MAXBUF);
1089 comm.handler_function = f;
1090 comm.flags_needed = flags;
1091 comm.min_params = minparams;
1093 comm.total_bytes = 0;
1094 cmdlist.push_back(comm);
1095 log(DEBUG,"Added command %s (%lu parameters)",cmd,(unsigned long)minparams);
1099 void SetupCommandTable(void)
1101 createcommand("USER",handle_user,0,4,"<core>");
1102 createcommand("NICK",handle_nick,0,1,"<core>");
1103 createcommand("QUIT",handle_quit,0,0,"<core>");
1104 createcommand("VERSION",handle_version,0,0,"<core>");
1105 createcommand("PING",handle_ping,0,1,"<core>");
1106 createcommand("PONG",handle_pong,0,1,"<core>");
1107 createcommand("ADMIN",handle_admin,0,0,"<core>");
1108 createcommand("PRIVMSG",handle_privmsg,0,2,"<core>");
1109 createcommand("INFO",handle_info,0,0,"<core>");
1110 createcommand("TIME",handle_time,0,0,"<core>");
1111 createcommand("WHOIS",handle_whois,0,1,"<core>");
1112 createcommand("WALLOPS",handle_wallops,'o',1,"<core>");
1113 createcommand("NOTICE",handle_notice,0,2,"<core>");
1114 createcommand("JOIN",handle_join,0,1,"<core>");
1115 createcommand("NAMES",handle_names,0,0,"<core>");
1116 createcommand("PART",handle_part,0,1,"<core>");
1117 createcommand("KICK",handle_kick,0,2,"<core>");
1118 createcommand("MODE",handle_mode,0,1,"<core>");
1119 createcommand("TOPIC",handle_topic,0,1,"<core>");
1120 createcommand("WHO",handle_who,0,1,"<core>");
1121 createcommand("MOTD",handle_motd,0,0,"<core>");
1122 createcommand("RULES",handle_rules,0,0,"<core>");
1123 createcommand("OPER",handle_oper,0,2,"<core>");
1124 createcommand("LIST",handle_list,0,0,"<core>");
1125 createcommand("DIE",handle_die,'o',1,"<core>");
1126 createcommand("RESTART",handle_restart,'o',1,"<core>");
1127 createcommand("KILL",handle_kill,'o',2,"<core>");
1128 createcommand("REHASH",handle_rehash,'o',0,"<core>");
1129 createcommand("LUSERS",handle_lusers,0,0,"<core>");
1130 createcommand("STATS",handle_stats,0,1,"<core>");
1131 createcommand("USERHOST",handle_userhost,0,1,"<core>");
1132 createcommand("AWAY",handle_away,0,0,"<core>");
1133 createcommand("ISON",handle_ison,0,0,"<core>");
1134 createcommand("SUMMON",handle_summon,0,0,"<core>");
1135 createcommand("USERS",handle_users,0,0,"<core>");
1136 createcommand("INVITE",handle_invite,0,0,"<core>");
1137 createcommand("PASS",handle_pass,0,1,"<core>");
1138 createcommand("TRACE",handle_trace,'o',0,"<core>");
1139 createcommand("WHOWAS",handle_whowas,0,1,"<core>");
1140 createcommand("CONNECT",handle_connect,'o',1,"<core>");
1141 createcommand("SQUIT",handle_squit,'o',0,"<core>");
1142 createcommand("MODULES",handle_modules,0,0,"<core>");
1143 createcommand("LINKS",handle_links,0,0,"<core>");
1144 createcommand("MAP",handle_map,0,0,"<core>");
1145 createcommand("KLINE",handle_kline,'o',1,"<core>");
1146 createcommand("GLINE",handle_gline,'o',1,"<core>");
1147 createcommand("ZLINE",handle_zline,'o',1,"<core>");
1148 createcommand("QLINE",handle_qline,'o',1,"<core>");
1149 createcommand("ELINE",handle_eline,'o',1,"<core>");
1150 createcommand("LOADMODULE",handle_loadmodule,'o',1,"<core>");
1151 createcommand("UNLOADMODULE",handle_unloadmodule,'o',1,"<core>");
1152 createcommand("SERVER",handle_server,0,0,"<core>");
1153 createcommand("COMMANDS",handle_commands,0,0,"<core>");
1156 bool DirValid(char* dirandfile)
1159 char buffer[MAXBUF], otherdir[MAXBUF];
1160 strlcpy(work,dirandfile,MAXBUF);
1161 int p = strlen(work);
1162 // we just want the dir
1172 // Get the current working directory
1173 if( getcwd( buffer, MAXBUF ) == NULL )
1176 if( getcwd( otherdir, MAXBUF ) == NULL )
1179 if (strlen(otherdir) >= strlen(work))
1181 otherdir[strlen(work)] = '\0';
1182 if (!strcmp(otherdir,work))
1191 std::string GetFullProgDir(char** argv, int argc)
1194 char buffer[MAXBUF], otherdir[MAXBUF];
1195 strlcpy(work,argv[0],MAXBUF);
1196 int p = strlen(work);
1197 // we just want the dir
1207 // Get the current working directory
1208 if( getcwd( buffer, MAXBUF ) == NULL )
1211 if( getcwd( otherdir, MAXBUF ) == NULL )