/* eggdrop module to handle msg, notice, channel msg, channel notice, and elementary ctcp and ctcp-replies. */ #include #include #include #include #include "eggdrop.h" #define FINGER "is an EGGDROP bot, idle 0 seconds always." #define SOURCE "email rpointe@eng.clemson.edu" #define CLIENTINFO "FINGER PING ECHO ERRMSG VERSION SOURCE USERINFO CLIENTINFO DCC" /* used as a parameter to detect_flood */ #define _NICK 1 #define _PRIVMSG 2 #define _NOTICE 3 #define _CTCP 4 /* whether or not to display the time with console output */ int shtime=0; /* whether or not to do console output at all */ int use_console=1; /* if true, display to console all msgs & publics */ int spymode=0; /* if true, show public spies too */ int spypub=0; extern int serv; extern int memused; extern int backgrd; extern int con_chan; extern int term_z; extern char botname[]; extern char helpbot[]; extern char version[]; extern char curchan[]; extern char logfile[]; extern struct dcc_t dcc[MAXDCC]; extern int dcc_total; extern char admin[]; void console(va_alist) va_dcl { int i; char s1[41],s[512],s2[512]; char *format; va_list va; time_t tt; FILE *f; if (!use_console) return; va_start(va); format=va_arg(va,char *); vsprintf(s,format,va); if (s[0]==0) strcpy(s,"\n"); else if (shtime) { tt=time(NULL); strcpy(s1,ctime(&tt)); strcpy(s1,&s1[11]); s1[5]=0; sprintf(s2,"[%s] %s\n",s1,s); strcpy(s,s2); } else strcat(s,"\n"); if ((backgrd) || (con_chan) || (term_z)) { f=fopen(logfile,"a+"); if (f!=NULL) { fprintf(f,"%s",s); fclose(f); } } else printf("%s",s); for (i=0; i %s",nick,msg); else console("<%s:%s> %s",nick,to,msg); } } /* public notice on channel */ void gotpublicnotice(from,to,msg) char *from,*to,*msg; { char nick[10]; detect_flood(from,_NOTICE,1); splitnick(nick,from); if ((spymode) && (spypub)) console("-%s:%s- %s",nick,to,msg); } /* private message */ void gotmsg(from,msg) char *from,*msg; { char to[81],nick[10],ctcp[512]; char *p,*p1; split(to,msg); fixcolon(msg); /* check for CTCP: */ p=strchr(msg,1); while (p!=NULL) { p++; p1=p; while ((*p != 1) && (*p != 0)) p++; if (*p==1) { *p=0; strcpy(ctcp,p1); strcpy(p1-1,p+1); } else { strcpy(ctcp,p1); strcpy(p1-1,p); } detect_flood(from,_CTCP,0); gotctcp(from,to,ctcp); p=strchr(msg,1); } if (msg[0]==0) return; /* oh. no msg. well forget it then! */ if ((to[0]=='#') || (to[0]=='&')) { /* it's a public msg */ gotpublic(from,to,msg); } else { detect_flood(from,_PRIVMSG,0); splitnick(nick,from); gotcmd(nick,from,msg); } } /* private notice */ void gotnotice(from,msg) char *from,*msg; { char to[81],nick[10],ctcp[512]; char *p,*p1; split(to,msg); fixcolon(msg); /* check for CTCP: */ p=strchr(msg,1); while (p!=NULL) { p++; p1=p; while ((*p != 1) && (*p != 0)) p++; if (*p==1) { *p=0; strcpy(ctcp,p1); strcpy(p1-1,p+1); } else { strcpy(ctcp,p1); strcpy(p1-1,p); } detect_flood(from,_CTCP,0); gotctcpreply(from,to,ctcp); p=strchr(msg,1); } if (msg[0]==0) return; /* oh. no msg. well forget it then! */ if ((to[0]=='#') || (to[0]=='&')) { /* it's a public msg */ gotpublicnotice(from,to,msg); } else { detect_flood(from,_NOTICE,0); if (spymode) { /* server notice? */ if (from[0]==0) { console("-NOTICE- %s",msg); } else { splitnick(nick,from); console("-%s (%s)- %s",nick,from,msg); } } } }