view plugins/autorecon.c @ 1345:d6e6fcaa1f39

[gaim-migrate @ 1355] ok. messages work. transports sort of work (you'll sign into them if you have them, but you won't see them and you can't add or remove them). resource is not a part of buddy's names, which is a very very big plus, since it means things will work incredibly well now. at some point the resource may be added back somehow but if it is it won't be part of the name. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 21 Dec 2000 13:54:22 +0000
parents 3daec853f3c6
children aedeb1218a0a
line wrap: on
line source

#define GAIM_PLUGINS
#include "gaim.h"
#include <gtk/gtk.h>

extern GtkWidget *imaway;

static int recon;
static int away_state;
static int forced_off = 0;
static struct away_message *last_away;

char *name() {
	return "Auto Reconnect";
}

char *description() {
	return "When AOL kicks you off, this auto-reconnects you.";
}

void do_signon(char *name) {
	struct aim_user *u = find_user(name, -1);
	g_free(name);
	gtk_timeout_remove(recon);
	if (!u) return;
	serv_login(u);
	forced_off = 0;
	if (away_state) do_away_message(NULL, last_away);
}

void reconnect(struct gaim_connection *gc, void *m) {
	char *name = g_strdup(gc->username);
	recon = gtk_timeout_add(8000, (GtkFunction)do_signon, name);
	forced_off = 1;
}

void away_toggle(void *m) {
	if ((int)m == 1) {
		last_away = awaymessage;
		away_state = 1;
	} else if (!forced_off)
		away_state = 0;
}

char *gaim_plugin_init(GModule *handle) {
	if (imaway) {
		away_state = 1;
		last_away = awaymessage;
	} else
		away_state = 0;

	gaim_signal_connect(handle, event_away, away_toggle, (void *)1);
	gaim_signal_connect(handle, event_back, away_toggle, (void *)0);
	gaim_signal_connect(handle, event_signoff, reconnect, NULL);

	return NULL;
}