Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2004:
[Freeciv-Dev] Re: (PR#10518) hostname and ping times are not always show
Home

[Freeciv-Dev] Re: (PR#10518) hostname and ping times are not always show

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: awaris@xxxxxxxxx, per@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#10518) hostname and ping times are not always shown
From: "Mike Kaufman" <kaufman@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 21 Oct 2004 22:22:56 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10518 >

On Thu, Oct 21, 2004 at 08:28:15AM -0700, Jason Short wrote:
> 
> The patch seems to work, although I can't say I understand it.

only because you didn't try hard enough to break it. Here's a patch which I
think really works.

-mike

? .civgame-3500.sav.gz.swp
? gamelog
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.408.2.2
diff -u -r1.408.2.2 packhand.c
--- client/packhand.c   19 Oct 2004 18:11:23 -0000      1.408.2.2
+++ client/packhand.c   22 Oct 2004 05:20:39 -0000
@@ -1580,6 +1580,22 @@
     update_info_label();
   }
 
+  /* if the server requests that the client reset, then information about
+   * connections to this player are lost. If this is the case, insert the
+   * correct conn back into the player->connections list */
+  if (conn_list_size(&pplayer->connections) == 0) {
+    conn_list_iterate(game.est_connections, pconn) {
+      if (pconn->player == pplayer) {
+        /* insert the controller into first position */
+        if (pconn->observer) {
+          conn_list_insert_back(&pplayer->connections, pconn);
+        } else {
+          conn_list_insert(&pplayer->connections, pconn);
+        }
+      }
+    } conn_list_iterate_end;
+  }
+
   /* Just about any changes above require an update to the intelligence
    * dialog. */
   update_intel_dialog(pplayer);
@@ -1612,7 +1628,8 @@
   } else {
     /* Add or update the connection */
     struct player *pplayer =
-      ((pinfo->player_num >= 0 && pinfo->player_num < game.nplayers)
+      ((pinfo->player_num >= 0 
+        && pinfo->player_num < MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS)
        ? get_player(pinfo->player_num) : NULL);
     
     if (!pconn) {
Index: client/plrdlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/plrdlg_common.c,v
retrieving revision 1.10
diff -u -r1.10 plrdlg_common.c
--- client/plrdlg_common.c      15 Aug 2004 09:47:04 -0000      1.10
+++ client/plrdlg_common.c      22 Oct 2004 05:20:39 -0000
@@ -249,3 +249,24 @@
     player_dlg_columns[i].title = Q_(player_dlg_columns[i].title);
   }
 }
+
+/**************************************************************************
+  The only place where this is used is the player dialog.
+  Eventually this should go the way of the dodo with everything here
+  moved into col_host above, but some of the older clients (+win32) still
+  use this function directly.
+
+  This code in this function is only really needed so that the host is
+  kept as a blank address if no one is controlling a player, but there are
+  observers.
+**************************************************************************/
+const char *player_addr_hack(struct player *pplayer)
+{ 
+  conn_list_iterate(pplayer->connections, pconn) {
+    if (!pconn->observer) {
+      return pconn->addr;
+    }
+  } conn_list_iterate_end;
+
+  return blank_addr_str;
+}   
Index: client/plrdlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/plrdlg_common.h,v
retrieving revision 1.7
diff -u -r1.7 plrdlg_common.h
--- client/plrdlg_common.h      3 Sep 2004 04:22:36 -0000       1.7
+++ client/plrdlg_common.h      22 Oct 2004 05:20:39 -0000
@@ -45,4 +45,6 @@
 void init_player_dlg_common(void);
 int player_dlg_default_sort_column(void);
 
+const char *player_addr_hack(struct player *pplayer);
+
 #endif  /* FC__PLRDLG_COMMON_H */
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.157.2.1
diff -u -r1.157.2.1 player.c
--- common/player.c     8 Oct 2004 05:11:53 -0000       1.157.2.1
+++ common/player.c     22 Oct 2004 05:20:39 -0000
@@ -463,26 +463,6 @@
 }
 
 /**************************************************************************
-  Hack to support old code which expects player to have single address
-  string (possibly blank_addr_str) and not yet updated for multi-connects.
-  When all such code is converted, this function should be removed.
-  Returns "blank" address for no connections, single address for one,
-  or string "<multiple>" if there are multiple connections.
-  
-  Currently used by:
-      civserver.c: send_server_info_to_metaserver()
-      plrhand.c: send_player_info_c()
-      gui-{xaw,gtk,mui}/plrdlg.c: update_players_dialog()
-**************************************************************************/
-const char *player_addr_hack(struct player *pplayer)
-{
-  int n = conn_list_size(&pplayer->connections);
-  return ((n==0) ? blank_addr_str :
-         (n==1) ? conn_list_get(&pplayer->connections, 0)->addr :
-         "<multiple>");
-}
-
-/**************************************************************************
 Locate the city where the players palace is located, (NULL Otherwise) 
 **************************************************************************/
 struct city *find_palace(struct player *pplayer)
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.130
diff -u -r1.130 player.h
--- common/player.h     29 Sep 2004 02:24:23 -0000      1.130
+++ common/player.h     22 Oct 2004 05:20:39 -0000
@@ -260,8 +260,6 @@
 
 void player_limit_to_government_rates(struct player *pplayer);
 
