diff --git a/src/core/server-connect-rec.h b/src/core/server-connect-rec.h index f1b3d075..bf54f267 100644 --- a/src/core/server-connect-rec.h +++ b/src/core/server-connect-rec.h @@ -9,6 +9,7 @@ int proxy_port; char *proxy_string, *proxy_password; unsigned short family; /* 0 = don't care, AF_INET or AF_INET6 */ +char *tag; /* try to keep this tag when connected to server */ char *address; int port; char *chatnet; diff --git a/src/core/servers-reconnect.c b/src/core/servers-reconnect.c index a9491f92..32d8195a 100644 --- a/src/core/servers-reconnect.c +++ b/src/core/servers-reconnect.c @@ -37,6 +37,9 @@ static int reconnect_time; void reconnect_save_status(SERVER_CONNECT_REC *conn, SERVER_REC *server) { + g_free_not_null(conn->tag); + conn->tag = g_strdup(server->tag); + g_free_not_null(conn->away_reason); conn->away_reason = !server->usermode_away ? NULL : g_strdup(server->away_reason); @@ -133,6 +136,8 @@ server_connect_copy_skeleton(SERVER_CONNECT_REC *src, int connect_info) dest->proxy_string = g_strdup(src->proxy_string); dest->proxy_password = g_strdup(src->proxy_password); + dest->tag = g_strdup(src->tag); + if (connect_info) { dest->family = src->family; dest->address = g_strdup(src->address); @@ -224,7 +229,7 @@ static void sig_reconnect(SERVER_REC *server) } /* always try to first connect to the first on the list where we - haven't got unsuccessful connection attempts for the last half + haven't got unsuccessful connection attempts for the past half an hour. */ now = time(NULL); @@ -385,13 +390,11 @@ static void cmd_reconnect(const char *data, SERVER_REC *server) static void cmd_disconnect(const char *data, SERVER_REC *server) { RECONNECT_REC *rec; - int tag; if (g_strncasecmp(data, "RECON-", 6) != 0) return; /* handle only reconnection removing */ - rec = sscanf(data+6, "%d", &tag) == 1 && tag > 0 ? - reconnect_find_tag(tag) : NULL; + rec = reconnect_find_tag(atoi(data+6)); if (rec == NULL) signal_emit("server reconnect not found", 1, data); diff --git a/src/core/servers-reconnect.h b/src/core/servers-reconnect.h index b51486f6..bf3e640d 100644 --- a/src/core/servers-reconnect.h +++ b/src/core/servers-reconnect.h @@ -6,7 +6,7 @@ #define FAILED_RECONNECT_WAIT (60*30) typedef struct { - int tag; + int tag; time_t next_connect; SERVER_CONNECT_REC *conn; diff --git a/src/core/servers.c b/src/core/servers.c index f74e7f58..0707645c 100644 --- a/src/core/servers.c +++ b/src/core/servers.c @@ -101,12 +101,23 @@ static char *server_create_tag(SERVER_CONNECT_REC *conn) char *tag; int num; - g_return_val_if_fail(IS_SERVER_CONNECT(conn), NULL); + g_return_val_if_fail(IS_SERVER_CONNECT(conn), NULL); tag = conn->chatnet != NULL && *conn->chatnet != '\0' ? g_strdup(conn->chatnet) : server_create_address_tag(conn->address); + if (conn->tag != NULL && server_find_tag(conn->tag) == NULL && + strncmp(conn->tag, tag, strlen(tag)) == 0) { + /* use the existing tag if it begins with the same ID - + this is useful when you have several connections to + same server and you want to keep the same tags with + the servers (or it would cause problems when rejoining + /LAYOUT SAVEd channels). */ + return g_strdup(conn->tag); + } + + /* then just append numbers after tag until unused is found.. */ str = g_string_new(tag); for (num = 2; server_find_tag(str->str) != NULL; num++) @@ -410,6 +421,7 @@ void server_connect_free(SERVER_CONNECT_REC *conn) g_free_not_null(conn->proxy_string); g_free_not_null(conn->proxy_password); + g_free_not_null(conn->tag); g_free_not_null(conn->address); g_free_not_null(conn->chatnet);