From 617c641f21c4be1e14d463dec89821daa112b58d Mon Sep 17 00:00:00 2001 From: epochqwert Date: Mon, 5 Oct 2015 00:37:02 -0500 Subject: fixed up some of runem that hadn't been made for multiple fds. update to link example bot to use line_cutter --- examples/link.c | 63 ++++++++++++++------------------------------------------- 1 file changed, 15 insertions(+), 48 deletions(-) (limited to 'examples/link.c') diff --git a/examples/link.c b/examples/link.c index 680550c..3d5a0cc 100644 --- a/examples/link.c +++ b/examples/link.c @@ -33,70 +33,36 @@ void message_handler(int fd,char *from,struct user *user,char *line) { } void line_handler(int fd,char *line) {//this should be built into the libary? - char *s=line,*t=0,*u=0; char *temp; + char **a; char tmp[512]; struct user *user=malloc(sizeof(struct user)); - user->nick=0; - user->user=0; - user->host=0; - if(strchr(line,'\r')) *strchr(line,'\r')=0; - if(strchr(line,'\n')) *strchr(line,'\n')=0; printf("line: '%s'\n",line); - if(line[0]==':') { - if((user->nick=strchr(line,':'))) { - *(user->nick)=0; - (user->nick)++; - } - } - if(user->nick) { - if((s=strchr((user->nick),' '))) { - *s=0; - s++; - if((t=strchr(s,' '))) { - *t=0; - t++; - if((u=strchr(t,' '))) {//: - *u=0; - u++; - } - } - } - if(((user->user)=strchr((user->nick),'!'))) { - *(user->user)=0; - (user->user)++; - if(((user->host)=strchr((user->user),'@'))) { - *(user->host)=0; - (user->host)++; - } - } else { - user->host=user->nick; - } - } - if(!user->user && s) { - if(!strcmp(s,"004")) { + a=line_cutter(fd,line,user); + if(!user->user && a[0]) { + if(!strcmp(a[0],"004")) { snprintf(tmp,sizeof(tmp)-1,"JOIN %s\r\n",chans[fdtoi(fd)]); temp=strchr(chans[fdtoi(fd)],' '); if(temp) *temp=0; mywrite(fd,tmp); } } - if(s && t && u) { - if(!strcmp(s,"PRIVMSG")) { - message_handler(fd,*t=='#'?t:user->nick,user,++u); + if(a[0] && a[1] && a[2]) { + if(!strcmp(a[0],"PRIVMSG")) { + message_handler(fd,*a[1]=='#'?a[1]:user->nick,user,a[2]); } } - if(s && user->nick && t) { - if(!strcmp(s,"JOIN")) { - snprintf(tmp,sizeof(tmp)-1,"%cACTION %s has joined %s%c",1,user->nick,t+(*t==':'),1); + if(a[0] && user->nick && a[1]) { + if(!strcmp(a[0],"JOIN")) { + snprintf(tmp,sizeof(tmp)-1,"%cACTION %s has joined %s%c",1,user->nick,a[1]+(*a[1]==':'),1); privmsg_others(fd,tmp); } - if(!strcmp(s,"PART")) { - snprintf(tmp,sizeof(tmp)-1,"%cACTION %s has parted %s%c",1,user->nick,t+(*t==':'),1); + if(!strcmp(a[0],"PART")) { + snprintf(tmp,sizeof(tmp)-1,"%cACTION %s has parted %s%c",1,user->nick,a[1]+(*a[1]==':'),1); privmsg_others(fd,tmp); } - if(!strcmp(s,"QUIT")) { - snprintf(tmp,sizeof(tmp)-1,"%cACTION %s has quited %s%c",1,user->nick,t+(*t==':'),1); + if(!strcmp(a[0],"QUIT")) { + snprintf(tmp,sizeof(tmp)-1,"%cACTION %s has quited %s%c",1,user->nick,a[1]+(*a[1]==':'),1); privmsg_others(fd,tmp); } } @@ -119,6 +85,7 @@ int main(int argc,char *argv[]) { for(i=0;((i*3)+3)