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

> [book - Thu Nov 20 05:31:37 2008]:
> 
> Attached patch fixes the is_allowed_to_take() function
> to always set the reason string when it returns FALSE
> so that the above sending of an uninitialized string
> does not occur.

And here's the S2_1 version.


-----------------------------------------------------------------------
喋るな、蛆虫。

diff --git a/server/stdinhand.c b/server/stdinhand.c
index 0d7c7b4..5195a5c 100644
--- a/server/stdinhand.c
+++ b/server/stdinhand.c
@@ -2639,7 +2639,10 @@ static bool set_command(struct connection *caller, char *str, bool check)
 }
 
 /**************************************************************************
- check game.allow_take for permission to take or observe a player
+  Check game.allow_take for permission to take or observe a player.
+
+  NB: If this function returns FALSE, then callers expect that 'msg' will
+  be filled in with a NULL-terminated string containing the reason.
 **************************************************************************/
 static bool is_allowed_to_take(struct player *pplayer, bool will_obs, 
                                char *msg)
@@ -2661,7 +2664,36 @@ static bool is_allowed_to_take(struct player *pplayer, bool will_obs,
     }
   } else if (!pplayer && !will_obs) {
     /* Auto-taking a new player */
-    return game.info.is_new_game && (S_S_INITIAL == server_state());
+
+    if (!game.info.is_new_game || server_state() != S_S_INITIAL) {
+      mystrlcpy(msg, _("You cannot take a new player at this time."),
+                MAX_LEN_MSG);
+      return FALSE;
+    }
+
+    if (player_count() >= game.info.max_players) {
+      my_snprintf(msg, MAX_LEN_MSG,
+                  /* TRANS: Do not translate "maxplayers". */
+                  PL_("You cannot take a new player because "
+                      "the maximum of %d player has already "
+                      "been reached (maxplayers setting).",
+                      "You cannot take a new player because "
+                      "the maximum of %d players has already "
+                      "been reached (maxplayers setting).",
+                      game.info.max_players),
+                  game.info.max_players);
+      return FALSE;
+    }
+
+    if (player_count() >= MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS) {
+      mystrlcpy(msg, _("You cannot take a new player because there "
+                       "are no free player slots."),
+                MAX_LEN_MSG);
+      return FALSE;
+    }
+
+    return TRUE;
+
   } else if (is_barbarian(pplayer)) {
     if (!(allow = strchr(game.allow_take, 'b'))) {
       if (will_obs) {
@@ -2973,7 +3005,7 @@ static bool take_command(struct connection *caller, char *str, bool check)
   /* taking your own player makes no sense. */
   if ((pplayer && !pconn->observer && pconn->player == pplayer)
       || (!pplayer && !pconn->observer && pconn->player)) {
-    cmd_reply(CMD_TAKE, caller, C_FAIL, _("%s already controls %s"),
+    cmd_reply(CMD_TAKE, caller, C_FAIL, _("%s already controls %s."),
               pconn->username,
               player_name(pconn->player));
     goto end;
@@ -2987,7 +3019,7 @@ static bool take_command(struct connection *caller, char *str, bool check)
       && (game.info.nplayers >= game.info.max_players
           || game.info.nplayers - game.info.nbarbarians >= game.playable_nations)) {
     cmd_reply(CMD_TAKE, caller, C_FAIL,
-              _("There is no free player slot for %s"),
+              _("There is no free player slot for %s."),
               pconn->username);
     goto end;
   }
@@ -3098,7 +3130,7 @@ static bool take_command(struct connection *caller, char *str, bool check)
   send_conn_info(pconn->self, game.est_connections);
 
   if (res) {
-    cmd_reply(CMD_TAKE, caller, C_OK, _("%s now controls %s (%s, %s)"), 
+    cmd_reply(CMD_TAKE, caller, C_OK, _("%s now controls %s (%s, %s)."),
               pconn->username,
               player_name(pplayer), 
               is_barbarian(pplayer)
@@ -3110,7 +3142,7 @@ static bool take_command(struct connection *caller, char *str, bool check)
               ? _("Alive")
               : _("Dead"));
   } else {
-    cmd_reply(CMD_TAKE, caller, C_FAIL, _("%s failed to attach to any player"),
+    cmd_reply(CMD_TAKE, caller, C_FAIL, _("%s failed to attach to any player."),
               pconn->username);
   }
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to