Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2005:
[Freeciv-Dev] (PR#13631) respect to_client in sending of options_settabl
Home

[Freeciv-Dev] (PR#13631) respect to_client in sending of options_settabl

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13631) respect to_client in sending of options_settable
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 8 Aug 2005 13:28:19 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch respects the to_client value when sending server settings to 
the client in the options_settable packet.

In the current code this value is ignored.  Even though /show mapseed 
will refuse to give you the seed (which would allow cheating in 
multi-player) looking at the settings dialog will show you the value. 
(This is true in 2.0 as well but isn't as big of a problem since these 
dangerous options aren't changeable in-game, and that *is* checked.)

This patch fixes it for the development branch.  The setting info is 
still sent to the client (preserving the continuity of the array) but no 
value is sent for it, and an is_visible value is sent as FALSE.  The 
client then displays these settings as "(hidden)".

You won't see this in action in a single-player game since to_client is 
ignored when you have HACK access.

Also attached is a simple fix for 2.0.  As I said the problem isn't as 
bad here, but it is buggy: it shows the map seed in pregame even though 
you can't see/set it through the chatline.

-jason

Index: client/repodlgs_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/repodlgs_common.c,v
retrieving revision 1.27
diff -p -u -r1.27 repodlgs_common.c
--- client/repodlgs_common.c    8 Aug 2005 16:30:22 -0000       1.27
+++ client/repodlgs_common.c    8 Aug 2005 20:12:38 -0000
@@ -273,6 +273,7 @@ void handle_options_settable(struct pack
   settable_options[i].type = packet->type;
   settable_options[i].class = packet->class;
   settable_options[i].category = packet->category;
+  settable_options[i].is_visible = packet->is_visible;
 
   switch (settable_options[i].type) {
   case SSET_BOOL:
Index: client/repodlgs_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/repodlgs_common.h,v
retrieving revision 1.10
diff -p -u -r1.10 repodlgs_common.h
--- client/repodlgs_common.h    8 Aug 2005 16:30:22 -0000       1.10
+++ client/repodlgs_common.h    8 Aug 2005 20:12:38 -0000
@@ -56,6 +56,7 @@ struct options_settable {
   enum sset_type type;
   enum sset_class class;
   unsigned char category;
+  bool is_visible;
 
   int val;
   int default_val;
Index: client/gui-gtk-2.0/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/repodlgs.c,v
retrieving revision 1.95
diff -p -u -r1.95 repodlgs.c
--- client/gui-gtk-2.0/repodlgs.c       8 Aug 2005 16:30:22 -0000       1.95
+++ client/gui-gtk-2.0/repodlgs.c       8 Aug 2005 20:12:38 -0000
@@ -1521,7 +1521,8 @@ static void create_settable_options_dial
       gtk_tooltips_set_tip(tips, ebox, buf, NULL);
     }
 
-    if (setting_class_is_changeable(settable_options[i].class)) {
+    if (setting_class_is_changeable(settable_options[i].class)
+       && settable_options[i].is_visible) {
       double step, max, min;
 
       /* create the proper entry method depending on the type */
@@ -1567,17 +1568,21 @@ static void create_settable_options_dial
     } else {
       char buf[1024];
 
-      switch (settable_options[i].type) {
-      case SSET_BOOL:
-       my_snprintf(buf, sizeof(buf), "%s",
-                   settable_options[i].val != 0 ? _("true") : _("false"));
-       break;
-      case SSET_INT:
-       my_snprintf(buf, sizeof(buf), "%d", settable_options[i].val);
-       break;
-      case SSET_STRING:
-       my_snprintf(buf, sizeof(buf), "%s", settable_options[i].strval);
-       break;
+      if (settable_options[i].is_visible) {
+       switch (settable_options[i].type) {
+       case SSET_BOOL:
+         my_snprintf(buf, sizeof(buf), "%s",
+                     settable_options[i].val != 0 ? _("true") : _("false"));
+         break;
+       case SSET_INT:
+         my_snprintf(buf, sizeof(buf), "%d", settable_options[i].val);
+         break;
+       case SSET_STRING:
+         my_snprintf(buf, sizeof(buf), "%s", settable_options[i].strval);
+         break;
+       }
+      } else {
+       my_snprintf(buf, sizeof(buf), "%s", _("(hidden)"));
       }
       ent = gtk_label_new(buf);
     }
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.263
diff -p -u -r1.263 capstr.c
--- common/capstr.c     8 Aug 2005 16:30:23 -0000       1.263
+++ common/capstr.c     8 Aug 2005 20:12:38 -0000
@@ -82,7 +82,7 @@ const char * const our_capability = our_
  *     as long as possible.  We want to maintain network compatibility with
  *     the stable branch for as long as possible.
  */
-#define CAPABILITY "+Freeciv.Devel.2005.Aug.12"
+#define CAPABILITY "+Freeciv.Devel.2005.Aug.8"
 
 void init_our_capability(void)
 {
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.148
diff -p -u -r1.148 packets.def
--- common/packets.def  8 Aug 2005 16:30:23 -0000       1.148
+++ common/packets.def  8 Aug 2005 20:12:39 -0000
@@ -1318,8 +1318,10 @@ PACKET_OPTIONS_SETTABLE=113;sc,lsend
   STRING name[MAX_LEN_NAME];
   STRING short_help[MAX_LEN_PACKET];
   STRING extra_help[MAX_LEN_PACKET];
+
   SSET_TYPE type;
   SSET_CLASS class;
+  BOOL is_visible;
 
   SINT32 val;                                  /* value for bool or int */
   SINT32 default_val;                          /* default for bool or int */
Index: server/settings.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settings.h,v
retrieving revision 1.6
diff -p -u -r1.6 settings.h
--- server/settings.h   8 Aug 2005 16:30:24 -0000       1.6
+++ server/settings.h   8 Aug 2005 20:12:39 -0000
@@ -22,9 +22,8 @@
  * server options; also determines whether clients can set them in principle.
  * Eg, not sent: seeds, saveturns, etc.
  */
-enum sset_to_client {
-  SSET_TO_CLIENT, SSET_SERVER_ONLY
-};
+#define SSET_TO_CLIENT TRUE
+#define SSET_SERVER_ONLY FALSE
 
 /* Categories allow options to be usefully organized when presented to the user
  */
@@ -57,7 +56,7 @@ extern const int OLEVELS_NUM;
 struct settings_s {
   const char *name;
   enum sset_class sclass;
-  enum sset_to_client to_client;
+  bool to_client;
 
   /*
    * Sould be less than 42 chars (?), or shorter if the values may
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.429
diff -p -u -r1.429 stdinhand.c
--- server/stdinhand.c  8 Aug 2005 16:30:24 -0000       1.429
+++ server/stdinhand.c  8 Aug 2005 20:12:39 -0000
@@ -117,6 +117,8 @@ sent to the client.
 *********************************************************************/
 static bool sset_is_to_client(int idx)
 {
+  assert(settings[idx].to_client == SSET_TO_CLIENT
+        || settings[idx].to_client == SSET_SERVER_ONLY);
   return (settings[idx].to_client == SSET_TO_CLIENT);
 }
 
@@ -1613,35 +1615,41 @@ static void send_server_setting(struct c
     dest = game.est_connections;
   }
 
-  memset(&packet, 0, sizeof(packet));
+  conn_list_iterate(dest, pconn) {
+    memset(&packet, 0, sizeof(packet));
 
-  packet.id = setting_id;
-  sz_strlcpy(packet.name, setting->name);
-  sz_strlcpy(packet.short_help, setting->short_help);
-  sz_strlcpy(packet.extra_help, setting->extra_help);
-
-  packet.category = setting->category;
-  packet.type = setting->type;
-  packet.class = setting->sclass;
+    packet.id = setting_id;
+    sz_strlcpy(packet.name, setting->name);
+    sz_strlcpy(packet.short_help, setting->short_help);
+    sz_strlcpy(packet.extra_help, setting->extra_help);
+
+    packet.category = setting->category;
+    packet.type = setting->type;
+    packet.class = setting->sclass;
+    packet.is_visible = (sset_is_to_client(setting_id)
+                        || pconn->access_level == ALLOW_HACK);
 
-  switch (setting->type) {
-  case SSET_STRING:
-    strcpy(packet.strval, setting->string_value);
-    strcpy(packet.default_strval, setting->string_default_value);
-    break;
-  case SSET_BOOL:
-    packet.val = *(setting->bool_value);
-    packet.default_val = setting->bool_default_value;
-    break;
-  case SSET_INT:
-    packet.min = setting->int_min_value;
-    packet.max = setting->int_max_value;
-    packet.val = *(setting->int_value);
-    packet.default_val = setting->int_default_value;
-    break;
-  }
+    if (packet.is_visible) {
+      switch (setting->type) {
+      case SSET_STRING:
+       strcpy(packet.strval, setting->string_value);
+       strcpy(packet.default_strval, setting->string_default_value);
+       break;
+      case SSET_BOOL:
+       packet.val = *(setting->bool_value);
+       packet.default_val = setting->bool_default_value;
+       break;
+      case SSET_INT:
+       packet.min = setting->int_min_value;
+       packet.max = setting->int_max_value;
+       packet.val = *(setting->int_value);
+       packet.default_val = setting->int_default_value;
+       break;
+      }
+    }
 
-  lsend_packet_options_settable(dest, &packet);
+    send_packet_options_settable(pconn, &packet);
+  } conn_list_iterate_end;
 }
 
 /****************************************************************************
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.354.2.38
diff -p -u -r1.354.2.38 stdinhand.c
--- server/stdinhand.c  8 Aug 2005 19:48:30 -0000       1.354.2.38
+++ server/stdinhand.c  8 Aug 2005 20:27:00 -0000
@@ -1705,6 +1705,10 @@ void report_settable_server_options(stru
     if (!sset_is_changeable(i)) {
       continue;
     }
+    if (settings[i].to_client == SSET_SERVER_ONLY
+       && dest->access_level != ALLOW_HACK) {
+      continue;
+    }
     s++;
   }
 
@@ -1723,6 +1727,10 @@ void report_settable_server_options(stru
     if (!sset_is_changeable(i)) {
       continue;
     }
+    if (settings[i].to_client == SSET_SERVER_ONLY
+       && dest->access_level != ALLOW_HACK) {
+      continue;
+    }
     memset(&packet, 0, sizeof(packet));
 
     packet.id = s++;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13631) respect to_client in sending of options_settable, Jason Short <=