Author: cazfi
Date: Thu Sep 10 21:45:35 2015
New Revision: 29856

URL: http://svn.gna.org/viewcvs/freeciv?rev=29856&view=rev
Log:
Keep track if player has a real name or not separately from the name to display.
Made the "Unassigned" player name translatable.

See patch #6282

Modified:
    branches/S2_6/client/packhand.c
    branches/S2_6/common/packets.def
    branches/S2_6/common/player.c
    branches/S2_6/common/player.h
    branches/S2_6/fc_version
    branches/S2_6/server/animals.c
    branches/S2_6/server/barbarian.c
    branches/S2_6/server/connecthand.c
    branches/S2_6/server/edithand.c
    branches/S2_6/server/plrhand.c
    branches/S2_6/server/savecompat.c
    branches/S2_6/server/savegame.c
    branches/S2_6/server/savegame2.c
    branches/S2_6/server/srv_main.c
    branches/S2_6/server/stdinhand.c

Modified: branches/S2_6/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/client/packhand.c     (original)
+++ branches/S2_6/client/packhand.c     Thu Sep 10 21:45:35 2015
@@ -162,8 +162,10 @@
   memset(invisible.placeholder, 0, sizeof(*invisible.placeholder));
   /* Set some values to prevent bugs ... */
   sz_strlcpy(invisible.placeholder->name, ANON_PLAYER_NAME);
-  sz_strlcpy(invisible.placeholder->username, ANON_USER_NAME);
+  sz_strlcpy(invisible.placeholder->username, _(ANON_USER_NAME));
+  invisible.placeholder->unassigned_user = TRUE;
   sz_strlcpy(invisible.placeholder->ranked_username, ANON_USER_NAME);
+  invisible.placeholder->unassigned_ranked = TRUE;
 }
 
 /****************************************************************************
@@ -2099,7 +2101,7 @@
   /* Now update the player information. */
   sz_strlcpy(pplayer->name, pinfo->name);
   sz_strlcpy(pplayer->username, pinfo->username);
-
+  pplayer->unassigned_user = pinfo->unassigned_user;
 
   is_new_nation = player_set_nation(pplayer, pnation);
   pplayer->is_male = pinfo->is_male;

Modified: branches/S2_6/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/packets.def?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/common/packets.def    (original)
+++ branches/S2_6/common/packets.def    Thu Sep 10 21:45:35 2015
@@ -760,6 +760,7 @@
   PLAYER playerno; key
   STRING name[MAX_LEN_NAME];
   STRING username[MAX_LEN_NAME];
+  BOOL unassigned_user;
 
   UINT32 score;
   BOOL is_male;

Modified: branches/S2_6/common/player.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/player.c?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/common/player.c       (original)
+++ branches/S2_6/common/player.c       Thu Sep 10 21:45:35 2015
@@ -520,8 +520,10 @@
   int i;
 
   sz_strlcpy(pplayer->name, ANON_PLAYER_NAME);
-  sz_strlcpy(pplayer->username, ANON_USER_NAME);
-  sz_strlcpy(pplayer->ranked_username, ANON_USER_NAME);
+  sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
+  pplayer->unassigned_user = TRUE;
+  sz_strlcpy(pplayer->ranked_username, _(ANON_USER_NAME));
+  pplayer->unassigned_ranked = TRUE;
   pplayer->user_turns = 0;
   pplayer->is_male = TRUE;
   pplayer->government = NULL;
