diff options
author | Haru <haru@dotalux.com> | 2016-02-12 12:43:14 +0100 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2016-08-19 21:32:23 +0200 |
commit | aa3a3f43b677f1646cc53f7a89ad11cdfd2fcc57 (patch) | |
tree | 764ef66928897fa988ca6ac9138a0d7852056080 | |
parent | 3f85b17f494a465daaf0cc8acb151d5d4ebbaa5d (diff) | |
download | hercules-aa3a3f43b677f1646cc53f7a89ad11cdfd2fcc57.tar.gz hercules-aa3a3f43b677f1646cc53f7a89ad11cdfd2fcc57.tar.bz2 hercules-aa3a3f43b677f1646cc53f7a89ad11cdfd2fcc57.tar.xz hercules-aa3a3f43b677f1646cc53f7a89ad11cdfd2fcc57.zip |
Ported script.conf to libconfig
Ported to modern Hercules and cleaned up from Panikon's commits: a0e4da63ef3afcd896603398e2468876681ac54a, b5f487c2676833492a6d4044b5d1f1bb1e552b04
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | conf/import-tmpl/script.conf | 32 | ||||
-rw-r--r-- | conf/import-tmpl/script_conf.txt | 0 | ||||
-rw-r--r-- | conf/map/script.conf | 64 | ||||
-rw-r--r-- | conf/script.conf | 28 | ||||
-rw-r--r-- | src/map/map.c | 7 | ||||
-rw-r--r-- | src/map/script.c | 85 | ||||
-rw-r--r-- | src/map/script.h | 8 | ||||
-rwxr-xr-x | tools/configconverter.pl | 12 |
9 files changed, 160 insertions, 77 deletions
diff --git a/.gitignore b/.gitignore index 84eb50456..877d93439 100644 --- a/.gitignore +++ b/.gitignore @@ -63,7 +63,6 @@ Thumbs.db /conf/import/battle_conf.txt /conf/import/msg_conf.txt /conf/import/packet_conf.txt -/conf/import/script_conf.txt # /log/ /log/*.log diff --git a/conf/import-tmpl/script.conf b/conf/import-tmpl/script.conf new file mode 100644 index 000000000..b354b2bf6 --- /dev/null +++ b/conf/import-tmpl/script.conf @@ -0,0 +1,32 @@ +//================= Hercules Configuration ================================ +//= _ _ _ +//= | | | | | | +//= | |_| | ___ _ __ ___ _ _| | ___ ___ +//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __| +//= | | | | __/ | | (__| |_| | | __/\__ \ +//= \_| |_/\___|_| \___|\__,_|_|\___||___/ +//================= License =============================================== +//= This file is part of Hercules. +//= http://herc.ws - http://github.com/HerculesWS/Hercules +//= +//= Copyright (C) 2014-2016 Hercules Dev Team +//= +//= Hercules is free software: you can redistribute it and/or modify +//= it under the terms of the GNU General Public License as published by +//= the Free Software Foundation, either version 3 of the License, or +//= (at your option) any later version. +//= +//= This program is distributed in the hope that it will be useful, +//= but WITHOUT ANY WARRANTY; without even the implied warranty of +//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//= GNU General Public License for more details. +//= +//= You should have received a copy of the GNU General Public License +//= along with this program. If not, see <http://www.gnu.org/licenses/>. +//========================================================================= +//= Hercules Script local configuration file. +//========================================================================= + +script_configuration: { + // See conf/map/script.conf for details +} diff --git a/conf/import-tmpl/script_conf.txt b/conf/import-tmpl/script_conf.txt deleted file mode 100644 index e69de29bb..000000000 --- a/conf/import-tmpl/script_conf.txt +++ /dev/null diff --git a/conf/map/script.conf b/conf/map/script.conf new file mode 100644 index 000000000..78514e637 --- /dev/null +++ b/conf/map/script.conf @@ -0,0 +1,64 @@ +//================= Hercules Configuration ================================ +//= _ _ _ +//= | | | | | | +//= | |_| | ___ _ __ ___ _ _| | ___ ___ +//= | _ |/ _ \ '__/ __| | | | |/ _ \/ __| +//= | | | | __/ | | (__| |_| | | __/\__ \ +//= \_| |_/\___|_| \___|\__,_|_|\___||___/ +//================= License =============================================== +//= This file is part of Hercules. +//= http://herc.ws - http://github.com/HerculesWS/Hercules +//= +//= Copyright (C) 2014-2016 Hercules Dev Team +//= +//= Hercules is free software: you can redistribute it and/or modify +//= it under the terms of the GNU General Public License as published by +//= the Free Software Foundation, either version 3 of the License, or +//= (at your option) any later version. +//= +//= This program is distributed in the hope that it will be useful, +//= but WITHOUT ANY WARRANTY; without even the implied warranty of +//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//= GNU General Public License for more details. +//= +//= You should have received a copy of the GNU General Public License +//= along with this program. If not, see <http://www.gnu.org/licenses/>. +//========================================================================= +//= Hercules Script Configuration File. +//========================================================================= + +script_configuration: { + // Specifies whether or not an error should be outputed when there's a + // mismatch between the number of provided arguments and of expected + // arguments + // Default: true + warn_func_mismatch_paramnum: true + + // Specifies whether or not each built-in function's arguments are + // checked for correct type. When a function is given an argument + // different from what it expects, a warning is thrown before the + // function is ran anyway. + // Default: true + warn_func_mismatch_argtypes: true + + // Maximum number of operations before considering a set of operations too intensive + // Defaults to 655360 + check_cmdcount: 655360 + + // Maximum number of iterations before considering a loop infinite + // Defaults to 2048 + check_gotocount: 2048 + + // Default value of the 'min' argument of the script command 'input'. + // When the 'min' argument isn't provided, this value is used instead. + // Defaults to 0. + //input_min_value: 0 + + // Default value of the 'max' argument of the script command 'input'. + // When the 'max' argument isn't provided, this value is used instead. + // Defaults to INT_MAX. + //input_max_value: 2147483647 + input_max_value: 10000000 +} + +import: "conf/import/script.conf" diff --git a/conf/script.conf b/conf/script.conf deleted file mode 100644 index 1512aa15a..000000000 --- a/conf/script.conf +++ /dev/null @@ -1,28 +0,0 @@ -//-------------------------------------------------------- -// Hercules Script Configuration File -//-------------------------------------------------------- - -warn_func_mismatch_paramnum: yes - -check_cmdcount: 655360 - -check_gotocount: 2048 - -// Default value of the 'min' argument of the script command 'input'. -// When the 'min' argument isn't provided, this value is used instead. -// Defaults to 0. -//input_min_value: 0 - -// Default value of the 'max' argument of the script command 'input'. -// When the 'max' argument isn't provided, this value is used instead. -// Defaults to INT_MAX. -//input_max_value: 2147483647 -input_max_value: 10000000 - -// Specifies whether or not each built-in function's arguments are checked for -// correct type. When a function is given an argument different from what it -// expects, a warning is thrown before the function is ran anyway. -// Default: yes -warn_func_mismatch_argtypes: yes - -import: conf/import/script_conf.txt diff --git a/src/map/map.c b/src/map/map.c index 9be68bdf5..afb81c33c 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -6369,7 +6369,7 @@ int do_init(int argc, char *argv[]) map->MAP_CONF_NAME = aStrdup("conf/map/map-server.conf"); map->BATTLE_CONF_FILENAME = aStrdup("conf/battle.conf"); map->ATCOMMAND_CONF_FILENAME = aStrdup("conf/atcommand.conf"); - map->SCRIPT_CONF_NAME = aStrdup("conf/script.conf"); + map->SCRIPT_CONF_NAME = aStrdup("conf/map/script.conf"); map->MSG_CONF_NAME = aStrdup("conf/messages.conf"); map->GRF_PATH_FILENAME = aStrdup("conf/grf-files.txt"); @@ -6400,6 +6400,7 @@ int do_init(int argc, char *argv[]) CHECK_OLD_LOCAL_CONF("conf/import/map_conf.txt", "conf/import/map-server.conf"); CHECK_OLD_LOCAL_CONF("conf/import/inter_conf.txt", "conf/import/inter-server.conf"); CHECK_OLD_LOCAL_CONF("conf/import/log_conf.txt", "conf/import/logs.conf"); + CHECK_OLD_LOCAL_CONF("conf/import/script_conf.txt", "conf/import/script.conf"); #undef CHECK_OLD_LOCAL_CONF } @@ -6435,7 +6436,7 @@ int do_init(int argc, char *argv[]) map->inter_config_read(map->INTER_CONF_NAME, false); logs->config_read(map->LOG_CONF_NAME, false); } - script->config_read(map->SCRIPT_CONF_NAME); + script->config_read(map->SCRIPT_CONF_NAME, false); map->id_db = idb_alloc(DB_OPT_BASE); map->pc_db = idb_alloc(DB_OPT_BASE); //Added for reliable map->id2sd() use. [Skotlex] @@ -6596,7 +6597,7 @@ void map_defaults(void) { map->MAP_CONF_NAME = "conf/map/map-server.conf"; map->BATTLE_CONF_FILENAME = "conf/battle.conf"; map->ATCOMMAND_CONF_FILENAME = "conf/atcommand.conf"; - map->SCRIPT_CONF_NAME = "conf/script.conf"; + map->SCRIPT_CONF_NAME = "conf/map/script.conf"; map->MSG_CONF_NAME = "conf/messages.conf"; map->GRF_PATH_FILENAME = "conf/grf-files.txt"; diff --git a/src/map/script.c b/src/map/script.c index 353d57a67..09cefa500 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -4521,52 +4521,55 @@ void run_script_main(struct script_state *st) { } } -int script_config_read(char *cfgName) { - int i; - char line[1024],w1[1024],w2[1024]; - FILE *fp; +/** + * Reads 'script_configuration' and initializes required variables. + * + * @param filename Path to configuration file. + * @param imported Whether the current config is imported from another file. + * + * @retval false in case of error. + */ +bool script_config_read(const char *filename, bool imported) +{ + struct config_t config; + struct config_setting_t * setting = NULL; + const char *import = NULL; + bool retval = true; - if( !( fp = fopen(cfgName,"r") ) ) { - ShowError("File not found: %s\n", cfgName); - return 1; + nullpo_retr(false, filename); + + if (!libconfig->load_file(&config, filename)) + return false; + + if ((setting = libconfig->lookup(&config, "script_configuration")) == NULL) { + libconfig->destroy(&config); + if (imported) + return true; + ShowError("script_config_read: script_configuration was not found in %s!\n", filename); + return false; } - while (fgets(line, sizeof(line), fp)) { - if (line[0] == '/' && line[1] == '/') - continue; - i = sscanf(line,"%1023[^:]: %1023[^\r\n]", w1, w2); - if(i!=2) - continue; - if(strcmpi(w1,"warn_func_mismatch_paramnum")==0) { - script->config.warn_func_mismatch_paramnum = config_switch(w2); - } - else if(strcmpi(w1,"check_cmdcount")==0) { - script->config.check_cmdcount = config_switch(w2); - } - else if(strcmpi(w1,"check_gotocount")==0) { - script->config.check_gotocount = config_switch(w2); - } - else if(strcmpi(w1,"input_min_value")==0) { - script->config.input_min_value = config_switch(w2); - } - else if(strcmpi(w1,"input_max_value")==0) { - script->config.input_max_value = config_switch(w2); - } - else if(strcmpi(w1,"warn_func_mismatch_argtypes")==0) { - script->config.warn_func_mismatch_argtypes = config_switch(w2); - } - else if(strcmpi(w1,"import")==0) { - script->config_read(w2); - } - else if(HPM->parseConf(w1, w2, HPCT_SCRIPT)) { - ; // handled by plugin + libconfig->setting_lookup_bool_real(setting, "warn_func_mismatch_paramnum", &script->config.warn_func_mismatch_paramnum); + libconfig->setting_lookup_bool_real(setting, "warn_func_mismatch_argtypes", &script->config.warn_func_mismatch_argtypes); + libconfig->setting_lookup_int(setting, "check_cmdcount", &script->config.check_cmdcount); + libconfig->setting_lookup_int(setting, "check_gotocount", &script->config.check_gotocount); + libconfig->setting_lookup_int(setting, "input_min_value", &script->config.input_min_value); + libconfig->setting_lookup_int(setting, "input_max_value", &script->config.input_max_value); + + // TODO HPM->parseConf(w1, w2, HPCT_SCRIPT)); + + // import should overwrite any previous configuration, so it should be called last + if (libconfig->lookup_string(&config, "import", &import) == CONFIG_TRUE) { + if (strcmp(import, filename) == 0 || strcmp(import, map->SCRIPT_CONF_NAME) == 0) { + ShowWarning("script_config_read: Loop detected! Skipping 'import'...\n"); } else { - ShowWarning("Unknown setting '%s' in file %s\n", w1, cfgName); + if (!script->config_read(import, true)) + retval = false; } } - fclose(fp); - return 0; + libconfig->destroy(&config); + return retval; } /** @@ -21449,8 +21452,8 @@ void script_defaults(void) { script->getfuncname = script_getfuncname; /* script_config base */ - script->config.warn_func_mismatch_argtypes = 1; - script->config.warn_func_mismatch_paramnum = 1; + script->config.warn_func_mismatch_argtypes = true; + script->config.warn_func_mismatch_paramnum = true; script->config.check_cmdcount = 65535; script->config.check_gotocount = 2048; script->config.input_min_value = 0; diff --git a/src/map/script.h b/src/map/script.h index 86cb20226..c4c082263 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -343,8 +343,8 @@ enum { **/ struct Script_Config { - unsigned warn_func_mismatch_argtypes : 1; - unsigned warn_func_mismatch_paramnum : 1; + bool warn_func_mismatch_argtypes; + bool warn_func_mismatch_paramnum; int check_cmdcount; int check_gotocount; int input_min_value; @@ -692,7 +692,7 @@ struct script_interface { void (*run_autobonus) (const char *autobonus,int id, int pos); void (*cleararray_pc) (struct map_session_data* sd, const char* varname, void* value); void (*setarray_pc) (struct map_session_data* sd, const char* varname, uint32 idx, void* value, int* refcache); - int (*config_read) (char *cfgName); + bool (*config_read) (const char *filename, bool imported); int (*add_str) (const char* p); const char* (*get_str) (int id); int (*search_str) (const char* p); diff --git a/tools/configconverter.pl b/tools/configconverter.pl index db34de2fd..958286c49 100755 --- a/tools/configconverter.pl +++ b/tools/configconverter.pl @@ -502,6 +502,18 @@ my @defaults = ( import => {parse => \&parsecfg_string, print => \&printcfg_nil, path => "", default => "conf/import/log_conf.txt"}, } }, + { + files => ['script.conf', 'import/script_conf.txt'], + settings => { + warn_func_mismatch_paramnum => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "script:script_configuration/", default => "true"}, + check_cmdcount => {parse => \&parsecfg_int, print => \&printcfg_int, path => "script:script_configuration/", default => 655360}, + check_gotocount => {parse => \&parsecfg_int, print => \&printcfg_int, path => "script:script_configuration/", default => 2048}, + input_min_value => {parse => \&parsecfg_int, print => \&printcfg_int, path => "script:script_configuration/", default => 0}, + input_max_value => {parse => \&parsecfg_int, print => \&printcfg_int, path => "script:script_configuration/", default => 10000000}, + warn_func_mismatch_argtypes => {parse => \&parsecfg_bool, print => \&printcfg_bool, path => "script:script_configuration/", default => "true"}, + import => {parse => \&parsecfg_string, print => \&printcfg_nil, path => "", default => "conf/import/script_conf.txt"}, + } + }, ); for (@ARGV) { |