]> git.cworth.org Git - loudgame/blobdiff - loudgame.c
Don't try to close connection if it's never been opened
[loudgame] / loudgame.c
index e2f0af2d5b751968725dfdd427b2e08b93e8f059..65aeb35f31ab95cfe420dbfb526b874b6997f452 100644 (file)
@@ -33,11 +33,16 @@ loudgame_quit (loudgame_t *lg, int return_value)
 
     lg->return_value = return_value;
 
-    if (! lm_connection_close (lg->connection, &error))
-       g_print ("An error occurred during lm_connection_close: %s\n",
-                error->message);
-
-    lm_connection_unref (lg->connection);
+    if (lg->connection)
+    {
+       if (! lm_connection_close (lg->connection, &error))
+       {
+           g_print ("An error occurred during lm_connection_close: %s\n",
+                    error->message);
+       }
+       lm_connection_unref (lg->connection);
+       lg->connection = NULL;
+    }
 
     g_main_loop_quit (lg->main_loop);
 }
@@ -93,6 +98,36 @@ loudgame_send (loudgame_t    *lg,
     }
 }
 
+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,
@@ -170,6 +205,11 @@ make_connection (gpointer closure)
        loudgame_quit (lg, 1);
     }
 
+    /* It seems to be necessary to explicitly tell the server we're
+     * still here. Let's see if one keep-alive every 60 seconds is
+     * sufficient. */
+    lm_connection_set_keep_alive_rate (lg->connection, 60);
+
     /* Return false to not schedule another call. */
     return 0;
 }