aboutsummaryrefslogtreecommitdiff
path: root/weechat/tomsg.c
diff options
context:
space:
mode:
Diffstat (limited to 'weechat/tomsg.c')
-rw-r--r--weechat/tomsg.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/weechat/tomsg.c b/weechat/tomsg.c
index 90e43b0..5a71afa 100644
--- a/weechat/tomsg.c
+++ b/weechat/tomsg.c
@@ -34,6 +34,8 @@ struct conndata{
struct t_gui_buffer *buffer;
+ bool negotiation_complete;
+
int nrooms,roomscap;
struct roomdata **rooms;
@@ -77,7 +79,7 @@ static void message_net_callback(int fd,struct net_response res,void *payload){
assert(conn);
if(res.type==NET_ERROR){
weechat_printf(conn->buffer,"tomsg: send threw error: %s",res.error);
- } else if(res.type!=NET_OK){
+ } else if(res.type!=NET_NUMBER){
fprintf(debugf,"message_net_callback: res.type=%d\n",res.type);
}
}
@@ -379,6 +381,11 @@ static int conn_input_cb(const void *conn_vp,void *_d,struct t_gui_buffer *buffe
(void)_d;
struct conndata *conn=(struct conndata*)conn_vp;
fprintf(debugf,"conn_input_cb(conn=%p,buffer=%p,input=\"%s\")\n",conn,buffer,input);
+
+ if(!conn->negotiation_complete){
+ weechat_printf(conn->buffer,"Server protocol version not yet negotiated, please wait...");
+ return WEECHAT_RC_OK;
+ }
char *input2=strdup(input);
assert(input2);
@@ -457,6 +464,20 @@ static int conn_close_cb(const void *conn_vp,void *_d,struct t_gui_buffer *buffe
return WEECHAT_RC_OK;
}
+static void version_net_callback(int fd,struct net_response res,void *payload){
+ (void)payload;
+ fprintf(debugf,"version_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_OK){
+ conn->negotiation_complete=true;
+ weechat_printf(conn->buffer,"Version negotiation complete.");
+ } else {
+ conn_destroy(conn);
+ weechat_printf(NULL,"tomsg: Server has incompatible protocol version (we want 1)!");
+ }
+}
+
static int connect_cb(const void *_p,void *hostname,int status,int _g,int fd,const char *err,const char *_i){
(void)_p; (void)_g; (void)_i;
switch(status){
@@ -466,6 +487,7 @@ static int connect_cb(const void *_p,void *hostname,int status,int _g,int fd,con
conn->fd=fd;
conn->fd_hook=weechat_hook_fd(fd,1,0,0,fd_hook_callback,conn,NULL);
conn->buffer=weechat_buffer_new((char*)hostname,conn_input_cb,conn,NULL,conn_close_cb,conn,NULL);
+ conn->negotiation_complete=false;
conn->nrooms=0;
conn->roomscap=2;
conn->rooms=malloc(conn->roomscap*sizeof(struct roomdata));
@@ -481,6 +503,8 @@ static int connect_cb(const void *_p,void *hostname,int status,int _g,int fd,con
weechat_hashtable_set(conntable,&fd,conn);
+ net_sendf(fd,version_net_callback,NULL,"version 1");
+
return WEECHAT_RC_OK;
}