diff options
author | Andrei Karas <akaras@inbox.ru> | 2018-07-17 02:57:06 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2018-07-19 21:53:40 +0300 |
commit | 2f80262667ece77ceb69de42b2cc4ce84aed6881 (patch) | |
tree | 326d86dae61a32bbd5a51ad9f2afdf2c91aba07a /src/map/itemdb.c | |
parent | b67565957203e5efae25b1a29d072c1b954ce394 (diff) | |
download | hercules-2f80262667ece77ceb69de42b2cc4ce84aed6881.tar.gz hercules-2f80262667ece77ceb69de42b2cc4ce84aed6881.tar.bz2 hercules-2f80262667ece77ceb69de42b2cc4ce84aed6881.tar.xz hercules-2f80262667ece77ceb69de42b2cc4ce84aed6881.zip |
Add new constant MAX_ITEM_ID for maximum allowed item id.
For clients older than 2018-07-04 Re maximum supported and enabled id is 65535 (0xffff).
For newer clients miximum id is 2147483648. Enabled by default 131072 (0x20000)
Diffstat (limited to 'src/map/itemdb.c')
-rw-r--r-- | src/map/itemdb.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/map/itemdb.c b/src/map/itemdb.c index c04639693..04f25ae5b 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -1700,9 +1700,9 @@ static int itemdb_validate_entry(struct item_data *entry, int n, const char *sou nullpo_ret(entry); nullpo_ret(source); - if( entry->nameid <= 0 || entry->nameid >= MAX_ITEMDB ) { - ShowWarning("itemdb_validate_entry: Invalid item ID %d in entry %d of '%s', allowed values 0 < ID < %d (MAX_ITEMDB), skipping.\n", - entry->nameid, n, source, MAX_ITEMDB); + if (entry->nameid <= 0 || entry->nameid > MAX_ITEM_ID) { + ShowWarning("itemdb_validate_entry: Invalid item ID %d in entry %d of '%s', allowed values 0 < ID < %d (MAX_ITEM_ID), skipping.\n", + entry->nameid, n, source, MAX_ITEM_ID); if (entry->script) { script->free_code(entry->script); entry->script = NULL; @@ -2346,6 +2346,7 @@ static bool itemdb_lookup_const_mask(const struct config_setting_t *it, const ch static int itemdb_readdb_libconfig(const char *filename) { bool duplicate[MAX_ITEMDB]; + struct DBMap *duplicate_db; struct config_t item_db_conf; struct config_setting_t *itdb, *it; char filepath[256]; @@ -2362,26 +2363,38 @@ static int itemdb_readdb_libconfig(const char *filename) return 0; } + // TODO add duplicates check for itemdb->other memset(&duplicate,0,sizeof(duplicate)); + duplicate_db = idb_alloc(DB_OPT_BASE); while( (it = libconfig->setting_get_elem(itdb,i++)) ) { int nameid = itemdb->readdb_libconfig_sub(it, i-1, filename); - if (nameid <= 0 || nameid >= MAX_ITEMDB) + if (nameid <= 0 || nameid > MAX_ITEM_ID) continue; itemdb->readdb_additional_fields(nameid, it, i - 1, filename); count++; - if( duplicate[nameid] ) { - ShowWarning("itemdb_readdb:%s: duplicate entry of ID #%d (%s/%s)\n", - filename, nameid, itemdb_name(nameid), itemdb_jname(nameid)); - } else - duplicate[nameid] = true; + if (nameid < MAX_ITEMDB) { + if (duplicate[nameid]) { + ShowWarning("itemdb_readdb:%s: duplicate entry of ID #%d (%s/%s)\n", + filename, nameid, itemdb_name(nameid), itemdb_jname(nameid)); + } else { + duplicate[nameid] = true; + } + } else { + if (idb_exists(duplicate_db, nameid)) { + ShowWarning("itemdb_readdb:%s: duplicate entry of ID #%d (%s/%s)\n", + filename, nameid, itemdb_name(nameid), itemdb_jname(nameid)); + } else { + idb_iput(duplicate_db, nameid, true); + } + } } + db_destroy(duplicate_db); libconfig->destroy(&item_db_conf); ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filename); - return count; } @@ -2411,6 +2424,7 @@ static void itemdb_read(bool minimal) for (i = 0; i < ARRAYLENGTH(filename); i++) itemdb->readdb_libconfig(filename[i]); + // TODO check duplicate names also in itemdb->other for( i = 0; i < ARRAYLENGTH(itemdb->array); ++i ) { if( itemdb->array[i] ) { if( itemdb->names->put(itemdb->names,DB->str2key(itemdb->array[i]->name),DB->ptr2data(itemdb->array[i]),&prev) ) { |