1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

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
This commit is contained in:
Timo Sirainen 2000-05-25 14:34:40 +00:00 committed by cras
parent 2440a5b0b6
commit c39c27a1ff
3 changed files with 35 additions and 15 deletions

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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