[Freeciv-Dev] (PR#40466) [Patch] Do not allow positive timeout less than 30

2008-10-19 Thread Madeline Book

http://bugs.freeciv.org/Ticket/Display.html?id=40466 >

Updated yet again, to apply cleanly to current codebase
and with some minor style improvements.


---
濡れた衣装が体にくっついている彼女がいるパーティーもいいですか。
 server/report.c|4 +++-
 server/report.h|4 +++-
 server/settings.c  |   45 +++--
 server/settings.h  |   14 +++---
 server/stdinhand.c |   30 ++
 5 files changed, 70 insertions(+), 27 deletions(-)

diff --git a/server/report.c b/server/report.c
index 6a11776..52cbe04 100644
--- a/server/report.c
+++ b/server/report.c
@@ -709,7 +709,9 @@ static void dem_line_item(char *outptr, size_t out_size,
   Other settings callback functions are in settings.c, but this one uses
   static values from this file so it's done separately.
 */
-bool is_valid_demography(const char *demography, const char **error_string)
+bool is_valid_demography(const char *demography,
+ struct connection *caller,
+ const char **error_string)
 {
   int len = strlen(demography), i;
 
diff --git a/server/report.h b/server/report.h
index 4dc515f..7a94fd2 100644
--- a/server/report.h
+++ b/server/report.h
@@ -24,7 +24,9 @@ void page_conn(struct conn_list *dest, const char *caption, const char *headline
 void make_history_report(void);
 void report_wonders_of_the_world(struct conn_list *dest);
 void report_top_five_cities(struct conn_list *dest);
-bool is_valid_demography(const char *demography, const char **error_message);
+bool is_valid_demography(const char *demography,
+ struct connection *caller,
+ const char **error_message);
 void report_demographics(struct connection *pconn);
 void report_final_scores(void);
 
diff --git a/server/settings.c b/server/settings.c
index d480d77..0550776 100644
--- a/server/settings.c
+++ b/server/settings.c
@@ -51,7 +51,9 @@ const int OLEVELS_NUM = ARRAY_SIZE(sset_level_names);
   Verify that a given allowtake string is valid.  See
   game.allow_take.
 */
-static bool allowtake_callback(const char *value, const char **error_string)
+static bool allowtake_callback(const char *value,
+   struct connection *caller,
+   const char **error_string)
 {
   int len = strlen(value), i;
   bool havecharacter_state = FALSE;
@@ -93,7 +95,9 @@ static bool allowtake_callback(const char *value, const char **error_string)
   Verify that a given startunits string is valid.  See
   game.info.start_units.
 */
-static bool startunits_callback(const char *value, const char **error_string)
+static bool startunits_callback(const char *value,
+struct connection *caller,
+const char **error_string)
 {
   int len = strlen(value), i;
   bool have_founder = FALSE;
@@ -132,7 +136,8 @@ static bool startunits_callback(const char *value, const char **error_string)
 /*
   Verify that a given endyear is valid.
 */
-static bool endyear_callback(int value, const char **error_string)
+static bool endyear_callback(int value, struct connection *caller,
+ const char **error_string)
 {
   if (value < game.info.year) {
 /* Tried to set endyear earlier than current year */
@@ -145,7 +150,8 @@ static bool endyear_callback(int value, const char **error_string)
 /*
   Verify that a given maxplayers string is valid.
 */
-static bool maxplayers_callback(int value, const char **error_string)
+static bool maxplayers_callback(int value, struct connection *caller,
+const char **error_string)
 {
 #ifdef GGZ_SERVER
   if (with_ggz) {
@@ -162,7 +168,23 @@ static bool maxplayers_callback(int value, const char **error_string)
 return FALSE;
   }
 
-  error_string = NULL;
+  *error_string = NULL;
+  return TRUE;
+}
+
+/*
+  Disallow low timeout values for non-hack connections.
+*/
+static bool timeout_callback(int value, struct connection *caller,
+ const char **error_string)
+{
+  if (caller && caller->access_level < ALLOW_HACK && value < 30) {
+*error_string = _("You are not allowed to set timeout values less "
+  "than 30 seconds.");
+return FALSE;
+ 

[Freeciv-Dev] (PR#40466) [Patch] Do not allow positive timeout less than 30

2008-10-06 Thread Madeline Book

http://bugs.freeciv.org/Ticket/Display.html?id=40466 >

Improved some formatting and fixed some calls to avoid the
missing format string warning in 40504.


---
殺意がなくなりました。どういう意味ですか?
diff --git a/server/report.c b/server/report.c
index 6834cb0..7bb265e 100644
--- a/server/report.c
+++ b/server/report.c
@@ -663,7 +663,9 @@ static void dem_line_item(char *outptr, size_t out_size,
   Other settings callback functions are in settings.c, but this one uses
   static values from this file so it's done separately.
 */
-bool is_valid_demography(const char *demography, const char **error_string)
+bool is_valid_demography(const char *demography,
+ struct connection *caller,
+ const char **error_string)
 {
   int len = strlen(demography), i;
 
diff --git a/server/report.h b/server/report.h
index 4dc515f..7a94fd2 100644
--- a/server/report.h
+++ b/server/report.h
@@ -24,7 +24,9 @@ void page_conn(struct conn_list *dest, const char *caption, const char *headline
 void make_history_report(void);
 void report_wonders_of_the_world(struct conn_list *dest);
 void report_top_five_cities(struct conn_list *dest);
-bool is_valid_demography(const char *demography, const char **error_message);
+bool is_valid_demography(const char *demography,
+ struct connection *caller,
+ const char **error_message);
 void report_demographics(struct connection *pconn);
 void report_final_scores(void);
 
diff --git a/server/settings.c b/server/settings.c
index 3937593..f13b13b 100644
--- a/server/settings.c
+++ b/server/settings.c
@@ -50,7 +50,9 @@ const int OLEVELS_NUM = ARRAY_SIZE(sset_level_names);
   Verify that a given allowtake string is valid.  See
   game.allow_take.
 */
-static bool allowtake_callback(const char *value, const char **error_string)
+static bool allowtake_callback(const char *value,
+   struct connection *caller,
+   const char **error_string)
 {
   int len = strlen(value), i;
   bool havecharacter_state = FALSE;
@@ -92,7 +94,9 @@ static bool allowtake_callback(const char *value, const char **error_string)
   Verify that a given startunits string is valid.  See
   game.info.start_units.
 */
-static bool startunits_callback(const char *value, const char **error_string)
+static bool startunits_callback(const char *value,
+struct connection *caller,
+const char **error_string)
 {
   int len = strlen(value), i;
   bool have_founder = FALSE;
@@ -131,7 +135,8 @@ static bool startunits_callback(const char *value, const char **error_string)
 /*
   Verify that a given endyear is valid.
 */
-static bool endyear_callback(int value, const char **error_string)
+static bool endyear_callback(int value, struct connection *caller,
+ const char **error_string)
 {
   if (value < game.info.year) {
 /* Tried to set endyear earlier than current year */
@@ -144,7 +149,8 @@ static bool endyear_callback(int value, const char **error_string)
 /*
   Verify that a given maxplayers string is valid.
 */
-static bool maxplayers_callback(int value, const char **error_string)
+static bool maxplayers_callback(int value, struct connection *caller,
+const char **error_string)
 {
 #ifdef GGZ_SERVER
   if (with_ggz) {
@@ -161,7 +167,23 @@ static bool maxplayers_callback(int value, const char **error_string)
 return FALSE;
   }
 
-  error_string = NULL;
+  *error_string = NULL;
+  return TRUE;
+}
+
+/*
+  Disallow low timeout values for non-hack connections.
+*/
+static bool timeout_callback(int value, struct connection *caller,
+ const char **error_string)
+{
+  if (caller && caller->access_level < ALLOW_HACK && value < 30) {
+*error_string = _("You are not allowed to set timeout values less "
+  "than 30 seconds.");
+return FALSE;
+  }
+
+  *error_string = NULL;
   return TRUE;
 }
 
@@ -854,10 +876,12 @@ struct settings_s settings[] = {
 	  N_("If all players have not hit \"Turn Done\" before this "
 	 "time is up, then the turn ends automatically. Zero "
 	 "means there is no timeout. In servers compiled with "
-	   

[Freeciv-Dev] (PR#40466) [Patch] Do not allow positive timeout less than 30

2008-09-17 Thread Madeline Book

http://bugs.freeciv.org/Ticket/Display.html?id=40466 >

Version 2 disallows non-hack connections from setting
the timeout to less than 30 at any time.

This is achieved by adding a 'struct connection' parameter
to each of the setting validate callback definitions.
The access level of the set command caller is checked
in the timeout callback and if it is less than ALLOW_HACK,
then values less than 30 are disallowed.

This is to prevent abuse on public servers, where setting
-1 (the server burns CPU until the game ends), 0 (the server
blocks indefinitely) or a very low timeout value (clients
do not have time to react to packets sent by server), would
be undesirable.

Unfortunately this patch is somewhat bloated by having to
update all of the setting callback arguments to match the
new definitions of the validate function typedefs. 

The timeout setting help text is also updated.


--
社会なしでいいのだろう。
 server/report.c|4 +++-
 server/report.h|4 +++-
 server/settings.c  |   46 +-
 server/settings.h  |   16 +---
 server/stdinhand.c |   27 ++-
 5 files changed, 74 insertions(+), 23 deletions(-)

diff --git a/server/report.c b/server/report.c
index 6834cb0..7bb265e 100644
--- a/server/report.c
+++ b/server/report.c
@@ -663,7 +663,9 @@ static void dem_line_item(char *outptr, size_t out_size,
   Other settings callback functions are in settings.c, but this one uses
   static values from this file so it's done separately.
 */
-bool is_valid_demography(const char *demography, const char **error_string)
+bool is_valid_demography(const char *demography,
+ struct connection *caller,
+ const char **error_string)
 {
   int len = strlen(demography), i;
 
diff --git a/server/report.h b/server/report.h
index 4dc515f..7a94fd2 100644
--- a/server/report.h
+++ b/server/report.h
@@ -24,7 +24,9 @@ void page_conn(struct conn_list *dest, const char *caption, const char *headline
 void make_history_report(void);
 void report_wonders_of_the_world(struct conn_list *dest);
 void report_top_five_cities(struct conn_list *dest);
-bool is_valid_demography(const char *demography, const char **error_message);
+bool is_valid_demography(const char *demography,
+ struct connection *caller,
+ const char **error_message);
 void report_demographics(struct connection *pconn);
 void report_final_scores(void);
 
diff --git a/server/settings.c b/server/settings.c
index 3937593..197069b 100644
--- a/server/settings.c
+++ b/server/settings.c
@@ -50,7 +50,9 @@ const int OLEVELS_NUM = ARRAY_SIZE(sset_level_names);
   Verify that a given allowtake string is valid.  See
   game.allow_take.
 */
-static bool allowtake_callback(const char *value, const char **error_string)
+static bool allowtake_callback(const char *value,
+   struct connection *caller,
+   const char **error_string)
 {
   int len = strlen(value), i;
   bool havecharacter_state = FALSE;
@@ -92,7 +94,9 @@ static bool allowtake_callback(const char *value, const char **error_string)
   Verify that a given startunits string is valid.  See
   game.info.start_units.
 */
-static bool startunits_callback(const char *value, const char **error_string)
+static bool startunits_callback(const char *value,
+struct connection *caller,
+const char **error_string)
 {
   int len = strlen(value), i;
   bool have_founder = FALSE;
@@ -131,7 +135,9 @@ static bool startunits_callback(const char *value, const char **error_string)
 /*
   Verify that a given endyear is valid.
 */
-static bool endyear_callback(int value, const char **error_string)
+static bool endyear_callback(int value,
+ struct connection *caller,
+ const char **error_string)
 {
   if (value < game.info.year) {
 /* Tried to set endyear earlier than current year */
@@ -144,7 +150,9 @@ static bool endyear_callback(int value, const char **error_string)
 /*
   Verify that a given maxplayers string is valid.
 */
-static bool maxplayers_callback(int value, const char **error_string)
+static bool maxplayers_callback(int value,
+struct connection *caller,
+const char **error

[Freeciv-Dev] (PR#40466) [Patch] Do not allow positive timeout less than 30

2008-08-27 Thread Madeline Book

http://bugs.freeciv.org/Ticket/Display.html?id=40466 >

As mentioned on the forums:
http://forum.freeciv.org/viewtopic.php?p=21251

Patch prevents setting timeout values greater than
zero but less than 30 seconds, preventing abuse
due to e.g. timeout=1.


--
犯罪者は処刑される。
diff --git a/server/settings.c b/server/settings.c
index e1bb83b..484fc45 100644
--- a/server/settings.c
+++ b/server/settings.c
@@ -196,6 +196,19 @@ static bool aifill_callback(int value, const char **error_string)
   return TRUE;
 }
 
+/*
+  Check that the timeout value is reasonable.
+*/
+static bool timeout_callback(int value, const char **error_string)
+{
+  if (0 < value && value < 30) {
+*error_string = _("That timeout value is too low.");
+return FALSE;
+  }
+  *error_string = NULL;
+  return TRUE;
+}
+
 #define GEN_BOOL(name, value, sclass, scateg, slevel, to_client,	\
 		 short_help, extra_help, func, default)			\
   {name, sclass, to_client, short_help, extra_help, SSET_BOOL,		\
@@ -884,11 +897,13 @@ struct settings_s settings[] = {
 	  N_("Maximum seconds per turn"),
 	  N_("If all players have not hit \"Turn Done\" before this "
 	 "time is up, then the turn ends automatically. Zero "
-	 "means there is no timeout. In servers compiled with "
+	 "means there is no timeout, and positive values below "
+	 "30 are not allowed. In servers compiled with "
 	 "debugging, a timeout "
 	 "of -1 sets the autogame test mode. Use this with the command "
-	 "\"timeoutincrease\" to have a dynamic timer."), NULL, 
-	   GAME_MIN_TIMEOUT, GAME_MAX_TIMEOUT, GAME_DEFAULT_TIMEOUT)
+	 "\"timeoutincrease\" to have a dynamic timer."),
+	  timeout_callback, GAME_MIN_TIMEOUT, GAME_MAX_TIMEOUT,
+	  GAME_DEFAULT_TIMEOUT)
 
   GEN_INT("timeaddenemymove", game.timeoutaddenemymove,
 	  SSET_META, SSET_INTERNAL, SSET_VITAL, SSET_TO_CLIENT,
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev