summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/inbound.c95
-rw-r--r--src/common/proto-irc.c4
-rw-r--r--src/common/servlist.c32
-rw-r--r--src/common/servlist.h3
4 files changed, 51 insertions, 83 deletions
diff --git a/src/common/inbound.c b/src/common/inbound.c
index ec625c03..953a78ee 100644
--- a/src/common/inbound.c
+++ b/src/common/inbound.c
@@ -1066,39 +1066,38 @@ inbound_nameslist_end (server *serv, char *chan)
 	return FALSE;
 }
 
-#if 0//FIXME remove when finished porting
-static gboolean
+static void
 check_autojoin_channels (server *serv)
 {
-	char *po;
+	int i = 0;
 	session *sess;
 	GSList *list = sess_list;
-	int i = 0;
-	GSList *channels, *keys;
+	GSList *sess_channels = NULL;			/* joined channels that are not in the favorites list */
 
-	/* shouldnt really happen, the io tag is destroyed in server.c */
+	/* shouldn't really happen, the io tag is destroyed in server.c */
 	if (!is_server (serv))
-		return FALSE;
+	{
+		return;
+	}
 
 	/* send auto join list */
-	if (serv->autojoin)
+	if (serv->favlist)
 	{
-		joinlist_split (serv->autojoin, &channels, &keys);
-		serv->p_join_list (serv, channels, keys);
-		joinlist_free (channels, keys);
-
-		free (serv->autojoin);
-		serv->autojoin = NULL;
+		serv->p_join_list (serv, serv->favlist);
 		i++;
+
+		/* FIXME this is not going to work and is not needed either. server_free() does the job already. */
+		/* g_slist_free_full (serv->favlist, (GDestroyNotify) servlist_favchan_free); */
 	}
 
-	/* this is really only for re-connects when you
-    * join channels not in the auto-join list. */
-	channels = NULL;
-	keys = NULL;
+	/* This is really only for re-connects when you
+	 * join channels not in the auto-join list.
+	 */
+
 	while (list)
 	{
 		sess = list->data;
+
 		if (sess->server == serv)
 		{
 			if (sess->willjoinchannel[0] != 0)
@@ -1106,69 +1105,23 @@ check_autojoin_channels (server *serv)
 				strcpy (sess->waitchannel, sess->willjoinchannel);
 				sess->willjoinchannel[0] = 0;
 
-				po = strchr (sess->waitchannel, ',');
-				if (po)
-					*po = 0;
-				po = strchr (sess->waitchannel, ' ');
-				if (po)
-					*po = 0;
-
-				/* There can be no gap between keys, list keyed chans first. */
-				if (sess->channelkey[0] != 0)
-				{
-					channels = g_slist_prepend (channels, g_strdup (sess->waitchannel));
-					keys = g_slist_prepend (keys, g_strdup (sess->channelkey));
-				}
-				else
+				if (!servlist_favchan_find (serv->network, sess->waitchannel, NULL))		/* don't reconnect if it's already in the favlist */
 				{
-					channels = g_slist_append (channels, g_strdup (sess->waitchannel));
-					keys = g_slist_append (keys, g_strdup (sess->channelkey));
+					sess_channels = servlist_favchan_listadd (sess_channels, sess->waitchannel, sess->channelkey);
+					i++;
 				}
-				i++;
 			}
 		}
-		list = list->next;
-	}
-
-	if (channels)
-	{
-		serv->p_join_list (serv, channels, keys);
-		joinlist_free (channels, keys);
-	}
 
-	serv->joindelay_tag = 0;
-	fe_server_event (serv, FE_SE_LOGGEDIN, i);
-	return FALSE;
-}
-#endif
-
-static void
-check_autojoin_channels (server *serv)
-{
-	int i = 0;
-
-	/* shouldn't really happen, the io tag is destroyed in server.c */
-	if (!is_server (serv))
-	{
-		return;
+		list = list->next;
 	}
 
-	/* send auto join list */
-	if (serv->favlist)
+	if (sess_channels)
 	{
-		serv->p_join_list (serv, serv->favlist);
-		i++;
-
-		/* FIXME this is not going to work and is not needed either. server_free() does the job already. */
-		/* g_slist_free_full (serv->favlist, (GDestroyNotify) servlist_favchan_free); */
+		serv->p_join_list (serv, sess_channels);
+		g_slist_free_full (sess_channels, (GDestroyNotify) servlist_favchan_free);
 	}
 
-	/* This is really only for re-connects when you
-	 * join channels not in the auto-join list.
-	 */
-
-	/* FIXME handle reconnects */
-
 	serv->joindelay_tag = 0;
 	fe_server_event (serv, FE_SE_LOGGEDIN, i);
 }
