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 static char textbuffer[MAXBUF];
68 static char tb[MAXBUF];
70 void log(int level,char *text, ...)
74 if (level < Config->LogLevel)
77 timeinfo = localtime(&TIME);
82 va_start (argsPtr, text);
83 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
85 strlcpy(b,asctime(timeinfo),MAXBUF);
86 b[24] = ':'; // we know this is the end of the time string
88 fprintf(Config->log_file,"%s %s\n",b,textbuffer);
91 // nofork enabled? display it on terminal too
92 printf("%s %s\n",b,textbuffer);
97 void readfile(file_cache &F, const char* fname)
100 char linebuf[MAXBUF];
102 log(DEBUG,"readfile: loading %s",fname);
104 file = fopen(fname,"r");
109 fgets(linebuf,sizeof(linebuf),file);
110 linebuf[strlen(linebuf)-1]='\0';
117 F.push_back(linebuf);
124 log(DEBUG,"readfile: failed to load file: %s",fname);
126 log(DEBUG,"readfile: loaded %s, %lu lines",fname,(unsigned long)F.size());
129 void Write(int sock,char *text, ...)
135 log(DEFAULT,"*** BUG *** Write was given an invalid parameter");
140 va_start (argsPtr, text);
141 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
143 int bytes = snprintf(tb,MAXBUF,"%s\r\n",textbuffer);
145 if (fd_ref_table[sock])
149 IOHookModule->OnRawSocketWrite(sock,tb,bytes);
153 fd_ref_table[sock]->AddWriteBuf(tb);
155 stats->statsSent += bytes;
157 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
160 /* write a server formatted numeric response to a single socket */
162 void WriteServ(int sock, char* text, ...)
168 log(DEFAULT,"*** BUG *** WriteServ was given an invalid parameter");
172 va_start (argsPtr, text);
174 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
176 int bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,textbuffer);
178 if (fd_ref_table[sock])
182 IOHookModule->OnRawSocketWrite(sock,tb,bytes);
186 fd_ref_table[sock]->AddWriteBuf(tb);
188 stats->statsSent += bytes;
190 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
193 /* write text from an originating user to originating user */
195 void WriteFrom(int sock, userrec *user,char* text, ...)
199 if ((!text) || (!user))
201 log(DEFAULT,"*** BUG *** WriteFrom was given an invalid parameter");
205 va_start (argsPtr, text);
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])
215 IOHookModule->OnRawSocketWrite(sock,tb,bytes);
219 fd_ref_table[sock]->AddWriteBuf(tb);
221 stats->statsSent += bytes;
223 else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
226 /* write text to an destination user from a source user (e.g. user privmsg) */
228 void WriteTo(userrec *source, userrec *dest,char *data, ...)
230 if ((!dest) || (!data))
232 log(DEFAULT,"*** BUG *** WriteTo was given an invalid parameter");
235 if (dest->fd == FD_MAGIC_NUMBER)
238 va_start (argsPtr, data);
239 vsnprintf(textbuffer, MAXBUF, data, argsPtr);
243 // if no source given send it from the server.
246 WriteServ(dest->fd,":%s %s",Config->ServerName,textbuffer);
250 WriteFrom(dest->fd,source,"%s",textbuffer);
254 /* write formatted text from a source user to all users on a channel
255 * including the sender (NOT for privmsg, notice etc!) */
257 void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...)
259 if ((!Ptr) || (!user) || (!text))
261 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
264 char textbuffer[MAXBUF];
266 va_start (argsPtr, text);
267 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
270 std::vector<char*> *ulist = Ptr->GetUsers();
271 unsigned int x = ulist->size();
272 for (unsigned int j = 0; j < x; j++)
274 char* o = (*ulist)[j];
275 userrec* otheruser = (userrec*)o;
276 if (otheruser->fd != FD_MAGIC_NUMBER)
277 WriteTo(user,otheruser,"%s",textbuffer);
281 /* write formatted text from a source user to all users on a channel
282 * including the sender (NOT for privmsg, notice etc!) doesnt send to
283 * users on remote servers */
285 void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...)
287 if ((!Ptr) || (!text))
289 log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
292 char textbuffer[MAXBUF];
294 va_start (argsPtr, text);
295 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
298 std::vector<char*> *ulist = Ptr->GetUsers();
299 unsigned int x = ulist->size();
300 for (unsigned int j = 0; j < x; j++)
302 char* o = (*ulist)[j];
303 userrec* otheruser = (userrec*)o;
304 if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser->fd != -1) && (otheruser != user))
308 WriteServ(otheruser->fd,"%s",textbuffer);
312 WriteTo(user,otheruser,"%s",textbuffer);
318 void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
320 if ((!Ptr) || (!text))
322 log(DEFAULT,"*** BUG *** WriteChannelWithServ was given an invalid parameter");
325 char textbuffer[MAXBUF];
327 va_start (argsPtr, text);
328 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
332 std::vector<char*> *ulist = Ptr->GetUsers();
333 unsigned int x = ulist->size();
334 for (unsigned int j = 0; j < x; j++)
336 char* o = (*ulist)[j];
337 userrec* otheruser = (userrec*)o;
338 if (otheruser->fd != FD_MAGIC_NUMBER)
339 WriteServ(otheruser->fd,"%s",textbuffer);
343 /* write formatted text from a source user to all users on a channel except
344 * for the sender (for privmsg etc) */
346 void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...)
348 if ((!Ptr) || (!user) || (!text))
350 log(DEFAULT,"*** BUG *** ChanExceptSender was given an invalid parameter");
353 char textbuffer[MAXBUF];
355 va_start (argsPtr, text);
356 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
359 std::vector<char*> *ulist = Ptr->GetUsers();
360 unsigned int x = ulist->size();
361 for (unsigned int j = 0; j < x; j++)
363 char* o = (*ulist)[j];
364 userrec* otheruser = (userrec*)o;
365 if ((otheruser->fd != FD_MAGIC_NUMBER) && (user != otheruser))
366 WriteFrom(otheruser->fd,user,"%s",textbuffer);
370 std::string GetServerDescription(char* servername)
372 std::string description = "";
373 FOREACH_MOD OnGetServerDescription(servername,description);
374 if (description != "")
380 return Config->ServerDesc; // not a remote server that can be found, it must be me.
384 /* write a formatted string to all users who share at least one common
385 * channel, including the source user e.g. for use in NICK */
387 void WriteCommon(userrec *u, char* text, ...)
391 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
395 if (u->registered != 7) {
396 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
400 char textbuffer[MAXBUF];
402 va_start (argsPtr, text);
403 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
406 // FIX: Stops a message going to the same person more than once
407 memset(&already_sent,0,MAXCLIENTS);
409 bool sent_to_at_least_one = false;
411 unsigned int y = u->chans.size();
412 for (unsigned int i = 0; i < y; i++)
414 if (u->chans[i].channel)
416 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
417 unsigned int x = ulist->size();
418 for (unsigned int j = 0; j < x; j++)
420 char* o = (*ulist)[j];
421 userrec* otheruser = (userrec*)o;
422 if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
424 already_sent[otheruser->fd] = 1;
425 WriteFrom(otheruser->fd,u,"%s",textbuffer);
426 sent_to_at_least_one = true;
431 // if the user was not in any channels, no users will receive the text. Make sure the user
432 // receives their OWN message for WriteCommon
433 if (!sent_to_at_least_one)
435 WriteFrom(u->fd,u,"%s",textbuffer);
439 /* write a formatted string to all users who share at least one common
440 * channel, NOT including the source user e.g. for use in QUIT */
442 void WriteCommonExcept(userrec *u, char* text, ...)
446 log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
450 if (u->registered != 7) {
451 log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
455 char textbuffer[MAXBUF];
457 va_start (argsPtr, text);
458 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
461 memset(&already_sent,0,MAXCLIENTS);
463 unsigned int y = u->chans.size();
464 for (unsigned int i = 0; i < y; i++)
466 if (u->chans[i].channel)
468 std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
469 unsigned int x = ulist->size();
470 for (unsigned int j = 0; j < x; j++)
472 char* o = (*ulist)[j];
473 userrec* otheruser = (userrec*)o;
476 if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
478 already_sent[otheruser->fd] = 1;
479 WriteFrom(otheruser->fd,u,"%s",textbuffer);
487 void WriteOpers(char* text, ...)
491 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
495 char textbuffer[MAXBUF];
497 va_start (argsPtr, text);
498 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
501 for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
504 if ((a) && (a->fd != FD_MAGIC_NUMBER))
506 if (strchr(a->modes,'s'))
508 // send server notices to all with +s
509 WriteServ(a->fd,"NOTICE %s :%s",a->nick,textbuffer);
515 void ServerNoticeAll(char* text, ...)
520 char textbuffer[MAXBUF];
522 va_start (argsPtr, text);
523 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
526 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
528 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
530 WriteServ(i->second->fd,"NOTICE $%s :%s",Config->ServerName,textbuffer);
535 void ServerPrivmsgAll(char* text, ...)
540 char textbuffer[MAXBUF];
542 va_start (argsPtr, text);
543 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
546 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
548 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
550 WriteServ(i->second->fd,"PRIVMSG $%s :%s",Config->ServerName,textbuffer);
555 void WriteMode(const char* modes, int flags, const char* text, ...)
557 if ((!text) || (!modes) || (!flags))
559 log(DEFAULT,"*** BUG *** WriteMode was given an invalid parameter");
563 char textbuffer[MAXBUF];
565 va_start (argsPtr, text);
566 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
568 int modelen = strlen(modes);
570 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
572 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
574 bool send_to_user = false;
579 for (int n = 0; n < modelen; n++)
581 if (!hasumode(i->second,modes[n]))
583 send_to_user = false;
588 else if (flags == WM_OR)
590 send_to_user = false;
591 for (int n = 0; n < modelen; n++)
593 if (hasumode(i->second,modes[n]))
603 WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,textbuffer);
609 void NoticeAll(userrec *source, bool local_only, char* text, ...)
611 if ((!text) || (!source))
613 log(DEFAULT,"*** BUG *** NoticeAll was given an invalid parameter");
617 char textbuffer[MAXBUF];
619 va_start (argsPtr, text);
620 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
623 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
625 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
627 WriteFrom(i->second->fd,source,"NOTICE $* :%s",textbuffer);
634 void WriteWallOps(userrec *source, bool local_only, char* text, ...)
636 if ((!text) || (!source))
638 log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
642 char textbuffer[MAXBUF];
644 va_start (argsPtr, text);
645 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
648 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
650 if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
652 if (strchr(i->second->modes,'w'))
654 WriteTo(source,i->second,"WALLOPS :%s",textbuffer);
660 /* convert a string to lowercase. Note following special circumstances
661 * taken from RFC 1459. Many "official" server branches still hold to this
662 * rule so i will too;
664 * Because of IRC's scandanavian origin, the characters {}| are
665 * considered to be the lower case equivalents of the characters []\,
666 * respectively. This is a critical issue when determining the
667 * equivalence of two nicknames.
670 void strlower(char *n)
674 for (char* t = n; *t; t++)
675 *t = lowermap[(unsigned)*t];
679 /* Find a user record by nickname and return a pointer to it */
681 userrec* Find(std::string nick)
683 user_hash::iterator iter = clientlist.find(nick);
685 if (iter == clientlist.end())
686 /* Couldn't find it */
692 /* find a channel record by channel name and return a pointer to it */
694 chanrec* FindChan(const char* chan)
698 log(DEFAULT,"*** BUG *** Findchan was given an invalid parameter");
702 chan_hash::iterator iter = chanlist.find(chan);
704 if (iter == chanlist.end())
705 /* Couldn't find it */
712 long GetMaxBans(char* name)
715 for (int count = 0; count < Config->ConfValueEnum("banlist",&Config->config_f); count++)
717 Config->ConfValue("banlist","chan",count,CM,&Config->config_f);
720 Config->ConfValue("banlist","limit",count,CM,&Config->config_f);
727 void purge_empty_chans(userrec* u)
732 // firstly decrement the count on each channel
733 for (unsigned int f = 0; f < u->chans.size(); f++)
735 if (u->chans[f].channel)
737 u->chans[f].channel->DelUser((char*)u);
741 for (unsigned int i = 0; i < u->chans.size(); i++)
743 if (u->chans[i].channel)
745 if (!usercount(u->chans[i].channel))
747 chan_hash::iterator i2 = chanlist.find(u->chans[i].channel->name);
748 /* kill the record */
749 if (i2 != chanlist.end())
751 log(DEBUG,"del_channel: destroyed: %s",i2->second->name);
756 u->chans[i].channel = NULL;
761 log(DEBUG,"skipped purge for %s",u->chans[i].channel->name);
765 log(DEBUG,"completed channel purge, killed %lu",(unsigned long)purge);
771 char* chanmodes(chanrec *chan)
773 static char scratch[MAXBUF];
774 static char sparam[MAXBUF];
775 char* offset = scratch;
779 log(DEFAULT,"*** BUG *** chanmodes was given an invalid parameter");
786 if (chan->binarymodes & CM_NOEXTERNAL)
788 if (chan->binarymodes & CM_TOPICLOCK)
794 if (chan->binarymodes & CM_INVITEONLY)
796 if (chan->binarymodes & CM_MODERATED)
798 if (chan->binarymodes & CM_SECRET)
800 if (chan->binarymodes & CM_PRIVATE)
803 snprintf(sparam,MAXBUF," %s",chan->key);
807 sprintf(foo," %lu",(unsigned long)chan->limit);
808 strlcat(sparam,foo,MAXBUF);
810 if (*chan->custom_modes)
812 for (char* t = chan->custom_modes; *t; t++)
814 for (int z = 0; chan->custom_modes[z]; z++)
816 std::string extparam = chan->GetModeParameter(chan->custom_modes[z]);
819 strlcat(sparam," ",MAXBUF);
820 strlcat(sparam,extparam.c_str(),MAXBUF);
824 /* Null terminate scratch */
826 strlcat(scratch,sparam,MAXMODES);
831 /* compile a userlist of a channel into a string, each nick seperated by
832 * spaces and op, voice etc status shown as @ and + */
834 void userlist(userrec *user,chanrec *c)
838 log(DEFAULT,"*** BUG *** userlist was given an invalid parameter");
842 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
844 std::vector<char*> *ulist = c->GetUsers();
845 for (unsigned int i = 0; i < ulist->size(); i++)
847 char* o = (*ulist)[i];
848 userrec* otheruser = (userrec*)o;
849 if ((!has_channel(user,c)) && (strchr(otheruser->modes,'i')))
851 /* user is +i, and source not on the channel, does not show
852 * nick in NAMES list */
855 strlcat(list,cmode(otheruser,c),MAXBUF);
856 strlcat(list,otheruser->nick,MAXBUF);
857 strlcat(list," ",MAXBUF);
858 if (strlen(list)>(480-NICKMAX))
860 /* list overflowed into
861 * multiple numerics */
862 WriteServ(user->fd,"%s",list);
863 snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
866 /* if whats left in the list isnt empty, send it */
867 if (list[strlen(list)-1] != ':')
869 WriteServ(user->fd,"%s",list);
873 /* return a count of the users on a specific channel accounting for
874 * invisible users who won't increase the count. e.g. for /LIST */
876 int usercount_i(chanrec *c)
882 log(DEFAULT,"*** BUG *** usercount_i was given an invalid parameter");
886 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
890 if (has_channel(i->second,c))
892 if (isnick(i->second->nick))
894 if ((!has_channel(i->second,c)) && (strchr(i->second->modes,'i')))
896 /* user is +i, and source not on the channel, does not show
897 * nick in NAMES list */
905 log(DEBUG,"usercount_i: %s %lu",c->name,(unsigned long)count);
910 int usercount(chanrec *c)
914 log(DEFAULT,"*** BUG *** usercount was given an invalid parameter");
917 int count = c->GetUserCounter();
918 log(DEBUG,"usercount: %s %lu",c->name,(unsigned long)count);
923 // looks up a users password for their connection class (<ALLOW>/<DENY> tags)
925 char* Passwd(userrec *user)
927 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
929 if ((i->type == CC_ALLOW) && match(user->host,i->host))
937 bool IsDenied(userrec *user)
939 for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
941 if ((i->type == CC_DENY) && match(user->host,i->host))
952 /* sends out an error notice to all connected clients (not to be used
955 void send_error(char *s)
957 log(DEBUG,"send_error: %s",s);
958 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
960 if (IS_LOCAL(i->second))
962 if (i->second->registered == 7)
964 WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,s);
968 // fix - unregistered connections receive ERROR, not NOTICE
969 Write(i->second->fd,"ERROR :%s",s);
975 void Error(int status)
977 signal (SIGALRM, SIG_IGN);
978 signal (SIGPIPE, SIG_IGN);
979 signal (SIGTERM, SIG_IGN);
980 signal (SIGABRT, SIG_IGN);
981 signal (SIGSEGV, SIG_IGN);
982 signal (SIGURG, SIG_IGN);
983 signal (SIGKILL, SIG_IGN);
984 log(DEFAULT,"*** fell down a pothole in the road to perfection ***");
985 send_error("Error! Segmentation fault! save meeeeeeeeeeeeee *splat!*");
989 // this function counts all users connected, wether they are registered or NOT.
992 return clientlist.size();
995 // this counts only registered users, so that the percentages in /MAP don't mess up when users are sitting in an unregistered state
996 int registered_usercount(void)
999 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1001 if (i->second->registered == 7) c++;
1006 int usercount_invisible(void)
1009 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1011 if ((isnick(i->second->nick)) && (strchr(i->second->modes,'i'))) c++;
1016 int usercount_opers(void)
1019 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1021 if ((isnick(i->second->nick)) && (strchr(i->second->modes,'o'))) c++;
1026 int usercount_unknown(void)
1030 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1032 if ((i->second->fd > -1) && (i->second->registered != 7))
1038 long chancount(void)
1040 return chanlist.size();
1046 for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
1048 if ((isnick(i->second->nick)) && (i->second->fd > -1)) c++;
1053 void ShowMOTD(userrec *user)
1055 static char mbuf[MAXBUF];
1056 static char crud[MAXBUF];
1057 std::string WholeMOTD = "";
1058 if (!Config->MOTD.size())
1060 WriteServ(user->fd,"422 %s :Message of the day file is missing.",user->nick);
1063 snprintf(crud,MAXBUF,":%s 372 %s :- ", Config->ServerName, user->nick);
1064 snprintf(mbuf,MAXBUF,":%s 375 %s :- %s message of the day\r\n", Config->ServerName, user->nick, Config->ServerName);
1065 WholeMOTD = WholeMOTD + mbuf;
1066 for (unsigned int i = 0; i < Config->MOTD.size(); i++)
1067 WholeMOTD = WholeMOTD + std::string(crud) + Config->MOTD[i].c_str() + std::string("\r\n");
1068 snprintf(mbuf,MAXBUF,":%s 376 %s :End of message of the day.\r\n", Config->ServerName, user->nick);
1069 WholeMOTD = WholeMOTD + mbuf;
1070 // only one write operation
1073 IOHookModule->OnRawSocketWrite(user->fd,(char*)WholeMOTD.c_str(),WholeMOTD.length());
1077 user->AddWriteBuf(WholeMOTD);
1079 stats->statsSent += WholeMOTD.length();
1082 void ShowRULES(userrec *user)
1084 if (!Config->RULES.size())
1086 WriteServ(user->fd,"NOTICE %s :Rules file is missing.",user->nick);
1089 WriteServ(user->fd,"NOTICE %s :%s rules",user->nick,Config->ServerName);
1090 for (unsigned int i = 0; i < Config->RULES.size(); i++)
1091 WriteServ(user->fd,"NOTICE %s :%s",user->nick,Config->RULES[i].c_str());
1092 WriteServ(user->fd,"NOTICE %s :End of %s rules.",user->nick,Config->ServerName);
1095 // this returns 1 when all modules are satisfied that the user should be allowed onto the irc server
1096 // (until this returns true, a user will block in the waiting state, waiting to connect up to the
1097 // registration timeout maximum seconds)
1098 bool AllModulesReportReady(userrec* user)
1100 for (int i = 0; i <= MODCOUNT; i++)
1102 int res = modules[i]->OnCheckReady(user);
1109 void createcommand(char* cmd, handlerfunc f, char flags, int minparams,char* source)
1112 /* create the command and push it onto the table */
1113 strlcpy(comm.command,cmd,MAXBUF);
1114 strlcpy(comm.source,source,MAXBUF);
1115 comm.handler_function = f;
1116 comm.flags_needed = flags;
1117 comm.min_params = minparams;
1119 comm.total_bytes = 0;
1120 cmdlist.push_back(comm);
1121 log(DEBUG,"Added command %s (%lu parameters)",cmd,(unsigned long)minparams);
1125 void SetupCommandTable(void)
1127 createcommand("USER",handle_user,0,4,"<core>");
1128 createcommand("NICK",handle_nick,0,1,"<core>");
1129 createcommand("QUIT",handle_quit,0,0,"<core>");
1130 createcommand("VERSION",handle_version,0,0,"<core>");
1131 createcommand("PING",handle_ping,0,1,"<core>");
1132 createcommand("PONG",handle_pong,0,1,"<core>");
1133 createcommand("ADMIN",handle_admin,0,0,"<core>");
1134 createcommand("PRIVMSG",handle_privmsg,0,2,"<core>");
1135 createcommand("INFO",handle_info,0,0,"<core>");
1136 createcommand("TIME",handle_time,0,0,"<core>");
1137 createcommand("WHOIS",handle_whois,0,1,"<core>");
1138 createcommand("WALLOPS",handle_wallops,'o',1,"<core>");
1139 createcommand("NOTICE",handle_notice,0,2,"<core>");
1140 createcommand("JOIN",handle_join,0,1,"<core>");
1141 createcommand("NAMES",handle_names,0,0,"<core>");
1142 createcommand("PART",handle_part,0,1,"<core>");
1143 createcommand("KICK",handle_kick,0,2,"<core>");
1144 createcommand("MODE",handle_mode,0,1,"<core>");
1145 createcommand("TOPIC",handle_topic,0,1,"<core>");
1146 createcommand("WHO",handle_who,0,1,"<core>");
1147 createcommand("MOTD",handle_motd,0,0,"<core>");
1148 createcommand("RULES",handle_rules,0,0,"<core>");
1149 createcommand("OPER",handle_oper,0,2,"<core>");
1150 createcommand("LIST",handle_list,0,0,"<core>");
1151 createcommand("DIE",handle_die,'o',1,"<core>");
1152 createcommand("RESTART",handle_restart,'o',1,"<core>");
1153 createcommand("KILL",handle_kill,'o',2,"<core>");
1154 createcommand("REHASH",handle_rehash,'o',0,"<core>");
1155 createcommand("LUSERS",handle_lusers,0,0,"<core>");
1156 createcommand("STATS",handle_stats,0,1,"<core>");
1157 createcommand("USERHOST",handle_userhost,0,1,"<core>");
1158 createcommand("AWAY",handle_away,0,0,"<core>");
1159 createcommand("ISON",handle_ison,0,0,"<core>");
1160 createcommand("SUMMON",handle_summon,0,0,"<core>");
1161 createcommand("USERS",handle_users,0,0,"<core>");
1162 createcommand("INVITE",handle_invite,0,0,"<core>");
1163 createcommand("PASS",handle_pass,0,1,"<core>");
1164 createcommand("TRACE",handle_trace,'o',0,"<core>");
1165 createcommand("WHOWAS",handle_whowas,0,1,"<core>");
1166 createcommand("CONNECT",handle_connect,'o',1,"<core>");
1167 createcommand("SQUIT",handle_squit,'o',0,"<core>");
1168 createcommand("MODULES",handle_modules,0,0,"<core>");
1169 createcommand("LINKS",handle_links,0,0,"<core>");
1170 createcommand("MAP",handle_map,0,0,"<core>");
1171 createcommand("KLINE",handle_kline,'o',1,"<core>");
1172 createcommand("GLINE",handle_gline,'o',1,"<core>");
1173 createcommand("ZLINE",handle_zline,'o',1,"<core>");
1174 createcommand("QLINE",handle_qline,'o',1,"<core>");
1175 createcommand("ELINE",handle_eline,'o',1,"<core>");
1176 createcommand("LOADMODULE",handle_loadmodule,'o',1,"<core>");
1177 createcommand("UNLOADMODULE",handle_unloadmodule,'o',1,"<core>");
1178 createcommand("SERVER",handle_server,0,0,"<core>");
1179 createcommand("COMMANDS",handle_commands,0,0,"<core>");
1182 bool DirValid(char* dirandfile)
1185 char buffer[MAXBUF], otherdir[MAXBUF];
1186 strlcpy(work,dirandfile,MAXBUF);
1187 int p = strlen(work);
1188 // we just want the dir
1198 // Get the current working directory
1199 if( getcwd( buffer, MAXBUF ) == NULL )
1202 if( getcwd( otherdir, MAXBUF ) == NULL )
1205 if (strlen(otherdir) >= strlen(work))
1207 otherdir[strlen(work)] = '\0';
1208 if (!strcmp(otherdir,work))
1217 std::string GetFullProgDir(char** argv, int argc)
1220 char buffer[MAXBUF], otherdir[MAXBUF];
1221 strlcpy(work,argv[0],MAXBUF);
1222 int p = strlen(work);
1223 // we just want the dir
1233 // Get the current working directory
1234 if( getcwd( buffer, MAXBUF ) == NULL )
1237 if( getcwd( otherdir, MAXBUF ) == NULL )