Index: irc.c
===================================================================
--- irc.c	(revision 43671b964b636520a54e343542c5958b30e9f589)
+++ irc.c	(revision 0e7ab64dfb66192a875c37322ca6f8a364ec5bc8)
@@ -658,5 +658,5 @@
 		}
 	}
-	else if( ( c = chat_by_channel( channel ) ) )
+	else if( ( c = irc_chat_by_channel( irc, channel ) ) )
 	{
 		GList *l;
@@ -811,5 +811,5 @@
 	else
 	{
-		struct groupchat *c = chat_by_channel( channel );
+		struct groupchat *c = irc_chat_by_channel( irc, channel );
 		
 		if( c )
@@ -949,5 +949,5 @@
 	if( *nick == '#' || *nick == '&' )
 	{
-		if( !( c = chat_by_channel( nick ) ) )
+		if( !( c = irc_chat_by_channel( irc, nick ) ) )
 		{
 			irc_reply( irc, 403, "%s :Channel does not exist", nick );
@@ -1215,2 +1215,18 @@
 	return TRUE;
 }
+
+struct groupchat *irc_chat_by_channel( irc_t *irc, char *channel )
+{
+	struct groupchat *c;
+	account_t *a;
+	
+	/* This finds the connection which has a conversation which belongs to this channel */
+	for( a = irc->accounts; a; a = a->next )
+	{
+		for( c = a->ic->groupchats; c && g_strcasecmp( c->channel, channel ) != 0; c = c->next );
+		if( c )
+			return c;
+	}
+	
+	return NULL;
+}
Index: irc.h
===================================================================
--- irc.h	(revision 43671b964b636520a54e343542c5958b30e9f589)
+++ irc.h	(revision 0e7ab64dfb66192a875c37322ca6f8a364ec5bc8)
@@ -140,4 +140,5 @@
 
 void buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags );
+struct groupchat *irc_chat_by_channel( irc_t *irc, char *channel );
 
 #endif
Index: irc_commands.c
===================================================================
--- irc_commands.c	(revision 43671b964b636520a54e343542c5958b30e9f589)
+++ irc_commands.c	(revision 0e7ab64dfb66192a875c37322ca6f8a364ec5bc8)
@@ -144,5 +144,5 @@
 		irc_join( irc, u, irc->channel );
 	}
-	else if( ( c = chat_by_channel( cmd[1] ) ) )
+	else if( ( c = irc_chat_by_channel( irc, cmd[1] ) ) )
 	{
 		user_t *u = user_find( irc, irc->nick );
@@ -201,5 +201,5 @@
 {
 	char *nick = cmd[1], *channel = cmd[2];
-	struct groupchat *c = chat_by_channel( channel );
+	struct groupchat *c = irc_chat_by_channel( irc, channel );
 	user_t *u = user_find( irc, nick );
 	
@@ -287,5 +287,5 @@
 			u = u->next;
 		}
-	else if( ( c = chat_by_channel( channel ) ) )
+	else if( ( c = irc_chat_by_channel( irc, channel ) ) )
 		for( l = c->in_room; l; l = l->next )
 		{
Index: protocols/jabber/conference.c
===================================================================
--- protocols/jabber/conference.c	(revision 43671b964b636520a54e343542c5958b30e9f589)
+++ protocols/jabber/conference.c	(revision 0e7ab64dfb66192a875c37322ca6f8a364ec5bc8)
@@ -102,5 +102,5 @@
 
 /* Not really the same syntax as the normal pkt_ functions, but this isn't
-   called by the xmltree parser exactly and this way I can add some extra
+   called by the xmltree parser directly and this way I can add some extra
    parameters so we won't have to repeat too many things done by the caller
    already. */
@@ -151,5 +151,5 @@
 		if( s ) *s = '/';
 	}
-	else if( type ) /* This only gets called if type=="unavailable" */
+	else if( type ) /* This only gets called if type is NULL or "unavailable" */
 	{
 		/* Won't handle this for now. */
Index: protocols/nogaim.c
===================================================================
--- protocols/nogaim.c	(revision 43671b964b636520a54e343542c5958b30e9f589)
+++ protocols/nogaim.c	(revision 0e7ab64dfb66192a875c37322ca6f8a364ec5bc8)
@@ -856,22 +856,4 @@
 /* Misc. BitlBee stuff which shouldn't really be here */
 
-struct groupchat *chat_by_channel( char *channel )
-{
-	struct im_connection *ic;
-	struct groupchat *c;
-	GSList *l;
-	
-	/* This finds the connection which has a conversation which belongs to this channel */
-	for( l = connections; l; l = l->next )
-	{
-		ic = l->data;
-		for( c = ic->groupchats; c && g_strcasecmp( c->channel, channel ) != 0; c = c->next );
-		if( c )
-			return c;
-	}
-	
-	return NULL;
-}
-
 char *set_eval_away_devoice( set_t *set, char *value )
 {
Index: protocols/nogaim.h
===================================================================
--- protocols/nogaim.h	(revision 43671b964b636520a54e343542c5958b30e9f589)
+++ protocols/nogaim.h	(revision 0e7ab64dfb66192a875c37322ca6f8a364ec5bc8)
@@ -207,5 +207,4 @@
 G_MODULE_EXPORT void imcb_chat_msg( struct groupchat *c, char *who, char *msg, u_int32_t flags, time_t sent_at );
 G_MODULE_EXPORT void imcb_chat_free( struct groupchat *c );
-struct groupchat *chat_by_channel( char *channel );
 
 /* Actions, or whatever. */
Index: root_commands.c
===================================================================
--- root_commands.c	(revision 43671b964b636520a54e343542c5958b30e9f589)
+++ root_commands.c	(revision 0e7ab64dfb66192a875c37322ca6f8a364ec5bc8)
@@ -918,5 +918,5 @@
 		char *s;
 		
-		channel = g_strdup( chat );
+		channel = g_strdup_printf( "&%s", chat );
 		if( ( s = strchr( channel, '@' ) ) )
 			*s = 0;
@@ -928,4 +928,17 @@
 	if( cmd[3] && cmd[4] && cmd[5] )
 		password = cmd[5];
+	
+	if( channel[0] != '#' && channel[0] != '&' )
+	{
+		irc_usermsg( irc, "Invalid channel name: %s", channel );
+		g_free( channel );
+		return;
+	}
+	else if( g_strcasecmp( channel, irc->channel ) == 0 || irc_chat_by_channel( irc, channel ) )
+	{
+		irc_usermsg( irc, "Channel already exists: %s", channel );
+		g_free( channel );
+		return;
+	}
 	
 	if( ( c = a->prpl->chat_join( ic, chat, nick, password ) ) )
