Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2005:
[Freeciv-Dev] Re: (PR#12913) send the ruleset to the clients always
Home

[Freeciv-Dev] Re: (PR#12913) send the ruleset to the clients always

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#12913) send the ruleset to the clients always
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 27 Apr 2005 19:06:06 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12913 >

Jason Short wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=12913 >
> 
> Currently the rulesets are sent to the client only on game start.
> There's a complicated mechanism for determining when they need to be
> sent.  In the new design the server always knows the rulesets and so
> should the client.  Ideally this should be quite simple:
> 
> 1.  Any time a client connects we send them the ruleset.
> 2.  Any time rulesets are changed we send out rulesets to everyone.
> 
> This patch accomplishes both of these, removing all other sending of the
> rulesets.  Thus the client *should* know the rulesets at all times.
> However it doesn't work because the client "automatically" forgets the
> rulesets sometimes, for instance if you do /observe.  So under this
> patch the client will crash if you try this.  However I can't figure out
> where the client is freeing this data so I don't see how to fix it.
> Mike, can you offer advice here?

Current CVS crashes when you do /obs too.  This is because the ruleset
cache is freed in detach_command, but the new rulesets aren't sent until
the client is reattached.  It worked before because the memory was
leaked and left in place, but since we fixed that memory leak now it
crashes.

This patch fixes everything (hopefully).  In addition to the above changes:

3.  Any time a client "reset" is done we *immediately* resend rulesets.
4.  Don't reset the client twice in observe_command().

It doesn't particularly attempt to fix the (horrible) take-detach design
but it should cause things to work now.

-jason

Index: server/connecthand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/connecthand.c,v
retrieving revision 1.42
diff -u -r1.42 connecthand.c
--- server/connecthand.c        31 Mar 2005 17:48:34 -0000      1.42
+++ server/connecthand.c        28 Apr 2005 02:05:20 -0000
@@ -112,6 +112,8 @@
     }
   } conn_list_iterate_end;
 
+  send_rulesets(dest);
+
   /* a player has already been created for this user, reconnect him */
   if ((pplayer = find_player_by_user(pconn->username))) {
     attach_connection_to_player(pconn, pplayer);
@@ -120,7 +122,6 @@
       /* Player and other info is only updated when the game is running.
        * See the comment in lost_connection_to_client(). */
       send_packet_freeze_hint(pconn);
-      send_rulesets(dest);
       send_all_info(dest);
       send_game_state(dest, CLIENT_GAME_RUNNING_STATE);
       send_player_info(NULL,NULL);
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.247
diff -u -r1.247 ruleset.c
--- server/ruleset.c    27 Apr 2005 16:31:46 -0000      1.247
+++ server/ruleset.c    28 Apr 2005 02:05:21 -0000
@@ -3129,6 +3129,12 @@
   load_ruleset_effects(&effectfile);
   load_ruleset_game();
   translate_data_names();
+
+  if (game.all_connections) {
+    /* Now that the rulesets are loaded we immediately send updates to any
+     * connected clients. */
+    send_rulesets(game.all_connections);
+  }
 }
 
 /**************************************************************************
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.247
diff -u -r1.247 srv_main.c
--- server/srv_main.c   27 Apr 2005 16:31:46 -0000      1.247
+++ server/srv_main.c   28 Apr 2005 02:05:21 -0000
@@ -1750,8 +1750,6 @@
 
 main_start_players:
 
-  send_rulesets(game.game_connections);
-
   if (map.num_start_positions > 0) {
     start_nations = TRUE;
 
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.399
diff -u -r1.399 stdinhand.c
--- server/stdinhand.c  27 Apr 2005 16:31:47 -0000      1.399
+++ server/stdinhand.c  28 Apr 2005 02:05:22 -0000
@@ -2777,12 +2777,6 @@
     goto end;
   }
 
-  /* if we want to switch players, reset the client */
-  if (pconn->player && server_state == RUN_GAME_STATE) {
-    send_game_state(pconn->self, CLIENT_PRE_GAME_STATE);
-    send_conn_info(game.est_connections,  pconn->self);
-  }
-
   /* if the connection is already attached to a player,
    * unattach and cleanup old player (rename, remove, etc) */
   if (pconn->player) {
@@ -2811,7 +2805,6 @@
 
   if (server_state == RUN_GAME_STATE) {
     send_packet_freeze_hint(pconn);
-    send_rulesets(pconn->self);
     send_all_info(pconn->self);
     send_game_state(pconn->self, CLIENT_GAME_RUNNING_STATE);
     send_player_info(NULL, NULL);
@@ -2923,6 +2916,7 @@
   /* if we want to switch players, reset the client if the game is running */
   if (pconn->player && server_state == RUN_GAME_STATE) {
     send_game_state(pconn->self, CLIENT_PRE_GAME_STATE);
+    send_rulesets(pconn->self);
     send_player_info_c(NULL, pconn->self);
     send_conn_info(game.est_connections,  pconn->self);
   }
@@ -2933,6 +2927,7 @@
     if (!aconn->observer) {
       if (server_state == RUN_GAME_STATE) {
         send_game_state(aconn->self, CLIENT_PRE_GAME_STATE);
+       send_rulesets(aconn->self);
       }
       notify_conn(aconn->self, _("being detached from %s."), pplayer->name);
       unattach_connection_from_player(aconn);
@@ -2973,7 +2968,6 @@
 
   if (server_state == RUN_GAME_STATE) {
     send_packet_freeze_hint(pconn);
-    send_rulesets(pconn->self);
     send_all_info(pconn->self);
     send_game_state(pconn->self, CLIENT_GAME_RUNNING_STATE);
     send_player_info(NULL, NULL);
@@ -3073,6 +3067,7 @@
   /* if we want to detach while the game is running, reset the client */
   if (server_state == RUN_GAME_STATE) {
     send_game_state(pconn->self, CLIENT_PRE_GAME_STATE);
+    send_rulesets(pconn->self);
     send_game_info(pconn->self);
     send_player_info_c(NULL, pconn->self);
     send_conn_info(game.est_connections, pconn->self);
@@ -3145,9 +3140,6 @@
   if (load_successful) {
     int i = 0;
 
-    /* We have to send ruleset info before sending the nations, below. */
-    send_rulesets(game.est_connections);
-
     players_iterate(pplayer) {
       if (game.nation_count && is_barbarian(pplayer)) {
        continue;

[Prev in Thread] Current Thread [Next in Thread]