summary refs log tree commit diff stats
path: root/src/common/inbound.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/inbound.c')
-rw-r--r--src/common/inbound.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/common/inbound.c b/src/common/inbound.c
index c04d0187..898dcf4b 100644
--- a/src/common/inbound.c
+++ b/src/common/inbound.c
@@ -1034,6 +1034,7 @@ check_autojoin_channels (server *serv)
 
 		free (serv->autojoin);
 		serv->autojoin = NULL;
+		i++;
 	}
 
 	/* this is really only for re-connects when you
@@ -1057,8 +1058,17 @@ check_autojoin_channels (server *serv)
 				if (po)
 					*po = 0;
 
-				channels = g_slist_append (channels, g_strdup (sess->waitchannel));
-				keys = g_slist_append (keys, g_strdup (sess->channelkey));
+				/* 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
+				{
+					channels = g_slist_append (channels, g_strdup (sess->waitchannel));
+					keys = g_slist_append (keys, g_strdup (sess->channelkey));
+				}
 				i++;
 			}
 		}