diff options
author | Haruna <haru@dotalux.com> | 2014-04-19 22:37:54 +0200 |
---|---|---|
committer | Haruna <haru@dotalux.com> | 2014-04-19 22:37:54 +0200 |
commit | 93584f7416164985220293b7c08fcc29c4d5060f (patch) | |
tree | 2f2f533682e54dfe501ff4a470953e3a6bd2462f /src | |
parent | cebfdc692ef4a5897c69304f88e585f8f1272c7e (diff) | |
parent | dd49dbc3e8d2033c0dddc80f1d5b3c8e6710a419 (diff) | |
download | hercules-93584f7416164985220293b7c08fcc29c4d5060f.tar.gz hercules-93584f7416164985220293b7c08fcc29c4d5060f.tar.bz2 hercules-93584f7416164985220293b7c08fcc29c4d5060f.tar.xz hercules-93584f7416164985220293b7c08fcc29c4d5060f.zip |
Merge pull request #272 from hemagx/master
Rewritten NSI_UNIQUE_ID system
Diffstat (limited to 'src')
-rw-r--r-- | src/char/char.c | 16 | ||||
-rw-r--r-- | src/char/int_auction.c | 4 | ||||
-rw-r--r-- | src/char/int_mail.c | 4 | ||||
-rw-r--r-- | src/char/inter.c | 19 | ||||
-rw-r--r-- | src/char/inter.h | 13 | ||||
-rw-r--r-- | src/common/mmo.h | 2 | ||||
-rw-r--r-- | src/config/core.h | 4 | ||||
-rw-r--r-- | src/map/itemdb.c | 42 | ||||
-rw-r--r-- | src/map/itemdb.h | 3 | ||||
-rw-r--r-- | src/map/pc.c | 6 |
10 files changed, 15 insertions, 98 deletions
diff --git a/src/char/char.c b/src/char/char.c index 1820c4b0c..cf961fd93 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -469,7 +469,8 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) (p->ele_id != cp->ele_id) || (p->shield != cp->shield) || (p->head_top != cp->head_top) || (p->head_mid != cp->head_mid) || (p->head_bottom != cp->head_bottom) || (p->delete_date != cp->delete_date) || (p->rename != cp->rename) || (p->slotchange != cp->slotchange) || (p->robe != cp->robe) || - (p->show_equip != cp->show_equip) || (p->allow_party != cp->allow_party) || (p->font != cp->font) + (p->show_equip != cp->show_equip) || (p->allow_party != cp->allow_party) || (p->font != cp->font) || + (p->uniqueitem_counter != cp->uniqueitem_counter ) ) { //Save status unsigned int opt = 0; @@ -485,7 +486,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) "`option`='%d',`party_id`='%d',`guild_id`='%d',`pet_id`='%d',`homun_id`='%d',`elemental_id`='%d'," "`weapon`='%d',`shield`='%d',`head_top`='%d',`head_mid`='%d',`head_bottom`='%d'," "`last_map`='%s',`last_x`='%d',`last_y`='%d',`save_map`='%s',`save_x`='%d',`save_y`='%d', `rename`='%d'," - "`delete_date`='%lu',`robe`='%d',`slotchange`='%d', `char_opt`='%u', `font`='%u'" + "`delete_date`='%lu',`robe`='%d',`slotchange`='%d', `char_opt`='%u', `font`='%u', `uniqueitem_counter` ='%u'" " WHERE `account_id`='%d' AND `char_id` = '%d'", char_db, p->base_level, p->job_level, p->base_exp, p->job_exp, p->zeny, @@ -496,7 +497,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus* p) mapindex_id2name(p->last_point.map), p->last_point.x, p->last_point.y, mapindex_id2name(p->save_point.map), p->save_point.x, p->save_point.y, p->rename, (unsigned long)p->delete_date, // FIXME: platform-dependent size - p->robe,p->slotchange,opt,p->font, + p->robe,p->slotchange,opt,p->font,p->uniqueitem_counter, p->account_id, p->char_id) ) { Sql_ShowDebug(sql_handle); @@ -841,10 +842,7 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit for( j = 0; j < MAX_SLOTS; ++j ) StrBuf->Printf(&buf, ", '%d'", items[i].card[j]); StrBuf->AppendStr(&buf, ")"); - - updateLastUid(items[i].unique_id); // Unique Non Stackable Item ID } - dbUpdateUid(sql_handle); // Unique Non Stackable Item ID if( found && SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { @@ -982,10 +980,7 @@ int inventory_to_sql(const struct item items[], int max, int id) { for( j = 0; j < MAX_SLOTS; ++j ) StrBuf->Printf(&buf, ", '%d'", items[i].card[j]); StrBuf->AppendStr(&buf, ")"); - - updateLastUid(items[i].unique_id);// Unique Non Stackable Item ID } - dbUpdateUid(sql_handle); if( found && SQL_ERROR == SQL->QueryStr(sql_handle, StrBuf->Value(&buf)) ) { Sql_ShowDebug(sql_handle); @@ -1130,7 +1125,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything "`status_point`,`skill_point`,`option`,`karma`,`manner`,`party_id`,`guild_id`,`pet_id`,`homun_id`,`elemental_id`,`hair`," "`hair_color`,`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`,`last_map`,`last_x`,`last_y`," "`save_map`,`save_x`,`save_y`,`partner_id`,`father`,`mother`,`child`,`fame`,`rename`,`delete_date`,`robe`,`slotchange`," - "`char_opt`,`font`" + "`char_opt`,`font`,`uniqueitem_counter`" " FROM `%s` WHERE `char_id`=? LIMIT 1", char_db) || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0) || SQL_ERROR == SQL->StmtExecute(stmt) @@ -1189,6 +1184,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything || SQL_ERROR == SQL->StmtBindColumn(stmt, 52, SQLDT_USHORT, &p->slotchange, 0, NULL, NULL) || SQL_ERROR == SQL->StmtBindColumn(stmt, 53, SQLDT_UINT, &opt, 0, NULL, NULL) || SQL_ERROR == SQL->StmtBindColumn(stmt, 54, SQLDT_UCHAR, &p->font, 0, NULL, NULL) + || SQL_ERROR == SQL->StmtBindColumn(stmt, 55, SQLDT_UINT, &p->uniqueitem_counter, 0, NULL, NULL) ) { SqlStmt_ShowDebug(stmt); diff --git a/src/char/int_auction.c b/src/char/int_auction.c index 47f3421c3..924930867 100644 --- a/src/char/int_auction.c +++ b/src/char/int_auction.c @@ -90,10 +90,6 @@ unsigned int auction_create(struct auction_data *auction) for( j = 0; j < MAX_SLOTS; j++ ) StrBuf->Printf(&buf, ",'%d'", auction->item.card[j]); StrBuf->AppendStr(&buf, ")"); - - //Unique Non Stackable Item ID - updateLastUid(auction->item.unique_id); - dbUpdateUid(sql_handle); stmt = SQL->StmtMalloc(sql_handle); if( SQL_SUCCESS != SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf)) diff --git a/src/char/int_mail.c b/src/char/int_mail.c index b69824d4b..826771676 100644 --- a/src/char/int_mail.c +++ b/src/char/int_mail.c @@ -117,10 +117,6 @@ int mail_savemessage(struct mail_message* msg) for (j = 0; j < MAX_SLOTS; j++) StrBuf->Printf(&buf, ", '%d'", msg->item.card[j]); StrBuf->AppendStr(&buf, ")"); - - //Unique Non Stackable Item ID - updateLastUid(msg->item.unique_id); - dbUpdateUid(sql_handle); // prepare and execute query stmt = SQL->StmtMalloc(sql_handle); diff --git a/src/char/inter.c b/src/char/inter.c index 059c33784..6a8412b25 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -1372,23 +1372,4 @@ int inter_parse_frommap(int fd) return 1; } -uint64 inter_chk_lastuid(int8 flag, uint64 value){ - static uint64 last_updt_uid = 0; - static int8 update = 0; - if(flag) - { - if(last_updt_uid < value){ - last_updt_uid = value; - update = 1; - } - - return 0; - }else if(update) - { - update = 0; - return last_updt_uid; - } - return 0; -} - diff --git a/src/char/inter.h b/src/char/inter.h index b484a1610..25b0c2a96 100644 --- a/src/char/inter.h +++ b/src/char/inter.h @@ -29,17 +29,4 @@ extern Sql* lsql_handle; int inter_accreg_tosql(int account_id, int char_id, struct accreg *reg, int type); -uint64 inter_chk_lastuid(int8 flag, uint64 value); -#ifdef NSI_UNIQUE_ID - #define updateLastUid(val_) inter_chk_lastuid(1, (val_)) - #define dbUpdateUid(handler_) do { \ - uint64 unique_id_ = inter_chk_lastuid(0, 0); \ - if (unique_id_ && SQL_ERROR == SQL->Query((handler_), "UPDATE `%s` SET `value`='%"PRIu64"' WHERE `varname`='unique_id'", interreg_db, unique_id_)) \ - Sql_ShowDebug(handler_);\ - } while(0) -#else - #define dbUpdateUid(handler_) - #define updateLastUid(val_) -#endif - #endif /* _CHAR_INTER_H_ */ diff --git a/src/common/mmo.h b/src/common/mmo.h index 04f3210ca..07a05677f 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -461,6 +461,8 @@ struct mmo_charstatus { unsigned short mod_exp,mod_drop,mod_death; unsigned char font; + + uint32 uniqueitem_counter; }; typedef enum mail_status { diff --git a/src/config/core.h b/src/config/core.h index edd5c2b2a..157d94b2f 100644 --- a/src/config/core.h +++ b/src/config/core.h @@ -57,10 +57,6 @@ /// When uncommented the cap takes place after modifiers. //#define HMAP_ZONE_DAMAGE_CAP_TYPE -/// Uncomment to enable Non Stackable items unique ID -/// By enabling it, the system will create an unique id for each new non stackable item created -//#define NSI_UNIQUE_ID - /// Comment to disable Guild/Party Bound item system #define GP_BOUND_ITEMS 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; diff --git a/src/map/itemdb.h b/src/map/itemdb.h index eebcd5d4d..77fb2e2ec 100644 --- a/src/map/itemdb.h +++ b/src/map/itemdb.h @@ -576,8 +576,7 @@ struct itemdb_interface { int (*readdb_libconfig_sub) (config_setting_t *it, int n, const char *source); int (*readdb_libconfig) (const char *filename); int (*readdb_sql) (const char *tablename); - uint64 (*unique_id) (int8 flag, int64 value); - int (*uid_load) (); + uint64 (*unique_id) (struct map_session_data *sd); 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); diff --git a/src/map/pc.c b/src/map/pc.c index c6bab4cfc..ba66bf7db 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -3992,10 +3992,10 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_l sd->inventory_data[i] = data; clif->additem(sd,i,amount,0); } -#ifdef NSI_UNIQUE_ID + if( !itemdb->isstackable2(data) && !item_data->unique_id ) - sd->status.inventory[i].unique_id = itemdb->unique_id(0,0); -#endif + sd->status.inventory[i].unique_id = itemdb->unique_id(sd); + logs->pick_pc(sd, log_type, amount, &sd->status.inventory[i],sd->inventory_data[i]); sd->weight += w; |