diff options
author | Timo Sirainen <cras@irssi.org> | 2000-06-11 19:34:29 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2000-06-11 19:34:29 +0000 |
commit | 524a7ca1b970a7e16c032fdc0dec179b68a8c1d8 (patch) | |
tree | 135eba69abb407e78205ff723ff8bf0a78423387 /src/irc | |
parent | e6187b66e9f0108af71ff23358fb19f5a2657cf0 (diff) | |
download | irssi-524a7ca1b970a7e16c032fdc0dec179b68a8c1d8.zip |
If you're not allowed to connect to server (K-lined, no I-line), Irssi
won't try to reconnect back to the server.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@322 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/irc')
-rw-r--r-- | src/irc/core/irc-server.c | 22 | ||||
-rw-r--r-- | src/irc/core/irc-server.h | 1 | ||||
-rw-r--r-- | src/irc/core/server-reconnect.c | 18 | ||||
-rw-r--r-- | src/irc/core/server-setup.h | 3 |
4 files changed, 36 insertions, 8 deletions
diff --git a/src/irc/core/irc-server.c b/src/irc/core/irc-server.c index 417beb38..d4d58774 100644 --- a/src/irc/core/irc-server.c +++ b/src/irc/core/irc-server.c @@ -66,7 +66,7 @@ void irc_server_connect_free(IRC_SERVER_CONNECT_REC *rec) g_free_not_null(rec->channels); g_free_not_null(rec->away_reason); g_free_not_null(rec->usermode); - g_free(rec->address); + g_free_not_null(rec->address); g_free(rec); } @@ -404,6 +404,22 @@ static void event_server_info(const char *data, IRC_SERVER_REC *server) g_free(params); } +static void event_server_banned(const char *data, IRC_SERVER_REC *server) +{ + g_return_if_fail(server != NULL); + + server->banned = TRUE; +} + +static void event_error(const char *data, IRC_SERVER_REC *server) +{ + g_return_if_fail(server != NULL); + + if (!server->connected && (stristr(data, "Unauthorized") != NULL || + stristr(data, "K-lined") != NULL)) + server->banned = TRUE; +} + static void event_ping(const char *data, IRC_SERVER_REC *server) { char *str; @@ -432,6 +448,8 @@ void irc_servers_init(void) signal_add_last("server connect failed", (SIGNAL_FUNC) sig_connect_failed); signal_add("event 001", (SIGNAL_FUNC) event_connected); signal_add("event 004", (SIGNAL_FUNC) event_server_info); + signal_add("event 465", (SIGNAL_FUNC) event_server_banned); + signal_add("event error", (SIGNAL_FUNC) event_error); signal_add("event ping", (SIGNAL_FUNC) event_ping); signal_add("event empty", (SIGNAL_FUNC) event_empty); @@ -455,6 +473,8 @@ void irc_servers_deinit(void) signal_remove("server connect failed", (SIGNAL_FUNC) sig_connect_failed); signal_remove("event 001", (SIGNAL_FUNC) event_connected); signal_remove("event 004", (SIGNAL_FUNC) event_server_info); + signal_remove("event 465", (SIGNAL_FUNC) event_server_banned); + signal_remove("event error", (SIGNAL_FUNC) event_error); signal_remove("event ping", (SIGNAL_FUNC) event_ping); signal_remove("event empty", (SIGNAL_FUNC) event_empty); diff --git a/src/irc/core/irc-server.h b/src/irc/core/irc-server.h index 00ced177..36eac8ab 100644 --- a/src/irc/core/irc-server.h +++ b/src/irc/core/irc-server.h @@ -85,6 +85,7 @@ typedef struct { char *away_reason; int usermode_away:1; int server_operator:1; + int banned:1; /* not allowed to connect to this server */ int whois_coming:1; /* Mostly just to display away message right.. */ int whois_found:1; /* Did WHOIS return any entries? */ diff --git a/src/irc/core/server-reconnect.c b/src/irc/core/server-reconnect.c index c4821364..ea947133 100644 --- a/src/irc/core/server-reconnect.c +++ b/src/irc/core/server-reconnect.c @@ -128,6 +128,10 @@ static void server_connect_copy_skeleton(IRC_SERVER_CONNECT_REC *dest, IRC_SERVE dest->max_msgs = src->max_msgs; } +#define server_should_reconnect(server) \ + (irc_server_check(server) && (server)->connection_lost && \ + ((server)->connrec->ircnet != NULL || !(server)->banned)) + static void sig_reconnect(IRC_SERVER_REC *server) { IRC_SERVER_CONNECT_REC *conn; @@ -138,7 +142,7 @@ static void sig_reconnect(IRC_SERVER_REC *server) g_return_if_fail(server != NULL); - if (reconnect_time == -1 || !server->connection_lost || !irc_server_check(server)) + if (reconnect_time == -1 || !server_should_reconnect(server)) return; conn = g_new0(IRC_SERVER_CONNECT_REC, 1); @@ -168,6 +172,7 @@ static void sig_reconnect(IRC_SERVER_REC *server) sserver->last_connect = server->connect_time == 0 ? time(NULL) : server->connect_time; sserver->last_failed = !server->connected; + if (server->banned) sserver->banned = TRUE; } if (sserver == NULL || conn->ircnet == NULL) { @@ -198,10 +203,9 @@ static void sig_reconnect(IRC_SERVER_REC *server) for (tmp = setupservers; tmp != NULL; tmp = tmp->next) { SETUP_SERVER_REC *rec = tmp->data; - if (rec->ircnet == NULL || g_strcasecmp(conn->ircnet, rec->ircnet) != 0) - continue; - - if (!rec->last_connect || !rec->last_failed || rec->last_connect < now-FAILED_RECONNECT_WAIT) { + if (rec->ircnet != NULL && g_strcasecmp(conn->ircnet, rec->ircnet) == 0 && + !rec->banned && (!rec->last_connect || !rec->last_failed || + rec->last_connect < now-FAILED_RECONNECT_WAIT)) { sserver_connect(rec, conn); return; } @@ -215,7 +219,8 @@ static void sig_reconnect(IRC_SERVER_REC *server) if (!found && g_strcasecmp(rec->address, server->connrec->address) == 0 && server->connrec->port == rec->port) found = TRUE; - else if (found && rec->ircnet != NULL && g_strcasecmp(conn->ircnet, rec->ircnet) == 0) { + else if (found && !rec->banned && rec->ircnet != NULL && + g_strcasecmp(conn->ircnet, rec->ircnet) == 0) { sserver_connect(rec, conn); break; } @@ -228,6 +233,7 @@ static void sig_reconnect(IRC_SERVER_REC *server) if (through) { /* shouldn't happen unless there's no servers in this ircnet in setup.. */ + irc_server_connect_free(conn); break; } diff --git a/src/irc/core/server-setup.h b/src/irc/core/server-setup.h index 5c893044..8fc6d378 100644 --- a/src/irc/core/server-setup.h +++ b/src/irc/core/server-setup.h @@ -18,7 +18,8 @@ typedef struct { IPADDR *own_ip; /* resolved own_address if not NULL */ time_t last_connect; /* to avoid reconnecting too fast.. */ - int last_failed; /* if last connection attempt failed */ + int last_failed:1; /* if last connection attempt failed */ + int banned:1; /* if we're banned from this server */ } SETUP_SERVER_REC; extern GSList *setupservers; /* list of irc servers */ |