diff --git a/src/common/proto-irc.c b/src/common/proto-irc.c
index 8beb83f2..792927db 100644
--- a/src/common/proto-irc.c
+++ b/src/common/proto-irc.c
@@ -185,13 +185,13 @@ irc_join_list (server *serv, GSList *favorites)
 
 		g_string_append (chanlist, fav->name);
 
-		if (fav->key)
+		if (fav->key && strlen (fav->key))					/* strlen() is required since key can be '' for session->channelkey */
 		{
 			g_string_append (keylist, fav->key);
 		}
 		else
 		{
-			g_string_append_c (keylist, 'x');				/* 'x' filler for keyless channels */
+			g_string_append_c (keylist, 'x');				/* 'x' filler for keyless channels so that our JOIN command is always well-formatted */
 		}
 
 		first_item = 0;
diff --git a/src/common/servlist.c b/src/common/servlist.c
index b55498cc..da0b746d 100644
--- a/src/common/servlist.c
+++ b/src/common/servlist.c
@@ -998,30 +998,44 @@ servlist_command_add (ircnet *net, char *cmd)
 	return entry;
 }
 
-favchannel *
-servlist_favchan_add (ircnet *net, char *channel)
+GSList *
+servlist_favchan_listadd (GSList *chanlist, char *channel, char *key)
 {
-	int pos;
 	favchannel *chan;
 
 	chan = malloc (sizeof (favchannel));
 	memset (chan, 0, sizeof (favchannel));
 
+	chan->name = g_strdup (channel);
+	chan->key = g_strdup (key);
+	chanlist = g_slist_append (chanlist, chan);
+
+	return chanlist;
+}
+
+void
+servlist_favchan_add (ircnet *net, char *channel)
+{
+	int pos;
+	char *name;
+	char *key;
+
 	if (strchr (channel, ',') != NULL)
 	{
 		pos = (int) (strchr (channel, ',') - channel);
-		chan->name = g_strndup (channel, pos);
-		chan->key = g_strdup (channel + pos + 1);
+		name = g_strndup (channel, pos);
+		key = g_strdup (channel + pos + 1);
 	}
 	else
 	{
-		chan->name = g_strdup (channel);
-		chan->key = NULL;
+		name = g_strdup (channel);
+		key = NULL;
 	}
 
-	net->favchanlist = g_slist_append (net->favchanlist, chan);
+	net->favchanlist = servlist_favchan_listadd (net->favchanlist, name, key);
 
-	return chan;
+	g_free (name);
+	g_free (key);
 }
 
 void
diff --git a/src/common/servlist.h b/src/common/servlist.h
index dd88de1d..92100b9b 100644
--- a/src/common/servlist.h
+++ b/src/common/servlist.h
@@ -100,7 +100,7 @@ favchannel *servlist_favchan_find (ircnet *net, char *channel, int *pos);
 
 ircserver *servlist_server_add (ircnet *net, char *name);
 commandentry *servlist_command_add (ircnet *net, char *command);
-favchannel *servlist_favchan_add (ircnet *net, char *channel);
+void servlist_favchan_add (ircnet *net, char *channel);
 
 void servlist_command_free (commandentry *entry);
 void servlist_favchan_free (favchannel *channel);
@@ -110,6 +110,7 @@ void servlist_command_remove (ircnet *net, commandentry *entry);
 void servlist_favchan_remove (ircnet *net, favchannel *channel);
 
 favchannel *servlist_favchan_copy (favchannel *fav);
+GSList *servlist_favchan_listadd (GSList *chanlist, char *channel, char *key);
 
 gboolean joinlist_is_in_list (server *serv, char *channel);