# HG changeset patch
# Node ID 42f657a73d93699cb8ff1a2f26fa15abb8ce9b19
# Parent  497c03200a9989cf440cc57389613d290bc92e88
diff --git a/protocols/ircv3/purpleircv3connection.c b/protocols/ircv3/purpleircv3connection.c
--- a/protocols/ircv3/purpleircv3connection.c
+++ b/protocols/ircv3/purpleircv3connection.c
@@ -66,39 +66,6 @@
  * Helpers
  *****************************************************************************/
 static void
-purple_ircv3_connection_add_message_handlers(PurpleIRCv3Connection *connection,
-                                             IbisClient *client)
-{
-	g_signal_connect_object(client, "message::" IBIS_MSG_TOPIC,
-	                        G_CALLBACK(purple_ircv3_message_handler_topic),
-	                        connection, G_CONNECT_DEFAULT);
-	g_signal_connect_object(client, "message::" IBIS_RPL_NOTOPIC,
-	                        G_CALLBACK(purple_ircv3_message_handler_topic),
-	                        connection, G_CONNECT_DEFAULT);
-	g_signal_connect_object(client, "message::" IBIS_RPL_TOPIC,
-	                        G_CALLBACK(purple_ircv3_message_handler_topic),
-	                        connection, G_CONNECT_DEFAULT);
-
-	g_signal_connect_object(client, "message::" IBIS_MSG_PRIVMSG,
-	                        G_CALLBACK(purple_ircv3_message_handler_privmsg),
-	                        connection, G_CONNECT_DEFAULT);
-	g_signal_connect_object(client, "message::" IBIS_MSG_NOTICE,
-	                        G_CALLBACK(purple_ircv3_message_handler_privmsg),
-	                        connection, G_CONNECT_DEFAULT);
-
-	g_signal_connect_object(client, "message::" IBIS_MSG_JOIN,
-	                        G_CALLBACK(purple_ircv3_message_handler_join),
-	                        connection, G_CONNECT_DEFAULT);
-	g_signal_connect_object(client, "message::" IBIS_MSG_PART,
-	                        G_CALLBACK(purple_ircv3_message_handler_part),
-	                        connection, G_CONNECT_DEFAULT);
-
-	g_signal_connect_object(client, "message",
-	                        G_CALLBACK(purple_ircv3_connection_unknown_message_cb),
-	                        connection, G_CONNECT_AFTER);
-}
-
-static void
 purple_ircv3_connection_rejoin_channels(PurpleIRCv3Connection *connection) {
 	PurpleIRCv3ConnectionPrivate *priv = NULL;
 	PurpleAccount *account = NULL;
@@ -174,6 +141,189 @@
 }
 
 /******************************************************************************
+ * Message Handlers
+ *****************************************************************************/
+static gboolean
+purple_ircv3_connection_saslsuccess(IbisClient *client,
+                                    G_GNUC_UNUSED const char *command,
+                                    G_GNUC_UNUSED IbisMessage *message,
+                                    gpointer data)
+{
+	PurpleIRCv3Connection *connection = data;
+	PurpleAccount *account = NULL;
+	const char *value = NULL;
+
+	account = purple_connection_get_account(PURPLE_CONNECTION(connection));
+	value = purple_account_get_string(account, "sasl-login-name", NULL);
+
+	/* If the sasl-login-name is empty, we set it to the current username in
+	 * our hasl context that was used to login.
+	 */
+	if(purple_strempty(value)) {
+		HaslContext *hasl_context = NULL;
+
+		hasl_context = ibis_client_get_hasl_context(client);
+		if(HASL_IS_CONTEXT(hasl_context)) {
+			purple_account_set_string(account, "sasl-login-name",
+			                          hasl_context_get_username(hasl_context));
+
+		}
+	}
+
+	/* We don't actually handle SASLSUCCESS, but we just needed to know if it
+	 * was sent.
+	 */
+	return FALSE;
+}
+
+static gboolean
+purple_ircv3_server_message_handler(G_GNUC_UNUSED IbisClient *client,
+                                    G_GNUC_UNUSED const char *command,
+                                    IbisMessage *message,
+                                    gpointer data)
+{
+	PurpleIRCv3Connection *connection = data;
+	PurpleIRCv3ConnectionPrivate *priv = NULL;
+	PurpleMessage *purple_message = NULL;
+	GStrv params = NULL;
+	char *body = NULL;
+	const char *source = NULL;
+
+	priv = purple_ircv3_connection_get_instance_private(connection);
+
+	/* The first parameter is supposed to be our nick which we don't want to
+	 * echo so we skip past it.
+	 */
+	params = ibis_message_get_params(message);
+	body = g_strjoinv(" ", params + 1);
+
+	source = ibis_message_get_source(message);
+
+	purple_message = g_object_new(
+		PURPLE_TYPE_MESSAGE,
+		"author", source,
+		"contents", body,
+		NULL);
+
+	g_free(body);
+
+	purple_conversation_write_message(priv->status_conversation,
+	                                  purple_message);
+	g_clear_object(&purple_message);
+
+	return TRUE;
+}
+
+static gboolean
+purple_ircv3_server_no_motd_handler(G_GNUC_UNUSED IbisClient *client,
+                                    G_GNUC_UNUSED const char *command,
+                                    IbisMessage *message,
+                                    gpointer data)
+{
+	PurpleIRCv3Connection *connection = data;
+	PurpleIRCv3ConnectionPrivate *priv = NULL;
+	PurpleMessage *purple_message = NULL;
+	const char *source = NULL;
+
+	priv = purple_ircv3_connection_get_instance_private(connection);
+
+	source = ibis_message_get_source(message);
+
+	purple_message = g_object_new(
+		PURPLE_TYPE_MESSAGE,
+		"author", source,
+		"contents", _("no message of the day found"),
+		NULL);
+
+
+	purple_conversation_write_message(priv->status_conversation,
+	                                  purple_message);
+	g_clear_object(&purple_message);
+
+	return TRUE;
+}
+
+static void
+purple_ircv3_connection_add_message_handlers(PurpleIRCv3Connection *connection,
+                                             IbisClient *client)
+{
+	g_signal_connect_object(client, "message::" IBIS_RPL_WELCOME,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_YOURHOST,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_CREATED,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_MYINFO,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_LUSERCLIENT,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_LUSEROP,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_LUSERUNKNOWN,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_LUSERCHANNELS,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_LUSERME,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_LOCALUSERS,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_GLOBALUSERS,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_MOTD,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_MOTDSTART,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_UMODEIS,
+	                        G_CALLBACK(purple_ircv3_server_message_handler),
+	                        connection, G_CONNECT_DEFAULT);
+
+	g_signal_connect_object(client, "message::" IBIS_ERR_NOMOTD,
+	                        G_CALLBACK(purple_ircv3_server_no_motd_handler),
+	                        connection, G_CONNECT_DEFAULT);
+
+	g_signal_connect_object(client, "message::" IBIS_MSG_TOPIC,
+	                        G_CALLBACK(purple_ircv3_message_handler_topic),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_NOTOPIC,
+	                        G_CALLBACK(purple_ircv3_message_handler_topic),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_RPL_TOPIC,
+	                        G_CALLBACK(purple_ircv3_message_handler_topic),
+	                        connection, G_CONNECT_DEFAULT);
+
+	g_signal_connect_object(client, "message::" IBIS_MSG_PRIVMSG,
+	                        G_CALLBACK(purple_ircv3_message_handler_privmsg),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_MSG_NOTICE,
+	                        G_CALLBACK(purple_ircv3_message_handler_privmsg),
+	                        connection, G_CONNECT_DEFAULT);
+
+	g_signal_connect_object(client, "message::" IBIS_MSG_JOIN,
+	                        G_CALLBACK(purple_ircv3_message_handler_join),
+	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_MSG_PART,
+	                        G_CALLBACK(purple_ircv3_message_handler_part),
+	                        connection, G_CONNECT_DEFAULT);
+
+	g_signal_connect_object(client, "message",
+	                        G_CALLBACK(purple_ircv3_connection_unknown_message_cb),
+	                        connection, G_CONNECT_AFTER);
+}
+
+/******************************************************************************
  * Callbacks
  *****************************************************************************/
 static gboolean
