summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/map')
-rw-r--r--src/map/map.c7
-rw-r--r--src/map/script.c85
-rw-r--r--src/map/script.h8
3 files changed, 52 insertions, 48 deletions
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);