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

I can confirm that by modifying the client source
(i.e. changing can_intel_with_player to always return
TRUE) a player could access information not normally
available (the other players' gold amounts and
governments, even without contact).

The attached patch changes the server to only send the
gold and government information if the player's info
level is INFO_MEETING or greater. Otherwise zero is
sent as the gold value and -1 (corresponding to NULL
on the client side) for the government.

Unfortunately the seem to be a lot of places where the
client assumes that the government will never be NULL.
The patch changes some of the common/government.c
functions to be more forgiving of NULL input; hopefully
these were the only places where such assumptions were
made.


The alternative would be to modify the client to always
allow showing the gold and government information, but
I do not really like that this information is available
in the first place. My opinion is that it would be better
if this information remain hidden from players without
contact.


----------------------------------------------------------------------
一緒にプチプチつぶししませんか?
 common/government.c |   33 ++++++++++++++++++++++-----------
 server/plrhand.c    |   14 +++++++++-----
 2 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/common/government.c b/common/government.c
index 8fc37ac..57fe090 100644
--- a/common/government.c
+++ b/common/government.c
@@ -30,8 +30,6 @@
 
 struct government *governments = NULL;
 
-#define CHECK_GOVERNMENT(gp) assert((NULL != gp) && ((gp) == &governments[(gp)->index]))
-
 /****************************************************************************
   Returns the government that has the given (translated) name.
   Returns NULL if none match.
@@ -102,7 +100,10 @@ struct government *government_of_city(const struct city *pcity)
 ****************************************************************************/
 const char *government_rule_name(const struct government *gov)
 {
-  CHECK_GOVERNMENT(gov);
+  if (!gov) {
+    return "Unknown";
+  }
+
   return Qn_(gov->name.vernacular);
 }
 
