Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2003:
[Freeciv-Dev] Re: (PR#4737) allowconnect option is now obsolete
Home

[Freeciv-Dev] Re: (PR#4737) allowconnect option is now obsolete

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: matusik_s@xxxxx
Subject: [Freeciv-Dev] Re: (PR#4737) allowconnect option is now obsolete
From: "Mike Kaufman" <kaufman@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 7 Aug 2003 06:58:26 -0700
Reply-to: rt@xxxxxxxxxxxxxx

here is a patch that eliminates allowconnect in favor of allowtake.
Behavior is different! Here's the help text:

Option: allowtake  -  Players that users are allowed to take
Description:
  This should be a string of characters, each of which specifies a type or
  status of a civilization, or "player".  Clients will only be permitted to
  take or observe those players which match one of the specified letters. 
  This only affects future uses of the take or observe command.  The
  characters and their meanings are:
      H,h = Human players
      A,a = AI players
      d   = Dead players
      b   = Barbarian players
  The first description from the _bottom_ which matches a player is the one
  which applies.  Thus 'd' does not include Barbarians, 'a' does not include
  dead AI players, and so on.  Upper case letters apply before the game has
  started, lower case letters afterwards.
  Each character above may be followed by one of the following numbers to
  allow or restrict the manner of connection:
    (none) = Controller allowed, observers allowed,
             can displace connections.
    1 = Controller allowed, observers allowed,
        can't displace connections;
    2 = Controller allowed, no observers allowed,
        can displace connections;
    3 = Controller allowed, no observers allowed,
        can't displace connections;
    4 = No controller allowed, observers allowed;
  "Displacing a connection" means that you may take over a player that another
  user already has control of.
Status: changeable
Value: "HAhad", Default: "HAhad"

****************************************************

So characters have been replaced by numbers, the higher, the less
permissive. Also the 'N' category has been removed. For the default, I've
given the most permissive defaults, but pubserver will almost certainly
want to have something like "H3h3A1a1d4" similar.

Comments are welcome, especially from mulitplayer people.

-mike

diff -Nur -Xsnap/diff_ignore snap/common/game.c snap-take/common/game.c
--- snap/common/game.c  2003-08-05 19:01:19.000000000 -0500
+++ snap-take/common/game.c     2003-08-07 08:27:49.000000000 -0500
@@ -276,7 +276,7 @@
   game.ai_goal_government = G_MAGIC;        /* flag */
 
   sz_strlcpy(game.demography, GAME_DEFAULT_DEMOGRAPHY);
-  sz_strlcpy(game.allow_connect, GAME_DEFAULT_ALLOW_CONNECT);
+  sz_strlcpy(game.allow_take, GAME_DEFAULT_ALLOW_TAKE);
 
   game.save_options.save_random = TRUE;
   game.save_options.save_players = TRUE;
diff -Nur -Xsnap/diff_ignore snap/common/game.h snap-take/common/game.h
--- snap/common/game.h  2003-07-25 07:52:13.000000000 -0500
+++ snap-take/common/game.h     2003-08-07 08:27:49.000000000 -0500
@@ -26,7 +26,7 @@
 
 
 #define MAX_LEN_DEMOGRAPHY  16
-#define MAX_LEN_ALLOW_CONNECT 16
+#define MAX_LEN_ALLOW_TAKE 16
 #define MAX_ID_LEN 33
 
 enum server_states { 
@@ -203,7 +203,7 @@
   } rgame;
 
   char demography[MAX_LEN_DEMOGRAPHY];
-  char allow_connect[MAX_LEN_ALLOW_CONNECT];
+  char allow_take[MAX_LEN_ALLOW_TAKE];
 
   /* used by the map editor to control game_save; could be used by the server 
too */
   struct {
@@ -444,7 +444,7 @@
 #define GAME_OLD_DEFAULT_SKILL_LEVEL 5  /* normal; for old save games */
 
 #define GAME_DEFAULT_DEMOGRAPHY      "NASRLPEMOqrb"
-#define GAME_DEFAULT_ALLOW_CONNECT   "NHAhad"
+#define GAME_DEFAULT_ALLOW_TAKE      "HAhad"
 
 #define GAME_DEFAULT_COMPRESS_LEVEL 6    /* if we have compression */
 #define GAME_MIN_COMPRESS_LEVEL     0
diff -Nur -Xsnap/diff_ignore snap/server/stdinhand.c 
snap-take/server/stdinhand.c
--- snap/server/stdinhand.c     2003-08-05 19:01:33.000000000 -0500
+++ snap-take/server/stdinhand.c        2003-08-07 08:49:23.000000000 -0500
@@ -74,6 +74,9 @@
 static void set_ai_level(struct connection *caller, char *name, int level);
 static void set_away(struct connection *caller, char *name);
 
+static bool is_allowed_to_take(struct player *pplayer, bool will_obs, 
+                               char *msg);
+
 static void fix_command(struct connection *caller, char *str, int cmd_enum);
 static void observe_command(struct connection *caller, char *name);
 static void take_command(struct connection *caller, char *name);
@@ -171,8 +174,7 @@
 static bool valid_notradesize(int value, char **reject_message);
 static bool valid_fulltradesize(int value, char **reject_message);
 static bool autotoggle(bool value, char **reject_message);
-static bool is_valid_allowconnect(const char *allow_connect,
-                                 char **error_string);
+static bool is_valid_allowtake(const char *allow_take, char **error_string);
 
 static bool valid_max_players(int v, char **r_m)
 {
@@ -673,36 +675,38 @@
  * affect what happens in the game, it just determines when the
  * players stop playing and look at the score.)
  */
-  GEN_STRING("allowconnect", game.allow_connect, SSET_META, SSET_TO_CLIENT,
-            N_("What connections are allowed"),
-            N_("This should be a string of characters, each of which "
-               "specifies a type or status of a civilization, or "
-               "\"player\".  Clients will only be permitted to connect "
-               "to those players which match one of the specified "
-               "letters.  This only affects future connections, and "
-               "existing connections are unchanged.  "
-               "The characters and their meanings are:\n"
-               "    N   = New players (only applies pre-game)\n"
-               "    H,h = Human players (pre-existing)\n"
-               "    A,a = AI players\n"
-               "    d   = Dead players\n"
-               "    b   = Barbarian players\n"
-               "The first description from the _bottom_ which matches a "
-               "player is the one which applies.  Thus 'd' does not "
-               "include Barbarians, 'a' does not include dead AI "
-               "players, and so on.  Upper case letters apply before "
-               "the game has started, lower case letters afterwards.\n"
-               "Each character above may be followed by one of the "
-               "following special characters to allow or restrict "
-               "multiple and observer connections:\n"
-               "   * = Multiple controlling connections allowed;\n"
-               "   + = One controller and multiple observers allowed;\n"
-               "   = = Multiple observers allowed, no controllers;\n"
-               "   - = Single observer only, no controllers;\n"
-               "   (none) = Single controller only.\n"
-               "Multiple connections and observer connections are "
-               "currently EXPERIMENTAL."), is_valid_allowconnect,
-            GAME_DEFAULT_ALLOW_CONNECT)
+  GEN_STRING("allowtake", game.allow_take, SSET_META, SSET_TO_CLIENT,
+             N_("Players that users are allowed to take"),
+             N_("This should be a string of characters, each of which "
+                "specifies a type or status of a civilization, or "
+                "\"player\".  Clients will only be permitted to take "
+                "or observe those players which match one of the specified "
+                "letters.  This only affects future uses of the take or "
+                "observe command.  The characters and their meanings are:\n"
+                "    H,h = Human players\n"
+                "    A,a = AI players\n"
+                "    d   = Dead players\n"
+                "    b   = Barbarian players\n"
+                "The first description from the _bottom_ which matches a "
+                "player is the one which applies.  Thus 'd' does not "
+                "include Barbarians, 'a' does not include dead AI "
+                "players, and so on.  Upper case letters apply before "
+                "the game has started, lower case letters afterwards.\n"
+                "Each character above may be followed by one of the "
+                "following numbers to allow or restrict the manner "
+                "of connection:\n"
+                "  (none) = Controller allowed, observers allowed,\n"
+                "           can displace connections.\n"
+                "  1 = Controller allowed, observers allowed,\n"
+                "      can't displace connections;\n"
+                "  2 = Controller allowed, no observers allowed,\n"
+                "      can displace connections;\n"
+                "  3 = Controller allowed, no observers allowed,\n"
+                "      can't displace connections;\n"
+                "  4 = No controller allowed, observers allowed;\n"
+                "\"Displacing a connection\" means that you may take over "
+                "a player that another user already has control of."),
+                is_valid_allowtake, GAME_DEFAULT_ALLOW_TAKE)
 
   GEN_BOOL("autotoggle", game.auto_ai_toggle, SSET_META, SSET_TO_CLIENT,
           N_("Whether AI-status toggles with connection"),
@@ -3087,6 +3091,84 @@
   }
 }
 
+
+/**************************************************************************
+ check game.allow_take for permission to take or observe a player
+**************************************************************************/
+static bool is_allowed_to_take(struct player *pplayer, bool will_obs, 
+                               char *msg)
+{
+  const char *allow;
+
+  if (is_barbarian(pplayer)) {
+    if (!(allow = strchr(game.allow_take, 'b'))) {
+      if (will_obs) {
+        mystrlcpy(msg, _("Sorry, you can't observe barbarians in this game."),
+                  MAX_LEN_MSG);
+      } else {
+        mystrlcpy(msg, _("Sorry, you can't take barbarians in this game."),
+                  MAX_LEN_MSG);
+      }
+      return FALSE;
+    }
+  } else if (!pplayer->is_alive) {
+    if (!(allow = strchr(game.allow_take, 'd'))) {
+      if (will_obs) {
+        mystrlcpy(msg, _("Sorry, you can't observe dead players in this 
game."),
+                  MAX_LEN_MSG);
+      } else {
+        mystrlcpy(msg, _("Sorry, you can't take dead players in this game."),
+                  MAX_LEN_MSG);
+      }
+      return FALSE;
+    }
+  } else if (pplayer->ai.control) {
+    if (!(allow = strchr(game.allow_take, (game.is_new_game ? 'A' : 'a')))) {
+      if (will_obs) {
+        mystrlcpy(msg, _("Sorry, you can't observe AI players in this game."),
+                  MAX_LEN_MSG);
+      } else {
+        mystrlcpy(msg, _("Sorry, you can't take AI players in this game."),
+                  MAX_LEN_MSG);
+      }
+      return FALSE;
+    }
+  } else { 
+    if (!(allow = strchr(game.allow_take, (game.is_new_game ? 'H' : 'h')))) {
+      if (will_obs) {
+        mystrlcpy(msg, 
+                  _("Sorry, you can't observe human players in this game."),
+                  MAX_LEN_MSG);
+      } else {
+        mystrlcpy(msg, _("Sorry, you can't take human players in this game."),
+                  MAX_LEN_MSG);
+      }
+      return FALSE;
+    }
+  }
+
+  allow++;
+
+  if (will_obs && (*allow == '2' || *allow == '3')) {
+    mystrlcpy(msg, _("Sorry, you can't observe in this game."), MAX_LEN_MSG);
+    return FALSE;
+  }
+
+  if (!will_obs && *allow == '4') {
+    mystrlcpy(msg, _("Sorry, you can't take players in this game."),
+              MAX_LEN_MSG);
+    return FALSE;
+  }
+
+  if (!will_obs && pplayer->is_connected && (*allow == '1' || *allow == '3')) {
+    mystrlcpy(msg, _("Sorry, you can't take players already connected "
+                     "in this game."), MAX_LEN_MSG);
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
 /**************************************************************************
  Observe another player. If we were already attached, detach 
  (see detach_command()). The console and those with ALLOW_HACK can
@@ -3095,7 +3177,7 @@
 static void observe_command(struct connection *caller, char *str)
 {
   int i = 0, ntokens = 0;
-  char buf[MAX_LEN_CONSOLE_LINE], *arg[2];  
+  char buf[MAX_LEN_CONSOLE_LINE], *arg[2], msg[MAX_LEN_MSG];  
   bool is_newgame = (server_state == PRE_GAME_STATE || 
                      server_state == SELECT_RACES_STATE) && game.is_new_game;
   
@@ -3166,6 +3248,12 @@
 
   /******** PART II: do the observing ********/
 
+  /* check allowtake for permission */
+  if (!is_allowed_to_take(pplayer, TRUE, msg)) {
+    cmd_reply(CMD_OBSERVE, caller, C_FAIL, msg);
+    goto end;
+  }
+
   /* observing your own player (during pregame) makes no sense. */
   if (pconn->player == pplayer && !pconn->observer
       && is_newgame && !pplayer->was_created) {
@@ -3238,7 +3326,7 @@
 static void take_command(struct connection *caller, char *str)
 {
   int i = 0, ntokens = 0;
-  char buf[MAX_LEN_CONSOLE_LINE], *arg[2];
+  char buf[MAX_LEN_CONSOLE_LINE], *arg[2], msg[MAX_LEN_MSG];
   bool is_newgame = (server_state == PRE_GAME_STATE || 
                      server_state == SELECT_RACES_STATE) && game.is_new_game;
 
@@ -3291,6 +3379,12 @@
 
   /******** PART II: do the attaching ********/
 
+  /* check allowtake for permission */
+  if (!is_allowed_to_take(pplayer, FALSE, msg)) {
+    cmd_reply(CMD_TAKE, caller, C_FAIL, msg);
+    goto end;
+  }
+
   /* taking your own player makes no sense. */
   if (pconn->player == pplayer && !pconn->observer) {
     cmd_reply(CMD_TAKE, caller, C_FAIL, _("%s already controls %s"),
@@ -4292,13 +4386,12 @@
 }
 
 /*************************************************************************
-  Verify that a given allowconnect string is valid.  See
-  game.allow_connect.
+  Verify that a given allowtake string is valid.  See
+  game.allow_take.
 *************************************************************************/
-static bool is_valid_allowconnect(const char *allow_connect,
-                                 char **error_string)
+static bool is_valid_allowtake(const char *allow_take, char **error_string)
 {
-  int len = strlen(allow_connect), i;
+  int len = strlen(allow_take), i;
   bool havecharacter_state = FALSE;
 
   /* We check each character individually to see if it's valid.  This
@@ -4311,22 +4404,21 @@
 
   for (i = 0; i < len; i++) {
     /* Check to see if the character is a primary label. */
-    if (strchr("NHhAadb", allow_connect[i])) {
+    if (strchr("HhAadb", allow_take[i])) {
       havecharacter_state = TRUE;
       continue;
     }
 
     /* If we've already passed a primary label, check to see if the
      * character is a modifier. */
-    if (havecharacter_state
-       && strchr("*+=-", allow_connect[i])) {
+    if (havecharacter_state && strchr("1234", allow_take[i])) {
       havecharacter_state = FALSE;
       continue;
     }
 
     /* Looks like the character was invalid. */
-    *error_string = _("Allowed connections string contains invalid\n"
-                     "characters.  Try \"help allowconnect\".");
+    *error_string = _("Allowed take string contains invalid\n"
+                     "characters.  Try \"help allowtake\".");
     return FALSE;
   }
 

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