Re: Gnibbles network patch



I've done some testing of networking in iagno and gnibbles.
Here's a patch to fix some minor problems I discovered:

-Undo isn't implemented in network games, so the patch disables the menu
item for it. See bug: 118995

- In gnibbles, acknowledge messages sent from client to host. This is
necessary to make sure the move happens at the same time on both the host
and client.

- Handle disconnects during gnibbles network games properly.


Andreas Røsdal
diff -ruN -Xgnome-games/.cvsignore gnome-games-cvs/gnibbles/ChangeLog gnome-games/gnibbles/ChangeLog
--- gnome-games-cvs/gnibbles/ChangeLog	2004-09-20 09:59:39.000000000 +0200
+++ gnome-games/gnibbles/ChangeLog	2004-09-21 17:18:25.000000000 +0200
@@ -1,3 +1,8 @@
+2004-09-21 Andreas Røsdal <andrearo stud ntnu no>
+
+	* network.c: Acknowledge move messages from client to host,
+	and properly handle the end of the game.
+
 2004-09-20 Andreas Røsdal <andrearo stud ntnu no>
 
 	* main.c: Implement network mode. main_loop is controlled by
diff -ruN -Xgnome-games/.cvsignore gnome-games-cvs/gnibbles/network.c gnome-games/gnibbles/network.c
--- gnome-games-cvs/gnibbles/network.c	2004-09-21 09:10:38.000000000 +0200
+++ gnome-games/gnibbles/network.c	2004-09-21 17:18:25.000000000 +0200
@@ -78,7 +78,10 @@
 
   snprintf (msgbuf, sizeof (msgbuf), "move %u %u \n", x, current_worm_id);
   games_send_gamedata(msgbuf);
-  worm_set_direction (current_worm_id, x);
+
+  if (network_is_host ()) {
+    worm_set_direction (current_worm_id, x);
+  }
 }
 
 int
@@ -90,7 +93,7 @@
 static 
 void clear_board(void)
 {
-  end_game (0);
+  end_game (1);
 }
 
 static 
@@ -174,8 +177,28 @@
       network_set_status (ng, DISCONNECTED, _("Invalid game data (move)"));
       return;
     }
+    if (!network_is_host ()) {
+      worm_set_direction (me, x);
+    } else {
+      static char msgbuf[256];
+
+      snprintf (msgbuf, sizeof (msgbuf), "ack_move %u %u \n", x, me);
+      worm_set_direction (me, x);
+      games_send_gamedata(msgbuf);
+    }
+
+  /* Move messages from the client to the host must be acknowledged
+     by the host before the client can act upon it.  */
+  } else if (! strcmp (buf, "ack_move")) {
+    int x, y, me;
+
+    if (!args || sscanf(args, "%d %d", &x, &me) != 2) {
+      network_set_status (ng, DISCONNECTED, _("Invalid game data (move)"));
+      return;
+    }
     worm_set_direction (me, x);
 
+
   /* The move_worms message is used to synchronize the game.
      The host sends this message to the client, which then can
      move it's worms.   */
diff -ruN -Xgnome-games/.cvsignore gnome-games-cvs/iagno/ChangeLog gnome-games/iagno/ChangeLog
--- gnome-games-cvs/iagno/ChangeLog	2004-09-20 09:59:39.000000000 +0200
+++ gnome-games/iagno/ChangeLog	2004-09-21 17:19:27.000000000 +0200
@@ -1,4 +1,9 @@
-2004-09-20 Andreas Røsdal <andrearo stud ntnu no>
+2004-09-21 Andreas Røsdal <andrearo stud ntnu no>
+
+	* gnothello.c: Disable undo in network games.
+	* network.c: Implement is_network_running (). 
+
+2004-09-20 Andreas Røsdal <andrearo stud ntnu no
 	
 	* network.c: Use the new games_send_gamedata (),
 	and callback functions.
diff -ruN -Xgnome-games/.cvsignore gnome-games-cvs/iagno/gnothello.c gnome-games/iagno/gnothello.c
--- gnome-games-cvs/iagno/gnothello.c	2004-09-20 09:59:39.000000000 +0200
+++ gnome-games/iagno/gnothello.c	2004-09-21 17:18:26.000000000 +0200
@@ -799,7 +799,7 @@
 	gtk_label_set_text (GTK_LABEL (black_score), message);
 	sprintf (message, _("%.2d"), wcount);
 	gtk_label_set_text (GTK_LABEL (white_score), message);
-	undo_set_sensitive (move_count > 0);
+	undo_set_sensitive (move_count > 0 && !is_network_running ());
 }
 
 void
diff -ruN -Xgnome-games/.cvsignore gnome-games-cvs/iagno/network.c gnome-games/iagno/network.c
--- gnome-games-cvs/iagno/network.c	2004-09-20 09:59:39.000000000 +0200
+++ gnome-games/iagno/network.c	2004-09-21 17:18:26.000000000 +0200
@@ -52,6 +52,12 @@
   games_network_stop ();
 }
 
+gboolean
+is_network_running (void)
+{
+  return (get_network_status () == CONNECTED);
+}
+
 int
 game_move (guint x, guint y, guint me)
 {
diff -ruN -Xgnome-games/.cvsignore gnome-games-cvs/iagno/network.h gnome-games/iagno/network.h
--- gnome-games-cvs/iagno/network.h	2004-09-20 09:59:39.000000000 +0200
+++ gnome-games/iagno/network.h	2004-09-21 17:18:26.000000000 +0200
@@ -10,6 +10,7 @@
 extern void network_new (GtkWidget *parent_window);
 extern void network_start (void);
 extern void network_stop (void);
+extern gboolean is_network_running (void);
 
 #endif
 
diff -ruN -Xgnome-games/.cvsignore gnome-games-cvs/libgames-support/ChangeLog gnome-games/libgames-support/ChangeLog
--- gnome-games-cvs/libgames-support/ChangeLog	2004-09-20 10:03:50.000000000 +0200
+++ gnome-games/libgames-support/ChangeLog	2004-09-21 17:18:26.000000000 +0200
@@ -1,3 +1,7 @@
+2004-09-21  Andreas Røsdal <andrearo stud ntnu no>
+
+        * games-network.c: Update GUI when network disconnects. 
+
 2004-09-20  Callum McKenzie  <callum physics otago ac nz>
 
 	* games-network.h: 
diff -ruN -Xgnome-games/.cvsignore gnome-games-cvs/libgames-support/games-network.c gnome-games/libgames-support/games-network.c
--- gnome-games-cvs/libgames-support/games-network.c	2004-09-20 10:03:50.000000000 +0200
+++ gnome-games/libgames-support/games-network.c	2004-09-21 17:18:26.000000000 +0200
@@ -233,6 +233,7 @@
  errout:     
   /* Shut down the connection, either it was broken or someone is messing with us */
   network_set_status (ng, DISCONNECTED, _("The remote player disconnected"));
+  game_clear_cb ();
   return network_io_setup (ng, CALLER_READ_CB);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]