@@ -112,7 +113,10 @@ const char *government_rule_name(const struct government *gov)
 ****************************************************************************/
 const char *government_name_translation(struct government *gov)
 {
-  CHECK_GOVERNMENT(gov);
+  if (!gov) {
+    return _("Unknown");
+  }
+
   if (NULL == gov->name.translated) {
     /* delayed (unified) translation */
     gov->name.translated = ('\0' == gov->name.vernacular[0])
@@ -137,13 +141,22 @@ const char *government_name_for_player(const struct player *pplayer)
 ***************************************************************/
 const char *ruler_title_translation(const struct player *pp)
 {
-  struct government *gp = government_of_player(pp);
-  struct nation_type *np = nation_of_player(pp);
+  struct government *gp;
+  struct nation_type *np;
   struct ruler_title *best_match = NULL;
   struct name_translation *sex;
   int i;
 
-  CHECK_GOVERNMENT(gp);
+  if (!pp) {
+    return "";
+  }
+
+  gp = government_of_player(pp);
+  if (!gp) {
+    return pp->is_male ? _("Mr.") : _("Ms.");
+  }
+
+  np = nation_of_player(pp);
 
   for(i=0; i<gp->num_ruler_titles; i++) {
     struct ruler_title *title = &gp->ruler_titles[i];
@@ -163,7 +176,7 @@ const char *ruler_title_translation(const struct player *pp)
 	    gp->index,
 	    nation_rule_name(np),
 	    np->index);
-    return pp->is_male ? "Mr." : "Ms.";
+    return pp->is_male ? _("Mr.") : _("Ms.");
   }
 
   sex = pp->is_male ? &best_match->male : &best_match->female;
@@ -187,9 +200,7 @@ const char *ruler_title_translation(const struct player *pp)
 bool can_change_to_government(struct player *pplayer,
 			      const struct government *gov)
 {
-  CHECK_GOVERNMENT(gov);
-
-  if (!pplayer) {
+  if (!pplayer || !gov) {
     return FALSE;
   }
 
diff --git a/server/plrhand.c b/server/plrhand.c
index 49cae2c..a390a93 100644
--- a/server/plrhand.c
+++ b/server/plrhand.c
@@ -862,11 +862,6 @@ static void package_player_common(struct player *plr,
     packet->small_wonders[i] = plr->small_wonders[i];
   }
   packet->science_cost = plr->ai.science_cost;
-
-  packet->gold = plr->economic.gold;
-  packet->government = government_of_player(plr)
-                       ? government_of_player(plr)->index
-                       : -1;
 }
 
 /**************************************************************************
@@ -913,6 +908,15 @@ static void package_player_info(struct player *plr,
     packet->score = 0;
   }
 
+  if (info_level >= INFO_MEETING) {
+    packet->gold = plr->economic.gold;
+    packet->government = government_of_player(plr)
+      ? government_of_player(plr)->index : -1;
+  } else {
+    packet->gold = 0;
+    packet->government = -1;
+  }
+   
   /* Send diplomatic status of the player to everyone they are in
    * contact with. */
   if (info_level >= INFO_EMBASSY
 common/government.c |   33 ++++++++++++++++++++++-----------
 server/plrhand.c    |   14 +++++++++-----
 2 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/common/government.c b/common/government.c
index f97d514..dbf5186 100644
--- a/common/government.c
+++ b/common/government.c
@@ -30,8 +30,6 @@
 
 struct government *governments = NULL;
 
-#define CHECK_GOVERNMENT(gp) assert((NULL != gp) && ((gp) == &governments[(gp)->item_number]))
-
 /****************************************************************************
   Returns the government that has the given (translated) name.
   Returns NULL if none match.
@@ -131,7 +129,10 @@ struct government *government_of_city(const struct city *pcity)
 ****************************************************************************/
 const char *government_rule_name(const struct government *pgovern)
 {
-  CHECK_GOVERNMENT(pgovern);
+  if (!pgovern) {
+    return "Unknown";
+  }
+
   return Qn_(pgovern->name.vernacular);
 }
 
@@ -141,7 +142,10 @@ const char *government_rule_name(const struct government *pgovern)
 ****************************************************************************/
 const char *government_name_translation(struct government *pgovern)
 {
-  CHECK_GOVERNMENT(pgovern);
+  if (!pgovern) {
+    return _("Unknown");
+  }
+
   if (NULL == pgovern->name.translated) {
     /* delayed (unified) translation */
     pgovern->name.translated = ('\0' == pgovern->name.vernacular[0])
@@ -166,13 +170,22 @@ const char *government_name_for_player(const struct player *pplayer)
 ***************************************************************/
 const char *ruler_title_translation(const struct player *pp)
 {
-  struct government *gp = government_of_player(pp);
-  struct nation_type *np = nation_of_player(pp);
+  struct government *gp;
+  struct nation_type *np;
   struct ruler_title *best_match = NULL;
   struct name_translation *sex;
   int i;
 
-  CHECK_GOVERNMENT(gp);
+  if (!pp) {
+    return "";
+  }
+
+  gp = government_of_player(pp);
+  if (!gp) {
+    return pp->is_male ? _("Mr.") : _("Ms.");
+  }
+
+  np = nation_of_player(pp);
 
   for(i=0; i<gp->num_ruler_titles; i++) {
     struct ruler_title *title = &gp->ruler_titles[i];
@@ -192,7 +205,7 @@ const char *ruler_title_translation(const struct player *pp)
 	    government_number(gp),
 	    nation_rule_name(np),
 	    nation_number(np));
-    return pp->is_male ? "Mr." : "Ms.";
+    return pp->is_male ? _("Mr.") : _("Ms.");
   }
 
   sex = pp->is_male ? &best_match->male : &best_match->female;
@@ -216,9 +229,7 @@ const char *ruler_title_translation(const struct player *pp)
 bool can_change_to_government(struct player *pplayer,
 			      const struct government *gov)
 {
-  CHECK_GOVERNMENT(gov);
-
-  if (!pplayer) {
+  if (!pplayer || !gov) {
     return FALSE;
   }
 
diff --git a/server/plrhand.c b/server/plrhand.c
index 098bf5e..afa4ff2 100644
--- a/server/plrhand.c
+++ b/server/plrhand.c
@@ -877,11 +877,6 @@ static void package_player_common(struct player *plr,
     packet->small_wonders[i] = plr->small_wonders[i];
   }
   packet->science_cost = plr->ai.science_cost;
-
-  packet->gold = plr->economic.gold;
-  packet->government = government_of_player(plr)
-                       ? government_number(government_of_player(plr))
-                       : -1;
 }
 
 /**************************************************************************
@@ -928,6 +923,15 @@ static void package_player_info(struct player *plr,
     packet->score = 0;
   }
 
+  if (info_level >= INFO_MEETING) {
+    struct government *pgov = government_of_player(plr);
+    packet->gold = plr->economic.gold;
+    packet->government = pgov ? government_number(pgov) : -1;
+  } else {
+    packet->gold = 0;
+    packet->government = -1;
+  }
+   
   /* Send diplomatic status of the player to everyone they are in
    * contact with. */
   if (info_level >= INFO_EMBASSY
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to