@@ -857,7 +859,7 @@
 }
 
 /***************************************************************
-Find player by its user name (not player/leader name)
+ Find player by its user name (not player/leader name)
 ***************************************************************/
 struct player *player_by_user(const char *name)
 {

Modified: branches/S2_6/common/player.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/player.h?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/common/player.h       (original)
+++ branches/S2_6/common/player.h       Thu Sep 10 21:45:35 2015
@@ -39,7 +39,11 @@
 #define PLAYER_DEFAULT_LUXURY_RATE 0
 
 #define ANON_PLAYER_NAME "noname"
-#define ANON_USER_NAME "Unassigned"
+
+/* If changing this, be sure to adjust loading of pre-2.6 savegames
+ * which depend on saved username to tell if user (or ranked_user) is
+ * anonymous. */
+#define ANON_USER_NAME N_("Unassigned")
 
 enum plrcolor_mode {
   PLRCOL_PLR_ORDER,
@@ -214,7 +218,9 @@
   struct player_slot *slot;
   char name[MAX_LEN_NAME];
   char username[MAX_LEN_NAME];
+  bool unassigned_user;
   char ranked_username[MAX_LEN_NAME]; /* the user who will be ranked */
+  bool unassigned_ranked;
   int user_turns;            /* number of turns this user has played */
   bool is_male;
   struct government *government; /* may be NULL in pregame */

Modified: branches/S2_6/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/fc_version    (original)
+++ branches/S2_6/fc_version    Thu Sep 10 21:45:35 2015
@@ -54,7 +54,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Sep.05"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Sep.06"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: branches/S2_6/server/animals.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/animals.c?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/server/animals.c      (original)
+++ branches/S2_6/server/animals.c      Thu Sep 10 21:45:35 2015
@@ -113,7 +113,8 @@
 
   server.nbarbarians++;
 
-  sz_strlcpy(plr->username, ANON_USER_NAME);
+  sz_strlcpy(plr->username, _(ANON_USER_NAME));
+  plr->unassigned_user = TRUE;
   plr->is_connected = FALSE;
   plr->government = anination->init_government;
   plr->economic.gold = 100;

Modified: branches/S2_6/server/barbarian.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/barbarian.c?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/server/barbarian.c    (original)
+++ branches/S2_6/server/barbarian.c    Thu Sep 10 21:45:35 2015
@@ -111,7 +111,8 @@
         old_barbs->name[0] = '\0';
         sz_strlcpy(old_barbs->name,
                    pick_random_player_name(nation_of_player(old_barbs)));
-        sz_strlcpy(old_barbs->username, ANON_USER_NAME);
+        sz_strlcpy(old_barbs->username, _(ANON_USER_NAME));
+        old_barbs->unassigned_user = TRUE;
         /* I need to make them to forget the map, I think */
        whole_map_iterate(ptile) {
          map_clear_known(ptile, old_barbs);
@@ -144,7 +145,8 @@
 
   server.nbarbarians++;
 
-  sz_strlcpy(barbarians->username, ANON_USER_NAME);
+  sz_strlcpy(barbarians->username, _(ANON_USER_NAME));
+  barbarians->unassigned_user = TRUE;
   barbarians->is_connected = FALSE;
   barbarians->government = nation->init_government;
   fc_assert(barbarians->revolution_finishes < 0);

Modified: branches/S2_6/server/connecthand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/connecthand.c?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/server/connecthand.c  (original)
+++ branches/S2_6/server/connecthand.c  Thu Sep 10 21:45:35 2015
@@ -600,6 +600,7 @@
     }
 
     sz_strlcpy(pplayer->username, pconn->username);
+    pplayer->unassigned_user = FALSE;
     pplayer->user_turns = 0; /* reset for a new user */
     pplayer->is_connected = TRUE;
 
@@ -641,7 +642,8 @@
   players_iterate(aplayer) {
     if (aplayer != pplayer
         && 0 == strncmp(aplayer->username, pconn->username, MAX_LEN_NAME)) {
-      sz_strlcpy(aplayer->username, ANON_USER_NAME);
+      sz_strlcpy(aplayer->username, _(ANON_USER_NAME));
+      aplayer->unassigned_user = TRUE;
       send_player_info_c(aplayer, NULL);
     }
   } players_iterate_end;
@@ -811,6 +813,7 @@
     /* Setting orig_username in the player we're about to put aside is
      * a flag that no-one should be allowed to mess with it (e.g. /take). */
     struct player *oplayer = conn_get_player(pconn);
+
     fc_assert_ret_val(oplayer != dplayer, FALSE);
     fc_assert_ret_val(strlen(oplayer->server.orig_username) == 0, FALSE);
     sz_strlcpy(oplayer->server.orig_username, oplayer->username);

Modified: branches/S2_6/server/edithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/edithand.c?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/server/edithand.c     (original)
+++ branches/S2_6/server/edithand.c     Thu Sep 10 21:45:35 2015
@@ -1105,7 +1105,8 @@
     /* Find a color for the new player. */
     assign_player_colors();
   }
-  sz_strlcpy(pplayer->username, ANON_USER_NAME);
+  sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
+  pplayer->unassigned_user = TRUE;
   pplayer->is_connected = FALSE;
   pplayer->government = pnation->init_government;
   pplayer->server.got_first_city = FALSE;

Modified: branches/S2_6/server/plrhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/plrhand.c?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/server/plrhand.c      (original)
+++ branches/S2_6/server/plrhand.c      Thu Sep 10 21:45:35 2015
@@ -995,8 +995,9 @@
   packet->playerno = player_number(plr);
   sz_strlcpy(packet->name, player_name(plr));
   sz_strlcpy(packet->username, plr->username);
+  packet->unassigned_user = plr->unassigned_user;
   packet->nation = plr->nation ? nation_number(plr->nation) : NATION_NONE;
-  packet->is_male=plr->is_male;
+  packet->is_male = plr->is_male;
   packet->team = plr->team ? team_number(plr->team) : team_count();
   packet->is_ready = plr->is_ready;
   packet->was_created = plr->was_created;
@@ -2400,7 +2401,8 @@
   /* Send information about the used player slot to all connections. */
   send_player_info_c(cplayer, NULL);
 
-  sz_strlcpy(cplayer->username, ANON_USER_NAME);
+  sz_strlcpy(cplayer->username, _(ANON_USER_NAME));
+  cplayer->unassigned_user = TRUE;
   cplayer->is_connected = FALSE;
   cplayer->government = nation_of_player(cplayer)->init_government;
   fc_assert(cplayer->revolution_finishes < 0);

Modified: branches/S2_6/server/savecompat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savecompat.c?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/server/savecompat.c   (original)
+++ branches/S2_6/server/savecompat.c   Thu Sep 10 21:45:35 2015
@@ -763,6 +763,7 @@
     int old_barb_type;
     enum barbarian_type new_barb_type;
     int i;
+    const char *name;
 
     /* Renamed 'capital' to 'got_first_city'. */
     if (secfile_lookup_bool(loading->file, &got_first_city, 
@@ -770,6 +771,15 @@
       secfile_insert_bool(loading->file, got_first_city,
                           "player%d.got_first_city", plrno);
     }
+
+    /* Add 'anonymous' qualifiers for user names */
+    name = secfile_lookup_str_default(loading->file, "", "player%d.username", 
plrno);
+    secfile_insert_bool(loading->file, (!strcmp(name, ANON_USER_NAME)),
+                        "player%d.anon_user", plrno);
+
+    name = secfile_lookup_str_default(loading->file, "", 
"player%d.ranked_username", plrno);
+    secfile_insert_bool(loading->file, (!strcmp(name, ANON_USER_NAME)),
+                        "player%d.anon_ranked", plrno);
 
     /* Convert numeric barbarian type to textual */
     old_barb_type = secfile_lookup_int_default(loading->file, 0,
@@ -964,6 +974,27 @@
       }
     }
     secfile_insert_int(loading->file, count, "research.count");
+  }
+
+  nplayers = secfile_lookup_int_default(loading->file, 0, "players.nplayers");
+
+  for (plrno = 0; plrno < nplayers; plrno++) {
+    /* Add 'anonymous' qualifiers for user names */
+    if (secfile_entry_lookup(loading->file, "player%d.anon_user", plrno) == 
NULL) {
+      const char *name;
+
+      name = secfile_lookup_str_default(loading->file, "", 
"player%d.username", plrno);
+      secfile_insert_bool(loading->file, (!strcmp(name, ANON_USER_NAME)),
+                          "player%d.anon_user", plrno);
+    }
+
+    if (secfile_entry_lookup(loading->file, "player%d.anon_ranked", plrno) == 
NULL) {
+      const char *name;
+
+      name = secfile_lookup_str_default(loading->file, "", 
"player%d.ranked_username", plrno);
+      secfile_insert_bool(loading->file, (!strcmp(name, ANON_USER_NAME)),
+                          "player%d.anon_ranked", plrno);
+    }
   }
 }
 

