aboutsummaryrefslogtreecommitdiff
path: root/weechat
diff options
context:
space:
mode:
Diffstat (limited to 'weechat')
-rw-r--r--weechat/net.c10
-rw-r--r--weechat/net.h1
-rw-r--r--weechat/tomsg.c31
3 files changed, 29 insertions, 13 deletions
diff --git a/weechat/net.c b/weechat/net.c
index ce8da6a..5b88605 100644
--- a/weechat/net.c
+++ b/weechat/net.c
@@ -361,10 +361,14 @@ void net_handle_recv(int fd,const char *msg){
cb(fd,res,payload);
free(res.room);
free(res.username);
- } else if(cmdlen==6&&memcmp(cmd,"invite",6)==0){
+ } else if((cmdlen==6&&memcmp(cmd,"invite",6)==0)||
+ (cmdlen==5&&memcmp(cmd,"leave",5)==0)){
+ enum net_response_type cmd_type=cmdlen==6?NET_INVITE:NET_LEAVE;
+
const char *q;
if(*p=='\0'||(q=strchr(p+1,' '))==NULL){
- debugf("net_handle_recv: no arguments to 'invite' <%s>\n",msg);
+ debugf("net_handle_recv: no arguments to '%s' <%s>\n",
+ cmd_type==NET_INVITE?"invite":"leave",msg);
return;
}
const char *roomp=p+1;
@@ -373,7 +377,7 @@ void net_handle_recv(int fd,const char *msg){
i64 userlen=msglen-(userp-msg);
struct net_response res;
- res.type=NET_INVITE;
+ res.type=cmd_type;
res.room=malloc(roomlen+1);
res.username=malloc(userlen+1);
assert(res.room&&res.username);
diff --git a/weechat/net.h b/weechat/net.h
index 4a61bca..db86ec3 100644
--- a/weechat/net.h
+++ b/weechat/net.h
@@ -21,6 +21,7 @@ enum net_response_type{
NET_HISTORY, // room, username, timestamp, msgid, replyid, message
NET_JOIN, // room, username
NET_INVITE, // room, username
+ NET_LEAVE, // room, username
NET_ONLINE, // online.username, online.num
};
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;roomi<conn->nrooms;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(roomi<conn->nrooms-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;i<conn->nrooms;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;i<conn->nrooms;i++){
- weechat_hashtable_remove(roomtable,conn->rooms[i]->name);
- }
- }
for(int i=0;i<conn->nrooms;i++){
close_room(conn->rooms[i]);