diff -Nurd -Xfreeciv/diff_ignore freeciv/server/stdinhand.c freeciv+fixfree/server/stdinhand.c --- freeciv/server/stdinhand.c Sun Jun 16 01:02:15 2002 +++ freeciv+fixfree/server/stdinhand.c Sun Jun 16 10:00:07 2002 @@ -824,7 +824,7 @@ /******************************************************************** Returns whether the specified server setting (option) can currently -be changed. Does not indicate whether it can be changed by clients or not. +be changed. Does not indicate whether it can be changed by clients. *********************************************************************/ static bool sset_is_changeable(int idx) { @@ -856,6 +856,24 @@ } /******************************************************************** +Returns whether the specified server setting (option) can ever be changed +by a client while the game is running. Does not test whether the client +has sufficient access or the option has been /fixed. +*********************************************************************/ +static int sset_is_runtime_changeable_by_client(int idx) +{ + struct settings_s *op = &settings[idx]; + + switch(op->sclass) { + case SSET_RULES_FLEXIBLE: + case SSET_META: + return 1; + default: + return 0; + } +} + +/******************************************************************** Returns whether the specified server setting (option) should be sent to the client. *********************************************************************/ @@ -919,6 +937,8 @@ /* mostly non-harmful: */ CMD_SET, + CMD_FIX, + CMD_FREE, CMD_RULESETDIR, CMD_RENAME, CMD_METAINFO, @@ -953,6 +973,12 @@ CMD_AMBIGUOUS /* used as a possible iteration result */ }; +/******************************************************************** +Returns whether the specified server setting (option) has been +explicitly protected from change at runtime with /fix. Array of booleans. +*********************************************************************/ +static int sset_is_fixed[CMD_NUM]; + static const struct command commands[] = { {"start", ALLOW_CTRL, "start", @@ -1040,7 +1066,15 @@ }, {"set", ALLOW_CTRL, N_("set "), - N_("Set server options."), NULL + N_("Set server option."), NULL + }, + {"fix", ALLOW_CTRL, + N_("fix "), + N_("Make server option unchangeable during game.") + }, + {"free", ALLOW_CTRL, + N_("free "), + N_("Make server option changeable during game.") }, {"rulesetdir", ALLOW_CTRL, N_("rulesetdir "), @@ -1048,6 +1082,14 @@ "without any arguments will show you the currently selected " "ruleset."), NULL }, + {"fix", ALLOW_CTRL, + N_("fix "), + N_("Make server option unchangeable during game.") + }, + {"free", ALLOW_CTRL, + N_("free "), + N_("Make server option changeable during game.") + }, {"rename", ALLOW_CTRL, NULL, N_("This command is not currently implemented."), NULL @@ -1250,7 +1292,7 @@ /************************************************************************** Whether the caller can use the specified command. - caller == NULL means console. + Does not see if the setting has been /fixed. caller == NULL means console. **************************************************************************/ static bool may_use(struct connection *caller, enum command_id cmd) { @@ -1275,7 +1317,7 @@ /************************************************************************** Whether the caller can set the specified option (assuming that the state of the game would allow changing the option at all). - caller == NULL means console. + Does not see if the setting has been /fixed. caller == NULL means console. **************************************************************************/ static bool may_set_option(struct connection *caller, int option_idx) { @@ -1290,11 +1332,12 @@ /************************************************************************** Whether the caller can set the specified option, taking into account - both access and the game state. caller == NULL means console. + access, the game state, and /fix. caller == NULL means console. **************************************************************************/ static bool may_set_option_now(struct connection *caller, int option_idx) { return (may_set_option(caller, option_idx) + && !sset_is_fixed[option_idx] && sset_is_changeable(option_idx)); } @@ -1887,6 +1930,14 @@ } } + /* the 'fix'ed settings */ + + for (i=0;settings[i].name;i++) { + if (sset_is_fixed[i]) { + fprintf(script_file, "fix %s\n", settings[i].name); + } + } + fclose(script_file); } else { @@ -2729,6 +2780,11 @@ _("This setting can't be modified after the game has started.")); return; } + if (sset_is_fixed[cmd] && !(map_is_empty() || game.is_new_game)) { + cmd_reply(CMD_SET, caller, C_BOUNCE, + _("This setting is protected from being modified after the game has started.")); + return; + } op = &settings[cmd]; @@ -2824,6 +2880,79 @@ } /************************************************************************** + /fix and /free commands + allow runtime modifiable options to be (un)fixed before the game starts +**************************************************************************/ +static void fix_or_free_command(struct connection *caller, char *str, + int cmd_fix_or_free) +{ + char command[MAX_LEN_CONSOLE_LINE], arg[MAX_LEN_CONSOLE_LINE], *cptr_s, *cptr_d; + int opt; + char *msgf; + + assert(cmd_fix_or_free == CMD_FIX || cmd_fix_or_free == CMD_FREE); + + for(cptr_s=str; *cptr_s && !is_ok_opt_name_char(*cptr_s); cptr_s++); + + for(cptr_d=command; + *cptr_s && is_ok_opt_name_char(*cptr_s); + cptr_s++, cptr_d++) { + *cptr_d=*cptr_s; + } + *cptr_d='\0'; + + for(; *cptr_s && is_ok_opt_name_value_sep_char(*cptr_s); cptr_s++); + + for(cptr_d=arg; *cptr_s && is_ok_opt_value_char(*cptr_s); cptr_s++ , cptr_d++) + *cptr_d=*cptr_s; + *cptr_d='\0'; + + opt=lookup_option(command); + if (opt==-1) { + cmd_reply(cmd_fix_or_free, caller, C_SYNTAX, + _("Undefined argument. Usage: %s