From ced0c04fd6db87e35fe30e2aa3c7f1a40a4fd7e0 Mon Sep 17 00:00:00 2001 From: epoch Date: Sun, 2 Mar 2014 08:09:36 -0600 Subject: made some stuff a bit prettier. added %m and segnick variable for self nick stuff you can use git diff for anything else. --- compile.sh | 2 +- segfault.c | 113 ++++++++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 83 insertions(+), 32 deletions(-) diff --git a/compile.sh b/compile.sh index 6c17703..ced7354 100755 --- a/compile.sh +++ b/compile.sh @@ -2,4 +2,4 @@ cd libirc ./compile.sh cd .. -gcc -Wall -o segfault segfault.c -lirc -Llibirc -Ilibirc +gcc -pedantic -Wall -o segfault segfault.c -lirc -Llibirc -Ilibirc diff --git a/segfault.c b/segfault.c index 7f80155..0c12376 100644 --- a/segfault.c +++ b/segfault.c @@ -35,6 +35,7 @@ int start_time; +char *segnick; char *redo; int redirect_to_fd; int line_limit; @@ -75,8 +76,11 @@ void mywrite(int fd,char *b) { void ircmode(int fd,char *channel,char *mode,char *nick) { int sz=5+strlen(channel)+1+strlen(mode)+1+strlen(nick)+3;//"MODE ", " ", " ","\r\n\0" - char *hrm=malloc(sz+1); - if(!hrm) return mywrite(fd,"QUIT :malloc error 1! holy shit!\r\n"); + char *hrm; + if(!(hrm=malloc(sz+1))) { + mywrite(fd,"QUIT :malloc error 1! holy shit!\r\n"); + return; + } snprintf(hrm,sz,"MODE %s %s %s\r\n",channel,mode,nick); write(fd,hrm,strlen(hrm)); free(hrm); @@ -84,7 +88,7 @@ void ircmode(int fd,char *channel,char *mode,char *nick) { void privmsg(int fd,char *who,char *msg) { int i=0; - char *chunk; + char *chunk,*hrm; int sz; int cs; if(!who) return; @@ -92,8 +96,10 @@ void privmsg(int fd,char *who,char *msg) { for(i=0;i LINES_SENT_LIMIT) {//if it is still the same second, skip this function. return; } else { lines_sent=0; } - 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) { @@ -471,8 +497,11 @@ void c_alias(int fd,char *from,char *line) { } } tmp=a_end; - struct alias *tmp2=malloc(sizeof(struct alias)+20); - if(!tmp2) return (void)mywrite(fd,"QUIT :malloc error 7!!!\r\n"); + tmp2=malloc(sizeof(struct alias)+20); + if(!tmp2) { + mywrite(fd,"QUIT :malloc error 7!!!\r\n"); + return; + } if(a_end == 0) { a_end=tmp2; a_start=tmp2; @@ -570,9 +599,9 @@ char append_file(int fd,char *from,char *file,char *line,unsigned short nl) { int fdd; char tmp[512]; char derp[2]; + FILE *fp; derp[0]=(char)nl; derp[1]=0; - FILE *fp; if(line == 0) return mywrite(fd,"QUIT :line == 0 in append_file\r\n"),-1; fdd=open(file,O_WRONLY|O_NONBLOCK|O_APPEND|O_CREAT,0640);//HAVE to open named pipes as nonblocking. if(fdd == -1) { @@ -641,7 +670,10 @@ void c_tails(int fd,char *from) { if(tailf[i].fp) { l=(strlen(tailf[i].file) + strlen(tailf[i].to) + 50);//??? hack. fix it. tmp=malloc(l); - if(!tmp) return (void)mywrite(fd,"QUIT :malloc error 8\r\n"); + if(!tmp) { + mywrite(fd,"QUIT :malloc error 8\r\n"); + return; + } snprintf(tmp,l,"%s [i:%d] @ %ld (%d) --[%s(%02x)]--> %s",tailf[i].file,tailf[i].inode,ftell(tailf[i].fp),tailf[i].lines,tailmode_to_txt(tailf[i].opt),tailf[i].opt,tailf[i].to); privmsg(fd,from,tmp); free(tmp); @@ -756,6 +788,9 @@ 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,"!whoareyou",10) && !msg[10]) { + privmsg(fd,from,segnick); + } else if(!strncmp(msg,"!whoami",7) && !msg[7]) { privmsg(fd,from,nick); } @@ -834,7 +869,7 @@ void message_handler(int fd,char *from,char *nick,char *msg,int redones) { //if(!redo) (void *)mywrite(fd,"QUIT :malloc error 9!!!\r\n"); //this is where the format string is used... //generate an array based on the format string containing %N stuff in the right order. - // %u = user, %f = from (user/channel) + // %u = user, %f = from (user/channel), %s = argument // handling it here would be a bitch. maybe // redo=apply_alias(fd,from,sz,m->target) ??? new function would probably be good. redo=format_magic(fd,from,nick,m->target,*(msg+strlen(m->original)+1)=='\n'?"":(msg+strlen(m->original)+1)); @@ -919,7 +954,22 @@ void line_handler(int fd,char *line) {//this should be built into the libary? } if(s && nick && t) { if(!strcmp(s,"JOIN")) { - ircmode(fd,t+1,"+v",nick); + ircmode(fd,t+1,"+v",nick);//why t+1? it starts with :? + } + if(!strcmp(s,"MODE")) { + if(u) { + if(*u == '-') {//auto-give modes back that are removed in front of segfault. + *u='+'; + ircmode(fd,t,u,"");//u contains the nick the mode is being removed from. + } + } + } +//:Ishikawa-!~epoch@localhost NICK :checking + if(!strcmp(s,"NICK")) { + if(!strcmp(nick,segnick)) { + free(segnick); + segnick=strdup(t+1); + } } } } @@ -937,9 +987,10 @@ int main(int argc,char *argv[]) { a_start=0; a_end=0; redo=0; + segnick=strdup(NICK); printf("starting segfault...\n"); for(c=0;c1?argv[1]:NICK,"segfault segfault segfault :segfault"); + fd=ircConnect(SERVER,PORT,argc>1?argv[1]:"SegFault","segfault segfault segfault :segfault"); startup_stuff(fd); return runit(fd,line_handler,extra_handler); } -- cgit v1.2.3