forked from PsychoticNinja/irssi
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:
parent
2440a5b0b6
commit
c39c27a1ff
@ -31,6 +31,22 @@
|
|||||||
|
|
||||||
#define BOTNET_RECONNECT_TIME (60*5)
|
#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)
|
static void sig_bot_read(BOT_REC *bot)
|
||||||
{
|
{
|
||||||
BOTNET_REC *botnet;
|
BOTNET_REC *botnet;
|
||||||
@ -53,7 +69,7 @@ static void sig_bot_read(BOT_REC *bot)
|
|||||||
if (reconnect) {
|
if (reconnect) {
|
||||||
/* wasn't intentional disconnection from
|
/* wasn't intentional disconnection from
|
||||||
our uplink, reconnect */
|
our uplink, reconnect */
|
||||||
botnet_connect(botnet->name);
|
botnet_connect(botnet);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -178,7 +194,7 @@ static void sig_botnet_connected(int handle, BOT_UPLINK_REC *uplink)
|
|||||||
|
|
||||||
if (handle == -1) {
|
if (handle == -1) {
|
||||||
/* error, try another bot */
|
/* error, try another bot */
|
||||||
botnet_connect(botnet->name);
|
botnet_connect(botnet);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,20 +215,16 @@ static void sig_botnet_connected(int handle, BOT_UPLINK_REC *uplink)
|
|||||||
bot_send_cmdv(bot, "NICK %s", botnet->nick);
|
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_REC *bot;
|
||||||
BOT_UPLINK_REC *uplink, *best;
|
BOT_UPLINK_REC *uplink, *best;
|
||||||
GSList *tmp;
|
GSList *tmp;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
g_return_val_if_fail(network != NULL, FALSE);
|
g_return_if_fail(botnet != NULL);
|
||||||
|
|
||||||
/* find botnet */
|
|
||||||
botnet = botnet_find(network);
|
|
||||||
if (botnet == NULL) return FALSE;
|
|
||||||
|
|
||||||
|
botnet->reconnect = FALSE;
|
||||||
if (botnet->bots == NULL) {
|
if (botnet->bots == NULL) {
|
||||||
/* create bot record for us */
|
/* create bot record for us */
|
||||||
bot = g_new0(BOT_REC, 1);
|
bot = g_new0(BOT_REC, 1);
|
||||||
@ -255,13 +267,14 @@ int botnet_connect(const char *network)
|
|||||||
best = uplink;
|
best = uplink;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (best == NULL)
|
if (best == NULL) {
|
||||||
return FALSE;
|
/* reconnect later */
|
||||||
|
botnet->reconnect = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* connect to uplink */
|
/* connect to uplink */
|
||||||
best->last_connect = time(NULL);
|
best->last_connect = time(NULL);
|
||||||
net_connect_nonblock(best->host, best->port, NULL, (NET_CALLBACK) sig_botnet_connected, best);
|
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)
|
static int botnet_send_botinfo(GNode *node, BOT_REC *client)
|
||||||
@ -534,6 +547,8 @@ static void cmd_bots(void)
|
|||||||
|
|
||||||
void botnet_connection_init(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", (SIGNAL_FUNC) botnet_event);
|
||||||
signal_add("botnet event sync", (SIGNAL_FUNC) botnet_event_sync);
|
signal_add("botnet event sync", (SIGNAL_FUNC) botnet_event_sync);
|
||||||
signal_add("botnet event botinfo", (SIGNAL_FUNC) botnet_event_botinfo);
|
signal_add("botnet event botinfo", (SIGNAL_FUNC) botnet_event_botinfo);
|
||||||
@ -544,6 +559,8 @@ void botnet_connection_init(void)
|
|||||||
|
|
||||||
void botnet_connection_deinit(void)
|
void botnet_connection_deinit(void)
|
||||||
{
|
{
|
||||||
|
g_source_remove(reconnect_tag);
|
||||||
|
|
||||||
signal_remove("botnet event", (SIGNAL_FUNC) botnet_event);
|
signal_remove("botnet event", (SIGNAL_FUNC) botnet_event);
|
||||||
signal_remove("botnet event sync", (SIGNAL_FUNC) botnet_event_sync);
|
signal_remove("botnet event sync", (SIGNAL_FUNC) botnet_event_sync);
|
||||||
signal_remove("botnet event botinfo", (SIGNAL_FUNC) botnet_event_botinfo);
|
signal_remove("botnet event botinfo", (SIGNAL_FUNC) botnet_event_botinfo);
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
void botnet_connection_init(void);
|
void botnet_connection_init(void);
|
||||||
void botnet_connection_deinit(void);
|
void botnet_connection_deinit(void);
|
||||||
|
|
||||||
static GSList *botnets;
|
GSList *botnets;
|
||||||
|
|
||||||
void bot_send_cmd(BOT_REC *bot, char *data)
|
void bot_send_cmd(BOT_REC *bot, char *data)
|
||||||
{
|
{
|
||||||
@ -591,7 +591,7 @@ static void autoconnect_botnets(void)
|
|||||||
BOTNET_REC *rec = tmp->data;
|
BOTNET_REC *rec = tmp->data;
|
||||||
|
|
||||||
if (rec->autoconnect)
|
if (rec->autoconnect)
|
||||||
botnet_connect(rec->name);
|
botnet_connect(rec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,7 @@ typedef struct {
|
|||||||
struct _botnet_rec {
|
struct _botnet_rec {
|
||||||
int connected:1;
|
int connected:1;
|
||||||
int autoconnect:1;
|
int autoconnect:1;
|
||||||
|
int reconnect:1;
|
||||||
|
|
||||||
char *name; /* botnet name */
|
char *name; /* botnet name */
|
||||||
char *nick; /* our nick in botnet */
|
char *nick; /* our nick in botnet */
|
||||||
@ -90,6 +91,8 @@ struct _botnet_rec {
|
|||||||
BOT_REC *master; /* link to current master */
|
BOT_REC *master; /* link to current master */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern GSList *botnets;
|
||||||
|
|
||||||
void bot_send_cmd(BOT_REC *bot, char *data);
|
void bot_send_cmd(BOT_REC *bot, char *data);
|
||||||
void bot_send_cmdv(BOT_REC *bot, char *format, ...);
|
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_downlink_destroy(BOT_DOWNLINK_REC *rec);
|
||||||
void bot_uplink_destroy(BOT_UPLINK_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);
|
void botnet_disconnect(BOTNET_REC *botnet);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user