-static void
-handle_command (LmConnection *connection,
- const char *peer,
- const char *command,
- loudgame_t *lg)
-{
- char *error;
-
- if (strcmp (command, "quit") == 0) {
- loudgame_quit (lg, 0);
- return;
- }
-
- error = g_strdup_printf ("Unknown command: '%s'", command);
- send_reply (connection, peer, error, lg);
- free (error);
-}
-
-static LmHandlerResult
-handle_messages (LmMessageHandler *handler,
- LmConnection *connection,
- LmMessage *m,
- gpointer closure)
-{
- loudgame_t *lg = closure;
- LmMessageNode *body;
- const char *peer;
- const char *body_str;
-
- peer = lm_message_node_get_attribute (m->node, "from");
-
- body = lm_message_node_get_child (m->node, "body");
- if (body) {
- body_str = lm_message_node_get_value (body);
-
- if (body_str && body_str[0] == '%')
- handle_command (connection, peer, body_str + 1, lg);
- else
- send_reply (connection, peer, body_str, lg);
- }
-
- return LM_HANDLER_RESULT_REMOVE_MESSAGE;
-}
-
-static gboolean
-make_connection (gpointer closure)
-{
- loudgame_t *lg;
- LmMessageHandler *handler;
- gchar *jid;
- GError *error;
-
- lg = closure;
-
- lg->connection = lm_connection_new (lg->server);
-
- jid = g_strdup_printf ("%s@%s", lg->name, lg->server);
- lm_connection_set_jid (lg->connection, jid);
- g_free (jid);
-
- handler = lm_message_handler_new (handle_messages, lg, NULL);
- lm_connection_register_message_handler (lg->connection,
- handler,
- LM_MESSAGE_TYPE_MESSAGE,
- LM_HANDLER_PRIORITY_NORMAL);
-
- lm_message_handler_unref (handler);
-
- if (! lm_connection_open (lg->connection,
- (LmResultFunction) connection_open_cb,
- lg, NULL, &error))
- {
- g_print ("Opening connection failed: %s\n", error->message);
- loudgame_quit (lg, 1);
- }
-
- /* Return false to not schedule another call. */
- return 0;
-}
-