From 115003bd86a50e6d84fca063ab72451e317e787a Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Thu, 28 Jun 2007 17:23:18 +0000 Subject: Auto reconnect --- vchat-client.c | 27 ++++++++++++++++----------- vchat-commands.c | 11 +++++++++++ vchat-config.h | 1 + vchat-protocol.c | 1 + vchat.h | 2 +- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/vchat-client.c b/vchat-client.c index 56cc721..dc06015 100755 --- a/vchat-client.c +++ b/vchat-client.c @@ -37,7 +37,10 @@ char *vchat_cl_version = "$Id$"; /* we're logged in */ unsigned int loggedin = 0; /* we run as long as this is true */ -unsigned int status = 1; +int status = 1; +/* we set this, we WANT to quit */ +int ownquit = 0; + /* error string to show after exit */ char errstr[ERRSTRSIZE] = "\0"; @@ -522,9 +525,9 @@ main (int argc, char **argv) /* initialize userinterface */ initui (); - /* attempt connection */ - if (!vcconnect (getstroption(CF_SERVERHOST), getstroption(CF_SERVERPORT))) - { + while( status ) { + /* attempt connection */ + if (!vcconnect (getstroption(CF_SERVERHOST), getstroption(CF_SERVERPORT))) { snprintf (tmpstr, TMPSTRSIZE, "Could not connect to server, %s.", sys_errlist[errno]); strncpy(errstr,tmpstr,TMPSTRSIZE-2); @@ -533,20 +536,22 @@ main (int argc, char **argv) writecf (FS_ERR,tmpstr); /* exit condition */ status = 0; - } - else - { + } else { /* add stdin & server to masterdfs */ FD_ZERO (&masterfds); FD_SET (0, &masterfds); FD_SET (serverfd, &masterfds); } - while (status) - eventloop (); + while (status) + eventloop (); + + /* sanely close connection to server */ + vcdisconnect (); - /* sanely close connection to server */ - vcdisconnect (); + if( !ownquit && getintoption( CF_AUTORECONN ) ) + status = 1; + } /* call cleanup-hook without signal */ cleanup (0); diff --git a/vchat-commands.c b/vchat-commands.c index 5dc7b4f..8a4f475 100755 --- a/vchat-commands.c +++ b/vchat-commands.c @@ -27,6 +27,9 @@ /* version of this module */ char *vchat_cm_version = "$Id$"; +/* from vchat-client.c */ +extern int ownquit; + /* our "/command " table */ enum { COMMAND_VERSION, @@ -228,6 +231,10 @@ handleline (char *line) case 'O': dothink( line + 2, line[1] ); break; + case 'x': + /* inform vchat-client, that the following connection + drop was intentional */ + ownquit = 1; /* fallthrough intended */ default: /* generic server command, send to server, show to user */ snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_COMMAND), line); @@ -375,6 +382,10 @@ command_quit(char *tail) /* show action in channel window */ writechan (tmpstr); + + /* Inform vchat-client, that the closing connection + following is intended */ + ownquit = 1; } /* print out version */ diff --git a/vchat-config.h b/vchat-config.h index eb0afc1..34866b1 100755 --- a/vchat-config.h +++ b/vchat-config.h @@ -55,6 +55,7 @@ static volatile configoption configoptions[] = { {CF_SCROLLBPRIVT,CO_INT, "privscrollt",(char *) 0, (char *)-1, { NULL } }, {CF_SCROLLBACKT, CO_INT, "scrolltime", (char *) 86400, (char *)-1, { NULL } }, {CF_BELLPRIV, CO_INT, "bellonpm", (char *) 0, (char *)-1, { NULL } }, + {CF_AUTORECONN, CO_INT, "autoreconn", (char *) 0, (char *)-1, { NULL } }, {CF_NIL, CO_NIL, NULL, NULL, NULL, { NULL } }, }; diff --git a/vchat-protocol.c b/vchat-protocol.c index 274e856..af06c6a 100755 --- a/vchat-protocol.c +++ b/vchat-protocol.c @@ -243,6 +243,7 @@ serverlogin (char *message) networkoutput(".e utf8"); #endif } + /* parse and handle an idle message * format: 305 * vars: %s message */ diff --git a/vchat.h b/vchat.h index 83bae1f..613c0cd 100755 --- a/vchat.h +++ b/vchat.h @@ -39,7 +39,7 @@ typedef enum { CF_NIL, CF_NICK, CF_FROM, CF_SERVERHOST, CF_SERVERPORT, CF_CIPHERSUITE, CF_CONFIGFILE, CF_CERTFILE, CF_KEYFILE, CF_FORMFILE, CF_LOGINSCRIPT, CF_USESSL, CF_IGNSSL, CF_USECERT, CF_PRIVHEIGHT, CF_PRIVCOLLAPS, CF_HSCROLL, CF_CHANNEL, CF_USETIME, CF_USETOPIC, CF_SCROLLBPRIV, CF_SCROLLBACK, CF_SCROLLBPRIVT, CF_SCROLLBACKT, -CF_ENCODING, CF_BELLPRIV } confopt; +CF_ENCODING, CF_BELLPRIV, CF_AUTORECONN } confopt; /* format strings */ typedef enum { FS_PLAIN, FS_CHAN, FS_PRIV, FS_SERV, FS_GLOB, FS_DBG, FS_ERR, -- cgit v1.2.3