Modified: branches/S2_6/server/savegame.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savegame.c?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/server/savegame.c     (original)
+++ branches/S2_6/server/savegame.c     Thu Sep 10 21:45:35 2015
@@ -1655,9 +1655,11 @@
                                                  plrno));
   sz_strlcpy(plr->username,
             secfile_lookup_str_default(file, "", "player%d.username", plrno));
+  plr->unassigned_user = (!strcmp(plr->username, ANON_USER_NAME));
   sz_strlcpy(plr->ranked_username,
             secfile_lookup_str_default(file, "", "player%d.ranked_username", 
              plrno));
+  plr->unassigned_ranked = (!strcmp(plr->ranked_username, ANON_USER_NAME));
 
   /* 1.15 and later versions store nations by name.  Try that first. */
   p = secfile_lookup_str(file, "player%d.nation", plrno);

Modified: branches/S2_6/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savegame2.c?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/server/savegame2.c    (original)
+++ branches/S2_6/server/savegame2.c    Thu Sep 10 21:45:35 2015
@@ -3853,10 +3853,16 @@
   sz_strlcpy(plr->username,
              secfile_lookup_str_default(loading->file, "",
                                         "player%d.username", plrno));
+  sg_failure_ret(secfile_lookup_bool(loading->file, &plr->unassigned_user,
+                                     "player%d.unassigned_user", plrno),
+                 "%s", secfile_error());
   sz_strlcpy(plr->ranked_username,
              secfile_lookup_str_default(loading->file, "",
                                         "player%d.ranked_username",
                                         plrno));
+  sg_failure_ret(secfile_lookup_bool(loading->file, &plr->unassigned_ranked,
+                                     "player%d.unassigned_ranked", plrno),
+                 "%s", secfile_error());
   string = secfile_lookup_str_default(loading->file, "",
                                       "player%d.delegation_username",
                                       plrno);
@@ -4228,6 +4234,8 @@
                      "player%d.name", plrno);
   secfile_insert_str(saving->file, plr->username,
                      "player%d.username", plrno);
