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 static char textbuffer[MAXBUF];
67 static char tb[MAXBUF];
69 void log(int level,char *text, ...)
73 if (level < Config->LogLevel)
76 timeinfo = localtime(&TIME);
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");
139 va_start (argsPtr, text);
140 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
142 int bytes = snprintf(tb,MAXBUF,"%s\r\n",textbuffer);
144 if (fd_ref_table[sock])
147 FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes));
148 fd_ref_table[sock]->AddWriteBuf(tb);
149 stats->statsSent += bytes;
151 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
154 /* write a server formatted numeric response to a single socket */
156 void WriteServ(int sock, char* text, ...)
162 log(DEFAULT,"*** BUG *** WriteServ was given an invalid parameter");
166 va_start (argsPtr, text);
168 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
170 int bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,textbuffer);
172 if (fd_ref_table[sock])
175 FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes));
176 fd_ref_table[sock]->AddWriteBuf(tb);
177 stats->statsSent += bytes;
179 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
182 /* write text from an originating user to originating user */
184 void WriteFrom(int sock, userrec *user,char* text, ...)
188 if ((!text) || (!user))
190 log(DEFAULT,"*** BUG *** WriteFrom was given an invalid parameter");
194 va_start (argsPtr, text);
196 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
198 int bytes = snprintf(tb,MAXBUF,":%s!%s@%s %s\r\n",user->nick,user->ident,user->dhost,textbuffer);
200 if (fd_ref_table[sock])
203 FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes));
204 fd_ref_table[sock]->AddWriteBuf(tb);
205 stats->statsSent += bytes;
207 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
210 /* write text to an destination user from a source user (e.g. user privmsg) */
212 void WriteTo(userrec *source, userrec *dest,char *data, ...)
214 if ((!dest) || (!data))
216 log(DEFAULT,"*** BUG *** WriteTo was given an invalid parameter");
219 if (dest->fd == FD_MAGIC_NUMBER)
222 va_start (argsPtr, data);
223 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
227 // if no source given send it from the server.
230 WriteServ(dest->fd,":%s %s",Config->ServerName,textbuffer);
234 WriteFrom(dest->fd,source,"%s",textbuffer);
238 /* write formatted text from a source user to all users on a channel
239 * including the sender (NOT for privmsg, notice etc!) */
241 void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...)
243 if ((!Ptr) || (!user) || (!text))
245 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
248 char textbuffer[MAXBUF];
250 va_start (argsPtr, text);
251 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
254 std::vector<char*> *ulist = Ptr->GetUsers();
255 unsigned int x = ulist->size();
256 for (unsigned int j = 0; j < x; j++)
258 char* o = (*ulist)[j];
259 userrec* otheruser = (userrec*)o;
260 if (otheruser->fd != FD_MAGIC_NUMBER)
261 WriteTo(user,otheruser,"%s",textbuffer);
265 /* write formatted text from a source user to all users on a channel
266 * including the sender (NOT for privmsg, notice etc!) doesnt send to
267 * users on remote servers */
269 void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...)
271 if ((!Ptr) || (!text))
273 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
276 char textbuffer[MAXBUF];
278 va_start (argsPtr, text);
279 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
282 std::vector<char*> *ulist = Ptr->GetUsers();
283 unsigned int x = ulist->size();
284 for (unsigned int j = 0; j < x; j++)
286 char* o = (*ulist)[j];
287 userrec* otheruser = (userrec*)o;
288 if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser->fd != -1) && (otheruser != user))
292 WriteServ(otheruser->fd,"%s",textbuffer);
296 WriteTo(user,otheruser,"%s",textbuffer);
302 void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
304 if ((!Ptr) || (!text))
306 log(DEFAULT,"*** BUG *** WriteChannelWithServ was given an invalid parameter");
309 char textbuffer[MAXBUF];
311 va_start (argsPtr, text);
312 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
316 std::vector<char*> *ulist = Ptr->GetUsers();
317 unsigned int x = ulist->size();
318 for (unsigned int j = 0; j < x; j++)
320 char* o = (*ulist)[j];
321 userrec* otheruser = (userrec*)o;
322 if (otheruser->fd != FD_MAGIC_NUMBER)
323 WriteServ(otheruser->fd,"%s",textbuffer);
327 /* write formatted text from a source user to all users on a channel except
328 * for the sender (for privmsg etc) */
330 void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...)
332 if ((!Ptr) || (!user) || (!text))
334 log(DEFAULT,"*** BUG *** ChanExceptSender was given an invalid parameter");
337 char textbuffer[MAXBUF];
339 va_start (argsPtr, text);
340 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
343 std::vector<char*> *ulist = Ptr->GetUsers();
344 unsigned int x = ulist->size();
345 for (unsigned int j = 0; j < x; j++)
347 char* o = (*ulist)[j];
348 userrec* otheruser = (userrec*)o;
349 if ((otheruser->fd != FD_MAGIC_NUMBER) && (user != otheruser))
350 WriteFrom(otheruser->fd,user,"%s",textbuffer);
354 std::string GetServerDescription(char* servername)
356 std::string description = "";
357 FOREACH_MOD OnGetServerDescription(servername,description);
358 if (description != "")
364 return Config->ServerDesc; // not a remote server that can be found, it must be me.
368 /* write a formatted string to all users who share at least one common
369 * channel, including the source user e.g. for use in NICK */
371 void WriteCommon(userrec *u, char* text, ...)
375 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
379 if (u->registered != 7) {
380 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
384 char textbuffer[MAXBUF];
386 va_start (argsPtr, text);
387 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
390 // FIX: Stops a message going to the same person more than once
391 memset(&already_sent,0,MAXCLIENTS);
393 bool sent_to_at_least_one = false;
395 unsigned int y = u->chans.size();
396 for (unsigned int i = 0; i < y; i++)
398 if (u->chans[i].channel)
400 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
401 unsigned int x = ulist->size();
402 for (unsigned int j = 0; j < x; j++)
404 char* o = (*ulist)[j];
405 userrec* otheruser = (userrec*)o;
406 if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
408 already_sent[otheruser->fd] = 1;
409 WriteFrom(otheruser->fd,u,"%s",textbuffer);
410 sent_to_at_least_one = true;
415 // if the user was not in any channels, no users will receive the text. Make sure the user
416 // receives their OWN message for WriteCommon
417 if (!sent_to_at_least_one)
419 WriteFrom(u->fd,u,"%s",textbuffer);
423 /* write a formatted string to all users who share at least one common
424 * channel, NOT including the source user e.g. for use in QUIT */
426 void WriteCommonExcept(userrec *u, char* text, ...)
430 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
434 if (u->registered != 7) {
435 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
439 char textbuffer[MAXBUF];
441 va_start (argsPtr, text);
442 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
445 memset(&already_sent,0,MAXCLIENTS);
447 unsigned int y = u->chans.size();
448 for (unsigned int i = 0; i < y; i++)
450 if (u->chans[i].channel)
452 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
453 unsigned int x = ulist->size();
454 for (unsigned int j = 0; j < x; j++)
456 char* o = (*ulist)[j];
457 userrec* otheruser = (userrec*)o;
460 if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
462 already_sent[otheruser->fd] = 1;
463 WriteFrom(otheruser->fd,u,"%s",textbuffer);
471 void WriteOpers(char* text, ...)
475 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
479 char textbuffer[MAXBUF];
481 va_start (argsPtr, text);
482 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
485 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
488 if ((a) && (a->fd != FD_MAGIC_NUMBER))
490 if (strchr(a->modes,'s'))
492 // send server notices to all with +s
493 WriteServ(a->fd,"NOTICE %s :%s",a->nick,textbuffer);
499 void ServerNoticeAll(char* text, ...)
504 char textbuffer[MAXBUF];
506 va_start (argsPtr, text);
507 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
510 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
512 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
514 WriteServ(i->second->fd,"NOTICE $%s :%s",Config->ServerName,textbuffer);
519 void ServerPrivmsgAll(char* text, ...)
524 char textbuffer[MAXBUF];
526 va_start (argsPtr, text);
527 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
530 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
532 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
534 WriteServ(i->second->fd,"PRIVMSG $%s :%s",Config->ServerName,textbuffer);
539 void WriteMode(const char* modes, int flags, const char* text, ...)
541 if ((!text) || (!modes) || (!flags))
543 log(DEFAULT,"*** BUG *** WriteMode was given an invalid parameter");
547 char textbuffer[MAXBUF];
549 va_start (argsPtr, text);
550 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
552 int modelen = strlen(modes);
554 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
556 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
558 bool send_to_user = false;
563 for (int n = 0; n < modelen; n++)
565 if (!hasumode(i->second,modes[n]))
567 send_to_user = false;
572 else if (flags == WM_OR)
574 send_to_user = false;
575 for (int n = 0; n < modelen; n++)
577 if (hasumode(i->second,modes[n]))
587 WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,textbuffer);
593 void NoticeAll(userrec *source, bool local_only, char* text, ...)
595 if ((!text) || (!source))
597 log(DEFAULT,"*** BUG *** NoticeAll was given an invalid parameter");
601 char textbuffer[MAXBUF];
603 va_start (argsPtr, text);
604 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
607 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
609 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
611 WriteFrom(i->second->fd,source,"NOTICE $* :%s",textbuffer);
618 void WriteWallOps(userrec *source, bool local_only, char* text, ...)
620 if ((!text) || (!source))
622 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
626 char textbuffer[MAXBUF];
628 va_start (argsPtr, text);
629 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
632 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
634 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
636 if (strchr(i->second->modes,'w'))
638 WriteTo(source,i->second,"WALLOPS :%s",textbuffer);
644 /* convert a string to lowercase. Note following special circumstances
645 * taken from RFC 1459. Many "official" server branches still hold to this
646 * rule so i will too;
648 * Because of IRC's scandanavian origin, the characters {}| are
649 * considered to be the lower case equivalents of the characters []\,
650 * respectively. This is a critical issue when determining the
651 * equivalence of two nicknames.
654 void strlower(char *n)
658 for (char* t = n; *t; t++)
659 *t = lowermap[(unsigned)*t];
663 /* Find a user record by nickname and return a pointer to it */
665 userrec* Find(std::string nick)
667 user_hash::iterator iter = clientlist.find(nick);
669 if (iter == clientlist.end())
670 /* Couldn't find it */
676 /* find a channel record by channel name and return a pointer to it */
678 chanrec* FindChan(const char* chan)
682 log(DEFAULT,"*** BUG *** Findchan was given an invalid parameter");
686 chan_hash::iterator iter = chanlist.find(chan);
688 if (iter == chanlist.end())
689 /* Couldn't find it */
696 long GetMaxBans(char* name)
699 for (int count = 0; count < Config->ConfValueEnum("banlist",&Config->config_f); count++)
701 Config->ConfValue("banlist","chan",count,CM,&Config->config_f);
704 Config->ConfValue("banlist","limit",count,CM,&Config->config_f);
711 void purge_empty_chans(userrec* u)
716 // firstly decrement the count on each channel
717 for (unsigned int f = 0; f < u->chans.size(); f++)
719 if (u->chans[f].channel)
721 u->chans[f].channel->DelUser((char*)u);
725 for (unsigned int i = 0; i < u->chans.size(); i++)
727 if (u->chans[i].channel)
729 if (!usercount(u->chans[i].channel))
731 chan_hash::iterator i2 = chanlist.find(u->chans[i].channel->name);
732 /* kill the record */
733 if (i2 != chanlist.end())
735 log(DEBUG,"del_channel: destroyed: %s",i2->second->name);
740 u->chans[i].channel = NULL;
745 log(DEBUG,"skipped purge for %s",u->chans[i].channel->name);
749 log(DEBUG,"completed channel purge, killed %lu",(unsigned long)purge);
755 char* chanmodes(chanrec *chan)
757 static char scratch[MAXBUF];
758 static char sparam[MAXBUF];
759 char* offset = scratch;
763 log(DEFAULT,"*** BUG *** chanmodes was given an invalid parameter");
770 if (chan->binarymodes & CM_NOEXTERNAL)
772 if (chan->binarymodes & CM_TOPICLOCK)
778 if (chan->binarymodes & CM_INVITEONLY)
780 if (chan->binarymodes & CM_MODERATED)
782 if (chan->binarymodes & CM_SECRET)
784 if (chan->binarymodes & CM_PRIVATE)
787 snprintf(sparam,MAXBUF," %s",chan->key);
791 sprintf(foo," %lu",(unsigned long)chan->limit);
792 strlcat(sparam,foo,MAXBUF);
794 if (*chan->custom_modes)
796 for (char* t = chan->custom_modes; *t; t++)
798 for (int z = 0; chan->custom_modes[z]; z++)
800 std::string extparam = chan->GetModeParameter(chan->custom_modes[z]);
803 strlcat(sparam," ",MAXBUF);
804 strlcat(sparam,extparam.c_str(),MAXBUF);
808 /* Null terminate scratch */
810 strlcat(scratch,sparam,MAXMODES);
815 /* compile a userlist of a channel into a string, each nick seperated by
816 * spaces and op, voice etc status shown as @ and + */
818 void userlist(userrec *user,chanrec *c)
822 log(DEFAULT,"*** BUG *** userlist was given an invalid parameter");
826 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
828 std::vector<char*> *ulist = c->GetUsers();
829 for (unsigned int i = 0; i < ulist->size(); i++)
831 char* o = (*ulist)[i];
832 userrec* otheruser = (userrec*)o;
833 if ((!has_channel(user,c)) && (strchr(otheruser->modes,'i')))
835 /* user is +i, and source not on the channel, does not show
836 * nick in NAMES list */
839 strlcat(list,cmode(otheruser,c),MAXBUF);
840 strlcat(list,otheruser->nick,MAXBUF);
841 strlcat(list," ",MAXBUF);
842 if (strlen(list)>(480-NICKMAX))
844 /* list overflowed into
845 * multiple numerics */
846 WriteServ(user->fd,"%s",list);
847 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
850 /* if whats left in the list isnt empty, send it */
851 if (list[strlen(list)-1] != ':')
853 WriteServ(user->fd,"%s",list);
857 /* return a count of the users on a specific channel accounting for
858 * invisible users who won't increase the count. e.g. for /LIST */
860 int usercount_i(chanrec *c)
866 log(DEFAULT,"*** BUG *** usercount_i was given an invalid parameter");
870 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
874 if (has_channel(i->second,c))
876 if (isnick(i->second->nick))
878 if ((!has_channel(i->second,c)) && (strchr(i->second->modes,'i')))
880 /* user is +i, and source not on the channel, does not show
881 * nick in NAMES list */
889 log(DEBUG,"usercount_i: %s %lu",c->name,(unsigned long)count);
894 int usercount(chanrec *c)
898 log(DEFAULT,"*** BUG *** usercount was given an invalid parameter");
901 int count = c->GetUserCounter();
902 log(DEBUG,"usercount: %s %lu",c->name,(unsigned long)count);
907 // looks up a users password for their connection class (<ALLOW>/<DENY> tags)
909 char* Passwd(userrec *user)
911 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
913 if ((i->type == CC_ALLOW) && match(user->host,i->host))
921 bool IsDenied(userrec *user)
923 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
925 if ((i->type == CC_DENY) && match(user->host,i->host))
936 /* sends out an error notice to all connected clients (not to be used
939 void send_error(char *s)
941 log(DEBUG,"send_error: %s",s);
942 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
944 if (IS_LOCAL(i->second))
946 if (i->second->registered == 7)
948 WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,s);
952 // fix - unregistered connections receive ERROR, not NOTICE
953 Write(i->second->fd,"ERROR :%s",s);
959 void Error(int status)
961 signal (SIGALRM, SIG_IGN);
962 signal (SIGPIPE, SIG_IGN);
963 signal (SIGTERM, SIG_IGN);
964 signal (SIGABRT, SIG_IGN);
965 signal (SIGSEGV, SIG_IGN);
966 signal (SIGURG, SIG_IGN);
967 signal (SIGKILL, SIG_IGN);
968 log(DEFAULT,"*** fell down a pothole in the road to perfection ***");
969 send_error("Error! Segmentation fault! save meeeeeeeeeeeeee *splat!*");
973 // this function counts all users connected, wether they are registered or NOT.
976 return clientlist.size();
979 // this counts only registered users, so that the percentages in /MAP don't mess up when users are sitting in an unregistered state
980 int registered_usercount(void)
983 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
985 if (i->second->registered == 7) c++;
990 int usercount_invisible(void)
993 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
995 if ((isnick(i->second->nick)) && (strchr(i->second->modes,'i'))) c++;
1000 int usercount_opers(void)
1003 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1005 if ((isnick(i->second->nick)) && (strchr(i->second->modes,'o'))) c++;
1010 int usercount_unknown(void)
1014 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1016 if ((i->second->fd > -1) && (i->second->registered != 7))
1022 long chancount(void)
1024 return chanlist.size();
1030 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1032 if ((isnick(i->second->nick)) && (i->second->fd > -1)) c++;
1037 void ShowMOTD(userrec *user)
1039 static char mbuf[MAXBUF];
1040 static char crud[MAXBUF];
1041 std::string WholeMOTD = "";
1042 if (!Config->MOTD.size())
1044 WriteServ(user->fd,"422 %s :Message of the day file is missing.",user->nick);
1047 snprintf(crud,MAXBUF,":%s 372 %s :- ", Config->ServerName, user->nick);
1048 snprintf(mbuf,MAXBUF,":%s 375 %s :- %s message of the day\r\n", Config->ServerName, user->nick, Config->ServerName);
1049 WholeMOTD = WholeMOTD + mbuf;
1050 for (unsigned int i = 0; i < Config->MOTD.size(); i++)
1051 WholeMOTD = WholeMOTD + std::string(crud) + Config->MOTD[i].c_str() + std::string("\r\n");
1052 snprintf(mbuf,MAXBUF,":%s 376 %s :End of message of the day.\r\n", Config->ServerName, user->nick);
1053 WholeMOTD = WholeMOTD + mbuf;
1054 // only one write operation
1055 user->AddWriteBuf(WholeMOTD);
1056 stats->statsSent += WholeMOTD.length();
1059 void ShowRULES(userrec *user)
1061 if (!Config->RULES.size())
1063 WriteServ(user->fd,"NOTICE %s :Rules file is missing.",user->nick);
1066 WriteServ(user->fd,"NOTICE %s :%s rules",user->nick,Config->ServerName);
1067 for (unsigned int i = 0; i < Config->RULES.size(); i++)
1068 WriteServ(user->fd,"NOTICE %s :%s",user->nick,Config->RULES[i].c_str());
1069 WriteServ(user->fd,"NOTICE %s :End of %s rules.",user->nick,Config->ServerName);
1072 // this returns 1 when all modules are satisfied that the user should be allowed onto the irc server
1073 // (until this returns true, a user will block in the waiting state, waiting to connect up to the
1074 // registration timeout maximum seconds)
1075 bool AllModulesReportReady(userrec* user)
1077 for (int i = 0; i <= MODCOUNT; i++)
1079 int res = modules[i]->OnCheckReady(user);
1086 void createcommand(char* cmd, handlerfunc f, char flags, int minparams,char* source)
1089 /* create the command and push it onto the table */
1090 strlcpy(comm.command,cmd,MAXBUF);
1091 strlcpy(comm.source,source,MAXBUF);
1092 comm.handler_function = f;
1093 comm.flags_needed = flags;
1094 comm.min_params = minparams;
1096 comm.total_bytes = 0;
1097 cmdlist.push_back(comm);
1098 log(DEBUG,"Added command %s (%lu parameters)",cmd,(unsigned long)minparams);
1102 void SetupCommandTable(void)
1104 createcommand("USER",handle_user,0,4,"<core>");
1105 createcommand("NICK",handle_nick,0,1,"<core>");
1106 createcommand("QUIT",handle_quit,0,0,"<core>");
1107 createcommand("VERSION",handle_version,0,0,"<core>");
1108 createcommand("PING",handle_ping,0,1,"<core>");
1109 createcommand("PONG",handle_pong,0,1,"<core>");
1110 createcommand("ADMIN",handle_admin,0,0,"<core>");
1111 createcommand("PRIVMSG",handle_privmsg,0,2,"<core>");
1112 createcommand("INFO",handle_info,0,0,"<core>");
1113 createcommand("TIME",handle_time,0,0,"<core>");
1114 createcommand("WHOIS",handle_whois,0,1,"<core>");
1115 createcommand("WALLOPS",handle_wallops,'o',1,"<core>");
1116 createcommand("NOTICE",handle_notice,0,2,"<core>");
1117 createcommand("JOIN",handle_join,0,1,"<core>");
1118 createcommand("NAMES",handle_names,0,0,"<core>");
1119 createcommand("PART",handle_part,0,1,"<core>");
1120 createcommand("KICK",handle_kick,0,2,"<core>");
1121 createcommand("MODE",handle_mode,0,1,"<core>");
1122 createcommand("TOPIC",handle_topic,0,1,"<core>");
1123 createcommand("WHO",handle_who,0,1,"<core>");
1124 createcommand("MOTD",handle_motd,0,0,"<core>");
1125 createcommand("RULES",handle_rules,0,0,"<core>");
1126 createcommand("OPER",handle_oper,0,2,"<core>");
1127 createcommand("LIST",handle_list,0,0,"<core>");
1128 createcommand("DIE",handle_die,'o',1,"<core>");
1129 createcommand("RESTART",handle_restart,'o',1,"<core>");
1130 createcommand("KILL",handle_kill,'o',2,"<core>");
1131 createcommand("REHASH",handle_rehash,'o',0,"<core>");
1132 createcommand("LUSERS",handle_lusers,0,0,"<core>");
1133 createcommand("STATS",handle_stats,0,1,"<core>");
1134 createcommand("USERHOST",handle_userhost,0,1,"<core>");
1135 createcommand("AWAY",handle_away,0,0,"<core>");
1136 createcommand("ISON",handle_ison,0,0,"<core>");
1137 createcommand("SUMMON",handle_summon,0,0,"<core>");
1138 createcommand("USERS",handle_users,0,0,"<core>");
1139 createcommand("INVITE",handle_invite,0,0,"<core>");
1140 createcommand("PASS",handle_pass,0,1,"<core>");
1141 createcommand("TRACE",handle_trace,'o',0,"<core>");
1142 createcommand("WHOWAS",handle_whowas,0,1,"<core>");
1143 createcommand("CONNECT",handle_connect,'o',1,"<core>");
1144 createcommand("SQUIT",handle_squit,'o',0,"<core>");
1145 createcommand("MODULES",handle_modules,0,0,"<core>");
1146 createcommand("LINKS",handle_links,0,0,"<core>");
1147 createcommand("MAP",handle_map,0,0,"<core>");
1148 createcommand("KLINE",handle_kline,'o',1,"<core>");
1149 createcommand("GLINE",handle_gline,'o',1,"<core>");
1150 createcommand("ZLINE",handle_zline,'o',1,"<core>");
1151 createcommand("QLINE",handle_qline,'o',1,"<core>");
1152 createcommand("ELINE",handle_eline,'o',1,"<core>");
1153 createcommand("LOADMODULE",handle_loadmodule,'o',1,"<core>");
1154 createcommand("UNLOADMODULE",handle_unloadmodule,'o',1,"<core>");
1155 createcommand("SERVER",handle_server,0,0,"<core>");
1156 createcommand("COMMANDS",handle_commands,0,0,"<core>");
1159 bool DirValid(char* dirandfile)
1162 char buffer[MAXBUF], otherdir[MAXBUF];
1163 strlcpy(work,dirandfile,MAXBUF);
1164 int p = strlen(work);
1165 // we just want the dir
1175 // Get the current working directory
1176 if( getcwd( buffer, MAXBUF ) == NULL )
1179 if( getcwd( otherdir, MAXBUF ) == NULL )
1182 if (strlen(otherdir) >= strlen(work))
1184 otherdir[strlen(work)] = '\0';
1185 if (!strcmp(otherdir,work))
1194 std::string GetFullProgDir(char** argv, int argc)
1197 char buffer[MAXBUF], otherdir[MAXBUF];
1198 strlcpy(work,argv[0],MAXBUF);
1199 int p = strlen(work);
1200 // we just want the dir
1210 // Get the current working directory
1211 if( getcwd( buffer, MAXBUF ) == NULL )
1214 if( getcwd( otherdir, MAXBUF ) == NULL )