From ebecc72d189d931d1b5d8269afd0e89c8ac73c3d Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 18 Sep 2016 01:14:24 +0200 Subject: Corrected some issues in the npc_removed_list and map_removed processing - Removed the unnecessary DB_OPT_RELEASE_KEY flag (we don't want to release the original key, but only the duplicate one, which is already managed by DB_OPT_DUP_KEY) - Added DB_OPT_NULL_DATA to the npc_removed_list DBMap (follow-up to 4aa5286, related #1430) Signed-off-by: Haru --- src/map/map.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/map/map.c b/src/map/map.c index d22b28689..5408cfbfa 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -3996,7 +3996,7 @@ bool map_config_read_map_list(const char *filename, struct config_t *config, boo nullpo_retr(false, filename); nullpo_retr(false, config); - deleted_maps = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_KEY|DB_OPT_ALLOW_NULL_DATA, MAP_NAME_LENGTH); + deleted_maps = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_ALLOW_NULL_DATA, MAP_NAME_LENGTH); // Remove maps if ((setting = libconfig->lookup(config, "map_configuration/map_removed")) != NULL) { @@ -4136,9 +4136,9 @@ bool map_read_npclist(const char *filename, bool imported) if (!libconfig->load_file(&config, filename)) return false; - deleted_npcs = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_KEY, MAP_NAME_LENGTH); + deleted_npcs = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_ALLOW_NULL_DATA, MAP_NAME_LENGTH); - // Remove maps + // Remove NPCs if ((setting = libconfig->lookup(&config, "npc_removed_list")) != NULL) { int i, del_count = libconfig->setting_length(setting); for (i = 0; i < del_count; i++) { @@ -4149,7 +4149,7 @@ bool map_read_npclist(const char *filename, bool imported) strdb_put(deleted_npcs, scriptname, NULL); - if (imported) // Map list is empty on the first run, only do this for imported files. + if (imported) // NPC list is empty on the first run, only do this for imported files. npc->delsrcfile(scriptname); } } -- cgit v1.2.3-70-g09d2 From 53dcedee75954229dcd56c2f04e42e725a1a7359 Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 18 Sep 2016 01:30:36 +0200 Subject: Restored handling of "all" in npc_removed_list - The feature was missing/incomplete since the conversion to libconfig - Fixes #1425 Signed-off-by: Haru --- src/map/map.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/map/map.c b/src/map/map.c index 5408cfbfa..308aa82cc 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -4128,6 +4128,7 @@ bool map_read_npclist(const char *filename, bool imported) struct config_setting_t *setting = NULL; const char *import = NULL; bool retval = true; + bool remove_all = false; struct DBMap *deleted_npcs; @@ -4147,10 +4148,13 @@ bool map_read_npclist(const char *filename, bool imported) if ((scriptname = libconfig->setting_get_string_elem(setting, i)) == NULL || scriptname[0] == '\0') continue; - strdb_put(deleted_npcs, scriptname, NULL); - - if (imported) // NPC list is empty on the first run, only do this for imported files. + if (strcmp(scriptname, "all") == 0) { + remove_all = true; + npc->clearsrcfile(); + } else { + strdb_put(deleted_npcs, scriptname, NULL); npc->delsrcfile(scriptname); + } } } @@ -4168,7 +4172,7 @@ bool map_read_npclist(const char *filename, bool imported) if ((scriptname = libconfig->setting_get_string_elem(setting, i)) == NULL || scriptname[0] == '\0') continue; - if (strdb_exists(deleted_npcs, scriptname)) + if (remove_all || strdb_exists(deleted_npcs, scriptname)) continue; npc->addsrcfile(scriptname); -- cgit v1.2.3-70-g09d2 From c940d5f31aea1220c684189dc06206a400f59e99 Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 18 Sep 2016 01:32:22 +0200 Subject: Removed special handling of "all" by npc->delsrcfile() - Use npc->clearsrcfile() instead. Signed-off-by: Haru --- src/map/npc.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/map/npc.c b/src/map/npc.c index 36078837f..efc27c258 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2464,24 +2464,21 @@ void npc_addsrcfile(const char* name) file_prev->next = file; } -/// Removes a npc source file (or all) -void npc_delsrcfile(const char* name) +/** + * Removes a npc source file. + * + * @param name The file name to remove. + */ +void npc_delsrcfile(const char *name) { struct npc_src_list* file = npc->src_files; struct npc_src_list* file_prev = NULL; nullpo_retv(name); - if( strcmpi(name, "all") == 0 ) - { - npc->clearsrcfile(); - return; - } - while( file != NULL ) - { - if( strcmp(file->name, name) == 0 ) - { - if( npc->src_files == file ) + while (file != NULL) { + if (strcmp(file->name, name) == 0) { + if (npc->src_files == file) npc->src_files = file->next; else file_prev->next = file->next; -- cgit v1.2.3-70-g09d2 From 9068ec7dc0e85cd3f7f8f9a11a3b7f06dc24f4f6 Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 18 Sep 2016 01:36:17 +0200 Subject: Removed special handling of "clear" in npc->addsrcfile() - Use npc->clearsrcfile() instead. Signed-off-by: Haru --- src/map/map.c | 2 +- src/map/npc.c | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/map/map.c b/src/map/map.c index 308aa82cc..47e22fa9b 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -4212,7 +4212,7 @@ bool map_read_npclist(const char *filename, bool imported) void map_reloadnpc(bool clear) { int i; if (clear) - npc->addsrcfile("clear"); // this will clear the current script list + npc->clearsrcfile(); #ifdef RENEWAL map->read_npclist("npc/re/scripts_main.conf", false); diff --git a/src/map/npc.c b/src/map/npc.c index efc27c258..9791b66a5 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2432,24 +2432,22 @@ void npc_clearsrcfile(void) npc->src_files = NULL; } -/// Adds a npc source file (or removes all) -void npc_addsrcfile(const char* name) +/** + * Adds a npc source file. + * + * @param name The file name to add. + */ +void npc_addsrcfile(const char *name) { struct npc_src_list* file; struct npc_src_list* file_prev = NULL; nullpo_retv(name); - if( strcmpi(name, "clear") == 0 ) - { - npc->clearsrcfile(); - return; - } // prevent multiple insert of source files file = npc->src_files; - while( file != NULL ) - { - if( strcmp(name, file->name) == 0 ) + while (file != NULL) { + if (strcmp(name, file->name) == 0) return;// found the file, no need to insert it again file_prev = file; file = file->next; -- cgit v1.2.3-70-g09d2