From c39c27a1ff26bc6deee5335db85d3f993d2aca55 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 25 May 2000 14:34:40 +0000 Subject: If we couldn't connect to any of our uplinks, wait for 5 minutes and try again. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@240 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/irc/bot/botnet-connection.c | 41 +++++++++++++++++++++++++++++------------ src/irc/bot/botnet.c | 4 ++-- src/irc/bot/botnet.h | 5 ++++- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/irc/bot/botnet-connection.c b/src/irc/bot/botnet-connection.c index fa0d10c5..2b402e88 100644 --- a/src/irc/bot/botnet-connection.c +++ b/src/irc/bot/botnet-connection.c @@ -31,6 +31,22 @@ #define BOTNET_RECONNECT_TIME (60*5) +static int reconnect_tag; + +static int sig_reconnect(void) +{ + GSList *tmp; + + for (tmp = botnets; tmp != NULL; tmp = tmp->next) { + BOTNET_REC *rec = tmp->data; + + if (rec->reconnect) + botnet_connect(rec); + } + + return 1; +} + static void sig_bot_read(BOT_REC *bot) { BOTNET_REC *botnet; @@ -53,7 +69,7 @@ static void sig_bot_read(BOT_REC *bot) if (reconnect) { /* wasn't intentional disconnection from our uplink, reconnect */ - botnet_connect(botnet->name); + botnet_connect(botnet); } break; } @@ -178,7 +194,7 @@ static void sig_botnet_connected(int handle, BOT_UPLINK_REC *uplink) if (handle == -1) { /* error, try another bot */ - botnet_connect(botnet->name); + botnet_connect(botnet); return; } @@ -199,20 +215,16 @@ static void sig_botnet_connected(int handle, BOT_UPLINK_REC *uplink) bot_send_cmdv(bot, "NICK %s", botnet->nick); } -int botnet_connect(const char *network) +void botnet_connect(BOTNET_REC *botnet) { - BOTNET_REC *botnet; BOT_REC *bot; BOT_UPLINK_REC *uplink, *best; GSList *tmp; time_t now; - g_return_val_if_fail(network != NULL, FALSE); - - /* find botnet */ - botnet = botnet_find(network); - if (botnet == NULL) return FALSE; + g_return_if_fail(botnet != NULL); + botnet->reconnect = FALSE; if (botnet->bots == NULL) { /* create bot record for us */ bot = g_new0(BOT_REC, 1); @@ -255,13 +267,14 @@ int botnet_connect(const char *network) best = uplink; } - if (best == NULL) - return FALSE; + if (best == NULL) { + /* reconnect later */ + botnet->reconnect = TRUE; + } /* connect to uplink */ best->last_connect = time(NULL); net_connect_nonblock(best->host, best->port, NULL, (NET_CALLBACK) sig_botnet_connected, best); - return TRUE; } static int botnet_send_botinfo(GNode *node, BOT_REC *client) @@ -534,6 +547,8 @@ static void cmd_bots(void) void botnet_connection_init(void) { + reconnect_tag = g_timeout_add(BOTNET_RECONNECT_TIME*1000, (GSourceFunc) sig_reconnect, NULL); + signal_add("botnet event", (SIGNAL_FUNC) botnet_event); signal_add("botnet event sync", (SIGNAL_FUNC) botnet_event_sync); signal_add("botnet event botinfo", (SIGNAL_FUNC) botnet_event_botinfo); @@ -544,6 +559,8 @@ void botnet_connection_init(void) void botnet_connection_deinit(void) { + g_source_remove(reconnect_tag); + signal_remove("botnet event", (SIGNAL_FUNC) botnet_event); signal_remove("botnet event sync", (SIGNAL_FUNC) botnet_event_sync); signal_remove("botnet event botinfo", (SIGNAL_FUNC) botnet_event_botinfo); diff --git a/src/irc/bot/botnet.c b/src/irc/bot/botnet.c index 9331e1d4..03a1749c 100644 --- a/src/irc/bot/botnet.c +++ b/src/irc/bot/botnet.c @@ -32,7 +32,7 @@ void botnet_connection_init(void); void botnet_connection_deinit(void); -static GSList *botnets; +GSList *botnets; void bot_send_cmd(BOT_REC *bot, char *data) { @@ -591,7 +591,7 @@ static void autoconnect_botnets(void) BOTNET_REC *rec = tmp->data; if (rec->autoconnect) - botnet_connect(rec->name); + botnet_connect(rec); } } diff --git a/src/irc/bot/botnet.h b/src/irc/bot/botnet.h index 309d6745..722ba8be 100644 --- a/src/irc/bot/botnet.h +++ b/src/irc/bot/botnet.h @@ -71,6 +71,7 @@ typedef struct { struct _botnet_rec { int connected:1; int autoconnect:1; + int reconnect:1; char *name; /* botnet name */ char *nick; /* our nick in botnet */ @@ -90,6 +91,8 @@ struct _botnet_rec { BOT_REC *master; /* link to current master */ }; +extern GSList *botnets; + void bot_send_cmd(BOT_REC *bot, char *data); void bot_send_cmdv(BOT_REC *bot, char *format, ...); @@ -118,7 +121,7 @@ void bot_destroy(BOT_REC *bot); void bot_downlink_destroy(BOT_DOWNLINK_REC *rec); void bot_uplink_destroy(BOT_UPLINK_REC *rec); -int botnet_connect(const char *network); +void botnet_connect(BOTNET_REC *botnet); void botnet_disconnect(BOTNET_REC *botnet); #endif -- cgit v1.2.3