From 01659e3ff66af10d4fb8efaa7a5ac8400712a959 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sun, 8 May 2005 15:50:59 +0000 Subject: [PATCH] Fixed server delete config handling --- mbtask/taskibc.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/mbtask/taskibc.c b/mbtask/taskibc.c index 81190e06..f932b65f 100644 --- a/mbtask/taskibc.c +++ b/mbtask/taskibc.c @@ -578,8 +578,8 @@ void check_servers(void) { char *errmsg, scfgfn[PATH_MAX]; FILE *fp; - ncs_list *tnsl; - int j, inlist; + ncs_list *tnsl, **tmp; + int j, inlist, Remove; int a1, a2, a3, a4; struct servent *se; struct hostent *he; @@ -613,6 +613,7 @@ void check_servers(void) if (!inlist ) { fill_ncslist(&ncsl, ibcsrv.server, ibcsrv.myname, ibcsrv.passwd); srvchg = TRUE; + callchg = TRUE; Syslog('+', "IBC: new configured Internet BBS Chatserver: %s", ibcsrv.server); } } @@ -635,6 +636,7 @@ void check_servers(void) tnsl->remove = TRUE; tnsl->action = now; srvchg = TRUE; + callchg = TRUE; } } fclose(fp); @@ -645,6 +647,49 @@ void check_servers(void) dump_ncslist(); + Remove = FALSE; + for (tnsl = ncsl; tnsl; tnsl = tnsl->next) { + if (tnsl->remove) { + Remove = TRUE; + Syslog('r', "Remove server %s", tnsl->server); + if (tnsl->state == NCS_CONNECT) { + broadcast(tnsl->server, "SQUIT %s Removed from configuration\r\n", tnsl->server); + send_msg(tnsl, "SQUIT %s Your system is removed from configuration\r\n", tnsl->myname); + del_router(&servers, tnsl->server); + } + if (tnsl->socket != -1) { + Syslog('r', "Closing socket %d", tnsl->socket); + shutdown(tnsl->socket, SHUT_WR); + tnsl->socket = -1; + } + callchg = TRUE; + srvchg = TRUE; + } + } + + dump_ncslist(); + + /* + * If a neighbour is removed by configuration, remove it from the list. + */ + if (Remove) { + Syslog('r', "Starting remove list"); + tmp = &ncsl; + while (*tmp) { + if ((*tmp)->remove) { + Syslog('r', "do %s", (*tmp)->server); + tnsl = *tmp; + *tmp = (*tmp)->next; + free(tnsl); + callchg = TRUE; + } else { + tmp = &((*tmp)->next); + } + } + } + + dump_ncslist(); + /* * Check if we need to make state changes */