view plugins/autorecon.c @ 3510:e23909729192

[gaim-migrate @ 3576] A GNOME2 docklet. This follows the opendesktop.org specs used by GNOME2 and (I think) KDE in Redhat's null (I don't think vanilla KDE supports it yet) For GNOME--you will need to have the GNOME Panel Notification Area installed. This replaces the applet--thanks Robert McQueen. CVS: ---------------------------------------------------------------------- CVS: Enter Log. Lines beginning with `CVS:' are removed automatically CVS: CVS: Committing in . CVS: CVS: Modified Files: CVS: configure.ac configure.in plugins/Makefile.am src/aim.c CVS: src/buddy.c src/core.h src/module.c src/multi.c src/perl.c CVS: src/server.c src/ui.h CVS: ---------------------------------------------------------------------- committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Sat, 14 Sep 2002 23:27:28 +0000
parents 837f8ff999be
children 9682c0e022c6
line wrap: on
line source

#define GAIM_PLUGINS
#include "gaim.h"
#include "prpl.h"

#define INITIAL 8000
#define MAXTIME 1024000

static GHashTable *hash = NULL;

static guint tim = 0;

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

char *description() {
	return "When you are kicked offline, this reconnects you.";
}

static gboolean do_signon(gpointer data) {
	struct aim_user *u = data;
	if (g_slist_index(aim_users, u) < 0)
		return FALSE;
	serv_login(u);
	tim = 0;
	return FALSE;
}

static void reconnect(struct gaim_connection *gc, void *m) {
	if (!gc->wants_to_die) {
		int del;
		del = (int)g_hash_table_lookup(hash, gc->user);
		if (!del)
			del = INITIAL;
		else
			del = MAX(2 * del, MAXTIME);
		tim = g_timeout_add(del, do_signon, gc->user);
		g_hash_table_insert(hash, gc->user, (gpointer)del);
	} else {
		g_hash_table_remove(hash, gc->user);
	}
}

char *gaim_plugin_init(GModule *handle) {
	hash = g_hash_table_new(g_int_hash, g_int_equal);

	gaim_signal_connect(handle, event_signoff, reconnect, NULL);

	return NULL;
}

void gaim_plugin_remove() {
	if (tim)
		g_source_remove(tim);
	g_hash_table_destroy(hash);
	hash = NULL;
	tim = 0;
}