diff options
author | Ibrahim Hossam <ibrahem.h.basyone@gmail.com> | 2014-04-08 20:40:12 +0200 |
---|---|---|
committer | Ibrahim Hossam <ibrahem.h.basyone@gmail.com> | 2014-04-18 09:58:42 +0200 |
commit | dd49dbc3e8d2033c0dddc80f1d5b3c8e6710a419 (patch) | |
tree | 219025c6ac65f2cf72798a45c926507633f3446f /src/map/itemdb.c | |
parent | 47680829048288376aec23102b9660f36f4463ee (diff) | |
download | hercules-dd49dbc3e8d2033c0dddc80f1d5b3c8e6710a419.tar.gz hercules-dd49dbc3e8d2033c0dddc80f1d5b3c8e6710a419.tar.bz2 hercules-dd49dbc3e8d2033c0dddc80f1d5b3c8e6710a419.tar.xz hercules-dd49dbc3e8d2033c0dddc80f1d5b3c8e6710a419.zip |
Rewritten NSI_UNIQUE_ID system to get rid of the cross-database interreg dependency
- Removes the need for map-server to access the interreg table to store the last used ID.
- Login, char and map databases can now be hosted separately.
- Note: the unique_id structure has changed, and it now contains the generator character ID in its upper 32 bits.
- Now NSI_UNIQUE_ID System is enabled always
Special thanks to Haruna.
Diffstat (limited to 'src/map/itemdb.c')
-rw-r--r-- | src/map/itemdb.c | 42 |
1 files changed, 3 insertions, 39 deletions
diff --git a/src/map/itemdb.c b/src/map/itemdb.c index bfcc6f795..abe899412 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -1966,44 +1966,10 @@ int itemdb_readdb_sql(const char *tablename) { /*========================================== * Unique item ID function * Only one operation by once -* Flag: -* 0 return new id -* 1 set new value, checked with current value -* 2 set new value bypassing anything -* 3/other return last value *------------------------------------------*/ -uint64 itemdb_unique_id(int8 flag, int64 value) { - static uint64 item_uid = 0; - - if(flag) - { - if(flag == 1) - { if(item_uid < value) - return (item_uid = value); - }else if(flag == 2) - return (item_uid = value); - - return item_uid; - } - - return ++item_uid; -} -int itemdb_uid_load() { - char * uid; - if (SQL_ERROR == SQL->Query(map->mysql_handle, "SELECT `value` FROM `%s` WHERE `varname`='unique_id'",map->interreg_db)) - Sql_ShowDebug(map->mysql_handle); +uint64 itemdb_unique_id(struct map_session_data *sd) { - if( SQL_SUCCESS != SQL->NextRow(map->mysql_handle) ) { - ShowError("itemdb_uid_load: Unable to fetch unique_id data\n"); - SQL->FreeResult(map->mysql_handle); - return -1; - } - - SQL->GetData(map->mysql_handle, 0, &uid, NULL); - itemdb->unique_id(1, (uint64)strtoull(uid, NULL, 10)); - SQL->FreeResult(map->mysql_handle); - - return 0; + return ((uint64)sd->status.char_id << 32) | sd->status.uniqueitem_counter++; } /** @@ -2057,8 +2023,7 @@ void itemdb_read(bool minimal) { sv->readdb(map->db_path, "item_stack.txt", ',', 3, 3, -1, itemdb->read_stack); sv->readdb(map->db_path, DBPATH"item_buyingstore.txt", ',', 1, 1, -1, itemdb->read_buyingstore); sv->readdb(map->db_path, "item_nouse.txt", ',', 3, 3, -1, itemdb->read_nouse); - - itemdb->uid_load(); + } /** @@ -2348,7 +2313,6 @@ void itemdb_defaults(void) { itemdb->readdb_libconfig = itemdb_readdb_libconfig; itemdb->readdb_sql = itemdb_readdb_sql; itemdb->unique_id = itemdb_unique_id; - itemdb->uid_load = itemdb_uid_load; itemdb->read = itemdb_read; itemdb->destroy_item_data = destroy_item_data; itemdb->final_sub = itemdb_final_sub; |