From cabb16d3efbbae19f4da4ceed46610f63e0cd0ae Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 29 Sep 2020 23:14:32 +0200 Subject: weechat: Protocol version 3 compatible (sortof) --- weechat/tomsg.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'weechat/tomsg.c') diff --git a/weechat/tomsg.c b/weechat/tomsg.c index e5577bc..9701509 100644 --- a/weechat/tomsg.c +++ b/weechat/tomsg.c @@ -22,7 +22,7 @@ WEECHAT_PLUGIN_PRIORITY(1000) static const char *errpfx,*netpfx; -#define PROTOCOL_VERSION 2 +#define PROTOCOL_VERSION 3 #define NICK_COLOR "default" #define NICK_AWAY_COLOR "weechat.color.nicklist_away" @@ -272,8 +272,9 @@ static void room_update_attributes(struct roomdata *room){ static void close_room(struct roomdata *room){ debugf("close_room(room=%p)\n",room); - free(room->name); if(room->buffer)weechat_buffer_close(room->buffer); + if(roomtable)weechat_hashtable_remove(roomtable,room->name); + free(room->name); free(room); } @@ -454,7 +455,8 @@ static void push_net_callback(int fd,struct net_response res,void *payload){ debugf("push_net_callback(fd=%d,res={.type=%d})\n",fd,res.type); struct conndata *conn=weechat_hashtable_get(conntable,&fd); assert(conn); - if(res.type==NET_MESSAGE||res.type==NET_HISTORY||res.type==NET_JOIN||res.type==NET_INVITE){ + if(res.type==NET_MESSAGE||res.type==NET_HISTORY||res.type==NET_JOIN|| + res.type==NET_INVITE||res.type==NET_LEAVE){ i64 roomi; for(roomi=0;roominrooms;roomi++){ if(strcmp(conn->rooms[roomi]->name,res.room)==0){ @@ -466,7 +468,7 @@ static void push_net_callback(int fd,struct net_response res,void *payload){ return; } struct roomdata *room=conn->rooms[roomi]; - if(room->buffer==NULL){ + if(room->buffer==NULL&&res.type!=NET_LEAVE){ create_room_buffer(room); } @@ -498,8 +500,21 @@ static void push_net_callback(int fd,struct net_response res,void *payload){ room->nmembers++; room_update_attributes(room); } else if(res.type==NET_INVITE){ - weechat_printf(room->buffer,"%sYou were invited into this room",netpfx); + if(conn->username!=NULL&&strcmp(res.username,conn->username)==0){ + weechat_printf(room->buffer,"%sYou created this room in another session",netpfx); + } else { + weechat_printf(room->buffer,"%sYou were invited into this room",netpfx); + } net_sendf(fd,history_net_callback,room,"history %s 10",room->name); + } else if(res.type==NET_LEAVE){ + if(conn->username!=NULL&&strcmp(res.username,conn->username)==0){ + close_room(room); + if(roominrooms-1)conn->rooms[roomi]=conn->rooms[conn->nrooms-1]; + conn->nrooms--; + } else { + weechat_printf(room->buffer,"%sUser %s left the room",netpfx,res.username); + net_sendf(fd,members_net_callback,room,"list_members %s",room->name); + } } else { assert(false); } @@ -509,6 +524,7 @@ static void push_net_callback(int fd,struct net_response res,void *payload){ debugf(" NET_ONLINE with username='%s' num='%" PRIi64 "'\n",res.online.username,res.online.num); const char *color=res.online.num>0 ? NICK_COLOR : NICK_AWAY_COLOR; for(i64 i=0;inrooms;i++){ + if(!conn->rooms[i]->buffer)continue; struct t_gui_nick *nickp=weechat_nicklist_search_nick( conn->rooms[i]->buffer,conn->rooms[i]->buffer_nickgroup,res.online.username); if(nickp!=NULL){ @@ -594,11 +610,6 @@ static void conn_destroy(struct conndata *conn){ weechat_unhook(conn->fd_hook); if(conntable)weechat_hashtable_remove(conntable,&conn->fd); - if(roomtable){ - for(int i=0;inrooms;i++){ - weechat_hashtable_remove(roomtable,conn->rooms[i]->name); - } - } for(int i=0;inrooms;i++){ close_room(conn->rooms[i]); -- cgit v1.2.3-54-g00ecf