From 95eec6affee455e1ba935a1781495682b2ee7e9a Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 15 Apr 2017 18:53:00 +0200 Subject: weechat: Handle _push online --- weechat/net.c | 20 ++++++++++++++++++++ weechat/net.h | 5 +++++ weechat/tomsg.c | 13 ++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) (limited to 'weechat') diff --git a/weechat/net.c b/weechat/net.c index b8e3827..656a7a5 100644 --- a/weechat/net.c +++ b/weechat/net.c @@ -347,6 +347,26 @@ void net_handle_recv(int fd,const char *msg){ res.room[roomlen]='\0'; cb(fd,res,payload); free(res.room); + } else if(cmdlen==6&&memcmp(cmd,"online",6)==0){ + const char *q; + if(*p=='\0'||(q=strchr(p+1,' '))==NULL){ + fprintf(debugf,"net_handle_recv: not enough arguments to 'online' <%s>\n",msg); + return; + } + const char *nump=p+1; + const char *usernamep=q+1; + const char *endp; + struct net_response res=(struct net_response){ + .type=NET_ONLINE, + .online.username=strdup(usernamep), + .online.num=strtol(nump,(char**)&endp,10) + }; + if(nump[0]==' '||*endp!=' '){ + fprintf(debugf,"net_handle_recv: invalid number argument to 'online' <%s>\n",msg); + return; + } + cb(fd,res,payload); + free(res.online.username); } else { fprintf(debugf,"net_handle_recv: unknown command <%s>\n",msg); } diff --git a/weechat/net.h b/weechat/net.h index 7e18f4c..335664c 100644 --- a/weechat/net.h +++ b/weechat/net.h @@ -15,6 +15,7 @@ enum net_response_type{ NET_MESSAGE, NET_JOIN, NET_INVITE, + NET_ONLINE, }; struct net_history_item{ @@ -43,6 +44,10 @@ struct net_response{ i64 timestamp; char *message; }; + struct { + char *username; + i64 num; + } online; }; }; diff --git a/weechat/tomsg.c b/weechat/tomsg.c index 01aa995..6e9042b 100644 --- a/weechat/tomsg.c +++ b/weechat/tomsg.c @@ -155,7 +155,6 @@ static void isonline_net_callback(int fd,struct net_response res,void *payload){ free(rn); struct t_gui_nick *nickp=weechat_nicklist_search_nick(room->buffer,room->buffer_nickgroup,name); - fprintf(debugf," nickp=%p: setting '%s' to '%s'\n",nickp,name,color); free(name); if(nickp==NULL)return; weechat_nicklist_nick_set(room->buffer,nickp,"color",color); @@ -232,6 +231,18 @@ static void push_net_callback(int fd,struct net_response res,void *payload){ } else { assert(false); } + } else if(res.type==NET_PONG){ + // ok + } else if(res.type==NET_ONLINE){ + fprintf(debugf," NET_ONLINE with username='%s' num='%" PRIi64 "'\n",res.online.username,res.online.num); + const char *color=res.online.num>0 ? "weechat.color.chat_nick" : "weechat.color.nicklist_away"; + for(i64 i=0;inrooms;i++){ + struct t_gui_nick *nickp=weechat_nicklist_search_nick( + conn->rooms[i]->buffer,conn->rooms[i]->buffer_nickgroup,res.online.username); + if(nickp!=NULL){ + weechat_nicklist_nick_set(conn->rooms[i]->buffer,nickp,"color",color); + } + } } else { fprintf(debugf,"push_net_callback: unknown response type %d\n",res.type); } -- cgit v1.2.3-70-g09d2