summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2007-06-28 17:23:18 +0000
committererdgeist <>2007-06-28 17:23:18 +0000
commit115003bd86a50e6d84fca063ab72451e317e787a (patch)
tree492860e645ebae00dbd2269e4554c2506bd074fa
parent3c11bea99886b006ca499e1be6a3a17d225cedc7 (diff)
Auto reconnect
-rwxr-xr-xvchat-client.c27
-rwxr-xr-xvchat-commands.c11
-rwxr-xr-xvchat-config.h1
-rwxr-xr-xvchat-protocol.c1
-rwxr-xr-xvchat.h2
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$";
37/* we're logged in */ 37/* we're logged in */
38unsigned int loggedin = 0; 38unsigned int loggedin = 0;
39/* we run as long as this is true */ 39/* we run as long as this is true */
40unsigned int status = 1; 40int status = 1;
41/* we set this, we WANT to quit */
42int ownquit = 0;
43
41/* error string to show after exit */ 44/* error string to show after exit */
42char errstr[ERRSTRSIZE] = "\0"; 45char errstr[ERRSTRSIZE] = "\0";
43 46
@@ -522,9 +525,9 @@ main (int argc, char **argv)
522 /* initialize userinterface */ 525 /* initialize userinterface */
523 initui (); 526 initui ();
524 527
525 /* attempt connection */ 528 while( status ) {
526 if (!vcconnect (getstroption(CF_SERVERHOST), getstroption(CF_SERVERPORT))) 529 /* attempt connection */
527 { 530 if (!vcconnect (getstroption(CF_SERVERHOST), getstroption(CF_SERVERPORT))) {
528 snprintf (tmpstr, TMPSTRSIZE, "Could not connect to server, %s.", 531 snprintf (tmpstr, TMPSTRSIZE, "Could not connect to server, %s.",
529 sys_errlist[errno]); 532 sys_errlist[errno]);
530 strncpy(errstr,tmpstr,TMPSTRSIZE-2); 533 strncpy(errstr,tmpstr,TMPSTRSIZE-2);
@@ -533,20 +536,22 @@ main (int argc, char **argv)
533 writecf (FS_ERR,tmpstr); 536 writecf (FS_ERR,tmpstr);
534 /* exit condition */ 537 /* exit condition */
535 status = 0; 538 status = 0;
536 } 539 } else {
537 else
538 {
539 /* add stdin & server to masterdfs */ 540 /* add stdin & server to masterdfs */
540 FD_ZERO (&masterfds); 541 FD_ZERO (&masterfds);
541 FD_SET (0, &masterfds); 542 FD_SET (0, &masterfds);
542 FD_SET (serverfd, &masterfds); 543 FD_SET (serverfd, &masterfds);
543 } 544 }
544 545
545 while (status) 546 while (status)
546 eventloop (); 547 eventloop ();
548
549 /* sanely close connection to server */
550 vcdisconnect ();
547 551
548 /* sanely close connection to server */ 552 if( !ownquit && getintoption( CF_AUTORECONN ) )
549 vcdisconnect (); 553 status = 1;
554 }
550 555
551 /* call cleanup-hook without signal */ 556 /* call cleanup-hook without signal */
552 cleanup (0); 557 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 @@
27/* version of this module */ 27/* version of this module */
28char *vchat_cm_version = "$Id$"; 28char *vchat_cm_version = "$Id$";
29 29
30/* from vchat-client.c */
31extern int ownquit;
32
30/* our "/command " table */ 33/* our "/command " table */
31enum { 34enum {
32COMMAND_VERSION, 35COMMAND_VERSION,
@@ -228,6 +231,10 @@ handleline (char *line)
228 case 'O': 231 case 'O':
229 dothink( line + 2, line[1] ); 232 dothink( line + 2, line[1] );
230 break; 233 break;
234 case 'x':
235 /* inform vchat-client, that the following connection
236 drop was intentional */
237 ownquit = 1; /* fallthrough intended */
231 default: 238 default:
232 /* generic server command, send to server, show to user */ 239 /* generic server command, send to server, show to user */
233 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_COMMAND), line); 240 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_COMMAND), line);
@@ -375,6 +382,10 @@ command_quit(char *tail)
375 382
376 /* show action in channel window */ 383 /* show action in channel window */
377 writechan (tmpstr); 384 writechan (tmpstr);
385
386 /* Inform vchat-client, that the closing connection
387 following is intended */
388 ownquit = 1;
378} 389}
379 390
380/* print out version */ 391/* 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[] = {
55 {CF_SCROLLBPRIVT,CO_INT, "privscrollt",(char *) 0, (char *)-1, { NULL } }, 55 {CF_SCROLLBPRIVT,CO_INT, "privscrollt",(char *) 0, (char *)-1, { NULL } },
56 {CF_SCROLLBACKT, CO_INT, "scrolltime", (char *) 86400, (char *)-1, { NULL } }, 56 {CF_SCROLLBACKT, CO_INT, "scrolltime", (char *) 86400, (char *)-1, { NULL } },
57 {CF_BELLPRIV, CO_INT, "bellonpm", (char *) 0, (char *)-1, { NULL } }, 57 {CF_BELLPRIV, CO_INT, "bellonpm", (char *) 0, (char *)-1, { NULL } },
58 {CF_AUTORECONN, CO_INT, "autoreconn", (char *) 0, (char *)-1, { NULL } },
58 {CF_NIL, CO_NIL, NULL, NULL, NULL, { NULL } }, 59 {CF_NIL, CO_NIL, NULL, NULL, NULL, { NULL } },
59}; 60};
60 61
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)
243 networkoutput(".e utf8"); 243 networkoutput(".e utf8");
244#endif 244#endif
245} 245}
246
246/* parse and handle an idle message 247/* parse and handle an idle message
247 * format: 305 248 * format: 305
248 * vars: %s message */ 249 * 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,
39CF_CIPHERSUITE, CF_CONFIGFILE, CF_CERTFILE, CF_KEYFILE, CF_FORMFILE, CF_LOGINSCRIPT, 39CF_CIPHERSUITE, CF_CONFIGFILE, CF_CERTFILE, CF_KEYFILE, CF_FORMFILE, CF_LOGINSCRIPT,
40CF_USESSL, CF_IGNSSL, CF_USECERT, CF_PRIVHEIGHT, CF_PRIVCOLLAPS, CF_HSCROLL, CF_CHANNEL, CF_USETIME, 40CF_USESSL, CF_IGNSSL, CF_USECERT, CF_PRIVHEIGHT, CF_PRIVCOLLAPS, CF_HSCROLL, CF_CHANNEL, CF_USETIME,
41CF_USETOPIC, CF_SCROLLBPRIV, CF_SCROLLBACK, CF_SCROLLBPRIVT, CF_SCROLLBACKT, 41CF_USETOPIC, CF_SCROLLBPRIV, CF_SCROLLBACK, CF_SCROLLBPRIVT, CF_SCROLLBACKT,
42CF_ENCODING, CF_BELLPRIV } confopt; 42CF_ENCODING, CF_BELLPRIV, CF_AUTORECONN } confopt;
43 43
44/* format strings */ 44/* format strings */
45typedef enum { FS_PLAIN, FS_CHAN, FS_PRIV, FS_SERV, FS_GLOB, FS_DBG, FS_ERR, 45typedef enum { FS_PLAIN, FS_CHAN, FS_PRIV, FS_SERV, FS_GLOB, FS_DBG, FS_ERR,