diff options
-rw-r--r-- | src/common/HPM.c | 23 | ||||
-rw-r--r-- | src/common/conf.c | 158 | ||||
-rw-r--r-- | src/common/conf.h | 92 | ||||
-rw-r--r-- | src/common/core.c | 2 | ||||
-rw-r--r-- | src/map/atcommand.c | 40 | ||||
-rw-r--r-- | src/map/battleground.c | 50 | ||||
-rw-r--r-- | src/map/clif.c | 73 | ||||
-rw-r--r-- | src/map/itemdb.c | 178 | ||||
-rw-r--r-- | src/map/map.c | 160 | ||||
-rw-r--r-- | src/map/pc.c | 28 | ||||
-rw-r--r-- | src/map/pc_groups.c | 72 | ||||
-rw-r--r-- | src/plugins/db2sql.c | 23 |
12 files changed, 525 insertions, 374 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c index 426fac94a..e31437b72 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -261,21 +261,21 @@ void hplugins_config_read(void) { fclose(fp); } - if (conf_read_file(&plugins_conf, config_filename)) + if (libconfig->read_file(&plugins_conf, config_filename)) return; if( HPM->symbol_defaults_sub ) HPM->symbol_defaults_sub(); - plist = config_lookup(&plugins_conf, "plugins_list"); + plist = libconfig->lookup(&plugins_conf, "plugins_list"); if (plist != NULL) { - int length = config_setting_length(plist), i; + int length = libconfig->setting_length(plist), i; char filename[60]; for(i = 0; i < length; i++) { - if( !strcmpi(config_setting_get_string_elem(plist,i),"HPMHooking") ) {//must load it first + if( !strcmpi(libconfig->setting_get_string_elem(plist,i),"HPMHooking") ) {//must load it first struct hplugin *plugin; - snprintf(filename, 60, "plugins/%s%s", config_setting_get_string_elem(plist,i), DLL_EXT); + snprintf(filename, 60, "plugins/%s%s", libconfig->setting_get_string_elem(plist,i), DLL_EXT); if( ( plugin = HPM->load(filename) ) ) { bool (*func)(bool *fr); bool (*addhook_sub) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID); @@ -289,12 +289,12 @@ void hplugins_config_read(void) { } } for(i = 0; i < length; i++) { - if( strcmpi(config_setting_get_string_elem(plist,i),"HPMHooking") ) {//now all others - snprintf(filename, 60, "plugins/%s%s", config_setting_get_string_elem(plist,i), DLL_EXT); + if( strcmpi(libconfig->setting_get_string_elem(plist,i),"HPMHooking") ) {//now all others + snprintf(filename, 60, "plugins/%s%s", libconfig->setting_get_string_elem(plist,i), DLL_EXT); HPM->load(filename); } } - config_destroy(&plugins_conf); + libconfig->destroy(&plugins_conf); } if( HPM->plugin_count ) @@ -688,11 +688,8 @@ void hplugins_share_defaults(void) { HPM->share(SQL,"SQL"); /* timer */ HPM->share(timer,"timer"); - /* libconfig (temp) */ - HPM->share(config_setting_lookup_string,"config_setting_lookup_string"); - HPM->share(config_setting_lookup_int,"config_setting_lookup_int"); - HPM->share(config_setting_get_member,"config_setting_get_member"); - HPM->share(config_setting_length,"config_setting_length"); + /* libconfig */ + HPM->share(libconfig,"libconfig"); } void hpm_init(void) { diff --git a/src/common/conf.c b/src/common/conf.c index 813069ac4..b816b2f7f 100644 --- a/src/common/conf.c +++ b/src/common/conf.c @@ -7,13 +7,16 @@ #include "../common/showmsg.h" // ShowError -int conf_read_file(config_t *config, const char *config_filename) -{ - config_init(config); - if (!config_read_file(config, config_filename)) { +/* interface source */ +struct libconfig_interface libconfig_s; + + +int conf_read_file(config_t *config, const char *config_filename) { + libconfig->init(config); + if (!libconfig->read_file_src(config, config_filename)) { ShowError("%s:%d - %s\n", config_error_file(config), config_error_line(config), config_error_text(config)); - config_destroy(config); + libconfig->destroy(config); return 1; } return 0; @@ -22,71 +25,63 @@ int conf_read_file(config_t *config, const char *config_filename) // // Functions to copy settings from libconfig/contrib // -static void config_setting_copy_simple(config_setting_t *parent, const config_setting_t *src); -static void config_setting_copy_elem(config_setting_t *parent, const config_setting_t *src); -static void config_setting_copy_aggregate(config_setting_t *parent, const config_setting_t *src); -int config_setting_copy(config_setting_t *parent, const config_setting_t *src); - -void config_setting_copy_simple(config_setting_t *parent, const config_setting_t *src) -{ +void config_setting_copy_simple(config_setting_t *parent, const config_setting_t *src) { if (config_setting_is_aggregate(src)) { - config_setting_copy_aggregate(parent, src); + libconfig->setting_copy_aggregate(parent, src); } else { config_setting_t *set; - if( config_setting_get_member(parent, config_setting_name(src)) != NULL ) + if( libconfig->setting_get_member(parent, config_setting_name(src)) != NULL ) return; - if ((set = config_setting_add(parent, config_setting_name(src), config_setting_type(src))) == NULL) + if ((set = libconfig->setting_add(parent, config_setting_name(src), config_setting_type(src))) == NULL) return; if (CONFIG_TYPE_INT == config_setting_type(src)) { - config_setting_set_int(set, config_setting_get_int(src)); - config_setting_set_format(set, src->format); + libconfig->setting_set_int(set, libconfig->setting_get_int(src)); + libconfig->setting_set_format(set, src->format); } else if (CONFIG_TYPE_INT64 == config_setting_type(src)) { - config_setting_set_int64(set, config_setting_get_int64(src)); - config_setting_set_format(set, src->format); + libconfig->setting_set_int64(set, libconfig->setting_get_int64(src)); + libconfig->setting_set_format(set, src->format); } else if (CONFIG_TYPE_FLOAT == config_setting_type(src)) { - config_setting_set_float(set, config_setting_get_float(src)); + libconfig->setting_set_float(set, libconfig->setting_get_float(src)); } else if (CONFIG_TYPE_STRING == config_setting_type(src)) { - config_setting_set_string(set, config_setting_get_string(src)); + libconfig->setting_set_string(set, libconfig->setting_get_string(src)); } else if (CONFIG_TYPE_BOOL == config_setting_type(src)) { - config_setting_set_bool(set, config_setting_get_bool(src)); + libconfig->setting_set_bool(set, libconfig->setting_get_bool(src)); } } } -void config_setting_copy_elem(config_setting_t *parent, const config_setting_t *src) -{ +void config_setting_copy_elem(config_setting_t *parent, const config_setting_t *src) { config_setting_t *set = NULL; if (config_setting_is_aggregate(src)) - config_setting_copy_aggregate(parent, src); + libconfig->setting_copy_aggregate(parent, src); else if (CONFIG_TYPE_INT == config_setting_type(src)) { - set = config_setting_set_int_elem(parent, -1, config_setting_get_int(src)); - config_setting_set_format(set, src->format); + set = libconfig->setting_set_int_elem(parent, -1, libconfig->setting_get_int(src)); + libconfig->setting_set_format(set, src->format); } else if (CONFIG_TYPE_INT64 == config_setting_type(src)) { - set = config_setting_set_int64_elem(parent, -1, config_setting_get_int64(src)); - config_setting_set_format(set, src->format); + set = libconfig->setting_set_int64_elem(parent, -1, libconfig->setting_get_int64(src)); + libconfig->setting_set_format(set, src->format); } else if (CONFIG_TYPE_FLOAT == config_setting_type(src)) { - config_setting_set_float_elem(parent, -1, config_setting_get_float(src)); + libconfig->setting_set_float_elem(parent, -1, libconfig->setting_get_float(src)); } else if (CONFIG_TYPE_STRING == config_setting_type(src)) { - config_setting_set_string_elem(parent, -1, config_setting_get_string(src)); + libconfig->setting_set_string_elem(parent, -1, libconfig->setting_get_string(src)); } else if (CONFIG_TYPE_BOOL == config_setting_type(src)) { - config_setting_set_bool_elem(parent, -1, config_setting_get_bool(src)); + libconfig->setting_set_bool_elem(parent, -1, libconfig->setting_get_bool(src)); } } -void config_setting_copy_aggregate(config_setting_t *parent, const config_setting_t *src) -{ +void config_setting_copy_aggregate(config_setting_t *parent, const config_setting_t *src) { config_setting_t *newAgg; int i, n; - if( config_setting_get_member(parent, config_setting_name(src)) != NULL ) + if( libconfig->setting_get_member(parent, config_setting_name(src)) != NULL ) return; - newAgg = config_setting_add(parent, config_setting_name(src), config_setting_type(src)); + newAgg = libconfig->setting_add(parent, config_setting_name(src), config_setting_type(src)); if (newAgg == NULL) return; @@ -95,22 +90,101 @@ void config_setting_copy_aggregate(config_setting_t *parent, const config_settin for (i = 0; i < n; i++) { if (config_setting_is_group(src)) { - config_setting_copy_simple(newAgg, config_setting_get_elem(src, i)); + libconfig->setting_copy_simple(newAgg, libconfig->setting_get_elem(src, i)); } else { - config_setting_copy_elem(newAgg, config_setting_get_elem(src, i)); + libconfig->setting_copy_elem(newAgg, libconfig->setting_get_elem(src, i)); } } } -int config_setting_copy(config_setting_t *parent, const config_setting_t *src) -{ +int config_setting_copy(config_setting_t *parent, const config_setting_t *src) { + if (!config_setting_is_group(parent) && !config_setting_is_list(parent)) return CONFIG_FALSE; if (config_setting_is_aggregate(src)) { - config_setting_copy_aggregate(parent, src); + libconfig->setting_copy_aggregate(parent, src); } else { - config_setting_copy_simple(parent, src); + libconfig->setting_copy_simple(parent, src); } return CONFIG_TRUE; } + +void libconfig_defaults(void) { + libconfig = &libconfig_s; + + libconfig->read = config_read; + libconfig->write = config_write; + /* */ + libconfig->set_auto_convert = config_set_auto_convert; + libconfig->get_auto_convert = config_get_auto_convert; + /* */ + libconfig->read_string = config_read_string; + libconfig->read_file_src = config_read_file; + libconfig->write_file = config_write_file; + /* */ + libconfig->set_destructor = config_set_destructor; + libconfig->set_include_dir = config_set_include_dir; + /* */ + libconfig->init = config_init; + libconfig->destroy = config_destroy; + /* */ + libconfig->setting_get_int = config_setting_get_int; + libconfig->setting_get_int64 = config_setting_get_int64; + libconfig->setting_get_float = config_setting_get_float; + libconfig->setting_get_bool = config_setting_get_bool; + libconfig->setting_get_string = config_setting_get_string; + /* */ + libconfig->setting_lookup_int = config_setting_lookup_int; + libconfig->setting_lookup_int64 = config_setting_lookup_int64; + libconfig->setting_lookup_float = config_setting_lookup_float; + libconfig->setting_lookup_bool = config_setting_lookup_bool; + libconfig->setting_lookup_string = config_setting_lookup_string; + /* */ + libconfig->setting_set_int = config_setting_set_int; + libconfig->setting_set_int64 = config_setting_set_int64; + libconfig->setting_set_bool = config_setting_set_bool; + libconfig->setting_set_string = config_setting_set_string; + /* */ + libconfig->setting_set_format = config_setting_set_format; + libconfig->setting_get_format = config_setting_get_format; + /* */ + libconfig->setting_get_int_elem = config_setting_get_int_elem; + libconfig->setting_get_int64_elem = config_setting_get_int64_elem; + libconfig->setting_get_float_elem = config_setting_get_float_elem; + libconfig->setting_get_bool_elem = config_setting_get_bool_elem; + libconfig->setting_get_string_elem = config_setting_get_string_elem; + /* */ + libconfig->setting_set_int_elem = config_setting_set_int_elem; + libconfig->setting_set_int64_elem = config_setting_set_int64_elem; + libconfig->setting_set_float_elem = config_setting_set_float_elem; + libconfig->setting_set_bool_elem = config_setting_set_bool_elem; + libconfig->setting_set_string_elem = config_setting_set_string_elem; + /* */ + libconfig->setting_index = config_setting_index; + libconfig->setting_length = config_setting_length; + /* */ + libconfig->setting_get_elem = config_setting_get_elem; + libconfig->setting_get_member = config_setting_get_member; + /* */ + libconfig->setting_add = config_setting_add; + libconfig->setting_remove = config_setting_remove; + libconfig->setting_remove_elem = config_setting_remove_elem; + /* */ + libconfig->setting_set_hook = config_setting_set_hook; + /* */ + libconfig->lookup = config_lookup; + libconfig->lookup_from = config_lookup_from; + /* */ + libconfig->lookup_int = config_lookup_int; + libconfig->lookup_int64 = config_lookup_int64; + libconfig->lookup_float = config_lookup_float; + libconfig->lookup_bool = config_lookup_bool; + libconfig->lookup_string = config_lookup_string; + /* those are custom and are from src/common/conf.c */ + libconfig->read_file = conf_read_file; + libconfig->setting_copy_simple = config_setting_copy_simple; + libconfig->setting_copy_elem = config_setting_copy_elem; + libconfig->setting_copy_aggregate = config_setting_copy_aggregate; + libconfig->setting_copy = config_setting_copy; +} diff --git a/src/common/conf.h b/src/common/conf.h index d223505db..05e2b1ada 100644 --- a/src/common/conf.h +++ b/src/common/conf.h @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena Dev Teams #ifndef _CONF_H_ #define _CONF_H_ @@ -7,7 +8,90 @@ #include "../common/cbasetypes.h" #include "../../3rdparty/libconfig/libconfig.h" -int conf_read_file(config_t *config, const char *config_filename); -int config_setting_copy(config_setting_t *parent, const config_setting_t *src); +/** + * The libconfig interface -- specially for plugins, but we enforce it throughought the core to be consistent + **/ +struct libconfig_interface { + int (*read) (config_t *config, FILE *stream); + void (*write) (const config_t *config, FILE *stream); + /* */ + void (*set_auto_convert) (config_t *config, int flag); + int (*get_auto_convert) (const config_t *config); + /* */ + int (*read_string) (config_t *config, const char *str); + int (*read_file_src) (config_t *config, const char *filename); + int (*write_file) (config_t *config, const char *filename); + + void (*set_destructor) (config_t *config, void (*destructor)(void *)); + void (*set_include_dir) (config_t *config, const char *include_dir); + + void (*init) (config_t *config); + void (*destroy) (config_t *config); + + int (*setting_get_int) (const config_setting_t *setting); + long long (*setting_get_int64) (const config_setting_t *setting); + double (*setting_get_float) (const config_setting_t *setting); + + int (*setting_get_bool) (const config_setting_t *setting); + + const char * (*setting_get_string) (const config_setting_t *setting); + + int (*setting_lookup_int) (const config_setting_t *setting, const char *name, int *value); + int (*setting_lookup_int64) (const config_setting_t *setting, const char *name, long long *value); + int (*setting_lookup_float) (const config_setting_t *setting, const char *name, double *value); + int (*setting_lookup_bool) (const config_setting_t *setting, const char *name, int *value); + int (*setting_lookup_string) (const config_setting_t *setting, const char *name, const char **value); + int (*setting_set_int) (config_setting_t *setting ,int value); + int (*setting_set_int64) (config_setting_t *setting, long long value); + int (*setting_set_float) (config_setting_t *setting, double value); + int (*setting_set_bool) (config_setting_t *setting, int value); + int (*setting_set_string) (config_setting_t *setting, const char *value); + + int (*setting_set_format) (config_setting_t *setting, short format); + short (*setting_get_format) (const config_setting_t *setting); + + int (*setting_get_int_elem) (const config_setting_t *setting, int idx); + long long (*setting_get_int64_elem) (const config_setting_t *setting, int idx); + double (*setting_get_float_elem) (const config_setting_t *setting, int idx); + int (*setting_get_bool_elem) (const config_setting_t *setting, int idx); + const char * (*setting_get_string_elem) (const config_setting_t *setting, int idx); + config_setting_t * (*setting_set_int_elem) (config_setting_t *setting, int idx, int value); + config_setting_t * (*setting_set_int64_elem) (config_setting_t *setting, int idx, long long value); + config_setting_t * (*setting_set_float_elem) (config_setting_t *setting, int idx, double value); + config_setting_t * (*setting_set_bool_elem) (config_setting_t *setting, int idx, int value); + config_setting_t * (*setting_set_string_elem) (config_setting_t *setting, int idx, const char *value); + + int (*setting_index) (const config_setting_t *setting); + int (*setting_length) (const config_setting_t *setting); + + config_setting_t * (*setting_get_elem) (const config_setting_t *setting, unsigned int idx); + config_setting_t * (*setting_get_member) (const config_setting_t *setting, const char *name); + + config_setting_t * (*setting_add) (config_setting_t *parent, const char *name, int type); + int (*setting_remove) (config_setting_t *parent, const char *name); + + int (*setting_remove_elem) (config_setting_t *parent, unsigned int idx); + void (*setting_set_hook) (config_setting_t *setting, void *hook); + + config_setting_t * (*lookup) (const config_t *config, const char *path); + config_setting_t * (*lookup_from) (config_setting_t *setting, const char *path); + int (*lookup_int) (const config_t *config, const char *path, int *value); + int (*lookup_int64) (const config_t *config, const char *path, long long *value); + int (*lookup_float) (const config_t *config, const char *path, double *value); + int (*lookup_bool) (const config_t *config, const char *path, int *value); + int (*lookup_string) (const config_t *config, const char *path, const char **value); + + /* those are custom and are from src/common/conf.c */ + /* Functions to copy settings from libconfig/contrib */ + int (*read_file) (config_t *config, const char *config_filename); + void (*setting_copy_simple) (config_setting_t *parent, const config_setting_t *src); + void (*setting_copy_elem) (config_setting_t *parent, const config_setting_t *src); + void (*setting_copy_aggregate) (config_setting_t *parent, const config_setting_t *src); + int (*setting_copy) (config_setting_t *parent, const config_setting_t *src); +}; + +struct libconfig_interface *libconfig; + +void libconfig_defaults(void); #endif // _CONF_H_ diff --git a/src/common/core.c b/src/common/core.c index 8178a48a5..5c1e58801 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -19,6 +19,7 @@ #include "../config/core.h" #include "../common/HPM.h" #include "../common/utils.h" + #include "../common/conf.h" #endif #include <stdio.h> @@ -282,6 +283,7 @@ void core_defaults(void) { strlib_defaults(); malloc_defaults(); #ifndef MINICORE + libconfig_defaults(); sql_defaults(); timer_defaults(); db_defaults(); diff --git a/src/map/atcommand.c b/src/map/atcommand.c index e5d14fc21..3cdfb0e29 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -3544,19 +3544,19 @@ ACMD(reloadskilldb) ACMD(reloadatcommand) { config_t run_test; - if (conf_read_file(&run_test, "conf/groups.conf")) { + if (libconfig->read_file(&run_test, "conf/groups.conf")) { clif->message(fd, msg_txt(1036)); // Error reading groups.conf, reload failed. return false; } - config_destroy(&run_test); + libconfig->destroy(&run_test); - if (conf_read_file(&run_test, map->ATCOMMAND_CONF_FILENAME)) { + if (libconfig->read_file(&run_test, map->ATCOMMAND_CONF_FILENAME)) { clif->message(fd, msg_txt(1037)); // Error reading atcommand.conf, reload failed. return false; } - config_destroy(&run_test); + libconfig->destroy(&run_test); atcommand->doload(); pcg->reload(); @@ -9959,11 +9959,11 @@ void atcommand_config_read(const char* config_filename) { const char *symbol = NULL; int num_aliases = 0; - if (conf_read_file(&atcommand_config, config_filename)) + if (libconfig->read_file(&atcommand_config, config_filename)) return; // Command symbols - if (config_lookup_string(&atcommand_config, "atcommand_symbol", &symbol)) { + if (libconfig->lookup_string(&atcommand_config, "atcommand_symbol", &symbol)) { if (ISPRINT(*symbol) && // no control characters *symbol != '/' && // symbol of client commands *symbol != '%' && // symbol of party chat @@ -9972,7 +9972,7 @@ void atcommand_config_read(const char* config_filename) { atcommand->at_symbol = *symbol; } - if (config_lookup_string(&atcommand_config, "charcommand_symbol", &symbol)) { + if (libconfig->lookup_string(&atcommand_config, "charcommand_symbol", &symbol)) { if (ISPRINT(*symbol) && // no control characters *symbol != '/' && // symbol of client commands *symbol != '%' && // symbol of party chat @@ -9982,10 +9982,10 @@ void atcommand_config_read(const char* config_filename) { } // Command aliases - aliases = config_lookup(&atcommand_config, "aliases"); + aliases = libconfig->lookup(&atcommand_config, "aliases"); if (aliases != NULL) { int i = 0; - int count = config_setting_length(aliases); + int count = libconfig->setting_length(aliases); for (i = 0; i < count; ++i) { config_setting_t *command; @@ -9993,7 +9993,7 @@ void atcommand_config_read(const char* config_filename) { int j = 0, alias_count = 0; AtCommandInfo *commandinfo = NULL; - command = config_setting_get_elem(aliases, i); + command = libconfig->setting_get_elem(aliases, i); if (config_setting_type(command) != CONFIG_TYPE_ARRAY) continue; commandname = config_setting_name(command); @@ -10001,9 +10001,9 @@ void atcommand_config_read(const char* config_filename) { ShowConfigWarning(command, "atcommand_config_read: can not set alias for non-existent command %s", commandname); continue; } - alias_count = config_setting_length(command); + alias_count = libconfig->setting_length(command); for (j = 0; j < alias_count; ++j) { - const char *alias = config_setting_get_string_elem(command, j); + const char *alias = libconfig->setting_get_string_elem(command, j); if (alias != NULL) { AliasInfo *alias_info; if (strdb_exists(atcommand->alias_db, alias)) { @@ -10020,17 +10020,17 @@ void atcommand_config_read(const char* config_filename) { } } - nolog = config_lookup(&atcommand_config, "nolog"); + nolog = libconfig->lookup(&atcommand_config, "nolog"); if (nolog != NULL) { int i = 0; - int count = config_setting_length(nolog); + int count = libconfig->setting_length(nolog); for (i = 0; i < count; ++i) { config_setting_t *command; const char *commandname = NULL; AtCommandInfo *commandinfo = NULL; - command = config_setting_get_elem(nolog, i); + command = libconfig->setting_get_elem(nolog, i); commandname = config_setting_name(command); if ( !( commandinfo = atcommand_exists(commandname) ) ) { ShowConfigWarning(command, "atcommand_config_read: can not disable logging for non-existent command %s", commandname); @@ -10042,9 +10042,9 @@ void atcommand_config_read(const char* config_filename) { // Commands help // We only check if all commands exist - help = config_lookup(&atcommand_config, "help"); + help = libconfig->lookup(&atcommand_config, "help"); if (help != NULL) { - int count = config_setting_length(help); + int count = libconfig->setting_length(help); int i; for (i = 0; i < count; ++i) { @@ -10052,13 +10052,13 @@ void atcommand_config_read(const char* config_filename) { const char *commandname; AtCommandInfo *commandinfo = NULL; - command = config_setting_get_elem(help, i); + command = libconfig->setting_get_elem(help, i); commandname = config_setting_name(command); if ( !( commandinfo = atcommand_exists(commandname) ) ) ShowConfigWarning(command, "atcommand_config_read: command %s does not exist", commandname); else { if( commandinfo->help == NULL ) { - const char *str = config_setting_get_string(command); + const char *str = libconfig->setting_get_string(command); size_t len = strlen(str); commandinfo->help = aMalloc( len * sizeof(char) ); safestrncpy(commandinfo->help, str, len); @@ -10069,7 +10069,7 @@ void atcommand_config_read(const char* config_filename) { ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' command aliases in '"CL_WHITE"%s"CL_RESET"'.\n", num_aliases, config_filename); - config_destroy(&atcommand_config); + libconfig->destroy(&atcommand_config); return; } diff --git a/src/map/battleground.c b/src/map/battleground.c index ab44b0953..65f475124 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -257,34 +257,34 @@ void bg_config_read(void) { config_setting_t *data = NULL; const char *config_filename = "conf/battlegrounds.conf"; // FIXME hardcoded name - if (conf_read_file(&bg_conf, config_filename)) + if (libconfig->read_file(&bg_conf, config_filename)) return; - data = config_lookup(&bg_conf, "battlegrounds"); + data = libconfig->lookup(&bg_conf, "battlegrounds"); if (data != NULL) { - config_setting_t *settings = config_setting_get_elem(data, 0); + config_setting_t *settings = libconfig->setting_get_elem(data, 0); config_setting_t *arenas; const char *delay_var; int i, arena_count = 0, offline = 0; - if( !config_setting_lookup_string(settings, "global_delay_var", &delay_var) ) + if( !libconfig->setting_lookup_string(settings, "global_delay_var", &delay_var) ) delay_var = "BG_Delay_Tick"; safestrncpy(bg->gdelay_var, delay_var, BG_DELAY_VAR_LENGTH); - config_setting_lookup_int(settings, "maximum_afk_seconds", &bg->mafksec); + libconfig->setting_lookup_int(settings, "maximum_afk_seconds", &bg->mafksec); - config_setting_lookup_bool(settings, "feature_off", &offline); + libconfig->setting_lookup_bool(settings, "feature_off", &offline); if( offline == 0 ) bg->queue_on = true; - if( (arenas = config_setting_get_member(settings, "arenas")) != NULL ) { - arena_count = config_setting_length(arenas); + if( (arenas = libconfig->setting_get_member(settings, "arenas")) != NULL ) { + arena_count = libconfig->setting_length(arenas); CREATE( bg->arena, struct bg_arena *, arena_count ); for(i = 0; i < arena_count; i++) { - config_setting_t *arena = config_setting_get_elem(arenas, i); + config_setting_t *arena = libconfig->setting_get_elem(arenas, i); config_setting_t *reward; const char *aName, *aEvent, *aDelayVar; int minLevel = 0, maxLevel = 0; @@ -295,18 +295,18 @@ void bg_config_read(void) { bg->arena[i] = NULL; - if( !config_setting_lookup_string(arena, "name", &aName) ) { + if( !libconfig->setting_lookup_string(arena, "name", &aName) ) { ShowError("bg_config_read: failed to find 'name' for arena #%d\n",i); continue; } - if( !config_setting_lookup_string(arena, "event", &aEvent) ) { + if( !libconfig->setting_lookup_string(arena, "event", &aEvent) ) { ShowError("bg_config_read: failed to find 'event' for arena #%d\n",i); continue; } - config_setting_lookup_int(arena, "minLevel", &minLevel); - config_setting_lookup_int(arena, "maxLevel", &maxLevel); + libconfig->setting_lookup_int(arena, "minLevel", &minLevel); + libconfig->setting_lookup_int(arena, "maxLevel", &maxLevel); if( minLevel < 0 ) { ShowWarning("bg_config_read: invalid %d value for arena '%s' minLevel\n",minLevel,aName); @@ -317,14 +317,14 @@ void bg_config_read(void) { maxLevel = MAX_LEVEL; } - if( !(reward = config_setting_get_member(arena, "reward")) ) { + if( !(reward = libconfig->setting_get_member(arena, "reward")) ) { ShowError("bg_config_read: failed to find 'reward' for arena '%s'/#%d\n",aName,i); continue; } - config_setting_lookup_int(reward, "win", &prizeWin); - config_setting_lookup_int(reward, "loss", &prizeLoss); - config_setting_lookup_int(reward, "draw", &prizeDraw); + libconfig->setting_lookup_int(reward, "win", &prizeWin); + libconfig->setting_lookup_int(reward, "loss", &prizeLoss); + libconfig->setting_lookup_int(reward, "draw", &prizeDraw); if( prizeWin < 0 ) { ShowWarning("bg_config_read: invalid %d value for arena '%s' reward:win\n",prizeWin,aName); @@ -339,9 +339,9 @@ void bg_config_read(void) { prizeDraw = 0; } - config_setting_lookup_int(arena, "minPlayers", &minPlayers); - config_setting_lookup_int(arena, "maxPlayers", &maxPlayers); - config_setting_lookup_int(arena, "minTeamPlayers", &minTeamPlayers); + libconfig->setting_lookup_int(arena, "minPlayers", &minPlayers); + libconfig->setting_lookup_int(arena, "maxPlayers", &maxPlayers); + libconfig->setting_lookup_int(arena, "minTeamPlayers", &minTeamPlayers); if( minPlayers < 0 ) { ShowWarning("bg_config_read: invalid %d value for arena '%s' minPlayers\n",minPlayers,aName); @@ -356,20 +356,20 @@ void bg_config_read(void) { minTeamPlayers = 0; } - if( !config_setting_lookup_string(arena, "delay_var", &aDelayVar) ) { + if( !libconfig->setting_lookup_string(arena, "delay_var", &aDelayVar) ) { ShowError("bg_config_read: failed to find 'delay_var' for arena '%s'/#%d\n",aName,i); continue; } - config_setting_lookup_int(arena, "maxDuration", &maxDuration); + libconfig->setting_lookup_int(arena, "maxDuration", &maxDuration); if( maxDuration < 0 ) { ShowWarning("bg_config_read: invalid %d value for arena '%s' maxDuration\n",maxDuration,aName); maxDuration = 30; } - config_setting_lookup_int(arena, "fillDuration", &fillup_duration); - config_setting_lookup_int(arena, "pGameDuration", &pregame_duration); + libconfig->setting_lookup_int(arena, "fillDuration", &fillup_duration); + libconfig->setting_lookup_int(arena, "pGameDuration", &pregame_duration); if( fillup_duration < 20 ) { ShowWarning("bg_config_read: invalid %d value for arena '%s' fillDuration, minimum has to be 20, defaulting to 20.\n",fillup_duration,aName); @@ -408,7 +408,7 @@ void bg_config_read(void) { bg->arenas = arena_count; } - config_destroy(&bg_conf); + libconfig->destroy(&bg_conf); } } struct bg_arena *bg_name2arena (char *name) { diff --git a/src/map/clif.c b/src/map/clif.c index 7157914df..af328e7a7 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -2624,13 +2624,13 @@ void read_channels_config(void) { config_setting_t *chsys = NULL; const char *config_filename = "conf/channels.conf"; // FIXME hardcoded name - if (conf_read_file(&channels_conf, config_filename)) + if (libconfig->read_file(&channels_conf, config_filename)) return; - chsys = config_lookup(&channels_conf, "chsys"); + chsys = libconfig->lookup(&channels_conf, "chsys"); if (chsys != NULL) { - config_setting_t *settings = config_setting_get_elem(chsys, 0); + config_setting_t *settings = libconfig->setting_get_elem(chsys, 0); config_setting_t *channels; config_setting_t *colors; int i,k; @@ -2642,21 +2642,21 @@ void read_channels_config(void) { allow_user_channel_creation = 0, irc_enabled = 0; - if( !config_setting_lookup_string(settings, "map_local_channel_name", &local_name) ) + if( !libconfig->setting_lookup_string(settings, "map_local_channel_name", &local_name) ) local_name = "map"; safestrncpy(hChSys.local_name, local_name, HCHSYS_NAME_LENGTH); - if( !config_setting_lookup_string(settings, "ally_channel_name", &ally_name) ) + if( !libconfig->setting_lookup_string(settings, "ally_channel_name", &ally_name) ) ally_name = "ally"; safestrncpy(hChSys.ally_name, ally_name, HCHSYS_NAME_LENGTH); - if( !config_setting_lookup_string(settings, "irc_channel_name", &irc_name) ) + if( !libconfig->setting_lookup_string(settings, "irc_channel_name", &irc_name) ) irc_name = "irc"; safestrncpy(hChSys.irc_name, irc_name, HCHSYS_NAME_LENGTH); - config_setting_lookup_bool(settings, "map_local_channel", &local_enabled); - config_setting_lookup_bool(settings, "ally_channel_enabled", &ally_enabled); - config_setting_lookup_bool(settings, "irc_channel_enabled", &irc_enabled); + libconfig->setting_lookup_bool(settings, "map_local_channel", &local_enabled); + libconfig->setting_lookup_bool(settings, "ally_channel_enabled", &ally_enabled); + libconfig->setting_lookup_bool(settings, "irc_channel_enabled", &irc_enabled); if( local_enabled ) hChSys.local = true; @@ -2671,7 +2671,7 @@ void read_channels_config(void) { const char *irc_server, *irc_channel, *irc_nick, *irc_nick_pw; int irc_use_ghost = 0; - if( config_setting_lookup_string(settings, "irc_channel_network", &irc_server) ) { + if( libconfig->setting_lookup_string(settings, "irc_channel_network", &irc_server) ) { if( !strstr(irc_server,":") ) { hChSys.irc = false; ShowWarning("channels.conf : network port wasn't found in 'irc_channel_network', disabling irc channel...\n"); @@ -2695,13 +2695,13 @@ void read_channels_config(void) { hChSys.irc = false; ShowWarning("channels.conf : irc channel enabled but irc_channel_network wasn't found, disabling irc channel...\n"); } - if( config_setting_lookup_string(settings, "irc_channel_channel", &irc_channel) ) + if( libconfig->setting_lookup_string(settings, "irc_channel_channel", &irc_channel) ) safestrncpy(hChSys.irc_channel, irc_channel, 50); else { hChSys.irc = false; ShowWarning("channels.conf : irc channel enabled but irc_channel_channel wasn't found, disabling irc channel...\n"); } - if( config_setting_lookup_string(settings, "irc_channel_nick", &irc_nick) ) { + if( libconfig->setting_lookup_string(settings, "irc_channel_nick", &irc_nick) ) { if( strcmpi(irc_nick,"Hercules_chSysBot") == 0 ) { sprintf(hChSys.irc_nick, "Hercules_chSysBot%d",rand()%777); } else @@ -2710,7 +2710,7 @@ void read_channels_config(void) { hChSys.irc = false; ShowWarning("channels.conf : irc channel enabled but irc_channel_nick wasn't found, disabling irc channel...\n"); } - if( config_setting_lookup_string(settings, "irc_channel_nick_pw", &irc_nick_pw) ) { + if( libconfig->setting_lookup_string(settings, "irc_channel_nick_pw", &irc_nick_pw) ) { safestrncpy(hChSys.irc_nick_pw, irc_nick_pw, 30); config_setting_lookup_bool(settings, "irc_channel_use_ghost", &irc_use_ghost); hChSys.irc_use_ghost = irc_use_ghost; @@ -2718,37 +2718,37 @@ void read_channels_config(void) { } - config_setting_lookup_bool(settings, "map_local_channel_autojoin", &local_autojoin); - config_setting_lookup_bool(settings, "ally_channel_autojoin", &ally_autojoin); + libconfig->setting_lookup_bool(settings, "map_local_channel_autojoin", &local_autojoin); + libconfig->setting_lookup_bool(settings, "ally_channel_autojoin", &ally_autojoin); if( local_autojoin ) hChSys.local_autojoin = true; if( ally_autojoin ) hChSys.ally_autojoin = true; - config_setting_lookup_bool(settings, "allow_user_channel_creation", &allow_user_channel_creation); + libconfig->setting_lookup_bool(settings, "allow_user_channel_creation", &allow_user_channel_creation); if( allow_user_channel_creation ) hChSys.allow_user_channel_creation = true; - if( (colors = config_setting_get_member(settings, "colors")) != NULL ) { - int color_count = config_setting_length(colors); + if( (colors = libconfig->setting_get_member(settings, "colors")) != NULL ) { + int color_count = libconfig->setting_length(colors); CREATE( hChSys.colors, unsigned int, color_count ); CREATE( hChSys.colors_name, char *, color_count ); for(i = 0; i < color_count; i++) { - config_setting_t *color = config_setting_get_elem(colors, i); + config_setting_t *color = libconfig->setting_get_elem(colors, i); CREATE( hChSys.colors_name[i], char, HCHSYS_NAME_LENGTH ); safestrncpy(hChSys.colors_name[i], config_setting_name(color), HCHSYS_NAME_LENGTH); - hChSys.colors[i] = (unsigned int)strtoul(config_setting_get_string_elem(colors,i),NULL,0); + hChSys.colors[i] = (unsigned int)strtoul(libconfig->setting_get_string_elem(colors,i),NULL,0); hChSys.colors[i] = (hChSys.colors[i] & 0x0000FF) << 16 | (hChSys.colors[i] & 0x00FF00) | (hChSys.colors[i] & 0xFF0000) >> 16;//RGB to BGR } hChSys.colors_count = color_count; } - config_setting_lookup_string(settings, "map_local_channel_color", &local_color); + libconfig->setting_lookup_string(settings, "map_local_channel_color", &local_color); for (k = 0; k < hChSys.colors_count; k++) { if( strcmpi(hChSys.colors_name[k],local_color) == 0 ) @@ -2762,7 +2762,7 @@ void read_channels_config(void) { hChSys.local = false; } - config_setting_lookup_string(settings, "ally_channel_color", &ally_color); + libconfig->setting_lookup_string(settings, "ally_channel_color", &ally_color); for (k = 0; k < hChSys.colors_count; k++) { if( strcmpi(hChSys.colors_name[k],ally_color) == 0 ) @@ -2776,7 +2776,7 @@ void read_channels_config(void) { hChSys.ally = false; } - config_setting_lookup_string(settings, "irc_channel_color", &irc_color); + libconfig->setting_lookup_string(settings, "irc_channel_color", &irc_color); for (k = 0; k < hChSys.colors_count; k++) { if( strcmpi(hChSys.colors_name[k],irc_color) == 0 ) @@ -2801,13 +2801,13 @@ void read_channels_config(void) { ircbot->channel = chd; } - if( (channels = config_setting_get_member(settings, "default_channels")) != NULL ) { - int channel_count = config_setting_length(channels); + if( (channels = libconfig->setting_get_member(settings, "default_channels")) != NULL ) { + int channel_count = libconfig->setting_length(channels); for(i = 0; i < channel_count; i++) { - config_setting_t *channel = config_setting_get_elem(channels, i); + config_setting_t *channel = libconfig->setting_get_elem(channels, i); const char *name = config_setting_name(channel); - const char *color = config_setting_get_string_elem(channels,i); + const char *color = libconfig->setting_get_string_elem(channels,i); struct hChSysCh *chd; for (k = 0; k < hChSys.colors_count; k++) { @@ -2833,7 +2833,7 @@ void read_channels_config(void) { } ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' channels in '"CL_WHITE"%s"CL_RESET"'.\n", db_size(clif->channel_db), config_filename); - config_destroy(&channels_conf); + libconfig->destroy(&channels_conf); } } @@ -17378,32 +17378,33 @@ void clif_cashshop_db(void) { config_setting_t *cashshop = NULL, *cats = NULL; const char *config_filename = "db/cashshop_db.conf"; // FIXME hardcoded name int i, item_count_t = 0; + for( i = 0; i < CASHSHOP_TAB_MAX; i++ ) { CREATE(clif->cs.data[i], struct hCSData *, 1); clif->cs.item_count[i] = 0; } - if (conf_read_file(&cashshop_conf, config_filename)) { + if (libconfig->read_file(&cashshop_conf, config_filename)) { ShowError("can't read %s\n", config_filename); return; } - cashshop = config_lookup(&cashshop_conf, "cash_shop"); + cashshop = libconfig->lookup(&cashshop_conf, "cash_shop"); - if( cashshop != NULL && (cats = config_setting_get_elem(cashshop, 0)) != NULL ) { + if( cashshop != NULL && (cats = libconfig->setting_get_elem(cashshop, 0)) != NULL ) { for(i = 0; i < CASHSHOP_TAB_MAX; i++) { config_setting_t *cat; char entry_name[10]; sprintf(entry_name,"cat_%d",i); - if( (cat = config_setting_get_member(cats, entry_name)) != NULL ) { - int k, item_count = config_setting_length(cat); + if( (cat = libconfig->setting_get_member(cats, entry_name)) != NULL ) { + int k, item_count = libconfig->setting_length(cat); for(k = 0; k < item_count; k++) { - config_setting_t *entry = config_setting_get_elem(cat,k); + config_setting_t *entry = libconfig->setting_get_elem(cat,k); const char *name = config_setting_name(entry); - int price = config_setting_get_int(entry); + int price = libconfig->setting_get_int(entry); struct item_data * data = NULL; if( price < 1 ) { @@ -17434,7 +17435,7 @@ void clif_cashshop_db(void) { } } - config_destroy(&cashshop_conf); + libconfig->destroy(&cashshop_conf); } ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", item_count_t, config_filename); } diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 3bed3e03d..6db503214 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -642,18 +642,18 @@ void itemdb_read_groups(void) { int i = 0, count = 0, c; unsigned int *gsize = NULL; - if (conf_read_file(&item_group_conf, config_filename)) { + if (libconfig->read_file(&item_group_conf, config_filename)) { ShowError("can't read %s\n", config_filename); return; } - gsize = aMalloc( config_setting_length(item_group_conf.root) * sizeof(unsigned int) ); + gsize = aMalloc( libconfig->setting_length(item_group_conf.root) * sizeof(unsigned int) ); - for(i = 0; i < config_setting_length(item_group_conf.root); i++) + for(i = 0; i < libconfig->setting_length(item_group_conf.root); i++) gsize[i] = 0; i = 0; - while( (itg = config_setting_get_elem(item_group_conf.root,i++)) ) { + while( (itg = libconfig->setting_get_elem(item_group_conf.root,i++)) ) { const char *name = config_setting_name(itg); if( !itemdb->name2id(name) ) { @@ -664,9 +664,9 @@ void itemdb_read_groups(void) { } c = 0; - while( (it = config_setting_get_elem(itg,c++)) ) { + while( (it = libconfig->setting_get_elem(itg,c++)) ) { if( config_setting_is_list(it) ) - gsize[ i - 1 ] += config_setting_get_int_elem(it,1); + gsize[ i - 1 ] += libconfig->setting_get_int_elem(it,1); else gsize[ i - 1 ] += 1; } @@ -674,10 +674,10 @@ void itemdb_read_groups(void) { } i = 0; - CREATE(itemdb->groups, struct item_group, config_setting_length(item_group_conf.root)); - itemdb->group_count = (unsigned short)config_setting_length(item_group_conf.root); + CREATE(itemdb->groups, struct item_group, libconfig->setting_length(item_group_conf.root)); + itemdb->group_count = (unsigned short)libconfig->setting_length(item_group_conf.root); - while( (itg = config_setting_get_elem(item_group_conf.root,i++)) ) { + while( (itg = libconfig->setting_get_elem(item_group_conf.root,i++)) ) { struct item_data *data = itemdb->name2id(config_setting_name(itg)); int ecount = 0; @@ -688,13 +688,13 @@ void itemdb_read_groups(void) { CREATE(itemdb->groups[count].nameid, unsigned short, gsize[ count ] + 1); c = 0; - while( (it = config_setting_get_elem(itg,c++)) ) { + while( (it = libconfig->setting_get_elem(itg,c++)) ) { int repeat = 1; if( config_setting_is_list(it) ) { - itname = config_setting_get_string_elem(it,0); - repeat = config_setting_get_int_elem(it,1); + itname = libconfig->setting_get_string_elem(it,0); + repeat = libconfig->setting_get_int_elem(it,1); } else - itname = config_setting_get_string_elem(itg,c - 1); + itname = libconfig->setting_get_string_elem(itg,c - 1); if( itname[0] == 'I' && itname[1] == 'D' && strlen(itname) < 8 ) { if( !( data = itemdb->exists(atoi(itname+2)) ) ) @@ -716,7 +716,7 @@ void itemdb_read_groups(void) { count++; } - config_destroy(&item_group_conf); + libconfig->destroy(&item_group_conf); aFree(gsize); ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, config_filename); @@ -934,18 +934,18 @@ void itemdb_read_packages(void) { return; } - if (conf_read_file(&item_packages_conf, config_filename)) { + if (libconfig->read_file(&item_packages_conf, config_filename)) { ShowError("can't read %s\n", config_filename); return; } - must = aMalloc( config_setting_length(item_packages_conf.root) * sizeof(unsigned int) ); - random = aMalloc( config_setting_length(item_packages_conf.root) * sizeof(unsigned int) ); - rgroup = aMalloc( config_setting_length(item_packages_conf.root) * sizeof(unsigned int) ); - rgroups = aMalloc( config_setting_length(item_packages_conf.root) * sizeof(unsigned int *) ); + must = aMalloc( libconfig->setting_length(item_packages_conf.root) * sizeof(unsigned int) ); + random = aMalloc( libconfig->setting_length(item_packages_conf.root) * sizeof(unsigned int) ); + rgroup = aMalloc( libconfig->setting_length(item_packages_conf.root) * sizeof(unsigned int) ); + rgroups = aMalloc( libconfig->setting_length(item_packages_conf.root) * sizeof(unsigned int *) ); - for(i = 0; i < config_setting_length(item_packages_conf.root); i++) { + for(i = 0; i < libconfig->setting_length(item_packages_conf.root); i++) { must[i] = 0; random[i] = 0; rgroup[i] = 0; @@ -954,22 +954,22 @@ void itemdb_read_packages(void) { /* validate tree, drop poisonous fruits! */ i = 0; - while( (itg = config_setting_get_elem(item_packages_conf.root,i++)) ) { + while( (itg = libconfig->setting_get_elem(item_packages_conf.root,i++)) ) { const char *name = config_setting_name(itg); if( !itemdb->name2id(name) ) { ShowWarning("itemdb_read_packages: unknown package item '%s', skipping..\n",name); - config_setting_remove(item_packages_conf.root, name); + libconfig->setting_remove(item_packages_conf.root, name); --i; continue; } c = 0; - while( (it = config_setting_get_elem(itg,c++)) ) { + while( (it = libconfig->setting_get_elem(itg,c++)) ) { int rval = 0; - if( !( t = config_setting_get_member(it, "Random") ) || (rval = config_setting_get_int(t)) < 0 ) { + if( !( t = libconfig->setting_get_member(it, "Random") ) || (rval = libconfig->setting_get_int(t)) < 0 ) { ShowWarning("itemdb_read_packages: invalid 'Random' value (%d) for item '%s' in package '%s', defaulting to must!\n",rval,config_setting_name(it),name); - config_setting_remove(it, config_setting_name(it)); + libconfig->setting_remove(it, config_setting_name(it)); --c; continue; } @@ -991,7 +991,7 @@ void itemdb_read_packages(void) { prev[i] = NULL; } - for(i = 0; i < config_setting_length(item_packages_conf.root); i++ ) { + for(i = 0; i < libconfig->setting_length(item_packages_conf.root); i++ ) { rgroups[i] = aMalloc( rgroup[i] * sizeof(unsigned int) ); for( c = 0; c < rgroup[i]; c++ ) { rgroups[i][c] = 0; @@ -1000,22 +1000,22 @@ void itemdb_read_packages(void) { /* grab the known sizes */ i = 0; - while( (itg = config_setting_get_elem(item_packages_conf.root,i++)) ) { + while( (itg = libconfig->setting_get_elem(item_packages_conf.root,i++)) ) { c = 0; - while( (it = config_setting_get_elem(itg,c++)) ) { + while( (it = libconfig->setting_get_elem(itg,c++)) ) { int rval = 0; - if( ( t = config_setting_get_member(it, "Random")) && ( rval = config_setting_get_int(t) ) > 0 ) { + if( ( t = libconfig->setting_get_member(it, "Random")) && ( rval = libconfig->setting_get_int(t) ) > 0 ) { rgroups[i - 1][rval - 1] += 1; } } } - CREATE(itemdb->packages, struct item_package, config_setting_length(item_packages_conf.root)); - itemdb->package_count = (unsigned short)config_setting_length(item_packages_conf.root); + CREATE(itemdb->packages, struct item_package, libconfig->setting_length(item_packages_conf.root)); + itemdb->package_count = (unsigned short)libconfig->setting_length(item_packages_conf.root); /* write */ i = 0; - while( (itg = config_setting_get_elem(item_packages_conf.root,i++)) ) { + while( (itg = libconfig->setting_get_elem(item_packages_conf.root,i++)) ) { struct item_data *data = itemdb->name2id(config_setting_name(itg)); int r = 0, m = 0; @@ -1045,7 +1045,7 @@ void itemdb_read_packages(void) { CREATE(itemdb->packages[count].must_items, struct item_package_must_entry, itemdb->packages[count].must_qty); c = 0; - while( (it = config_setting_get_elem(itg,c++)) ) { + while( (it = libconfig->setting_get_elem(itg,c++)) ) { int icount = 1, expire = 0, rate = 10000, gid = 0; bool announce = false, named = false; @@ -1057,30 +1057,30 @@ void itemdb_read_packages(void) { } else if( !( data = itemdb->name2id(itname) ) ) ShowWarning("itemdb_read_packages: unknown item '%s' in package '%s'!\n",itname,config_setting_name(itg)); - if( ( t = config_setting_get_member(it, "Count")) ) - icount = config_setting_get_int(t); + if( ( t = libconfig->setting_get_member(it, "Count")) ) + icount = libconfig->setting_get_int(t); - if( ( t = config_setting_get_member(it, "Expire")) ) - expire = config_setting_get_int(t); + if( ( t = libconfig->setting_get_member(it, "Expire")) ) + expire = libconfig->setting_get_int(t); - if( ( t = config_setting_get_member(it, "Rate")) ) { - if( (rate = (unsigned short)config_setting_get_int(t)) > 10000 ) { + if( ( t = libconfig->setting_get_member(it, "Rate")) ) { + if( (rate = (unsigned short)libconfig->setting_get_int(t)) > 10000 ) { ShowWarning("itemdb_read_packages: invalid rate (%d) for item '%s' in package '%s'!\n",rate,itname,config_setting_name(itg)); rate = 10000; } } - if( ( t = config_setting_get_member(it, "Announce")) && config_setting_get_bool(t) ) + if( ( t = libconfig->setting_get_member(it, "Announce")) && libconfig->setting_get_bool(t) ) announce = true; - if( ( t = config_setting_get_member(it, "Named")) && config_setting_get_bool(t) ) + if( ( t = libconfig->setting_get_member(it, "Named")) && libconfig->setting_get_bool(t) ) named = true; - if( !( t = config_setting_get_member(it, "Random") ) ) { + if( !( t = libconfig->setting_get_member(it, "Random") ) ) { ShowWarning("itemdb_read_packages: missing 'Random' field for item '%s' in package '%s', defaulting to must!\n",itname,config_setting_name(itg)); gid = 0; } else - gid = config_setting_get_int(t); + gid = libconfig->setting_get_int(t); if( gid == 0 ) { itemdb->packages[count].must_items[m].id = data ? data->nameid : 0; @@ -1131,14 +1131,14 @@ void itemdb_read_packages(void) { aFree(must); aFree(random); - for(i = 0; i < config_setting_length(item_packages_conf.root); i++ ) { + for(i = 0; i < libconfig->setting_length(item_packages_conf.root); i++ ) { aFree(rgroups[i]); } aFree(rgroups); aFree(rgroup); aFree(prev); - config_destroy(&item_packages_conf); + libconfig->destroy(&item_packages_conf); if( HCache->enabled ) itemdb->write_cached_packages(config_filename); @@ -1156,26 +1156,26 @@ void itemdb_read_chains(void) { #endif int i = 0, count = 0; - if (conf_read_file(&item_chain_conf, config_filename)) { + if (libconfig->read_file(&item_chain_conf, config_filename)) { ShowError("can't read %s\n", config_filename); return; } - CREATE(itemdb->chains, struct item_chain, config_setting_length(item_chain_conf.root)); - itemdb->chain_count = (unsigned short)config_setting_length(item_chain_conf.root); + CREATE(itemdb->chains, struct item_chain, libconfig->setting_length(item_chain_conf.root)); + itemdb->chain_count = (unsigned short)libconfig->setting_length(item_chain_conf.root); - while( (itc = config_setting_get_elem(item_chain_conf.root,i++)) ) { + while( (itc = libconfig->setting_get_elem(item_chain_conf.root,i++)) ) { struct item_data *data = NULL; struct item_chain_entry *prev = NULL; const char *name = config_setting_name(itc); int c = 0; script->set_constant2(name,i-1,0); - itemdb->chains[count].qty = (unsigned short)config_setting_length(itc); + itemdb->chains[count].qty = (unsigned short)libconfig->setting_length(itc); - CREATE(itemdb->chains[count].items, struct item_chain_entry, config_setting_length(itc)); + CREATE(itemdb->chains[count].items, struct item_chain_entry, libconfig->setting_length(itc)); - while( (entry = config_setting_get_elem(itc,c++)) ) { + while( (entry = libconfig->setting_get_elem(itc,c++)) ) { const char *itname = config_setting_name(entry); if( itname[0] == 'I' && itname[1] == 'D' && strlen(itname) < 8 ) { if( !( data = itemdb->exists(atoi(itname+2)) ) ) @@ -1187,7 +1187,7 @@ void itemdb_read_chains(void) { prev->next = &itemdb->chains[count].items[c - 1]; itemdb->chains[count].items[c - 1].id = data ? data->nameid : 0; - itemdb->chains[count].items[c - 1].rate = data ? config_setting_get_int(entry) : 0; + itemdb->chains[count].items[c - 1].rate = data ? libconfig->setting_get_int(entry) : 0; prev = &itemdb->chains[count].items[c - 1]; } @@ -1198,7 +1198,7 @@ void itemdb_read_chains(void) { count++; } - config_destroy(&item_chain_conf); + libconfig->destroy(&item_chain_conf); if( !script->get_constant("ITMCHAIN_ORE",&i) ) ShowWarning("itemdb_read_chains: failed to find 'ITMCHAIN_ORE' chain to link to cache!\n"); @@ -1781,13 +1781,13 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source) * OnUnequipScript: <" OnUnequip Script "> * Inherit: inherit or override */ - if( !config_setting_lookup_int(it, "Id", &i32) ) { + if( !libconfig->setting_lookup_int(it, "Id", &i32) ) { ShowWarning("itemdb_readdb_libconfig_sub: Invalid or missing id in \"%s\", entry #%d, skipping.\n", source, n); return 0; } id.nameid = (uint16)i32; - if( (t = config_setting_get_member(it, "Inherit")) && (inherit = config_setting_get_bool(t)) ) { + if( (t = libconfig->setting_get_member(it, "Inherit")) && (inherit = libconfig->setting_get_bool(t)) ) { if( !itemdb->exists(id.nameid) ) { ShowWarning("itemdb_readdb_libconfig_sub: Trying to inherit nonexistent item %d, default values will be used instead.\n", id.nameid); inherit = false; @@ -1798,7 +1798,7 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source) } } - if( !config_setting_lookup_string(it, "AegisName", &str) || !*str ) { + if( !libconfig->setting_lookup_string(it, "AegisName", &str) || !*str ) { if( !inherit ) { ShowWarning("itemdb_readdb_libconfig_sub: Missing AegisName in item %d of \"%s\", skipping.\n", id.nameid, source); return 0; @@ -1807,7 +1807,7 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source) safestrncpy(id.name, str, sizeof(id.name)); } - if( !config_setting_lookup_string(it, "Name", &str) || !*str ) { + if( !libconfig->setting_lookup_string(it, "Name", &str) || !*str ) { if( !inherit ) { ShowWarning("itemdb_readdb_libconfig_sub: Missing Name in item %d of \"%s\", skipping.\n", id.nameid, source); return 0; @@ -1816,86 +1816,86 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source) safestrncpy(id.jname, str, sizeof(id.jname)); } - if( config_setting_lookup_int(it, "Type", &i32) ) + if( libconfig->setting_lookup_int(it, "Type", &i32) ) id.type = i32; else if( !inherit ) id.type = IT_UNKNOWN; - if( config_setting_lookup_int(it, "Buy", &i32) ) + if( libconfig->setting_lookup_int(it, "Buy", &i32) ) id.value_buy = i32; else if( !inherit ) id.value_buy = -1; - if( config_setting_lookup_int(it, "Sell", &i32) ) + if( libconfig->setting_lookup_int(it, "Sell", &i32) ) id.value_sell = i32; else if( !inherit ) id.value_sell = -1; - if( config_setting_lookup_int(it, "Weight", &i32) && i32 >= 0 ) + if( libconfig->setting_lookup_int(it, "Weight", &i32) && i32 >= 0 ) id.weight = i32; - if( config_setting_lookup_int(it, "Atk", &i32) && i32 >= 0 ) + if( libconfig->setting_lookup_int(it, "Atk", &i32) && i32 >= 0 ) id.atk = i32; - if( config_setting_lookup_int(it, "Matk", &i32) && i32 >= 0 ) + if( libconfig->setting_lookup_int(it, "Matk", &i32) && i32 >= 0 ) id.matk = i32; - if( config_setting_lookup_int(it, "Def", &i32) && i32 >= 0 ) + if( libconfig->setting_lookup_int(it, "Def", &i32) && i32 >= 0 ) id.def = i32; - if( config_setting_lookup_int(it, "Range", &i32) && i32 >= 0 ) + if( libconfig->setting_lookup_int(it, "Range", &i32) && i32 >= 0 ) id.range = i32; - if( config_setting_lookup_int(it, "Slots", &i32) && i32 >= 0 ) + if( libconfig->setting_lookup_int(it, "Slots", &i32) && i32 >= 0 ) id.slot = i32; - if( config_setting_lookup_int(it, "Job", &i32) ) // This is an unsigned value, do not check for >= 0 + if( libconfig->setting_lookup_int(it, "Job", &i32) ) // This is an unsigned value, do not check for >= 0 itemdb->jobid2mapid(id.class_base, (unsigned int)i32); else if( !inherit ) itemdb->jobid2mapid(id.class_base, UINT_MAX); - if( config_setting_lookup_int(it, "Upper", &i32) && i32 >= 0 ) + if( libconfig->setting_lookup_int(it, "Upper", &i32) && i32 >= 0 ) id.class_upper = (unsigned int)i32; else if( !inherit ) id.class_upper = ITEMUPPER_ALL; - if( config_setting_lookup_int(it, "Gender", &i32) && i32 >= 0 ) + if( libconfig->setting_lookup_int(it, "Gender", &i32) && i32 >= 0 ) id.sex = i32; else if( !inherit ) id.sex = 2; - if( config_setting_lookup_int(it, "Loc", &i32) && i32 >= 0 ) + if( libconfig->setting_lookup_int(it, "Loc", &i32) && i32 >= 0 ) id.equip = i32; - if( config_setting_lookup_int(it, "WeaponLv", &i32) && i32 >= 0 ) + if( libconfig->setting_lookup_int(it, "WeaponLv", &i32) && i32 >= 0 ) id.wlv = i32; - if( (t = config_setting_get_member(it, "EquipLv")) ) { + if( (t = libconfig->setting_get_member(it, "EquipLv")) ) { if( config_setting_is_aggregate(t) ) { - if( config_setting_length(t) >= 2 ) - id.elvmax = config_setting_get_int_elem(t, 1); - if( config_setting_length(t) >= 1 ) - id.elv = config_setting_get_int_elem(t, 0); + if( libconfig->setting_length(t) >= 2 ) + id.elvmax = libconfig->setting_get_int_elem(t, 1); + if( libconfig->setting_length(t) >= 1 ) + id.elv = libconfig->setting_get_int_elem(t, 0); } else { - id.elv = config_setting_get_int(t); + id.elv = libconfig->setting_get_int(t); } } - if( (t = config_setting_get_member(it, "Refine")) ) - id.flag.no_refine = config_setting_get_bool(t) ? 0 : 1; + if( (t = libconfig->setting_get_member(it, "Refine")) ) + id.flag.no_refine = libconfig->setting_get_bool(t) ? 0 : 1; - if( config_setting_lookup_int(it, "View", &i32) && i32 >= 0 ) + if( libconfig->setting_lookup_int(it, "View", &i32) && i32 >= 0 ) id.look = i32; - if( (t = config_setting_get_member(it, "BindOnEquip")) ) - id.flag.bindonequip = config_setting_get_bool(t) ? 1 : 0; + if( (t = libconfig->setting_get_member(it, "BindOnEquip")) ) + id.flag.bindonequip = libconfig->setting_get_bool(t) ? 1 : 0; - if( config_setting_lookup_string(it, "Script", &str) ) + if( libconfig->setting_lookup_string(it, "Script", &str) ) id.script = *str ? script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS) : NULL; - if( config_setting_lookup_string(it, "OnEquipScript", &str) ) + if( libconfig->setting_lookup_string(it, "OnEquipScript", &str) ) id.equip_script = *str ? script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS) : NULL; - if( config_setting_lookup_string(it, "OnUnequipScript", &str) ) + if( libconfig->setting_lookup_string(it, "OnUnequipScript", &str) ) id.unequip_script = *str ? script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS) : NULL; return itemdb->validate_entry(&id, n, source); @@ -1917,12 +1917,12 @@ int itemdb_readdb_libconfig(const char *filename) { sprintf(filepath, "%s/%s", map->db_path, filename); memset(&duplicate,0,sizeof(duplicate)); - if( conf_read_file(&item_db_conf, filepath) || !(itdb = config_setting_get_member(item_db_conf.root, "item_db")) ) { + if( libconfig->read_file(&item_db_conf, filepath) || !(itdb = libconfig->setting_get_member(item_db_conf.root, "item_db")) ) { ShowError("can't read %s\n", filepath); return 0; } - while( (it = config_setting_get_elem(itdb,i++)) ) { + while( (it = libconfig->setting_get_elem(itdb,i++)) ) { int nameid = itemdb->readdb_libconfig_sub(it, i-1, filename); if( !nameid ) @@ -1936,7 +1936,7 @@ int itemdb_readdb_libconfig(const char *filename) { } else duplicate[nameid] = true; } - config_destroy(&item_db_conf); + libconfig->destroy(&item_db_conf); ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filename); return count; diff --git a/src/map/map.c b/src/map/map.c index 5344d11bf..052d589b4 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -4577,10 +4577,10 @@ void read_map_zone_db(void) { #else const char *config_filename = "db/pre-re/map_zone_db.conf"; // FIXME hardcoded name #endif - if (conf_read_file(&map_zone_db, config_filename)) + if (libconfig->read_file(&map_zone_db, config_filename)) return; - zones = config_lookup(&map_zone_db, "zones"); + zones = libconfig->lookup(&map_zone_db, "zones"); if (zones != NULL) { struct map_zone_data *zone; @@ -4597,16 +4597,16 @@ void read_map_zone_db(void) { disabled_commands_count = 0, capped_skills_count = 0; enum map_zone_skill_subtype subtype; - zone_count = config_setting_length(zones); + zone_count = libconfig->setting_length(zones); for (i = 0; i < zone_count; ++i) { bool is_all = false; - zone_e = config_setting_get_elem(zones, i); + zone_e = libconfig->setting_get_elem(zones, i); - if (!config_setting_lookup_string(zone_e, "name", &zonename)) { + if (!libconfig->setting_lookup_string(zone_e, "name", &zonename)) { ShowError("map_zone_db: missing zone name, skipping... (%s:%d)\n", config_setting_source_file(zone_e), config_setting_source_line(zone_e)); - config_setting_remove_elem(zones,i);/* remove from the tree */ + libconfig->setting_remove_elem(zones,i);/* remove from the tree */ --zone_count; --i; continue; @@ -4614,7 +4614,7 @@ void read_map_zone_db(void) { if( strdb_exists(map->zone_db, zonename) ) { ShowError("map_zone_db: duplicate zone name '%s', skipping...\n",zonename); - config_setting_remove_elem(zones,i);/* remove from the tree */ + libconfig->setting_remove_elem(zones,i);/* remove from the tree */ --zone_count; --i; continue; @@ -4634,31 +4634,31 @@ void read_map_zone_db(void) { } safestrncpy(zone->name, zonename, MAP_ZONE_NAME_LENGTH); - if( (skills = config_setting_get_member(zone_e, "disabled_skills")) != NULL ) { - disabled_skills_count = config_setting_length(skills); + if( (skills = libconfig->setting_get_member(zone_e, "disabled_skills")) != NULL ) { + disabled_skills_count = libconfig->setting_length(skills); /* validate */ - for(h = 0; h < config_setting_length(skills); h++) { - config_setting_t *skillinfo = config_setting_get_elem(skills, h); + for(h = 0; h < libconfig->setting_length(skills); h++) { + config_setting_t *skillinfo = libconfig->setting_get_elem(skills, h); name = config_setting_name(skillinfo); if( !map->zone_str2skillid(name) ) { ShowError("map_zone_db: unknown skill (%s) in disabled_skills for zone '%s', skipping skill...\n",name,zone->name); - config_setting_remove_elem(skills,h); + libconfig->setting_remove_elem(skills,h); --disabled_skills_count; --h; continue; } - if( !map->zone_bl_type(config_setting_get_string_elem(skills,h),&subtype) )/* we dont remove it from the three due to inheritance */ + if( !map->zone_bl_type(libconfig->setting_get_string_elem(skills,h),&subtype) )/* we dont remove it from the three due to inheritance */ --disabled_skills_count; } /* all ok, process */ CREATE( zone->disabled_skills, struct map_zone_disabled_skill_entry *, disabled_skills_count ); - for(h = 0, v = 0; h < config_setting_length(skills); h++) { - config_setting_t *skillinfo = config_setting_get_elem(skills, h); + for(h = 0, v = 0; h < libconfig->setting_length(skills); h++) { + config_setting_t *skillinfo = libconfig->setting_get_elem(skills, h); struct map_zone_disabled_skill_entry * entry; enum bl_type type; name = config_setting_name(skillinfo); - if( (type = map->zone_bl_type(config_setting_get_string_elem(skills,h),&subtype)) ) { /* only add if enabled */ + if( (type = map->zone_bl_type(libconfig->setting_get_string_elem(skills,h),&subtype)) ) { /* only add if enabled */ CREATE( entry, struct map_zone_disabled_skill_entry, 1 ); entry->nameid = map->zone_str2skillid(name); @@ -4672,28 +4672,28 @@ void read_map_zone_db(void) { zone->disabled_skills_count = disabled_skills_count; } - if( (items = config_setting_get_member(zone_e, "disabled_items")) != NULL ) { - disabled_items_count = config_setting_length(items); + if( (items = libconfig->setting_get_member(zone_e, "disabled_items")) != NULL ) { + disabled_items_count = libconfig->setting_length(items); /* validate */ - for(h = 0; h < config_setting_length(items); h++) { - config_setting_t *item = config_setting_get_elem(items, h); + for(h = 0; h < libconfig->setting_length(items); h++) { + config_setting_t *item = libconfig->setting_get_elem(items, h); name = config_setting_name(item); if( !map->zone_str2itemid(name) ) { ShowError("map_zone_db: unknown item (%s) in disabled_items for zone '%s', skipping item...\n",name,zone->name); - config_setting_remove_elem(items,h); + libconfig->setting_remove_elem(items,h); --disabled_items_count; --h; continue; } - if( !config_setting_get_bool(item) )/* we dont remove it from the three due to inheritance */ + if( !libconfig->setting_get_bool(item) )/* we dont remove it from the three due to inheritance */ --disabled_items_count; } /* all ok, process */ CREATE( zone->disabled_items, int, disabled_items_count ); - for(h = 0, v = 0; h < config_setting_length(items); h++) { - config_setting_t *item = config_setting_get_elem(items, h); + for(h = 0, v = 0; h < libconfig->setting_length(items); h++) { + config_setting_t *item = libconfig->setting_get_elem(items, h); - if( config_setting_get_bool(item) ) { /* only add if enabled */ + if( libconfig->setting_get_bool(item) ) { /* only add if enabled */ name = config_setting_name(item); zone->disabled_items[v++] = map->zone_str2itemid(name); } @@ -4702,14 +4702,14 @@ void read_map_zone_db(void) { zone->disabled_items_count = disabled_items_count; } - if( (mapflags = config_setting_get_member(zone_e, "mapflags")) != NULL ) { - mapflags_count = config_setting_length(mapflags); + if( (mapflags = libconfig->setting_get_member(zone_e, "mapflags")) != NULL ) { + mapflags_count = libconfig->setting_length(mapflags); /* mapflags are not validated here, so we save all anyway */ CREATE( zone->mapflags, char *, mapflags_count ); for(h = 0; h < mapflags_count; h++) { CREATE( zone->mapflags[h], char, MAP_ZONE_MAPFLAG_LENGTH ); - name = config_setting_get_string_elem(mapflags, h); + name = libconfig->setting_get_string_elem(mapflags, h); safestrncpy(zone->mapflags[h], name, MAP_ZONE_MAPFLAG_LENGTH); @@ -4717,31 +4717,31 @@ void read_map_zone_db(void) { zone->mapflags_count = mapflags_count; } - if( (commands = config_setting_get_member(zone_e, "disabled_commands")) != NULL ) { - disabled_commands_count = config_setting_length(commands); + if( (commands = libconfig->setting_get_member(zone_e, "disabled_commands")) != NULL ) { + disabled_commands_count = libconfig->setting_length(commands); /* validate */ - for(h = 0; h < config_setting_length(commands); h++) { - config_setting_t *command = config_setting_get_elem(commands, h); + for(h = 0; h < libconfig->setting_length(commands); h++) { + config_setting_t *command = libconfig->setting_get_elem(commands, h); name = config_setting_name(command); if( !atcommand->exists(name) ) { ShowError("map_zone_db: unknown command '%s' in disabled_commands for zone '%s', skipping entry...\n",name,zone->name); - config_setting_remove_elem(commands,h); + libconfig->setting_remove_elem(commands,h); --disabled_commands_count; --h; continue; } - if( !config_setting_get_int(command) )/* we dont remove it from the three due to inheritance */ + if( !libconfig->setting_get_int(command) )/* we dont remove it from the three due to inheritance */ --disabled_commands_count; } /* all ok, process */ CREATE( zone->disabled_commands, struct map_zone_disabled_command_entry *, disabled_commands_count ); - for(h = 0, v = 0; h < config_setting_length(commands); h++) { - config_setting_t *command = config_setting_get_elem(commands, h); + for(h = 0, v = 0; h < libconfig->setting_length(commands); h++) { + config_setting_t *command = libconfig->setting_get_elem(commands, h); struct map_zone_disabled_command_entry * entry; int group_lv; name = config_setting_name(command); - if( (group_lv = config_setting_get_int(command)) ) { /* only add if enabled */ + if( (group_lv = libconfig->setting_get_int(command)) ) { /* only add if enabled */ CREATE( entry, struct map_zone_disabled_command_entry, 1 ); entry->cmd = atcommand->exists(name)->func; @@ -4753,35 +4753,35 @@ void read_map_zone_db(void) { zone->disabled_commands_count = disabled_commands_count; } - if( (caps = config_setting_get_member(zone_e, "skill_damage_cap")) != NULL ) { - capped_skills_count = config_setting_length(caps); + if( (caps = libconfig->setting_get_member(zone_e, "skill_damage_cap")) != NULL ) { + capped_skills_count = libconfig->setting_length(caps); /* validate */ - for(h = 0; h < config_setting_length(caps); h++) { - config_setting_t *cap = config_setting_get_elem(caps, h); + for(h = 0; h < libconfig->setting_length(caps); h++) { + config_setting_t *cap = libconfig->setting_get_elem(caps, h); name = config_setting_name(cap); if( !map->zone_str2skillid(name) ) { ShowError("map_zone_db: unknown skill (%s) in skill_damage_cap for zone '%s', skipping skill...\n",name,zone->name); - config_setting_remove_elem(caps,h); + libconfig->setting_remove_elem(caps,h); --capped_skills_count; --h; continue; } - if( !map->zone_bl_type(config_setting_get_string_elem(cap,1),&subtype) )/* we dont remove it from the three due to inheritance */ + if( !map->zone_bl_type(libconfig->setting_get_string_elem(cap,1),&subtype) )/* we dont remove it from the three due to inheritance */ --capped_skills_count; } /* all ok, process */ CREATE( zone->capped_skills, struct map_zone_skill_damage_cap_entry *, capped_skills_count ); - for(h = 0, v = 0; h < config_setting_length(caps); h++) { - config_setting_t *cap = config_setting_get_elem(caps, h); + for(h = 0, v = 0; h < libconfig->setting_length(caps); h++) { + config_setting_t *cap = libconfig->setting_get_elem(caps, h); struct map_zone_skill_damage_cap_entry * entry; enum bl_type type; name = config_setting_name(cap); - if( (type = map->zone_bl_type(config_setting_get_string_elem(cap,1),&subtype)) ) { /* only add if enabled */ + if( (type = map->zone_bl_type(libconfig->setting_get_string_elem(cap,1),&subtype)) ) { /* only add if enabled */ CREATE( entry, struct map_zone_skill_damage_cap_entry, 1 ); entry->nameid = map->zone_str2skillid(name); - entry->cap = config_setting_get_int_elem(cap,0); + entry->cap = libconfig->setting_get_int_elem(cap,0); entry->type = type; entry->subtype = subtype; zone->capped_skills[v++] = entry; @@ -4801,24 +4801,24 @@ void read_map_zone_db(void) { config_setting_t *new_entry = NULL; int inherit_count; - zone_e = config_setting_get_elem(zones, i); - config_setting_lookup_string(zone_e, "name", &zonename); + zone_e = libconfig->setting_get_elem(zones, i); + libconfig->setting_lookup_string(zone_e, "name", &zonename); if( strncmpi(zonename,MAP_ZONE_ALL_NAME,MAP_ZONE_NAME_LENGTH) == 0 ) { continue;/* all zone doesn't inherit anything (if it did, everything would link to each other and boom endless loop) */ } - if( (inherit_tree = config_setting_get_member(zone_e, "inherit")) != NULL ) { + if( (inherit_tree = libconfig->setting_get_member(zone_e, "inherit")) != NULL ) { /* append global zone to this */ - new_entry = config_setting_add(inherit_tree,MAP_ZONE_ALL_NAME,CONFIG_TYPE_STRING); - config_setting_set_string(new_entry,MAP_ZONE_ALL_NAME); + new_entry = libconfig->setting_add(inherit_tree,MAP_ZONE_ALL_NAME,CONFIG_TYPE_STRING); + libconfig->setting_set_string(new_entry,MAP_ZONE_ALL_NAME); } else { /* create inherit member and add global zone to it */ - inherit_tree = config_setting_add(zone_e, "inherit",CONFIG_TYPE_ARRAY); - new_entry = config_setting_add(inherit_tree,MAP_ZONE_ALL_NAME,CONFIG_TYPE_STRING); - config_setting_set_string(new_entry,MAP_ZONE_ALL_NAME); + inherit_tree = libconfig->setting_add(zone_e, "inherit",CONFIG_TYPE_ARRAY); + new_entry = libconfig->setting_add(inherit_tree,MAP_ZONE_ALL_NAME,CONFIG_TYPE_STRING); + libconfig->setting_set_string(new_entry,MAP_ZONE_ALL_NAME); } - inherit_count = config_setting_length(inherit_tree); + inherit_count = libconfig->setting_length(inherit_tree); for(h = 0; h < inherit_count; h++) { struct map_zone_data *izone; /* inherit zone */ int disabled_skills_count_i = 0; /* disabled skill count from inherit zone */ @@ -4828,8 +4828,8 @@ void read_map_zone_db(void) { int capped_skills_count_i = 0; /* skill capped count from inherit zone */ int j; - name = config_setting_get_string_elem(inherit_tree, h); - config_setting_lookup_string(zone_e, "name", &zonename);/* will succeed for we validated it earlier */ + name = libconfig->setting_get_string_elem(inherit_tree, h); + libconfig->setting_lookup_string(zone_e, "name", &zonename);/* will succeed for we validated it earlier */ if( !(izone = strdb_get(map->zone_db, name)) ) { ShowError("map_zone_db: Unknown zone '%s' being inherit by zone '%s', skipping...\n",name,zonename); @@ -4851,13 +4851,13 @@ void read_map_zone_db(void) { /* process everything to override, paying attention to config_setting_get_bool */ if( disabled_skills_count_i ) { - if( (skills = config_setting_get_member(zone_e, "disabled_skills")) == NULL ) - skills = config_setting_add(zone_e, "disabled_skills",CONFIG_TYPE_GROUP); - disabled_skills_count = config_setting_length(skills); + if( (skills = libconfig->setting_get_member(zone_e, "disabled_skills")) == NULL ) + skills = libconfig->setting_add(zone_e, "disabled_skills",CONFIG_TYPE_GROUP); + disabled_skills_count = libconfig->setting_length(skills); for(j = 0; j < disabled_skills_count_i; j++) { int k; for(k = 0; k < disabled_skills_count; k++) { - config_setting_t *skillinfo = config_setting_get_elem(skills, k); + config_setting_t *skillinfo = libconfig->setting_get_elem(skills, k); if( map->zone_str2skillid(config_setting_name(skillinfo)) == izone->disabled_skills[j]->nameid ) { break; } @@ -4874,18 +4874,18 @@ void read_map_zone_db(void) { } if( disabled_items_count_i ) { - if( (items = config_setting_get_member(zone_e, "disabled_items")) == NULL ) - items = config_setting_add(zone_e, "disabled_items",CONFIG_TYPE_GROUP); - disabled_items_count = config_setting_length(items); + if( (items = libconfig->setting_get_member(zone_e, "disabled_items")) == NULL ) + items = libconfig->setting_add(zone_e, "disabled_items",CONFIG_TYPE_GROUP); + disabled_items_count = libconfig->setting_length(items); for(j = 0; j < disabled_items_count_i; j++) { int k; for(k = 0; k < disabled_items_count; k++) { - config_setting_t *item = config_setting_get_elem(items, k); + config_setting_t *item = libconfig->setting_get_elem(items, k); name = config_setting_name(item); if( map->zone_str2itemid(name) == izone->disabled_items[j] ) { - if( config_setting_get_bool(item) ) + if( libconfig->setting_get_bool(item) ) continue; break; } @@ -4898,13 +4898,13 @@ void read_map_zone_db(void) { } if( mapflags_count_i ) { - if( (mapflags = config_setting_get_member(zone_e, "mapflags")) == NULL ) - mapflags = config_setting_add(zone_e, "mapflags",CONFIG_TYPE_ARRAY); - mapflags_count = config_setting_length(mapflags); + if( (mapflags = libconfig->setting_get_member(zone_e, "mapflags")) == NULL ) + mapflags = libconfig->setting_add(zone_e, "mapflags",CONFIG_TYPE_ARRAY); + mapflags_count = libconfig->setting_length(mapflags); for(j = 0; j < mapflags_count_i; j++) { int k; for(k = 0; k < mapflags_count; k++) { - name = config_setting_get_string_elem(mapflags, k); + name = libconfig->setting_get_string_elem(mapflags, k); if( strcmpi(name,izone->mapflags[j]) == 0 ) { break; @@ -4919,14 +4919,14 @@ void read_map_zone_db(void) { } if( disabled_commands_count_i ) { - if( (commands = config_setting_get_member(zone_e, "disabled_commands")) == NULL ) - commands = config_setting_add(zone_e, "disabled_commands",CONFIG_TYPE_GROUP); + if( (commands = libconfig->setting_get_member(zone_e, "disabled_commands")) == NULL ) + commands = libconfig->setting_add(zone_e, "disabled_commands",CONFIG_TYPE_GROUP); - disabled_commands_count = config_setting_length(commands); + disabled_commands_count = libconfig->setting_length(commands); for(j = 0; j < disabled_commands_count_i; j++) { int k; for(k = 0; k < disabled_commands_count; k++) { - config_setting_t *command = config_setting_get_elem(commands, k); + config_setting_t *command = libconfig->setting_get_elem(commands, k); if( atcommand->exists(config_setting_name(command))->func == izone->disabled_commands[j]->cmd ) { break; } @@ -4943,14 +4943,14 @@ void read_map_zone_db(void) { } if( capped_skills_count_i ) { - if( (caps = config_setting_get_member(zone_e, "skill_damage_cap")) == NULL ) - caps = config_setting_add(zone_e, "skill_damage_cap",CONFIG_TYPE_GROUP); + if( (caps = libconfig->setting_get_member(zone_e, "skill_damage_cap")) == NULL ) + caps = libconfig->setting_add(zone_e, "skill_damage_cap",CONFIG_TYPE_GROUP); - capped_skills_count = config_setting_length(caps); + capped_skills_count = libconfig->setting_length(caps); for(j = 0; j < capped_skills_count_i; j++) { int k; for(k = 0; k < capped_skills_count; k++) { - config_setting_t *cap = config_setting_get_elem(caps, k); + config_setting_t *cap = libconfig->setting_get_elem(caps, k); if( map->zone_str2skillid(config_setting_name(cap)) == izone->capped_skills[j]->nameid ) { break; } @@ -4972,7 +4972,7 @@ void read_map_zone_db(void) { ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' zones in '"CL_WHITE"%s"CL_RESET"'.\n", zone_count, config_filename); /* not supposed to go in here but in skill_final whatever */ - config_destroy(&map_zone_db); + libconfig->destroy(&map_zone_db); } } diff --git a/src/map/pc.c b/src/map/pc.c index cc2566a6e..f96b70cdb 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -9746,14 +9746,14 @@ void pc_read_skill_tree(void) { { "Rebellion", JOB_REBELLION }, }; - if (conf_read_file(&skill_tree_conf, config_filename)) { + if (libconfig->read_file(&skill_tree_conf, config_filename)) { ShowError("can't read %s\n", config_filename); return; } jnamelen = ARRAYLENGTH(jnames); - while( (skt = config_setting_get_elem(skill_tree_conf.root,i++)) ) { + while( (skt = libconfig->setting_get_elem(skill_tree_conf.root,i++)) ) { int k, idx; const char *name = config_setting_name(skt); @@ -9765,12 +9765,12 @@ void pc_read_skill_tree(void) { } - if( ( skills = config_setting_get_member(skt,"skills") ) ) { + if( ( skills = libconfig->setting_get_member(skt,"skills") ) ) { int c = 0; idx = pc->class2idx(jnames[k].id); - while( ( sk = config_setting_get_elem(skills,c++) ) ) { + while( ( sk = libconfig->setting_get_elem(skills,c++) ) ) { const char *sk_name = config_setting_name(sk); int skill_id; @@ -9790,23 +9790,23 @@ void pc_read_skill_tree(void) { if( config_setting_is_group(sk) ) { int max = 0, jlevel = 0; - config_setting_lookup_int(sk, "MaxLevel", &max); - config_setting_lookup_int(sk, "MinJobLevel", &jlevel); + libconfig->setting_lookup_int(sk, "MaxLevel", &max); + libconfig->setting_lookup_int(sk, "MinJobLevel", &jlevel); pc->skill_tree[idx][skidx].max = (unsigned char)max; pc->skill_tree[idx][skidx].joblv = (unsigned char)jlevel; - rlen = config_setting_length(sk); + rlen = libconfig->setting_length(sk); offset += jlevel ? 2 : 1; } else { - pc->skill_tree[idx][skidx].max = (unsigned char)config_setting_get_int(sk); + pc->skill_tree[idx][skidx].max = (unsigned char)libconfig->setting_get_int(sk); pc->skill_tree[idx][skidx].joblv = 0; } for( h = offset; h < rlen && h < MAX_PC_SKILL_REQUIRE; h++ ) { - config_setting_t *rsk = config_setting_get_elem(sk,h); + config_setting_t *rsk = libconfig->setting_get_elem(sk,h); if( rsk && ( rskid = skill->name2id(config_setting_name(rsk)) ) ) { pc->skill_tree[idx][skidx].need[h].id = rskid; pc->skill_tree[idx][skidx].need[h].idx = skill->get_index(rskid); - pc->skill_tree[idx][skidx].need[h].lv = (unsigned char)config_setting_get_int(rsk); + pc->skill_tree[idx][skidx].need[h].lv = (unsigned char)libconfig->setting_get_int(rsk); } else if( rsk ) { ShowWarning("pc_read_skill_tree: unknown requirement '%s' for '%s' in '%s'\n",config_setting_name(rsk),sk_name,name); } else { @@ -9822,7 +9822,7 @@ void pc_read_skill_tree(void) { } i = 0; - while( (skt = config_setting_get_elem(skill_tree_conf.root,i++)) ) { + while( (skt = libconfig->setting_get_elem(skill_tree_conf.root,i++)) ) { int k, idx, v = 0; const char *name = config_setting_name(skt); const char *iname; @@ -9836,8 +9836,8 @@ void pc_read_skill_tree(void) { } idx = pc->class2idx(jnames[k].id); - if( ( inherit = config_setting_get_member(skt,"inherit") ) ) { - while( ( iname = config_setting_get_string_elem(inherit, v++) ) ) { + if( ( inherit = libconfig->setting_get_member(skt,"inherit") ) ) { + while( ( iname = libconfig->setting_get_string_elem(inherit, v++) ) ) { int b = 0, a, d, f, fidx; ARR_FIND(0, jnamelen, b, strcmpi(jnames[b].name,iname) == 0 ); @@ -9869,7 +9869,7 @@ void pc_read_skill_tree(void) { } - config_destroy(&skill_tree_conf); + libconfig->destroy(&skill_tree_conf); /* lets update all players skill tree */ iter = mapit_getallusers(); diff --git a/src/map/pc_groups.c b/src/map/pc_groups.c index 4ddb95c9b..906462c7e 100644 --- a/src/map/pc_groups.c +++ b/src/map/pc_groups.c @@ -49,26 +49,26 @@ static void read_config(void) { const char *config_filename = "conf/groups.conf"; // FIXME hardcoded name int group_count = 0; - if (conf_read_file(&pc_group_config, config_filename)) + if (libconfig->read_file(&pc_group_config, config_filename)) return; - groups = config_lookup(&pc_group_config, "groups"); + groups = libconfig->lookup(&pc_group_config, "groups"); if (groups != NULL) { GroupSettings *group_settings = NULL; DBIterator *iter = NULL; int i, loop = 0; - group_count = config_setting_length(groups); + group_count = libconfig->setting_length(groups); for (i = 0; i < group_count; ++i) { int id = 0, level = 0; const char *groupname = NULL; int log_commands = 0; - config_setting_t *group = config_setting_get_elem(groups, i); + config_setting_t *group = libconfig->setting_get_elem(groups, i); - if (!config_setting_lookup_int(group, "id", &id)) { + if (!libconfig->setting_lookup_int(group, "id", &id)) { ShowConfigWarning(group, "pc_groups:read_config: \"groups\" list member #%d has undefined id, removing...", i); - config_setting_remove_elem(groups, i); + libconfig->setting_remove_elem(groups, i); --i; --group_count; continue; @@ -76,16 +76,16 @@ static void read_config(void) { if (pcg->exists(id)) { ShowConfigWarning(group, "pc_groups:read_config: duplicate group id %d, removing...", i); - config_setting_remove_elem(groups, i); + libconfig->setting_remove_elem(groups, i); --i; --group_count; continue; } - config_setting_lookup_int(group, "level", &level); - config_setting_lookup_bool(group, "log_commands", &log_commands); + libconfig->setting_lookup_int(group, "level", &level); + libconfig->setting_lookup_bool(group, "log_commands", &log_commands); - if (!config_setting_lookup_string(group, "name", &groupname)) { + if (!libconfig->setting_lookup_string(group, "name", &groupname)) { char temp[20]; config_setting_t *name = NULL; snprintf(temp, sizeof(temp), "Group %d", id); @@ -97,12 +97,12 @@ static void read_config(void) { --group_count; continue; } - config_setting_lookup_string(group, "name", &groupname); // Retrieve the pointer + libconfig->setting_lookup_string(group, "name", &groupname); // Retrieve the pointer } if (name2group(groupname) != NULL) { ShowConfigWarning(group, "pc_groups:read_config: duplicate group name %s, removing...", groupname); - config_setting_remove_elem(groups, i); + libconfig->setting_remove_elem(groups, i); --i; --group_count; continue; @@ -113,9 +113,9 @@ static void read_config(void) { group_settings->level = level; group_settings->name = aStrdup(groupname); group_settings->log_commands = (bool)log_commands; - group_settings->inherit = config_setting_get_member(group, "inherit"); - group_settings->commands = config_setting_get_member(group, "commands"); - group_settings->permissions = config_setting_get_member(group, "permissions"); + group_settings->inherit = libconfig->setting_get_member(group, "inherit"); + group_settings->commands = libconfig->setting_get_member(group, "commands"); + group_settings->permissions = libconfig->setting_get_member(group, "permissions"); group_settings->inheritance_done = false; group_settings->root = group; group_settings->index = i; @@ -124,7 +124,7 @@ static void read_config(void) { idb_put(pcg->db, id, group_settings); } - group_count = config_setting_length(groups); // Save number of groups + group_count = libconfig->setting_length(groups); // Save number of groups assert(group_count == db_size(pcg->db)); // Check if all commands and permissions exist @@ -135,15 +135,15 @@ static void read_config(void) { // Make sure there is "commands" group if (commands == NULL) - commands = group_settings->commands = config_setting_add(group_settings->root, "commands", CONFIG_TYPE_GROUP); - count = config_setting_length(commands); + commands = group_settings->commands = libconfig->setting_add(group_settings->root, "commands", CONFIG_TYPE_GROUP); + count = libconfig->setting_length(commands); for (i = 0; i < count; ++i) { - config_setting_t *command = config_setting_get_elem(commands, i); + config_setting_t *command = libconfig->setting_get_elem(commands, i); const char *name = config_setting_name(command); if (!atcommand->exists(name)) { ShowConfigWarning(command, "pc_groups:read_config: non-existent command name '%s', removing...", name); - config_setting_remove(commands, name); + libconfig->setting_remove(commands, name); --i; --count; } @@ -151,18 +151,18 @@ static void read_config(void) { // Make sure there is "permissions" group if (permissions == NULL) - permissions = group_settings->permissions = config_setting_add(group_settings->root, "permissions", CONFIG_TYPE_GROUP); - count = config_setting_length(permissions); + permissions = group_settings->permissions = libconfig->setting_add(group_settings->root, "permissions", CONFIG_TYPE_GROUP); + count = libconfig->setting_length(permissions); for(i = 0; i < count; ++i) { - config_setting_t *permission = config_setting_get_elem(permissions, i); + config_setting_t *permission = libconfig->setting_get_elem(permissions, i); const char *name = config_setting_name(permission); int j; ARR_FIND(0, pcg->permission_count, j, strcmp(pcg->permissions[j].name, name) == 0); if (j == pcg->permission_count) { ShowConfigWarning(permission, "pc_groups:read_config: non-existent permission name '%s', removing...", name); - config_setting_remove(permissions, name); + libconfig->setting_remove(permissions, name); --i; --count; } @@ -184,7 +184,7 @@ static void read_config(void) { continue; if ((inherit = group_settings->inherit) == NULL || - (inherit_count = config_setting_length(inherit)) <= 0) { // this group does not inherit from others + (inherit_count = libconfig->setting_length(inherit)) <= 0) { // this group does not inherit from others ++i; group_settings->inheritance_done = true; continue; @@ -192,16 +192,16 @@ static void read_config(void) { for (j = 0; j < inherit_count; ++j) { GroupSettings *inherited_group = NULL; - const char *groupname = config_setting_get_string_elem(inherit, j); + const char *groupname = libconfig->setting_get_string_elem(inherit, j); if (groupname == NULL) { ShowConfigWarning(inherit, "pc_groups:read_config: \"inherit\" array member #%d is not a name, removing...", j); - config_setting_remove_elem(inherit,j); + libconfig->setting_remove_elem(inherit,j); continue; } if ((inherited_group = name2group(groupname)) == NULL) { ShowConfigWarning(inherit, "pc_groups:read_config: non-existent group name \"%s\", removing...", groupname); - config_setting_remove_elem(inherit,j); + libconfig->setting_remove_elem(inherit,j); continue; } if (!inherited_group->inheritance_done) @@ -209,15 +209,15 @@ static void read_config(void) { // Copy settings (commands/permissions) that are not defined yet if (inherited_group->commands != NULL) { - int k = 0, commands_count = config_setting_length(inherited_group->commands); + int k = 0, commands_count = libconfig->setting_length(inherited_group->commands); for (k = 0; k < commands_count; ++k) - config_setting_copy(commands, config_setting_get_elem(inherited_group->commands, k)); + libconfig->setting_copy(commands, libconfig->setting_get_elem(inherited_group->commands, k)); } if (inherited_group->permissions != NULL) { - int k = 0, permissions_count = config_setting_length(inherited_group->permissions); + int k = 0, permissions_count = libconfig->setting_length(inherited_group->permissions); for (k = 0; k < permissions_count; ++k) - config_setting_copy(permissions, config_setting_get_elem(inherited_group->permissions, k)); + libconfig->setting_copy(permissions, libconfig->setting_get_elem(inherited_group->permissions, k)); } ++done; // copied commands and permissions from one of inherited groups @@ -241,12 +241,12 @@ static void read_config(void) { iter = db_iterator(pcg->db); for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) { config_setting_t *permissions = group_settings->permissions; - int count = config_setting_length(permissions); + int count = libconfig->setting_length(permissions); for (i = 0; i < count; ++i) { - config_setting_t *perm = config_setting_get_elem(permissions, i); + config_setting_t *perm = libconfig->setting_get_elem(permissions, i); const char *name = config_setting_name(perm); - int val = config_setting_get_bool(perm); + int val = libconfig->setting_get_bool(perm); int j; if (val == 0) // does not have this permission @@ -282,7 +282,7 @@ static void read_config(void) { ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' groups in '"CL_WHITE"%s"CL_RESET"'.\n", group_count, config_filename); // All data is loaded now, discard config - config_destroy(&pc_group_config); + libconfig->destroy(&pc_group_config); } /** diff --git a/src/plugins/db2sql.c b/src/plugins/db2sql.c index 58dee4306..e72d47b80 100644 --- a/src/plugins/db2sql.c +++ b/src/plugins/db2sql.c @@ -34,10 +34,6 @@ struct { bool torun = false; int (*itemdb_readdb_libconfig_sub) (config_setting_t *it, int n, const char *source); -int (*h_config_setting_lookup_string) (const config_setting_t *setting, const char *name, const char **value); -int (*h_config_setting_lookup_int) (const config_setting_t *setting, const char *name, int *value); -config_setting_t *(*h_config_setting_get_member) (const config_setting_t *setting, const char *name); -int (*h_config_setting_length) (const config_setting_t *setting); void hstr(const char *str) { if( strlen(str) > tosql.buf[3].len ) { @@ -60,18 +56,18 @@ int db2sql(config_setting_t *entry, int n, const char *source) { SQL->EscapeString(NULL, e_name, it->name); SQL->EscapeString(NULL, e_jname, it->jname); - if( it->script ) { h_config_setting_lookup_string(entry, "Script", &bonus); hstr(bonus); str = tosql.buf[3].p; if ( strlen(str) > tosql.buf[0].len ) { tosql.buf[0].len = tosql.buf[0].len + strlen(str) + 1000; RECREATE(tosql.buf[0].p,char,tosql.buf[0].len); } SQL->EscapeString(NULL, tosql.buf[0].p, str); } - if( it->equip_script ) { h_config_setting_lookup_string(entry, "OnEquipScript", &bonus); hstr(bonus); str = tosql.buf[3].p; if ( strlen(str) > tosql.buf[1].len ) { tosql.buf[1].len = tosql.buf[1].len + strlen(str) + 1000; RECREATE(tosql.buf[1].p,char,tosql.buf[1].len); } SQL->EscapeString(NULL, tosql.buf[1].p, str); } - if( it->unequip_script ) { h_config_setting_lookup_string(entry, "OnUnequipScript", &bonus); hstr(bonus); str = tosql.buf[3].p; if ( strlen(str) > tosql.buf[2].len ) { tosql.buf[2].len = tosql.buf[2].len + strlen(str) + 1000; RECREATE(tosql.buf[2].p,char,tosql.buf[2].len); } SQL->EscapeString(NULL, tosql.buf[2].p, str); } + if( it->script ) { libconfig->setting_lookup_string(entry, "Script", &bonus); hstr(bonus); str = tosql.buf[3].p; if ( strlen(str) > tosql.buf[0].len ) { tosql.buf[0].len = tosql.buf[0].len + strlen(str) + 1000; RECREATE(tosql.buf[0].p,char,tosql.buf[0].len); } SQL->EscapeString(NULL, tosql.buf[0].p, str); } + if( it->equip_script ) { libconfig->setting_lookup_string(entry, "OnEquipScript", &bonus); hstr(bonus); str = tosql.buf[3].p; if ( strlen(str) > tosql.buf[1].len ) { tosql.buf[1].len = tosql.buf[1].len + strlen(str) + 1000; RECREATE(tosql.buf[1].p,char,tosql.buf[1].len); } SQL->EscapeString(NULL, tosql.buf[1].p, str); } + if( it->unequip_script ) { libconfig->setting_lookup_string(entry, "OnUnequipScript", &bonus); hstr(bonus); str = tosql.buf[3].p; if ( strlen(str) > tosql.buf[2].len ) { tosql.buf[2].len = tosql.buf[2].len + strlen(str) + 1000; RECREATE(tosql.buf[2].p,char,tosql.buf[2].len); } SQL->EscapeString(NULL, tosql.buf[2].p, str); } - if( h_config_setting_lookup_int(entry, "Job", &i32) ) // This is an unsigned value, do not check for >= 0 + if( libconfig->setting_lookup_int(entry, "Job", &i32) ) // This is an unsigned value, do not check for >= 0 ui32 = (unsigned int)i32; else ui32 = UINT_MAX; job = ui32; - if( h_config_setting_lookup_int(entry, "Upper", &i32) && i32 >= 0 ) + if( libconfig->setting_lookup_int(entry, "Upper", &i32) && i32 >= 0 ) ui32 = (unsigned int)i32; else ui32 = ITEMUPPER_ALL; @@ -79,7 +75,7 @@ int db2sql(config_setting_t *entry, int n, const char *source) { upper = ui32; /* check if we have the equip_level_max, if so we send it -- otherwise we send NULL */ - if( (t = h_config_setting_get_member(entry, "EquipLv")) && config_setting_is_aggregate(t) && h_config_setting_length(t) >= 2 ) + if( (t = libconfig->setting_get_member(entry, "EquipLv")) && config_setting_is_aggregate(t) && libconfig->setting_length(t) >= 2 ) fprintf(tosql.fp,"REPLACE INTO `%s` VALUES ('%u','%s','%s','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%u','%s','%s','%s');\n", tosql.db_name,it->nameid,e_name,e_jname,it->flag.delay_consume?IT_DELAYCONSUME:it->type,it->value_buy,it->value_sell,it->weight,it->atk,it->matk,it->def,it->range,it->slot,job,upper,it->sex,it->equip,it->wlv,it->elv,it->elvmax,it->flag.no_refine?0:1,it->look,it->flag.bindonequip?1:0,it->script?tosql.buf[0].p:"",it->equip_script?tosql.buf[1].p:"",it->unequip_script?tosql.buf[2].p:""); else @@ -192,16 +188,13 @@ void db2sql_arg(char *param) { map->minimal = torun = true; } HPExport void server_preinit (void) { - h_config_setting_lookup_string = GET_SYMBOL("config_setting_lookup_string"); - h_config_setting_lookup_int = GET_SYMBOL("config_setting_lookup_int"); - h_config_setting_get_member = GET_SYMBOL("config_setting_get_member"); - h_config_setting_length = GET_SYMBOL("config_setting_length"); - SQL = GET_SYMBOL("SQL"); itemdb = GET_SYMBOL("itemdb"); map = GET_SYMBOL("map"); strlib = GET_SYMBOL("strlib"); iMalloc = GET_SYMBOL("iMalloc"); + libconfig = GET_SYMBOL("libconfig"); + addArg("--db2sql",false,db2sql_arg,NULL); } |