]> git.cworth.org Git - grrobot/blobdiff - src/grrobot.c
Add --watch option
[grrobot] / src / grrobot.c
index 98f14f2582fad574e77c4317ed16a6fd2a13318b..209c599d9fc1db6a3f5a31fd10ca996d985cbff1 100644 (file)
@@ -92,9 +92,16 @@ main (int argc, char **argv)
        return 1;
     }
 
-    status = rr_client_join (game.client, args.game);
-    if (status == RR_STATUS_NO_GAME) {
-       status = rr_client_new (game.client, args.game);
+    if (args.watch) {
+       status = rr_client_watch (game.client, args.game);
+       if (status == RR_STATUS_NO_GAME) {
+           fprintf (stderr, "No game %s to watch\n", args.game);
+       }
+    } else {
+       status = rr_client_join (game.client, args.game);
+       if (status == RR_STATUS_NO_GAME) {
+           status = rr_client_new (game.client, args.game);
+       }
     }
 
     game.board = rr_board_create (16, 16);
@@ -188,10 +195,16 @@ grr_game_read_notices (grr_game_t *game)
     while (rr_client_notice_pending (game->client)) {
        status = rr_client_next_notice (game->client, &notice);
        if (status) {
-           fprintf (stderr, "Error during rr_client_next_notice: %s\n",
-                    rr_status_str (status));
+           if (status == RR_STATUS_EOF)
+               fprintf (stderr, "The server has disconnected, exiting.\n");
+           else
+               fprintf (stderr, "Error during rr_client_next_notice: %s\n",
+                        rr_status_str (status));
            gtk_exit (1);
-           return;
+       }
+       if (!notice) {
+           fprintf (stderr, "Missing notice\n");
+           continue;
        }
 
        switch (notice->type) {