Author: cazfi
Date: Thu Jan 22 21:12:53 2015
New Revision: 27781

URL: http://svn.gna.org/viewcvs/freeciv?rev=27781&view=rev
Log:
Added server command 'default' to set setting to its default value, and to mark 
it as being
the default.

See patch #5731

Modified:
    trunk/server/commands.c
    trunk/server/commands.h
    trunk/server/settings.c
    trunk/server/settings.h
    trunk/server/stdinhand.c

Modified: trunk/server/commands.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/commands.c?rev=27781&r1=27780&r2=27781&view=diff
==============================================================================
--- trunk/server/commands.c     (original)
+++ trunk/server/commands.c     Thu Jan 22 21:12:53 2015
@@ -609,6 +609,14 @@
       "  default  - using default values\n"), NULL,
    CMD_ECHO_ALL, VCF_NONE, 50
   },
+  {"default",  ALLOW_CTRL,
+   /* no translatable parameters */
+   SYN_ORIG_("default <option name>"),
+   N_("Set option to its default value"),
+   N_("Set option to its default value, and track it as 'default' instead\n"
+      "of real value."), NULL,
+   CMD_ECHO_ALL, VCF_NONE, 50
+  },
   {"lua", ALLOW_ADMIN,
    /* TRANS: translate text between <> only */
    N_("lua cmd <script line>\n"

Modified: trunk/server/commands.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/commands.h?rev=27781&r1=27780&r2=27781&view=diff
==============================================================================
--- trunk/server/commands.h     (original)
+++ trunk/server/commands.h     Thu Jan 22 21:12:53 2015
@@ -90,6 +90,7 @@
   CMD_READ_SCRIPT,
   CMD_WRITE_SCRIPT,
   CMD_RESET,
+  CMD_DEFAULT,
   CMD_LUA,
   CMD_KICK,
   CMD_DELEGATE,

Modified: trunk/server/settings.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/settings.c?rev=27781&r1=27780&r2=27781&view=diff
==============================================================================
--- trunk/server/settings.c     (original)
+++ trunk/server/settings.c     Thu Jan 22 21:12:53 2015
@@ -167,7 +167,6 @@
   struct setting_list *level[OLEVELS_NUM];
 } setting_sorted = { .init = FALSE };
 
-static void setting_set_to_default(struct setting *pset);
 static bool setting_ruleset_one(struct section_file *file,
                                 const char *name, const char *path);
 static void setting_game_set(struct setting *pset, bool init);
@@ -3464,7 +3463,7 @@
 /****************************************************************************
   Update the setting to the default value
 ****************************************************************************/
-static void setting_set_to_default(struct setting *pset)
+void setting_set_to_default(struct setting *pset)
 {
   switch (pset->stype) {
   case SSET_BOOL:

Modified: trunk/server/settings.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/settings.h?rev=27781&r1=27780&r2=27781&view=diff
==============================================================================
--- trunk/server/settings.h     (original)
+++ trunk/server/settings.h     Thu Jan 22 21:12:53 2015
@@ -111,6 +111,8 @@
 const char *setting_default_name(const struct setting *pset, bool pretty,
                                  char *buf, size_t buf_len);
 
+void setting_set_to_default(struct setting *pset);
+
 /* Type SSET_BOOL setting functions. */
 bool setting_bool_set(struct setting *pset, const char *val,
                       struct connection *caller, char *reject_msg,

Modified: trunk/server/stdinhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/stdinhand.c?rev=27781&r1=27780&r2=27781&view=diff
==============================================================================
--- trunk/server/stdinhand.c    (original)
+++ trunk/server/stdinhand.c    Thu Jan 22 21:12:53 2015
@@ -142,6 +142,7 @@
                                   bool check, int read_recursion);
 static bool reset_command(struct connection *caller, char *arg, bool check,
                           int read_recursion);
+static bool default_command(struct connection *caller, char *arg, bool check);
 static bool lua_command(struct connection *caller, char *arg, bool check);
 static bool kick_command(struct connection *caller, char *name, bool check);
 static bool delegate_command(struct connection *caller, char *arg,
@@ -4275,6 +4276,8 @@
     return write_command(caller, arg, check);
   case CMD_RESET:
     return reset_command(caller, arg, check, read_recursion);
+  case CMD_DEFAULT:
+    return default_command(caller, arg, check);
   case CMD_LUA:
     return lua_command(caller, arg, check);
   case CMD_KICK:
@@ -4504,6 +4507,37 @@
 
   /* show ruleset description and list changed values */
   show_ruleset_info(caller, CMD_RESET, check, read_recursion);
+
+  return TRUE;
+}
+
+/**************************************************************************
+  Set a setting to its default value
+**************************************************************************/
+static bool default_command(struct connection *caller, char *arg, bool check)
+{
+  int cmd;
+  struct setting *pset;
+  char reject_msg[256] = "";
+
+  cmd = lookup_option(arg);
+
+  if (cmd <= 0) {
+    cmd_reply(CMD_DEFAULT, caller, C_FAIL, _("Unknown option %s"), arg);
+  }
+
+  pset = setting_by_number(cmd);
+
+  if (!setting_is_changeable(pset, caller, reject_msg, sizeof(reject_msg))) {
+    cmd_reply(CMD_SET, caller, C_FAIL, "%s", reject_msg);
+
+    return FALSE;
+  }
+
+  if (!check) {
+    setting_set_to_default(pset);
+    cmd_reply(CMD_DEFAULT, caller, C_OK, _("Setting %s set to default 
value."), arg);
+  }
 
   return TRUE;
 }


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

Reply via email to