summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/link.c63
1 files changed, 15 insertions, 48 deletions
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)<argc;i++) {
printf("%d server: %s port: %s channel: %s\n",i,argv[(i*3)+1],argv[(i*3)+2],argv[(i*3)+3]);
fds[i]=serverConnect(argv[(i*3)+1],argv[(i*3)+2]);
+ if(fds[i] == -1) return 1;
chans[i]=strdup(argv[(i*3)+3]);
mywrite(fds[i],"NICK link8239\r\nUSER a b c :d\r\n");
}