+  secfile_insert_bool(saving->file, plr->unassigned_user,
+                      "player%d.unassigned_user", plrno);
   if (plr->rgb != NULL) {
     rgbcolor_save(saving->file, plr->rgb, "player%d.color", plrno);
   } else {
@@ -4238,6 +4246,8 @@
   }
   secfile_insert_str(saving->file, plr->ranked_username,
                      "player%d.ranked_username", plrno);
+  secfile_insert_bool(saving->file, plr->unassigned_ranked,
+                      "player%d.unassigned_ranked", plrno);
   secfile_insert_str(saving->file,
                      player_delegation_get(plr) ? player_delegation_get(plr)
                                                 : "",

Modified: branches/S2_6/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.c?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/server/srv_main.c     (original)
+++ branches/S2_6/server/srv_main.c     Thu Sep 10 21:45:35 2015
@@ -931,10 +931,11 @@
    * for long enough. The first user to do so becomes "associated" to that
    * player for ranking purposes. */
   players_iterate(pplayer) {
-    if (strcmp(pplayer->ranked_username, ANON_USER_NAME) == 0
+    if (pplayer->unassigned_ranked
         && pplayer->user_turns++ > TURNS_NEEDED_TO_RANK
        && pplayer->is_alive) {
       sz_strlcpy(pplayer->ranked_username, pplayer->username);
+      pplayer->unassigned_ranked = pplayer->unassigned_user;
     }
   } players_iterate_end;
 
@@ -2148,7 +2149,8 @@
     } while (player_by_name(leader_name));
     server_player_set_name(pplayer, leader_name);
     pplayer->random_name = TRUE;
-    sz_strlcpy(pplayer->username, ANON_USER_NAME);
+    sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
+    pplayer->unassigned_user = TRUE;
 
     pplayer->ai_common.skill_level = game.info.skill_level;
     pplayer->ai_controlled = TRUE;

Modified: branches/S2_6/server/stdinhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/stdinhand.c?rev=29856&r1=29855&r2=29856&view=diff
==============================================================================
--- branches/S2_6/server/stdinhand.c    (original)
+++ branches/S2_6/server/stdinhand.c    Thu Sep 10 21:45:35 2015
@@ -191,6 +191,8 @@
              || fc_strcasecmp(name, "Observer") == 0) {
     fc_snprintf(buf, buflen, _("That name is not allowed."));
     /* "Observer" used to be illegal and we keep it that way for now. */
+    /* FIXME: This disallows anonymous player name as it appears in English,
+     * but not one in any other language that the user may see. */
     return FALSE;
   }
 
@@ -906,7 +908,8 @@
   give_initial_techs(presearch, 0);
 
   server_player_set_name(pplayer, name);
-  sz_strlcpy(pplayer->username, ANON_USER_NAME);
+  sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
+  pplayer->unassigned_user = TRUE;
 
   pplayer->was_created = TRUE; /* must use /remove explicitly to remove */
   pplayer->ai_controlled = TRUE;
@@ -1029,7 +1032,8 @@
   server_player_init(pplayer, FALSE, TRUE);
 
   server_player_set_name(pplayer, name);
-  sz_strlcpy(pplayer->username, ANON_USER_NAME);
+  sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
+  pplayer->unassigned_user = TRUE;
 
   pplayer->was_created = TRUE; /* must use /remove explicitly to remove */
   pplayer->random_name = rand_name;
@@ -3518,7 +3522,8 @@
    * reset its username. */
   players_iterate(aplayer) {
     if (0 == strncmp(aplayer->username, pconn->username, MAX_LEN_NAME)) {
-      sz_strlcpy(aplayer->username, ANON_USER_NAME);
+      sz_strlcpy(aplayer->username, _(ANON_USER_NAME));
+      aplayer->unassigned_user = TRUE;
       send_player_info_c(aplayer, NULL);
     }
   } players_iterate_end;
@@ -5690,7 +5695,8 @@
 
   if (conn_controls_player(ptarget)) {
     /* If we cut the connection, unassign the login name.*/
-    sz_strlcpy(ptarget->playing->username, ANON_USER_NAME);
+    sz_strlcpy(ptarget->playing->username, _(ANON_USER_NAME));
+    ptarget->playing->unassigned_user = TRUE;
   }
 
   cmd_reply(CMD_CUT, caller, C_DISCONNECTED,
@@ -5827,7 +5833,8 @@
 
     if (conn_controls_player(aconn)) {
       /* Unassign the username. */
-      sz_strlcpy(aconn->playing->username, ANON_USER_NAME);
+      sz_strlcpy(aconn->playing->username, _(ANON_USER_NAME));
+      aconn->playing->unassigned_user = TRUE;
     }
 
     kick_hash_replace(kick_table_by_user, aconn->username, now);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to