diff --git a/VERSIONS b/VERSIONS index 94ef6e6..bb97927 100644 --- a/VERSIONS +++ b/VERSIONS @@ -1,5 +1,7 @@ 3.1 -- WORK IN PROGRESS (~May, 2018) + * Fixed: If the network interface goes down, the mech will mark all servers as unconnectable, + permanently, so even when the network comes back up... Fixed! * Fixed: Bug with bigsay characters defined with blank lines. * Changed: Session config is saved to "filename.sessiontemp" and once the save is complete its moved to "filename.session", just in case something happens that might create a corrupt diff --git a/src/core.c b/src/core.c index 235178e..a38a1b0 100644 --- a/src/core.c +++ b/src/core.c @@ -216,7 +216,7 @@ int write_session(void) #ifdef DYNCMD /* - * because of "chaccess XXX disable" its best to save chaccess last + * because of "chaccess ___ disable" its best to save chaccess last */ for(j=0;mcmd[j].name;j++) { @@ -689,7 +689,7 @@ void connect_to_server(void) { if ((!sptry) || (sp->usenum < sptry->usenum)) { - if (sp->err == 0) + if (sp->err == 0 || sp->err == SP_ERRCONN) sptry = sp; else if ( @@ -1130,12 +1130,7 @@ void process_server_input(void) sp = find_server(current->server); if (!sp) { -#ifdef IDWRAP - unlink_identfile(); -#endif /* IDWRAP */ - close(current->sock); - current->sock = -1; - return; + goto breaksock2; } #ifdef DEBUG debug("[PSI] Connecting via WinGate proxy...\n"); @@ -1152,6 +1147,7 @@ void process_server_input(void) } current->connect = CN_WINGATEWAIT; current->conntry = now; + current->heartbeat = 0; return; } #endif /* WINGATE */ @@ -1184,16 +1180,12 @@ get_line: } else { -#ifdef IDWRAP - unlink_identfile(); -#endif /* IDWRAP */ - close(current->sock); - current->sock = -1; - return; + goto breaksock2; } } #endif /* WINGATE */ current->conntry = now; + current->heartbeat = 0; parse_server_input(linebuf); goto get_line; } @@ -1203,19 +1195,47 @@ get_line: case EAGAIN: break; default: -#ifdef DEBUG - debug("[PSI] {%i} errno = %i; closing server socket\n",current->sock,errno); -#endif /* DEBUG */ - *current->sockdata = 0; -#ifdef IDWRAP - unlink_identfile(); -#endif /* IDWRAP */ - close(current->sock); - current->sock = -1; - current->connect = CN_NOSOCK; - break; + goto breaksock; } } + + /* server has been quiet for too long */ + if (current->conntry + SERVERSILENCETIMEOUT <= now && current->heartbeat == 0) + { +#ifdef DEBUG + debug("[PSI] {%i} server has been quiet for too long (%is)...\n",current->sock,SERVERSILENCETIMEOUT); +#endif /* DEBUG */ + /* push something to the server to test the socket, this should break a zombie socket */ + to_server("PING :LT%lu\n",current->conntry); + current->heartbeat = 1; + } + + /* server has been quiet for WAY too long */ + if (current->conntry + (SERVERSILENCETIMEOUT*2) <= now) + { +#ifdef DEBUG + debug("[PSI] {%i} server has been quiet for WAY too long (%is), forcing reconnect...\n",current->sock,SERVERSILENCETIMEOUT*2); +#endif /* DEBUG */ + errno = 110; /* connection timed out */ + goto breaksock; + } + + /* situation normal */ + return; + +breaksock: +#ifdef DEBUG + debug("[PSI] {%i} errno = %i; closing server socket\n",current->sock,errno); +#endif /* DEBUG */ +breaksock2: + *current->sockdata = 0; +#ifdef IDWRAP + unlink_identfile(); +#endif /* IDWRAP */ + close(current->sock); + current->sock = -1; + current->connect = CN_NOSOCK; + return; } /* diff --git a/src/debug.c b/src/debug.c index 77ab75c..bc3a984 100644 --- a/src/debug.c +++ b/src/debug.c @@ -260,6 +260,8 @@ LS const DEFstruct CNdefs[] = { CN_DISCONNECT, "CN_DISCONNECT" }, { CN_BOTDIE, "CN_BOTDIE" }, { CN_NEXTSERV, "CN_NEXTSERV" }, +{ CN_WINGATEWAIT, "CN_WINGATEWAIT" }, +{ CN_SPINNING, "CN_SPINNING" }, { 0, }}; LS const DEFstruct SPdefs[] = diff --git a/src/main.c b/src/main.c index 2ea05bf..c8aabe8 100644 --- a/src/main.c +++ b/src/main.c @@ -665,6 +665,7 @@ doit_jumptonext: } #endif /* RAWDNS */ } + /* not an else block since previous block might set sock to != -1 */ if (current->sock != -1) { if (current->ip.s_addr == 0) @@ -785,15 +786,6 @@ restart_dcc: if (current->connect == CN_ONLINE) { - /* - * Its possible to get stuck waiting forever if a FIN packet is lost - * unless you do this... - */ - if ((current->conntry - now) > SERVERSILENCETIMEOUT) - { - to_server("PING :%lu\n",now); - current->conntry += 10; /* send more unless an answer is received in <10 seconds */ - } /* * Keep server idle-timer low to seem like you are chatting */ diff --git a/src/seen.c b/src/seen.c index f37b2ac..dbc2622 100644 --- a/src/seen.c +++ b/src/seen.c @@ -884,9 +884,9 @@ void do_seen(COMMAND_ARGS) } if (h || d) { - sprintf(ago,"%s%i hour%s and ",ago,h,EXTRA_CHAR(h)); + sprintf(ago+strlen(ago),"%i hour%s and ",h,EXTRA_CHAR(h)); } - sprintf(ago,"%s%i minute%s",ago,m,EXTRA_CHAR(m)); + sprintf(ago+strlen(ago),"%i minute%s",m,EXTRA_CHAR(m)); n = seen->nick; u = seen->userhost; diff --git a/src/structs.h b/src/structs.h index 1af6c8c..6cd9f6c 100644 --- a/src/structs.h +++ b/src/structs.h @@ -579,6 +579,7 @@ typedef struct Mech time_t conntry; /* when connect try started */ /* re-used for server activity once connected */ + int heartbeat; /* handle server timeout stuff */ time_t activity; /* Away timer (AAWAY) */ time_t ontime; /* how long the bot has been connected */