Skip to content

Commit

Permalink
Storage config reading
Browse files Browse the repository at this point in the history
- Check duplicate for non imported storage ID and overwrite when imported ID exist
- Move vector initialization on do_init_storage and transferred config reading after it
  • Loading branch information
jasonch35 committed Dec 11, 2024
1 parent 8df6252 commit 9f08c77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/map/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -7028,7 +7028,6 @@ int do_init(int argc, char *argv[])
atcommand->msg_read(map->MSG_CONF_NAME, false);
map->inter_config_read(map->INTER_CONF_NAME, false);
logs->config_read(map->LOG_CONF_NAME, false);
storage->config_read(map->STORAGE_CONF_FILENAME, false);
} else {
battle->config_read(map->BATTLE_CONF_FILENAME, false);
}
Expand Down
16 changes: 10 additions & 6 deletions src/map/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ bool storage_config_read(const char *filename, bool imported)
nullpo_retr(false, filename);

if (!imported)
VECTOR_INIT(storage->configuration);
VECTOR_CLEAR(storage->configuration);

struct config_t stor_libconf;
if (libconfig->load_file(&stor_libconf, filename) == CONFIG_FALSE)
Expand All @@ -1035,11 +1035,13 @@ bool storage_config_read(const char *filename, bool imported)
}

// Duplicate ID search and report...
int d = 0;
ARR_FIND(0, VECTOR_LENGTH(storage->configuration), d, VECTOR_INDEX(storage->configuration, d).uid == s_conf.uid);
if (d < VECTOR_LENGTH(storage->configuration)) {
ShowError("storage_config_read: Duplicate ID %d for storage. Skipping...\n", s_conf.uid);
continue;
if (!imported) {
int d = 0;
ARR_FIND(0, VECTOR_LENGTH(storage->configuration), d, VECTOR_INDEX(storage->configuration, d).uid == s_conf.uid);
if (d < VECTOR_LENGTH(storage->configuration)) {
ShowError("storage_config_read: Duplicate ID %d for storage. Skipping...\n", s_conf.uid);
continue;
}
}

// Check for an invalid ID...
Expand Down Expand Up @@ -1117,6 +1119,8 @@ static void do_init_storage(bool minimal)
{
if (minimal)
return;
VECTOR_INIT(storage->configuration);
storage->config_read(map->STORAGE_CONF_FILENAME, false);
}

/**
Expand Down

0 comments on commit 9f08c77

Please sign in to comment.