diff options
author | shennetsind <ind@henn.et> | 2013-11-11 17:56:48 -0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2013-11-14 20:15:28 +0100 |
commit | 091e235b78f83bd8c86c84e8b2db5ac9d5da98cd (patch) | |
tree | 79979f1f69e971be3c857b2a198977dc62f33348 /src/map | |
parent | 59b9acb3d50fe7bbcce0f141d450cf328c0b24b7 (diff) | |
download | hercules-091e235b78f83bd8c86c84e8b2db5ac9d5da98cd.tar.gz hercules-091e235b78f83bd8c86c84e8b2db5ac9d5da98cd.tar.bz2 hercules-091e235b78f83bd8c86c84e8b2db5ac9d5da98cd.tar.xz hercules-091e235b78f83bd8c86c84e8b2db5ac9d5da98cd.zip |
Updated db2sql plugin for the needs of the new itemdb
May be used as ./map-server --db2sql or by typing "server tools db2sql" within map-server console parse.
Special Thanks to Haruna.
Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/itemdb.c | 123 | ||||
-rw-r--r-- | src/map/itemdb.h | 3 | ||||
-rw-r--r-- | src/map/map.c | 9 | ||||
-rw-r--r-- | src/map/map.h | 1 |
4 files changed, 60 insertions, 76 deletions
diff --git a/src/map/itemdb.c b/src/map/itemdb.c index dff0207c7..f48ed8259 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -1826,43 +1826,36 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source) * Reading item from item db * item_db2 overwriting item_db *------------------------------------------*/ -int itemdb_readdb(void) { - const char* filename[] = { - DBPATH"item_db.conf", - "item_db2.conf", - }; +int itemdb_readdb(const char *filename) { bool duplicate[MAX_ITEMDB]; - int fi; config_t item_db_conf; config_setting_t *itdb, *it; + char filepath[256]; + int i = 0, count = 0; + + 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")) ) { + ShowError("can't read %s\n", filepath); + return 0; + } - for( fi = 0; fi < ARRAYLENGTH(filename); ++fi ) { - char filepath[256]; - int i = 0, count = 0; - sprintf(filepath, "%s/%s", map->db_path, filename[fi]); - memset(&duplicate,0,sizeof(duplicate)); - if( conf_read_file(&item_db_conf, filepath) || !(itdb = config_setting_get_member(item_db_conf.root, "item_db")) ) { - ShowError("can't read %s\n", filepath); - continue; - } - - while( (it = config_setting_get_elem(itdb,i++)) ) { - int nameid = itemdb->readdb_libconfig_sub(it, i-1, filename[fi]); + while( (it = config_setting_get_elem(itdb,i++)) ) { + int nameid = itemdb->readdb_libconfig_sub(it, i-1, filename); - if( !nameid ) - continue; + if( !nameid ) + continue; - count++; + count++; - if( duplicate[nameid] ) { - ShowWarning("itemdb_readdb:%s: duplicate entry of ID #%d (%s/%s)\n", - filename[fi], nameid, itemdb_name(nameid), itemdb_jname(nameid)); - } else - duplicate[nameid] = true; - } - config_destroy(&item_db_conf); - ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filename[fi]); + 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; } + config_destroy(&item_db_conf); + ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filename); return 0; } @@ -1956,8 +1949,15 @@ void itemdb_read(bool minimal) { if (map->db_use_sql_item_db) itemdb->read_sqldb(); - else - itemdb->readdb(); + else { + const char* filename[] = { + DBPATH"item_db.conf", + "item_db2.conf", + }; + + for(i = 0; i < ARRAYLENGTH(filename); i++) + itemdb->readdb(filename[i]); + } for( i = 0; i < ARRAYLENGTH(itemdb->array); ++i ) { if( itemdb->array[i] ) { @@ -2034,18 +2034,13 @@ int itemdb_final_sub(DBKey key, DBData *data, va_list ap) return 0; } - -void itemdb_reload(void) { - struct s_mapiterator* iter; - struct map_session_data* sd; - - int i,d,k; - +void itemdb_clear(bool total) { + int i; // clear the previous itemdb data for( i = 0; i < ARRAYLENGTH(itemdb->array); ++i ) if( itemdb->array[i] ) itemdb->destroy_item_data(itemdb->array[i], 1); - + for( i = 0; i < itemdb->group_count; i++ ) { if( itemdb->groups[i].nameid ) aFree(itemdb->groups[i].nameid); @@ -2084,12 +2079,24 @@ void itemdb_reload(void) { itemdb->packages = NULL; itemdb->package_count = 0; + if( total ) + return; + itemdb->other->clear(itemdb->other, itemdb->final_sub); memset(itemdb->array, 0, sizeof(itemdb->array)); db_clear(itemdb->names); - + +} +void itemdb_reload(void) { + struct s_mapiterator* iter; + struct map_session_data* sd; + + int i,d,k; + + itemdb->clear(false); + // read new data itemdb->read(false); @@ -2160,41 +2167,8 @@ void itemdb_force_name_constants(void) { dbi_destroy(iter); } void do_final_itemdb(void) { - int i; - - for( i = 0; i < ARRAYLENGTH(itemdb->array); ++i ) - if( itemdb->array[i] ) - itemdb->destroy_item_data(itemdb->array[i], 1); - - for( i = 0; i < itemdb->group_count; i++ ) { - if( itemdb->groups[i].nameid ) - aFree(itemdb->groups[i].nameid); - } - - if( itemdb->groups ) - aFree(itemdb->groups); - - for( i = 0; i < itemdb->chain_count; i++ ) { - if( itemdb->chains[i].items ) - aFree(itemdb->chains[i].items); - } - - if( itemdb->chains ) - aFree(itemdb->chains); - - for( i = 0; i < itemdb->package_count; i++ ) { - int c; - for( c = 0; c < itemdb->packages[i].random_qty; c++ ) - aFree(itemdb->packages[i].random_groups[c].random_list); - if( itemdb->packages[i].random_groups ) - aFree(itemdb->packages[i].random_groups); - if( itemdb->packages[i].must_items ) - aFree(itemdb->packages[i].must_items); - } + itemdb->clear(true); - if( itemdb->packages ) - aFree(itemdb->packages); - itemdb->other->destroy(itemdb->other, itemdb->final_sub); itemdb->destroy_item_data(&itemdb->dummy, 0); db_destroy(itemdb->names); @@ -2295,4 +2269,5 @@ void itemdb_defaults(void) { itemdb->read = itemdb_read; itemdb->destroy_item_data = destroy_item_data; itemdb->final_sub = itemdb_final_sub; + itemdb->clear = itemdb_clear; } diff --git a/src/map/itemdb.h b/src/map/itemdb.h index 870ecce58..533a808bc 100644 --- a/src/map/itemdb.h +++ b/src/map/itemdb.h @@ -349,13 +349,14 @@ struct itemdb_interface { int (*validate_entry) (struct item_data *entry, int n, const char *source); int (*readdb_sql_sub) (Sql *handle, int n, const char *source); int (*readdb_libconfig_sub) (config_setting_t *it, int n, const char *source); - int (*readdb) (void); + int (*readdb) (const char *filename); int (*read_sqldb) (void); uint64 (*unique_id) (int8 flag, int64 value); int (*uid_load) (); void (*read) (bool minimal); void (*destroy_item_data) (struct item_data *self, int free_self); int (*final_sub) (DBKey key, DBData *data, va_list ap); + void (*clear) (bool total); }; struct itemdb_interface *itemdb; diff --git a/src/map/map.c b/src/map/map.c index b846d6125..b0ae2f340 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -5438,6 +5438,7 @@ int do_init(int argc, char *argv[]) HPM->event(HPET_PRE_INIT); + minimal = map->minimal;/* temp (perhaps make minimal a mask with options of what to load? e.g. plugin 1 does minimal |= mob_db; */ for( i = 1; i < argc ; i++ ) { const char* arg = argv[i]; @@ -5619,12 +5620,17 @@ int do_init(int argc, char *argv[]) duel->init(minimal); vending->init(minimal); - if (minimal) { + if (scriptcheck) { if (npc->parsesrcfile(scriptcheck, false) == 0) exit(EXIT_SUCCESS); exit(EXIT_FAILURE); } + if( minimal ) { + HPM->event(HPET_READY); + exit(EXIT_SUCCESS); + } + npc->event_do_oninit(); // Init npcs (OnInit) if (battle_config.pk_mode) @@ -5659,6 +5665,7 @@ void map_defaults(void) { map = &map_s; /* */ + map->minimal = false; map->count = 0; sprintf(map->db_path ,"db"); diff --git a/src/map/map.h b/src/map/map.h index 4b2671702..4cb00f144 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -800,6 +800,7 @@ struct map_cache_map_info { struct map_interface { /* vars */ + bool minimal; int count; int autosave_interval; |