Author: cazfi
Date: Sun Aug  2 22:07:49 2015
New Revision: 29300

URL: http://svn.gna.org/viewcvs/freeciv?rev=29300&view=rev
Log:
Made 'timeout' and 'first_timeout' to work correctly at first turn, if set 
during it.

See bug #23724

Modified:
    trunk/server/settings.c

Modified: trunk/server/settings.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/settings.c?rev=29300&r1=29299&r2=29300&view=diff
==============================================================================
--- trunk/server/settings.c     (original)
+++ trunk/server/settings.c     Sun Aug  2 22:07:49 2015
@@ -655,8 +655,32 @@
 {
   if (S_S_RUNNING == server_state()) {
     int timeout = *pset->integer.pvalue;
-    /* This may cause the current turn to end immediately. */
-    game.tinfo.seconds_to_phasedone = timeout;
+
+    if (game.info.turn != 0 || game.info.first_timeout == -1) {
+      /* This may cause the current turn to end immediately. */
+      game.tinfo.seconds_to_phasedone = timeout;
+    }
+    send_game_info(NULL);
+  }
+}
+
+/*************************************************************************
+  Enact a change in the 'first_timeout' server setting immediately, if the game
+  is afoot.
+*************************************************************************/
+static void first_timeout_action(const struct setting *pset)
+{
+  if (S_S_RUNNING == server_state()) {
+    int timeout = *pset->integer.pvalue;
+
+    if (game.info.turn == 0) {
+      /* This may cause the current turn to end immediately. */
+      if (timeout != -1) {
+        game.tinfo.seconds_to_phasedone = timeout;
+      } else {
+        game.tinfo.seconds_to_phasedone = game.info.timeout;
+      }
+    }
     send_game_info(NULL);
   }
 }
@@ -967,6 +991,23 @@
                       _("'timeout' can not be lower than 3/2 of the "
                         "'unitwaittime' setting (= %d). Please change "
                         "'unitwaittime' first."), game.server.unitwaittime);
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
+/*************************************************************************
+  Validate the 'first_timeout' server setting.
+*************************************************************************/
+static bool first_timeout_callback(int value, struct connection *caller,
+                                   char *reject_msg, size_t reject_msg_len)
+{
+  /* Disallow low timeout values for non-hack connections. */
+  if (caller && caller->access_level < ALLOW_HACK && value < 30) {
+    settings_snprintf(reject_msg, reject_msg_len,
+                      _("You are not allowed to set timeout values less "
+                        "than 30 seconds."));
     return FALSE;
   }
 
@@ -2372,8 +2413,8 @@
              "If set to 0, T0 will not have a timeout.\n"
              "If set to -1, the special treatment of T0 will be disabled.\n"
              "See also 'timeout'."),
-          NULL, NULL, GAME_MIN_FIRST_TIMEOUT, GAME_MAX_FIRST_TIMEOUT,
-          GAME_DEFAULT_FIRST_TIMEOUT)
+          first_timeout_callback, first_timeout_action, GAME_MIN_FIRST_TIMEOUT,
+          GAME_MAX_FIRST_TIMEOUT, GAME_DEFAULT_FIRST_TIMEOUT)
 
   GEN_INT("timeaddenemymove", game.server.timeoutaddenemymove,
          SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,


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

Reply via email to