Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2005:
[Freeciv-Dev] (PR#13619) rewrite server settings editor
Home

[Freeciv-Dev] (PR#13619) rewrite server settings editor

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13619) rewrite server settings editor
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 5 Aug 2005 11:49:37 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch rewrites large parts of the 
send-server-settings-to-client-and-pop-up-a-dialog-to-edit-them code. 
The end result is that the code and interface are much less terrible, 
and several bugs are fixed.

It doesn't fix PR#13617 as server-only settings are still sent.

-jason

? sset.diff
Index: client/repodlgs_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/repodlgs_common.c,v
retrieving revision 1.26
diff -p -u -r1.26 repodlgs_common.c
--- client/repodlgs_common.c    22 Jul 2005 16:18:05 -0000      1.26
+++ client/repodlgs_common.c    5 Aug 2005 18:44:27 -0000
@@ -230,20 +230,22 @@ void handle_options_settable_control(
 
   settable_options_free();
 
-  options_categories = fc_malloc(packet->ncategories * sizeof(char *));
-  num_options_categories = packet->ncategories;
+  options_categories = fc_malloc(packet->num_categories
+                                * sizeof(*options_categories));
+  num_options_categories = packet->num_categories;
   
   for (i = 0; i < num_options_categories; i++) {
     options_categories[i] = mystrdup(packet->category_names[i]);
   }
 
   /* avoid a malloc of size 0 warning */
-  if (packet->nids == 0) {
+  if (packet->num_settings == 0) {
     return;
   }
 
-  settable_options = fc_malloc(packet->nids * sizeof(struct options_settable));
-  num_settable_options = packet->nids;
+  settable_options = fc_malloc(packet->num_settings
+                              * sizeof(*settable_options));
+  num_settable_options = packet->num_settings;
 
   for (i = 0; i < num_settable_options; i++) {
     settable_options[i].name = NULL;
@@ -269,35 +271,31 @@ void handle_options_settable(struct pack
   settable_options[i].extra_help = mystrdup(packet->extra_help);
 
   settable_options[i].type = packet->type;
+  settable_options[i].class = packet->class;
   settable_options[i].category = packet->category;
 
-  switch (packet->type) {
+  switch (settable_options[i].type) {
   case SSET_BOOL:
     settable_options[i].val = packet->val;
     settable_options[i].min = FALSE;
     settable_options[i].max = TRUE;
     settable_options[i].strval = NULL;
     settable_options[i].default_strval = NULL;
-    break;
+    return;
   case SSET_INT:
     settable_options[i].val = packet->val;
     settable_options[i].min = packet->min;
     settable_options[i].max = packet->max;
     settable_options[i].strval = NULL;
     settable_options[i].default_strval = NULL;
-    break;
+    return;
   case SSET_STRING:
     settable_options[i].strval = mystrdup(packet->strval);
     settable_options[i].default_strval = mystrdup(packet->default_strval);
-    break;
-  default:
-    assert(0);
+    return;
   }
 
-  /* if we've received all the options, pop up the settings dialog */
-  if (i == num_settable_options - 1) {
-    popup_settable_options_dialog();
-  }
+  assert(0);
 }
 
 /****************************************************************************
Index: client/repodlgs_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/repodlgs_common.h,v
retrieving revision 1.9
diff -p -u -r1.9 repodlgs_common.h
--- client/repodlgs_common.h    22 Jul 2005 16:18:05 -0000      1.9
+++ client/repodlgs_common.h    5 Aug 2005 18:44:27 -0000
@@ -14,6 +14,7 @@
 #ifndef FC__REPODLGS_COMMON_H
 #define FC__REPODLGS_COMMON_H
 
+#include "fc_types.h"
 #include "improvement.h"
 #include "unittype.h"
 
@@ -52,7 +53,8 @@ struct options_settable {
   char *name;
   char *short_help;
   char *extra_help;
-  int type;
+  enum sset_type type;
+  enum sset_class class;
   unsigned char category;
 
   int val;
Index: client/gui-gtk-2.0/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/menu.c,v
retrieving revision 1.82
diff -p -u -r1.82 menu.c
--- client/gui-gtk-2.0/menu.c   21 Jul 2005 08:07:19 -0000      1.82
+++ client/gui-gtk-2.0/menu.c   5 Aug 2005 18:44:28 -0000
@@ -80,8 +80,7 @@ enum MenuID {
 #endif
   MENU_GAME_SAVE_OPTIONS_ON_EXIT,
   MENU_GAME_SAVE_OPTIONS,
-  MENU_GAME_SERVER_OPTIONS1,
-  MENU_GAME_SERVER_OPTIONS2,
+  MENU_GAME_SERVER_OPTIONS,
   MENU_GAME_SAVE_GAME,
   MENU_GAME_SAVE_QUICK, 
   MENU_GAME_OUTPUT_LOG,
@@ -222,11 +221,8 @@ static void game_menu_callback(gpointer 
   case MENU_GAME_SAVE_OPTIONS:
     save_options();
     break;
-  case MENU_GAME_SERVER_OPTIONS1:
-    send_report_request(REPORT_SERVER_OPTIONS1);
-    break;
-  case MENU_GAME_SERVER_OPTIONS2:
-    send_report_request(REPORT_SERVER_OPTIONS2);
+  case MENU_GAME_SERVER_OPTIONS:
+    popup_settable_options_dialog();
     break;
   case MENU_GAME_SAVE_GAME:
     popup_save_dialog();
@@ -681,10 +677,8 @@ static GtkItemFactoryEntry menu_items[]    
        game_menu_callback,     MENU_GAME_SAVE_OPTIONS                          
        },
   { "/" N_("Game") "/sep2",                            NULL,
        NULL,                   0,                                      
"<Separator>"   },
-  { "/" N_("Game") "/" N_("_Initial Server Options"),NULL,
-       game_menu_callback,     MENU_GAME_SERVER_OPTIONS1                       
        },
   { "/" N_("Game") "/" N_("Server O_ptions"),  NULL,
-       game_menu_callback,     MENU_GAME_SERVER_OPTIONS2                       
        },
+    game_menu_callback,        MENU_GAME_SERVER_OPTIONS},
   { "/" N_("Game") "/sep3",                            NULL,
        NULL,                   0,                                      
"<Separator>"   },
   { "/" N_("Game") "/" N_("_Save Game"),               NULL,
@@ -1184,8 +1178,6 @@ void update_menus(void)
                      && get_client_state() >= CLIENT_GAME_RUNNING_STATE);
   menus_set_sensitive("<main>/_Game/Server O_ptions", 
                      aconnection.established);
-  menus_set_sensitive("<main>/_Game/_Initial Server Options", 
-                     get_client_state() >= CLIENT_GAME_RUNNING_STATE);
   menus_set_sensitive("<main>/_Game/L_eave", aconnection.established);
 
   if (!can_client_change_view()) {
Index: client/gui-gtk-2.0/pages.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/pages.c,v
retrieving revision 1.36
diff -p -u -r1.36 pages.c
--- client/gui-gtk-2.0/pages.c  18 Jul 2005 22:46:27 -0000      1.36
+++ client/gui-gtk-2.0/pages.c  5 Aug 2005 18:44:28 -0000
@@ -45,6 +45,7 @@
 #include "gui_stuff.h"
 #include "pages.h"
 #include "plrdlg.h" /* for get_flag() */
+#include "repodlgs.h"
 
 GtkWidget *start_message_area;
 
@@ -876,7 +877,7 @@ static GtkWidget *start_aifill_spin;
 **************************************************************************/
 static void game_options_callback(GtkWidget *w, gpointer data)
 {
-  send_report_request(REPORT_SERVER_OPTIONS2);
+  popup_settable_options_dialog();
 }
 
 /**************************************************************************
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.94
diff -p -u -r1.94 repodlgs.c
--- client/gui-gtk-2.0/repodlgs.c       26 Jul 2005 16:35:57 -0000      1.94
+++ client/gui-gtk-2.0/repodlgs.c       5 Aug 2005 18:44:28 -0000
@@ -1467,7 +1467,7 @@ static void create_settable_options_dial
   }
 
   tips = gtk_tooltips_new();
-  settable_options_dialog_shell = gtk_dialog_new_with_buttons(_("Game 
Options"),
+  settable_options_dialog_shell = gtk_dialog_new_with_buttons(_("Game 
Settings"),
       NULL, 0,
       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
       GTK_STOCK_OK, GTK_RESPONSE_OK,
@@ -1495,7 +1495,7 @@ static void create_settable_options_dial
 
   /* fill each category */
   for (i = 0; i < num_settable_options; i++) {
-    GtkWidget *ebox, *hbox, *ent;
+    GtkWidget *ebox, *hbox, *ent = NULL;
 
     /* create a box for the new option and insert it in the correct page */
     hbox = gtk_hbox_new(FALSE, 0);
@@ -1521,41 +1521,65 @@ static void create_settable_options_dial
       gtk_tooltips_set_tip(tips, ebox, buf, NULL);
     }
 
-    /* create the proper entry method depending on the type */
-    if (settable_options[i].type == 0) {
-      /* boolean */
-      ent = gtk_check_button_new();
-      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ent),
-                                   settable_options[i].val);
-
-      g_signal_connect(ent, "toggled", 
-                       G_CALLBACK(option_changed_callback), NULL);
-    } else if (settable_options[i].type == 1) {
-      /* integer */
+    if (setting_class_is_changeable(settable_options[i].class)) {
       double step, max, min;
 
-      min = settable_options[i].min;
-      max = settable_options[i].max;
- 
-      /* pick a reasonable step size */
-      step = ceil((max - min) / 100.0);
-      if (step > 100.0) {
-       /* this is ridiculous, the bounds must be meaningless */
-       step = 5.0;
-      }
+      /* create the proper entry method depending on the type */
+      switch (settable_options[i].type) {
+      case SSET_BOOL:
+       /* boolean */
+       ent = gtk_check_button_new();
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ent),
+                                    settable_options[i].val);
+
+       g_signal_connect(ent, "toggled", 
+                        G_CALLBACK(option_changed_callback), NULL);
+       break;
 
-      ent = gtk_spin_button_new_with_range(min, max, step);
-      gtk_spin_button_set_value(GTK_SPIN_BUTTON(ent), settable_options[i].val);
+      case SSET_INT:
+       /* integer */
 
-      g_signal_connect(ent, "changed", 
-                       G_CALLBACK(option_changed_callback), NULL);
+       min = settable_options[i].min;
+       max = settable_options[i].max;
+ 
+       /* pick a reasonable step size */
+       step = ceil((max - min) / 100.0);
+       if (step > 100.0) {
+         /* this is ridiculous, the bounds must be meaningless */
+         step = 5.0;
+       }
+
+       ent = gtk_spin_button_new_with_range(min, max, step);
+       gtk_spin_button_set_value(GTK_SPIN_BUTTON(ent), 
settable_options[i].val);
+
+       g_signal_connect(ent, "changed", 
+                        G_CALLBACK(option_changed_callback), NULL);
+       break;
+      case SSET_STRING:
+       /* string */
+       ent = gtk_entry_new();
+       gtk_entry_set_text(GTK_ENTRY(ent), settable_options[i].strval);
+
+       g_signal_connect(ent, "changed", 
+                        G_CALLBACK(option_changed_callback), NULL);
+       break;
+      }
     } else {
-      /* string */
-      ent = gtk_entry_new();
-      gtk_entry_set_text(GTK_ENTRY(ent), settable_options[i].strval);
+      char buf[1024];
 
-      g_signal_connect(ent, "changed", 
-                       G_CALLBACK(option_changed_callback), NULL);
+      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;
+      }
+      ent = gtk_label_new(buf);
     }
     gtk_box_pack_end(GTK_BOX(hbox), ent, FALSE, FALSE, 0);
 
Index: common/fc_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/fc_types.h,v
retrieving revision 1.31
diff -p -u -r1.31 fc_types.h
--- common/fc_types.h   31 Jul 2005 16:23:14 -0000      1.31
+++ common/fc_types.h   5 Aug 2005 18:44:28 -0000
@@ -50,6 +50,27 @@ enum sset_type {
   SSET_BOOL, SSET_INT, SSET_STRING
 };
 
+/* The following classes determine what can be changed when.
+ * Actually, some of them have the same "changeability", but
+ * different types are separated here in case they have
+ * other uses.
+ * Also, SSET_GAME_INIT/SSET_RULES separate the two sections
+ * of server settings sent to the client.
+ * See the settings[] array for what these correspond to and
+ * explanations.
+ */
+enum sset_class {
+  SSET_MAP_SIZE,
+  SSET_MAP_GEN,
+  SSET_MAP_ADD,
+  SSET_PLAYERS,
+  SSET_GAME_INIT,
+  SSET_RULES,
+  SSET_RULES_FLEXIBLE,
+  SSET_META,
+  SSET_LAST
+};
+
 enum output_type_id {
   O_FOOD, O_SHIELD, O_TRADE, O_GOLD, O_LUXURY, O_SCIENCE, O_LAST
 };
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.233
diff -p -u -r1.233 game.c
--- common/game.c       1 Aug 2005 22:38:25 -0000       1.233
+++ common/game.c       5 Aug 2005 18:44:28 -0000
@@ -621,3 +621,37 @@ const char *population_to_text(int thous
   return big_int_to_text(thousand_citizen, 3);
 }
 
+/****************************************************************************
+  Returns whether the specified server setting class can currently
+  be changed.  Does not indicate whether it can be changed by clients.
+****************************************************************************/
+bool setting_class_is_changeable(enum sset_class class)
+{
+  switch (class) {
+  case SSET_MAP_SIZE:
+  case SSET_MAP_GEN:
+    /* Only change map options if we don't yet have a map: */
+    return map_is_empty();
+
+  case SSET_MAP_ADD:
+  case SSET_PLAYERS:
+  case SSET_GAME_INIT:
+  case SSET_RULES:
+    /* Only change start params and most rules if we don't yet have a map,
+     * or if we do have a map but its a scenario one (ie, the game has
+     * never actually been started).
+     */
+    return (map_is_empty() || game.info.is_new_game);
+
+  case SSET_RULES_FLEXIBLE:
+  case SSET_META:
+    /* These can always be changed: */
+    return TRUE;
+
+  case SSET_LAST:
+    break;
+  }
+  freelog(LOG_ERROR, "Unexpected case %d in %s line %d",
+         class, __FILE__, __LINE__);
+  return FALSE;
+}
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.195
diff -p -u -r1.195 game.h
--- common/game.h       12 Jul 2005 21:51:23 -0000      1.195
+++ common/game.h       5 Aug 2005 18:44:28 -0000
@@ -145,6 +145,8 @@ const char *population_to_text(int thous
 extern struct civ_game game;
 extern bool is_server;
 
+bool setting_class_is_changeable(enum sset_class class);
+
 #define GAME_DEFAULT_SEED        0
 #define GAME_MIN_SEED            0
 #define GAME_MAX_SEED            (MAX_UINT32 >> 1)
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.147
diff -p -u -r1.147 packets.def
--- common/packets.def  1 Aug 2005 22:38:25 -0000       1.147
+++ common/packets.def  5 Aug 2005 18:44:29 -0000
@@ -189,6 +189,7 @@ type IMPR_GENUS             = uint8(enum impr_genus
 type DIRECTION         = uint8(enum direction8)
 type ORDERS            = uint8(enum unit_orders)
 type SSET_TYPE         = uint8(enum sset_type)
+type SSET_CLASS         = uint8(enum sset_class)
 type REQ_TYPE          = uint8(enum req_source_type)
 type REQ_RANGE         = uint8(enum req_range)
 type EFFECT_TYPE       = uint8(enum effect_type)
@@ -1306,18 +1307,19 @@ PACKET_GAME_LOAD=111;sc,handle-via-packe
   BOOL is_ai[MAX_NUM_PLAYERS:nplayers];
 end
 
-PACKET_OPTIONS_SETTABLE_CONTROL=112;sc,handle-via-packet
-  UINT16 nids;
-  UINT8 ncategories;
-  STRING category_names[256:ncategories][MAX_LEN_NAME];
+PACKET_OPTIONS_SETTABLE_CONTROL=112;sc,handle-via-packet,lsend
+  UINT16 num_settings;
+  UINT8 num_categories;
+  STRING category_names[256:num_categories][MAX_LEN_NAME];
 end
 
-PACKET_OPTIONS_SETTABLE=113;sc
+PACKET_OPTIONS_SETTABLE=113;sc,lsend
   UINT16 id;
   STRING name[MAX_LEN_NAME];
   STRING short_help[MAX_LEN_PACKET];
   STRING extra_help[MAX_LEN_PACKET];
   SSET_TYPE type;
+  SSET_CLASS class;
 
   SINT32 val;                                  /* value for bool or int */
   SINT32 default_val;                          /* default for bool or int */
Index: common/packets.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v
retrieving revision 1.165
diff -p -u -r1.165 packets.h
--- common/packets.h    17 May 2005 23:01:22 -0000      1.165
+++ common/packets.h    5 Aug 2005 18:44:29 -0000
@@ -39,10 +39,7 @@ struct data_in;
 enum report_type {
   REPORT_WONDERS_OF_THE_WORLD,
   REPORT_TOP_5_CITIES,
-  REPORT_DEMOGRAPHIC,
-  REPORT_SERVER_OPTIONS,   /* obsolete */
-  REPORT_SERVER_OPTIONS1,
-  REPORT_SERVER_OPTIONS2
+  REPORT_DEMOGRAPHIC
 };
 
 enum spaceship_place_type {
Index: manual/civmanual.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/manual/civmanual.c,v
retrieving revision 1.15
diff -p -u -r1.15 civmanual.c
--- manual/civmanual.c  1 Aug 2005 22:38:26 -0000       1.15
+++ manual/civmanual.c  5 Aug 2005 18:44:29 -0000
@@ -146,7 +146,7 @@ static bool manual_command(void)
        if (op->to_client == SSET_SERVER_ONLY) {
          fprintf(doc, _("Can only be used in server console. "));
        }
-       if (sset_is_changeable(i)) {
+       if (setting_is_changeable(i)) {
          fprintf(doc, _("Can be changed during a game. "));
        } else {
          fprintf(doc, _("Can <b>not</b> be changed during a game. "));
Index: server/connecthand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/connecthand.c,v
retrieving revision 1.52
diff -p -u -r1.52 connecthand.c
--- server/connecthand.c        14 Jun 2005 18:49:09 -0000      1.52
+++ server/connecthand.c        5 Aug 2005 18:44:29 -0000
@@ -114,6 +114,7 @@ static void establish_new_connection(str
   } conn_list_iterate_end;
 
   send_rulesets(dest);
+  send_server_settings(dest);
 
   /* a player has already been created for this user, reconnect him */
   if ((pplayer = find_player_by_user(pconn->username))) {
Index: server/settings.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settings.c,v
retrieving revision 1.29
diff -p -u -r1.29 settings.c
--- server/settings.c   12 Jul 2005 21:51:23 -0000      1.29
+++ server/settings.c   5 Aug 2005 18:44:30 -0000
@@ -1016,32 +1016,7 @@ const int SETTINGS_NUM = ARRAY_SIZE(sett
   Returns whether the specified server setting (option) can currently
   be changed.  Does not indicate whether it can be changed by clients.
 ****************************************************************************/
-bool sset_is_changeable(int idx)
+bool setting_is_changeable(int setting_id)
 {
-  struct settings_s *op = &settings[idx];
-
-  switch(op->sclass) {
-  case SSET_MAP_SIZE:
-  case SSET_MAP_GEN:
-    /* Only change map options if we don't yet have a map: */
-    return map_is_empty();
-  case SSET_MAP_ADD:
-  case SSET_PLAYERS:
-  case SSET_GAME_INIT:
-
-  case SSET_RULES:
-    /* Only change start params and most rules if we don't yet have a map,
-     * or if we do have a map but its a scenario one (ie, the game has
-     * never actually been started).
-     */
-    return (map_is_empty() || game.info.is_new_game);
-  case SSET_RULES_FLEXIBLE:
-  case SSET_META:
-    /* These can always be changed: */
-    return TRUE;
-  default:
-    freelog(LOG_ERROR, "Unexpected case %d in %s line %d",
-            op->sclass, __FILE__, __LINE__);
-    return FALSE;
-  }
+  return setting_class_is_changeable(settings[setting_id].sclass);
 }
Index: server/settings.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settings.h,v
retrieving revision 1.5
diff -p -u -r1.5 settings.h
--- server/settings.h   30 Jun 2005 20:38:42 -0000      1.5
+++ server/settings.h   5 Aug 2005 18:44:30 -0000
@@ -18,27 +18,6 @@
 
 #include "game.h"
 
-/* The following classes determine what can be changed when.
- * Actually, some of them have the same "changeability", but
- * different types are separated here in case they have
- * other uses.
- * Also, SSET_GAME_INIT/SSET_RULES separate the two sections
- * of server settings sent to the client.
- * See the settings[] array for what these correspond to and
- * explanations.
- */
-enum sset_class {
-  SSET_MAP_SIZE,
-  SSET_MAP_GEN,
-  SSET_MAP_ADD,
-  SSET_PLAYERS,
-  SSET_GAME_INIT,
-  SSET_RULES,
-  SSET_RULES_FLEXIBLE,
-  SSET_META,
-  SSET_LAST
-};
-
 /* Whether settings are sent to the client when the client lists
  * server options; also determines whether clients can set them in principle.
  * Eg, not sent: seeds, saveturns, etc.
@@ -124,6 +103,6 @@ struct settings_s {
 extern struct settings_s settings[];
 extern const int SETTINGS_NUM;
 
-bool sset_is_changeable(int idx);
+bool setting_is_changeable(int setting_id);
 
 #endif                         /* FC__SETTINGS_H */
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.282
diff -p -u -r1.282 srv_main.c
--- server/srv_main.c   26 Jul 2005 17:21:53 -0000      1.282
+++ server/srv_main.c   5 Aug 2005 18:44:30 -0000
@@ -801,6 +801,7 @@ void start_game(void)
 
   server_state = RUN_GAME_STATE; /* loaded ??? */
   force_end_of_sniff = TRUE;
+  send_server_settings(NULL);
 }
 
 /**************************************************************************
@@ -822,32 +823,24 @@ void handle_report_req(struct connection
 {
   struct conn_list *dest = pconn->self;
   
-  if (server_state != RUN_GAME_STATE && server_state != GAME_OVER_STATE
-      && type != REPORT_SERVER_OPTIONS1 && type != REPORT_SERVER_OPTIONS2) {
+  if (server_state != RUN_GAME_STATE && server_state != GAME_OVER_STATE) {
     freelog(LOG_ERROR, "Got a report request %d before game start", type);
     return;
   }
 
   switch(type) {
-   case REPORT_WONDERS_OF_THE_WORLD:
+  case REPORT_WONDERS_OF_THE_WORLD:
     report_wonders_of_the_world(dest);
-    break;
-   case REPORT_TOP_5_CITIES:
+    return;
+  case REPORT_TOP_5_CITIES:
     report_top_five_cities(dest);
-    break;
-   case REPORT_DEMOGRAPHIC:
+    return;
+  case REPORT_DEMOGRAPHIC:
     report_demographics(pconn);
-    break;
-  case REPORT_SERVER_OPTIONS1:
-    report_settable_server_options(pconn, 1);
-    break;
-  case REPORT_SERVER_OPTIONS2:
-    report_settable_server_options(pconn, 2);
-    break;
-  case REPORT_SERVER_OPTIONS: /* obsolete */
-  default:
-    notify_conn(dest, _("request for unknown report (type %d)"), type);
+    return;
   }
+
+  notify_conn(dest, _("request for unknown report (type %d)"), type);
 }
 
 /**************************************************************************
@@ -1807,6 +1800,7 @@ static void srv_loop(void)
 
   server_state = RUN_GAME_STATE;
   (void) send_server_info_to_metaserver(META_INFO);
+  send_server_settings(NULL);
 
   if(game.info.is_new_game) {
     /* Before the player map is allocated (and initiailized)! */
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.427
diff -p -u -r1.427 stdinhand.c
--- server/stdinhand.c  18 Jul 2005 22:46:29 -0000      1.427
+++ server/stdinhand.c  5 Aug 2005 18:44:31 -0000
@@ -313,7 +313,7 @@ static bool may_set_option(struct connec
 static bool may_set_option_now(struct connection *caller, int option_idx)
 {
   return (may_set_option(caller, option_idx)
-         && sset_is_changeable(option_idx));
+         && setting_is_changeable(option_idx));
 }
 
 /**************************************************************************
@@ -1492,7 +1492,7 @@ static void show_help_option(struct conn
                     "  ", "  %s", abuf.str);
   }
   cmd_reply(help_cmd, caller, C_COMMENT,
-           _("Status: %s"), (sset_is_changeable(id)
+           _("Status: %s"), (setting_is_changeable(id)
                                  ? _("changeable") : _("fixed")));
   
   if (may_view_option(caller, id)) {
@@ -1601,136 +1601,77 @@ static bool wall(char *str, bool check)
   }
   return TRUE;
 }
-  
-/******************************************************************
-Send a report with server options to specified connections.
-"which" should be one of:
-1: initial options only
-2: ongoing options only 
-(which=0 means all options; this is now obsolete and no longer used.)
-******************************************************************/
-void report_server_options(struct conn_list *dest, int which)
+
+/****************************************************************************
+  Tell the client about just one server setting.  Call this after a setting
+  is saved.
+****************************************************************************/
+static void send_server_setting(struct conn_list *dest, int setting_id)
 {
-  int i, c;
-  char buffer[4096];
-  char title[128];
-  const char *caption;
+  struct packet_options_settable packet;
+  struct settings_s *setting = &settings[setting_id];
 
-  buffer[0] = '\0';
-  my_snprintf(title, sizeof(title), _("%-20svalue  (min , max)"), _("Option"));
-  caption = (which == 1) ?
-    _("Server Options (initial)") :
-    _("Server Options (ongoing)");
-
-  for (c = 0; c < SSET_NUM_CATEGORIES; c++) {
-    cat_snprintf(buffer, sizeof(buffer), "%s:\n", sset_category_names[c]);
-    for (i = 0; settings[i].name; i++) {
-      struct settings_s *op = &settings[i];
-      if (!sset_is_to_client(i)) {
-        continue;
-      }
-      if (which == 1 && op->sclass > SSET_GAME_INIT) {
-        continue;
-      }
-      if (which == 2 && op->sclass <= SSET_GAME_INIT) {
-        continue;
-      }
-      if (op->category != c) {
-        continue;
-      }
-      switch (op->type) {
-      case SSET_BOOL:
-       cat_snprintf(buffer, sizeof(buffer), "%-20s%c%-6d (0,1)\n",
-                    op->name,
-                    (*op->bool_value == op->bool_default_value) ? '*' : ' ',
-                    *op->bool_value);
-       break;
-       
-      case SSET_INT:
-       cat_snprintf(buffer, sizeof(buffer), "%-20s%c%-6d (%d,%d)\n", op->name,
-                    (*op->int_value == op->int_default_value) ? '*' : ' ',
-                    *op->int_value, op->int_min_value, op->int_max_value);
-       break;
-      case SSET_STRING:
-       cat_snprintf(buffer, sizeof(buffer), "%-20s%c\"%s\"\n", op->name,
-                    (strcmp(op->string_value,
-                            op->string_default_value) == 0) ? '*' : ' ',
-                    op->string_value);
-       break;
-      }
-    }
-    cat_snprintf(buffer, sizeof(buffer), "\n");
+  if (!dest) {
+    dest = game.est_connections;
   }
-  freelog(LOG_DEBUG, "report_server_options buffer len %d", i);
-  page_conn(dest, caption, title, buffer);
-}
 
-/******************************************************************
-  Deliver options to the client for setting
+  memset(&packet, 0, sizeof(packet));
 
-  which == 1 : REPORT_SERVER_OPTIONS1
-  which == 2 : REPORT_SERVER_OPTIONS2
-******************************************************************/
-void report_settable_server_options(struct connection *dest, int which)
-{
-  static struct packet_options_settable_control control;
-  static struct packet_options_settable packet;
-  int i, s = 0;
-
-  if (dest->access_level == ALLOW_NONE
-      || (which == 1 && server_state > PRE_GAME_STATE)) {
-    report_server_options(dest->self, which);
-    return;
+  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;
+
+  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;
   }
 
-  memset(&control, 0, sizeof(struct packet_options_settable_control));
+  lsend_packet_options_settable(dest, &packet);
+}
 
-  /* count the number of settings */
-  for (i = 0; settings[i].name; i++) {
-    if (!sset_is_changeable(i)) {
-      continue;
-    }
-    s++;
+/****************************************************************************
+  Tell the client about all server settings.
+****************************************************************************/
+void send_server_settings(struct conn_list *dest)
+{
+  struct packet_options_settable_control control;
+  int i;
+
+  if (!dest) {
+    dest = game.est_connections;
   }
 
-  control.nids = s;
+  /* count the number of settings */
+  control.num_settings = SETTINGS_NUM;
 
   /* fill in the category strings */
-  control.ncategories = SSET_NUM_CATEGORIES;
+  control.num_categories = SSET_NUM_CATEGORIES;
   for (i = 0; i < SSET_NUM_CATEGORIES; i++) {
     strcpy(control.category_names[i], sset_category_names[i]);
   }
 
   /* send off the control packet */
-  send_packet_options_settable_control(dest, &control);
-
-  for (s = 0, i = 0; settings[i].name; i++) {
-    if (!sset_is_changeable(i)) {
-      continue;
-    }
-
-    packet.id = s++;
-    sz_strlcpy(packet.name, settings[i].name);
-    sz_strlcpy(packet.short_help, settings[i].short_help);
-    sz_strlcpy(packet.extra_help, settings[i].extra_help);
-
-    packet.category = settings[i].category;
-    packet.type = settings[i].type;
-
-    if (settings[i].type == SSET_STRING) {
-      strcpy(packet.strval, settings[i].string_value);
-      strcpy(packet.default_strval, settings[i].string_default_value);
-    } else if (settings[i].type == SSET_BOOL) {
-      packet.val = *(settings[i].bool_value);
-      packet.default_val = settings[i].bool_default_value;
-    } else {
-      packet.min = settings[i].int_min_value;
-      packet.max = settings[i].int_max_value;
-      packet.val = *(settings[i].int_value);
-      packet.default_val = settings[i].int_default_value;
-    }
+  lsend_packet_options_settable_control(dest, &control);
 
-    send_packet_options_settable(dest, &packet);
+  for (i = 0; i < SETTINGS_NUM; i++) {
+    send_server_setting(dest, i);
   }
 }
 
@@ -2457,7 +2398,7 @@ static bool set_command(struct connectio
               _("You are not allowed to set this option."));
     return FALSE;
   }
-  if (!sset_is_changeable(cmd)) {
+  if (!setting_is_changeable(cmd)) {
     cmd_reply(CMD_SET, caller, C_BOUNCE,
              _("This setting can't be modified after the game has started."));
     return FALSE;
@@ -2549,6 +2490,7 @@ static bool set_command(struct connectio
   }
 
   if (!check && do_update) {
+    send_server_setting(NULL, cmd);
     reset_all_start_commands();
     send_server_info_to_metaserver(META_INFO);
     /* 
@@ -2889,6 +2831,7 @@ static bool take_command(struct connecti
   if (pconn->player && server_state == RUN_GAME_STATE) {
     send_game_state(pconn->self, CLIENT_PRE_GAME_STATE);
     send_rulesets(pconn->self);
+    send_server_settings(pconn->self);
     send_player_info_c(NULL, pconn->self);
     send_conn_info(game.est_connections,  pconn->self);
   }
@@ -2900,6 +2843,7 @@ static bool take_command(struct connecti
       if (server_state == RUN_GAME_STATE) {
         send_game_state(aconn->self, CLIENT_PRE_GAME_STATE);
        send_rulesets(aconn->self);
+       send_server_settings(aconn->self);
       }
       notify_conn(aconn->self, _("being detached from %s."), pplayer->name);
       unattach_connection_from_player(aconn);
@@ -3039,6 +2983,7 @@ static bool detach_command(struct connec
   if (server_state == RUN_GAME_STATE) {
     send_game_state(pconn->self, CLIENT_PRE_GAME_STATE);
     send_rulesets(pconn->self);
+    send_server_settings(pconn->self);
     send_game_info(pconn->self);
     send_player_info_c(NULL, pconn->self);
     send_conn_info(game.est_connections, pconn->self);
@@ -3185,6 +3130,7 @@ bool load_command(struct connection *cal
   sz_strlcpy(srvarg.load_filename, arg);
 
   game_load(&file);
+  send_server_settings(NULL);
   init_available_nations();
   section_file_check_unused(&file, arg);
   section_file_free(&file);
Index: server/stdinhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.h,v
retrieving revision 1.30
diff -p -u -r1.30 stdinhand.h
--- server/stdinhand.h  9 Dec 2004 16:38:35 -0000       1.30
+++ server/stdinhand.h  5 Aug 2005 18:44:31 -0000
@@ -25,7 +25,7 @@ void stdinhand_free(void);
 
 bool handle_stdin_input(struct connection *caller, char *str, bool check);
 void report_server_options(struct conn_list *dest, int which);
-void report_settable_server_options(struct connection *dest, int which);
+void send_server_settings(struct conn_list *dest);
 void set_ai_level_direct(struct player *pplayer, int level);
 void set_ai_level_directer(struct player *pplayer, int level);
 bool read_init_script(struct connection *caller, char *script_filename);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13619) rewrite server settings editor, Jason Short <=