From 47ca11b7152363b8ae0bb0fbef461155fbe3bf73 Mon Sep 17 00:00:00 2001 From: epoch Date: Mon, 10 Feb 2014 07:02:09 -0600 Subject: fixed some command conflict issues based on only checking part of a string. --- segfault.c | 245 +++++++++++++++++-------------------------------------------- 1 file changed, 66 insertions(+), 179 deletions(-) diff --git a/segfault.c b/segfault.c index 304aea3..7f80155 100644 --- a/segfault.c +++ b/segfault.c @@ -6,36 +6,32 @@ #include #include #include -#include #include - -#define SERVER "192.168.0.2" -#define PORT "6667" -#define NICK "SegFault" - -#define LINE_LIMIT line_limit - -#define LINES_SENT_LIMIT 1 - -#define LINELEN 400 - -#define RAWLOG "./files/rawlog" -#define LOG "./files/log" - -#define MAXTAILS 400 //just to have it more than the system default. - +#include //epoch's libirc. should be included with segfault. + + +//might want to change some of these. +#define SERVER "192.168.0.2" +#define PORT "6667" +#define NICK "SegFault" //override with argv[0] +#define LINE_LIMIT line_limit +#define LINES_SENT_LIMIT 1 +#define LINELEN 400 +#define RAWLOG "/home/segfault/files/rawlog" +#define LOG "/home/segfault/files/log" +#define MAXTAILS 400 //just to have it more than the system default. #define BS 502 - -//!c uses 56 for its tail. -// 56 = 32 + 16 + 8 = 0x38 = 0x20+0x10+0x8 = SPAM | BEGIN | MSG -#define TAILO_RAW (0x1) -#define TAILO_EVAL (0x2) -#define TAILO_CLOSE (0x4) -#define TAILO_MSG (0x8) -#define TAILO_BEGIN (0x10) +// !c uses 56 for its tail. +// 56 == 32 + 16 + 8 == 0x38 == 0x20+0x10+0x8 == SPAM | BEGIN | MSG +#define TAILO_RAW (0x1) //output gets sent directly to server +#define TAILO_EVAL (0x2) //interpret the lines read from the tail as if they were messages to segfault +#define TAILO_CLOSE (0x4) //close the file at EOF, default is to leave it open. +#define TAILO_MSG (0x8) //output gets sent as a PM to the place the tail was made. +#define TAILO_BEGIN (0x10) //start the tail at the beginning of the file instead of the end. #define TAILO_SPAM (0x20) //Spam control is enabled for this stream. #define TAILO_ENDMSG (0x40) //show a message when the tail reaches the end of a chunk -#define TAILO_Q_EVAL (TAILO_EVAL|TAILO_CLOSE|TAILO_BEGIN) //0x2+0x4+0x10= 2+4+16=22 +#define TAILO_Q_EVAL (TAILO_EVAL|TAILO_CLOSE|TAILO_BEGIN) //0x2+0x4+0x10 = 2+4+16 = 22 +#define TAILO_Q_COUT (TAILO_SPAM|TAILO_BEGIN|TAILO_MSG) //0x20+0x10+0x8 = 32+16+8 = 56 int start_time; @@ -45,8 +41,31 @@ int line_limit; int debug; timer_t timer; int lines_sent; +unsigned long oldtime; + + +struct tail { + FILE *fp; + char *file; + char *to; + char *args; + char opt; + unsigned int inode; + int lines; +} tailf[MAXTAILS]; + +struct alias { + char *original; + char *target; + struct alias *prev;// doubly linked list. + struct alias *next; +} *a_start,*a_end; + + +void message_handler(int fd,char *from,char *nick,char *msg,int redones); +void c_untail(int fd,char *from, char *file); + -//this should add a line to an outgoing queue? void mywrite(int fd,char *b) { if(!b) return; if(fd<0) return; @@ -66,20 +85,10 @@ void ircmode(int fd,char *channel,char *mode,char *nick) { void privmsg(int fd,char *who,char *msg) { int i=0; char *chunk; - if(!who) { - who="epoch"; - msg="didn't have a who. sending this."; - } - if(!msg) { - who="epoch"; - msg="didn't have a message. sending this."; - } - if(!msg && !who) { - who="epoch"; - msg="didn't have a message or a who. sending this."; - } int sz; int cs; + if(!who) return; + if(!msg) return; for(i=0;i1)) { - privmsg(fd,from,"can only use %s and only once."); - snprintf(tmp,sizeof(tmp)-1,"bad format string: %s",line); - privmsg(fd,from,tmp); - return 0; - } - i++; - } - } - return line; -} -//this has a LOT of shit in it. -unsigned long oldtime; +//this function got scary. void extra_handler(int fd) { if(oldtime == time(0) && lines_sent > LINES_SENT_LIMIT) {//if it is still the same second, skip this function. return; - } else {//different second. reset count. + } else { lines_sent=0; } - int i; - int tmpo; + int tmpo,i; static int mmerp=0; char tmp[BS+1]; char *tmp2; - if(redirect_to_fd != -1) { fd=redirect_to_fd; } - for(i=0;inext) { @@ -869,19 +756,19 @@ void message_handler(int fd,char *from,char *nick,char *msg,int redones) { if(!strncmp(msg,"!leetsetout ",12)) { c_leetsetout(fd,from,msg+12); } - else if(!strncmp(msg,"!whoami",7)) { + else if(!strncmp(msg,"!whoami",7) && !msg[7]) { privmsg(fd,from,nick); } - else if(!strncmp(msg,"!whereami",9)) { + else if(!strncmp(msg,"!whereami",9) && !msg[9]) { privmsg(fd,from,from); } - else if(!strncmp(msg,"!resetout",9)) { + else if(!strncmp(msg,"!resetout",9) && !msg[9]) { c_resetout(fd,from); } - else if(!strncmp(msg,"!botup",6)) { + else if(!strncmp(msg,"!botup",6) && !msg[6]) { c_botup(fd,from); } - else if(!strncmp(msg,"!linelimit",10)) { + else if(!strncmp(msg,"!linelimit",10) && (!msg[10] || msg[10] == ' ')) { c_linelimit(fd,from,*(msg+10)?msg+11:0); } else if(!strncmp(msg,"!tailunlock ",12)) { @@ -890,7 +777,7 @@ void message_handler(int fd,char *from,char *nick,char *msg,int redones) { else if(!strncmp(msg,"!changetail ",12)) { c_changetail(fd,from,msg+12); } - else if(!strncmp(msg,"!tails",6)) { + else if(!strncmp(msg,"!tails",6) && !msg[6]) { c_tails(fd,from); } else if(!strncmp(msg,"!record ",8)) { @@ -922,7 +809,7 @@ void message_handler(int fd,char *from,char *nick,char *msg,int redones) { else if(!strncmp(msg,"!say ",5)) { privmsg(fd,from,msg+5); } - else if(!strncmp(msg,"!id",3)) { + else if(!strncmp(msg,"!id",3) && !msg[3]) { c_id(fd,from); } else if(!strncmp(msg,"!kill ",6)) { @@ -934,7 +821,7 @@ void message_handler(int fd,char *from,char *nick,char *msg,int redones) { else if(!strncmp(msg,"!rmalias ",9)) { c_rmalias(fd,from,msg+9); } - else if(!strncmp(msg,"!aliases",8)) { + else if(!strncmp(msg,"!aliases",8) && (!msg[8] || msg[8] == ' ')) { c_aliases(fd,from,*(msg+8)?msg+9:0); } else if(redones < 5) { -- cgit v1.2.3