From dd49dbc3e8d2033c0dddc80f1d5b3c8e6710a419 Mon Sep 17 00:00:00 2001 From: Ibrahim Hossam Date: Tue, 8 Apr 2014 20:40:12 +0200 Subject: 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. --- src/char/char.c | 16 ++++++---------- src/char/int_auction.c | 4 ---- src/char/int_mail.c | 4 ---- src/char/inter.c | 19 ------------------- src/char/inter.h | 13 ------------- 5 files changed, 6 insertions(+), 50 deletions(-) (limited to 'src/char') diff --git a/src/char/char.c b/src/char/char.c index d460e4c85..a4bc9cef9 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_ */ -- cgit v1.2.3-70-g09d2