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);
}
}
}
+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,
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;
}
return 0;
}
+static void
+loudgame_fini (loudgame_t *lg)
+{
+ g_main_loop_unref (lg->main_loop);
+}
+
int
loudgame_run (loudgame_t *lg)
{
g_main_loop_run (lg->main_loop);
- g_main_loop_unref (lg->main_loop);
+ loudgame_fini (lg);
return lg->return_value;
}