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);
while (rr_client_notice_pending (game->client)) {
status = rr_client_next_notice (game->client, ¬ice);
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) {
grr_game_printf (game, "\nGame state changed to: %s.",
rr_gamestate_str (notice->u.gamestate));
break;
+ case RR_NOTICE_TURN:
+ grr_game_print (game, "\nNew round!");
+ rr_board_set_goal_target (board, notice->u.target);
+ gtk_widget_queue_draw (GTK_WIDGET (game->window));
+ break;
+ case RR_NOTICE_GAMEOVER:
+ {
+ char *diagram;
+ grr_game_printf (game, "\nGame over. New game will begin now.");
+ /* XXX: Can drop this when the BOARD NOTICE is added in the server */
+ rr_client_show (game->client, &diagram);
+ rr_board_parse (board, diagram);
+ free (diagram);
+ gtk_widget_queue_draw (GTK_WIDGET (game->window));
+ }
+ break;
case RR_NOTICE_JOIN:
grr_game_printf (game, "\nUser %s has joined the game.",
notice->u.string);
notice->u.position.x, notice->u.position.y);
gtk_widget_queue_draw (GTK_WIDGET (game->window));
break;
- case RR_NOTICE_TURN:
- grr_game_print (game, "\nNew round!");
- rr_board_set_goal_target (board, notice->u.target);
- gtk_widget_queue_draw (GTK_WIDGET (game->window));
- break;
}
free (notice);
}