-const char *player_addr_hack(struct player *pplayer);
-
 struct city *find_palace(struct player *pplayer);
 
 bool ai_handicap(struct player *pplayer, enum handicap_type htype);
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.354.2.4
diff -u -r1.354.2.4 stdinhand.c
--- server/stdinhand.c  9 Oct 2004 21:41:52 -0000       1.354.2.4
+++ server/stdinhand.c  22 Oct 2004 05:20:41 -0000
@@ -2622,6 +2622,11 @@
       }
 
       game.nplayers++;
+
+      /* tell everyone that game.nplayers has been updated */
+      send_game_info(NULL);
+      send_player_info(pplayer, NULL);
+
       notify_player(NULL, _("Game: A global observer has been created"));
     }
   }
@@ -2659,6 +2664,7 @@
   /* 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,
@@ -2685,6 +2691,7 @@
   /* attach pconn to new player as an observer */
   pconn->observer = TRUE; /* do this before attach! */
   attach_connection_to_player(pconn, pplayer);
+  send_conn_info(&pconn->self, &game.est_connections);
 
   if (server_state == RUN_GAME_STATE) {
     send_packet_freeze_hint(pconn);
@@ -2697,9 +2704,6 @@
     send_packet_start_turn(pconn);
   }
 
-  /* tell everyone that pconn is observing */
-  send_conn_info(&pconn->self, &game.est_connections);
-
   cmd_reply(CMD_OBSERVE, caller, C_OK, _("%s now observes %s"),
             pconn->username, pplayer->name);
 
@@ -2803,6 +2807,8 @@
   /* 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_player_info_c(NULL, &pconn->self);
+    send_conn_info(&game.est_connections,  &pconn->self);
   }
 
   /* if we're taking another player with a user attached, 
@@ -2814,6 +2820,7 @@
       }
       notify_conn(&aconn->self, _("being detached from %s."), pplayer->name);
       unattach_connection_from_player(aconn);
+      send_conn_info(&aconn->self, &game.est_connections);
     }
   } conn_list_iterate_end;
 
@@ -2840,6 +2847,7 @@
 
   /* now attach to new player */
   attach_connection_to_player(pconn, pplayer);
+  send_conn_info(&pconn->self, &game.est_connections);
  
   /* if pplayer wasn't /created, and we're still in pregame, change its name */
   if (!pplayer->was_created && is_newgame) {
@@ -2949,10 +2957,14 @@
   /* 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_game_info(&pconn->self);
+    send_player_info_c(NULL, &pconn->self);
+    send_conn_info(&game.est_connections, &pconn->self);
   }
 
   /* actually do the detaching */
   unattach_connection_from_player(pconn);
+  send_conn_info(&pconn->self, &game.est_connections);
   cmd_reply(CMD_DETACH, caller, C_COMMENT,
             _("%s detaching from %s"), pconn->username, pplayer->name);
 
@@ -2965,6 +2977,7 @@
     conn_list_iterate(pplayer->connections, aconn) {
       if (aconn->observer) {
         unattach_connection_from_player(aconn);
+        send_conn_info(&aconn->self, &game.est_connections);
         notify_conn(&aconn->self, _("detaching from %s."), pplayer->name);
       }
     } conn_list_iterate_end;

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