]> git.cworth.org Git - loudgame/blobdiff - loudgame.c
Implement simple show, hint, and shuffle commands for lg-set.
[loudgame] / loudgame.c
index 53b392b1b0d9440f97da8162b204cae85b8e3123..2cb9a1869f62e16160909a4fad2add98524abb7e 100644 (file)
@@ -70,11 +70,10 @@ connection_open_cb (LmConnection *connection, gboolean result, loudgame_t *lg)
                                authentication_cb, lg, FALSE,  NULL);
 }
 
-static void
-send_reply (LmConnection       *connection,
-           const char          *peer,
-           const char          *message,
-           loudgame_t          *lg)
+void
+loudgame_send (loudgame_t      *lg,
+              const char       *peer,
+              const char       *message)
 {
     LmMessage *reply;
     gboolean result;
@@ -84,15 +83,46 @@ send_reply (LmConnection    *connection,
 
     lm_message_node_add_child (reply->node, "body", message);
 
-    result = lm_connection_send (connection, reply, &error);
+    result = lm_connection_send (lg->connection, reply, &error);
     lm_message_unref (reply);
 
     if (! result) {
-       g_error ("lm_connection_send failed: error->message");
+       g_error ("lm_connection_send failed: %s\n",
+                error->message);
        loudgame_quit (lg, 1);
     }
 }
 
+void
+loudgame_vsendf (loudgame_t    *lg,
+                const char     *peer,
+                const char     *format,
+                va_list         va)
+{
+    char *str;
+
+    str = g_strdup_vprintf (format, va);
+
+    loudgame_send (lg, peer, str);
+
+    free (str);
+}
+
+void
+loudgame_sendf (loudgame_t     *lg,
+               const char      *peer,
+               const char      *format,
+               ...)
+{
+    va_list va;
+
+    va_start (va, format);
+
+    loudgame_vsendf (lg, peer, format, va);
+
+    va_end (va);
+}
+
 static void
 handle_command (LmConnection   *connection,
                const char      *peer,
@@ -107,7 +137,7 @@ handle_command (LmConnection        *connection,
     }
 
     error = g_strdup_printf ("Unknown command: '%s'", command);
-    send_reply (connection, peer, error, lg);
+    loudgame_send (lg, peer, error);
     free (error);
 }