From d192cd24925f2925b577b721edbf80e65dc3d73c Mon Sep 17 00:00:00 2001 From: epochqwert Date: Mon, 16 May 2016 10:15:04 +0000 Subject: updated link.c to better handle ACTIONs and made presence be notices instead of PM. --- Makefile | 2 +- examples/link.c | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index e6c38fb..26490c5 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,6 @@ $(TARGET): clean: rm -f libirc.so -install: +install: all cp $(TARGET) /usr/local/lib/$(TARGET) cp irc.h /usr/local/include/irc.h diff --git a/examples/link.c b/examples/link.c index 3d5a0cc..73af3b8 100644 --- a/examples/link.c +++ b/examples/link.c @@ -1,7 +1,7 @@ #include #include #include -#include "../irc.h" +#include #define mywrite(a,b) write(a,b,strlen(b)) @@ -12,23 +12,26 @@ void extra_handler(int fd) { return; } -void privmsg_others(int fd,char *msg) { +void sendto_others(int fd,char *action,char *msg) { int i; char tmp[512]; for(i=0;fds[i] != -1;i++) { if(fds[i] != fd) { - snprintf(tmp,sizeof(tmp)-1,"PRIVMSG %s :%s\r\n",chans[fdtoi(fds[i])],msg); + snprintf(tmp,sizeof(tmp)-1,"%s %s :%s\r\n",action,chans[fdtoi(fds[i])],msg); write(fds[i],tmp,strlen(tmp)); } } } void message_handler(int fd,char *from,struct user *user,char *line) { - int i; char tmp[512]; if(!strcmp(from,chans[fdtoi(fd)])) {//don't want to be forwarding PMs. :P - snprintf(tmp,sizeof(tmp)-1,"<%s> %s",user->nick,line); - privmsg_others(fd,tmp); + if(line[0] == '\x01' && strlen(line) > 9 && !strncmp(line+1,"ACTION ",7) && line[strlen(line)-1] == '\x01') { + snprintf(tmp,sizeof(tmp)-1,"%cACTION %s %s",1,user->nick,line+8); + } else { + snprintf(tmp,sizeof(tmp)-1,"<%s> %s",user->nick,line); + } + sendto_others(fd,"PRIVMSG",tmp); } } @@ -54,16 +57,16 @@ void line_handler(int fd,char *line) {//this should be built into the libary? } 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); + snprintf(tmp,sizeof(tmp)-1,"%s has joined %s",user->nick,a[1]+(*a[1]==':')); + sendto_others(fd,"NOTICE",tmp); } 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); + snprintf(tmp,sizeof(tmp)-1,"%s has parted %s",user->nick,a[1]+(*a[1]==':')); + sendto_others(fd,"NOTICE",tmp); } 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); + snprintf(tmp,sizeof(tmp)-1,"%s has quited %s",user->nick,a[1]+(*a[1]==':')); + sendto_others(fd,"NOTICE",tmp); } } free(user); -- cgit v1.2.3