diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-04-15 09:59:11 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-04-15 09:59:11 +0200 |
commit | 9800ecb1e93d398988a6904d5e4dc6c4e11aedb0 (patch) | |
tree | c7da366fb4c640bba0b205d0b44013883b772cef | |
parent | ffda2b39b6fe070a3f5edb229dd7806c362cc9e1 (diff) |
weechat: Support sending user pings
-rw-r--r-- | weechat/net.c | 5 | ||||
-rw-r--r-- | weechat/net.h | 1 | ||||
-rw-r--r-- | weechat/tomsg.c | 14 |
3 files changed, 20 insertions, 0 deletions
diff --git a/weechat/net.c b/weechat/net.c index 6324cb7..fb9ec8e 100644 --- a/weechat/net.c +++ b/weechat/net.c @@ -154,6 +154,11 @@ void net_handle_recv(int fd,const char *msg){ free(res.name); } else if(cmdlen==4&&memcmp(cmd,"ping",4)==0){ // Do nothing + } else if(cmdlen==4&&memcmp(cmd,"pong",4)==0){ + struct net_response res=(struct net_response){ + .type=NET_PONG + }; + cb(fd,res,payload); } else if(cmdlen==4&&memcmp(cmd,"list",4)==0){ struct net_response res=(struct net_response){.type=NET_LIST}; if(*p=='\0'){ diff --git a/weechat/net.h b/weechat/net.h index c8b0f03..86aa271 100644 --- a/weechat/net.h +++ b/weechat/net.h @@ -9,6 +9,7 @@ enum net_response_type{ NET_ERROR, NET_NAME, NET_LIST, + NET_PONG, NET_HISTORY, NET_MESSAGE, NET_JOIN, diff --git a/weechat/tomsg.c b/weechat/tomsg.c index 2954a47..3b188ec 100644 --- a/weechat/tomsg.c +++ b/weechat/tomsg.c @@ -259,6 +259,18 @@ static void login_net_callback(int fd,struct net_response res,void *payload){ } } +static void pong_net_callback(int fd,struct net_response res,void *payload){ + (void)payload; + fprintf(debugf,"pong_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_PONG){ + weechat_printf(conn->buffer,"pong"); + } else { + fprintf(debugf,"pong_net_callback: res.type=%d\n",res.type); + } +} + static void conn_destroy(struct conndata *conn){ fprintf(debugf,"conn_destroy(conn=%p (fd=%d))\n",conn,conn->fd); weechat_unhook(conn->fd_hook); @@ -335,6 +347,8 @@ static int conn_input_cb(const void *conn_vp,void *_d,struct t_gui_buffer *buffe if(conn->pending_username)free(conn->pending_username); conn->pending_username=strdup(username); net_sendf(conn->fd,login_net_callback,NULL,"login %s %s",username,password); + } else if(strcmp(cmd,"ping")==0){ + net_sendf(conn->fd,pong_net_callback,NULL,"ping"); } else { weechat_printf(conn->buffer,"Unknown command '%s'",cmd); } |