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

Almost all references to game.info.player_idx were eliminated in PR#39872.
This removes the remaining 9 instances in 6 files.

While investigating, another bug was discovered!  When players are
renumbered during pre-game, aconnection.player was not updated.

After considerable discussion in PR#40113, there are no intended differences
between client.playing (nee game.info.player_ptr) and aconnection.player.
This codifies the duplication by always setting them at the same time.

   client.playing:     910 instances in 91 files.
   aconnection.player:   8 instances in  4 files.

Both are duplicates of the actual connection[i].player.

   pc->player:           2 instances in  2 files.
   conn([.->]+)player:  82 instances in 20 files.

Index: server/gamehand.c
===================================================================
--- server/gamehand.c   (revision 14424)
+++ server/gamehand.c   (working copy)
@@ -367,8 +367,6 @@
   }
 
   conn_list_iterate(dest, pconn) {
-    /* ? fixme: check for non-players: */
-    ginfo.player_idx = (pconn->player ? player_number(pconn->player) : -1);
     send_packet_game_info(pconn, &ginfo);
   }
   conn_list_iterate_end;
Index: server/savegame.c
===================================================================
--- server/savegame.c   (revision 14424)
+++ server/savegame.c   (working copy)
@@ -4407,8 +4407,6 @@
     shuffle_players();
   }
 
-  game.info.player_idx = 0;
-
   /* Fix ferrying sanity */
   players_iterate(pplayer) {
     unit_list_iterate_safe(pplayer->units, punit) {
Index: common/packets.def
===================================================================
--- common/packets.def  (revision 14424)
+++ common/packets.def  (working copy)
@@ -380,7 +380,6 @@
   PLAYER min_players;
   PLAYER max_players;
   PLAYER nplayers;
-  PLAYER player_idx;
 
   UINT32 globalwarming, heating, warminglevel;
   UINT32 nuclearwinter, cooling, coolinglevel;
Index: common/game.c
===================================================================
--- common/game.c       (revision 14424)
+++ common/game.c       (working copy)
@@ -382,7 +382,7 @@
     game.info.global_advances[i]=FALSE;
   for (i=0; i<B_LAST; i++)      /* game.num_impr_types = 0 here */
     game.info.great_wonders[i]=0;
-  game.info.player_idx = 0;
+
   terrain_control.river_help_text[0] = '\0';
 
   game.meta_info.user_message_set = FALSE;
@@ -608,11 +608,6 @@
     assert(city_list_size(game.players[i].cities) == 0);
   }
 
-  /* has no effect in server, but adjusts in client */
-  if(game.info.player_idx > plrno) {
-    game.info.player_idx--;
-  }
-
   game.info.nplayers--;
 
   player_init(&game.players[game.info.nplayers]);
Index: client/packhand.c
===================================================================
--- client/packhand.c   (revision 14424)
+++ client/packhand.c   (working copy)
@@ -218,9 +218,9 @@
     freelog(LOG_VERBOSE, "join game accept:%s", message);
     aconnection.established = TRUE;
     aconnection.id = conn_id;
+
     agents_game_joined();
     update_menus();
-
     set_server_busy(FALSE);
     
     if (get_client_page() == PAGE_MAIN
@@ -235,11 +235,13 @@
     my_snprintf(msg, sizeof(msg),
                _("You were rejected from the game: %s"), message);
     append_output_window(msg);
-    aconnection.id = 0;
+    aconnection.id = -1; /* not in range of conn_info id */
+
     if (auto_connect) {
       freelog(LOG_NORMAL, "%s", msg);
     }
     gui_server_connect();
+
     if (!with_ggz) {
       set_client_page(in_ggz ? PAGE_MAIN : PAGE_GGZ);
     }
@@ -1540,7 +1542,7 @@
     return;
   }
 
-  if (packet->owner == game.info.player_idx) {
+  if (valid_player_by_number(packet->owner) == client.playing) {
     freelog(LOG_ERROR, "handle_unit_short_info() for own unit.");
   }
 
@@ -1612,7 +1614,6 @@
 
   game.government_when_anarchy =
     government_by_number(game.info.government_when_anarchy_id);
-  client.playing = valid_player_by_number(game.info.player_idx);
 
   if (C_S_PREPARING == client_state()) {
     /* FIXME: only for change in nations */
@@ -1954,6 +1955,8 @@
       aconnection.established = pconn->established;
       aconnection.observer = pconn->observer;
       aconnection.access_level = pconn->access_level;
+      /* FIXME: duplication */
+      client.playing =
       aconnection.player = pplayer;
     }
   }
Index: client/climisc.c
===================================================================
--- client/climisc.c    (revision 14424)
+++ client/climisc.c    (working copy)
@@ -62,11 +62,15 @@
 **************************************************************************/
 void client_remove_player(int plrno)
 {
+  struct connection *pc = find_conn_by_id(aconnection.id);
+
   game_remove_player(player_by_number(plrno));
   game_renumber_players(plrno);
-  /* ensure our pointer is valid */
-  client.playing = valid_player_by_number(game.info.player_idx);
 
+  /* ensure our duplicate pointers are valid */
+  client.playing =
+  aconnection.player = pc->player;
+
   update_conn_list_dialog();
   races_toggles_set_sensitive();
 }
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to