@@ -207,39 +357,6 @@
 	return TRUE;
 }
 
-static gboolean
-purple_ircv3_connection_saslsuccess(IbisClient *client,
-                                    G_GNUC_UNUSED const char *command,
-                                    G_GNUC_UNUSED IbisMessage *message,
-                                    gpointer data)
-{
-	PurpleIRCv3Connection *connection = data;
-	PurpleAccount *account = NULL;
-	const char *value = NULL;
-
-	account = purple_connection_get_account(PURPLE_CONNECTION(connection));
-	value = purple_account_get_string(account, "sasl-login-name", NULL);
-
-	/* If the sasl-login-name is empty, we set it to the current username in
-	 * our hasl context that was used to login.
-	 */
-	if(purple_strempty(value)) {
-		HaslContext *hasl_context = NULL;
-
-		hasl_context = ibis_client_get_hasl_context(client);
-		if(HASL_IS_CONTEXT(hasl_context)) {
-			purple_account_set_string(account, "sasl-login-name",
-			                          hasl_context_get_username(hasl_context));
-
-		}
-	}
-
-	/* We don't actually handle SASLSUCCESS, but we just needed to know if it
-	 * was sent.
-	 */
-	return FALSE;
-}
-
 static void
 purple_ircv3_connection_connect_cb(GObject *source,
                                    G_GNUC_UNUSED GParamSpec *pspec,
