Beispiel #1
0
static void update_reconnection(SERVER_CONNECT_REC *conn, SERVER_REC *server)
{
	SERVER_CONNECT_REC *oldconn;
	RECONNECT_REC *recon;

	if (server != NULL) {
		oldconn = server->connrec;
                server_connect_ref(oldconn);
                reconnect_save_status(conn, server);
	} else {
		/* maybe we can reconnect some server from
		   reconnection queue */
		recon = find_reconnect_server(conn->chat_type,
					      conn->address, conn->port);
		if (recon == NULL) return;

		oldconn = recon->conn;
                server_connect_ref(oldconn);
		server_reconnect_destroy(recon);

		conn->away_reason = g_strdup(oldconn->away_reason);
		conn->channels = g_strdup(oldconn->channels);
	}

	conn->reconnection = TRUE;

	if (conn->chatnet == NULL && oldconn->chatnet != NULL)
		conn->chatnet = g_strdup(oldconn->chatnet);

	server_connect_unref(oldconn);
	if (server != NULL) {
		signal_emit("command disconnect", 2,
			    "* Changing server", server);
	}
}
Beispiel #2
0
/* SYNTAX: SERVER [-ircnet <ircnet>] [-host <hostname>]
                  [+]<address>|<ircnet> [<port> [<password> [<nick>]]] */
static void cmd_server(const char *data, IRC_SERVER_REC *server,
		       void *item)
{
	GHashTable *optlist;
	IRC_SERVER_CONNECT_REC *conn;
	char *addr, *port, *channels, *away_reason, *usermode, *ircnet;
	void *free_arg;
	int no_old_server;

	g_return_if_fail(data != NULL);

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS,
			    "connect", &optlist, &addr, &port))
		return;

	if (*addr == '\0' || strcmp(addr, "+") == 0)
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	conn = server == NULL ? NULL : server->connrec;
	if (*addr != '+' && conn == NULL) {
		/* check if there's a server waiting for removal in
		   reconnection queue.. */
		RECONNECT_REC *rec;

		rec = find_reconnect_server(addr, atoi(port));
		if (rec != NULL) {
			/* remove the reconnection.. */
                        conn = (IRC_SERVER_CONNECT_REC *) rec->conn;
			server_reconnect_destroy(rec, FALSE);
		}
	}

	no_old_server = server == NULL;
	ircnet = conn == NULL ? NULL : g_strdup(conn->chatnet);
	if (*addr == '+' || conn == NULL) {
		channels = away_reason = usermode = NULL;
	} else if (server != NULL) {
		channels = irc_server_get_channels((IRC_SERVER_REC *) server);
		if (*channels == '\0')
			g_free_and_null(channels);
		away_reason = !server->usermode_away ? NULL :
			g_strdup(server->away_reason);
		usermode = g_strdup(server->usermode);
		signal_emit("command disconnect", 3,
			    "* Changing server", server, item);
	} else {
		channels = g_strdup(conn->channels);
		away_reason = g_strdup(conn->away_reason);
		usermode = g_strdup(conn->usermode);
	}

	server = IRC_SERVER(irc_connect_server(data));
	if (*addr == '+' || server == NULL ||
	    (ircnet != NULL && server->connrec->chatnet != NULL &&
	     g_strcasecmp(ircnet, server->connrec->chatnet) != 0)) {
		g_free_not_null(channels);
		g_free_not_null(usermode);
		g_free_not_null(away_reason);
	} else if (server != NULL && conn != NULL) {
		server->connrec->reconnection = TRUE;
		server->connrec->channels = channels;
		server->connrec->usermode = usermode;
		server->connrec->away_reason = away_reason;
		if (no_old_server)
			server_connect_free(SERVER_CONNECT(conn));
	}
	g_free_not_null(ircnet);
	cmd_params_free(free_arg);
}