Storage types optimization fixes

* Fixed guild storage getting reset on server restart.
* Adjusted a guild bound item acknowledgment attempting to create guild storage data if not found.
* Added expire_time to guild storage data.
* Added some missing random option item checks.
Thanks to @Jeybla!
This commit is contained in:
aleos89 2016-09-06 13:16:14 -04:00
parent adbabeeef5
commit c3a308ffdb
2 changed files with 48 additions and 12 deletions

View File

@ -61,7 +61,8 @@ static bool inventory_fromsql(uint32 char_id, struct s_storage* p)
struct item tmp_item;
memset(p, 0, sizeof(struct s_storage)); //clean up memory
p->amount = 0;
p->id = char_id;
p->type = TABLE_INVENTORY;
stmt = SqlStmt_Malloc(sql_handle);
if (stmt == NULL) {
@ -69,11 +70,16 @@ static bool inventory_fromsql(uint32 char_id, struct s_storage* p)
return false;
}
// storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`/`option_id0`/`option_val0`/`option_parm0`/`option_id1`/`option_val1`/`option_parm1`/`option_id2`/`option_val2`/`option_parm2`/`option_id3`/`option_val3`/`option_parm3`/`option_id4`/`option_val4`/`option_parm4`}
// storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`expire_time`/`favorite`/`bound`/`unique_id`/`card0`/`card1`/`card2`/`card3`/`option_id0`/`option_val0`/`option_parm0`/`option_id1`/`option_val1`/`option_parm1`/`option_id2`/`option_val2`/`option_parm2`/`option_id3`/`option_val3`/`option_parm3`/`option_id4`/`option_val4`/`option_parm4`}
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `bound`, `unique_id`");
for( i = 0; i < MAX_SLOTS; ++i )
StringBuf_Printf(&buf, ", `card%d`", i);
for( i = 0; i < MAX_ITEM_RDM_OPT; ++i ) {
StringBuf_Printf(&buf, ", `option_id%d`", i);
StringBuf_Printf(&buf, ", `option_val%d`", i);
StringBuf_Printf(&buf, ", `option_parm%d`", i);
}
StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", schema_config.inventory_db, MAX_INVENTORY);
if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
@ -99,6 +105,11 @@ static bool inventory_fromsql(uint32 char_id, struct s_storage* p)
SqlStmt_BindColumn(stmt,10, SQLDT_ULONGLONG, &tmp_item.unique_id, 0, NULL, NULL);
for( i = 0; i < MAX_SLOTS; ++i )
SqlStmt_BindColumn(stmt, 11+i, SQLDT_USHORT, &tmp_item.card[i], 0, NULL, NULL);
for( i = 0; i < MAX_ITEM_RDM_OPT; ++i ) {
SqlStmt_BindColumn(stmt, 11+MAX_SLOTS+i*3, SQLDT_SHORT, &tmp_item.option[i].id, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 12+MAX_SLOTS+i*3, SQLDT_SHORT, &tmp_item.option[i].value, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 13+MAX_SLOTS+i*3, SQLDT_CHAR, &tmp_item.option[i].param, 0, NULL, NULL);
}
for( i = 0; i < MAX_INVENTORY && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i )
memcpy(&p->u.items_inventory[i], &tmp_item, sizeof(tmp_item));
@ -126,7 +137,8 @@ static bool cart_fromsql(uint32 char_id, struct s_storage* p)
struct item tmp_item;
memset(p, 0, sizeof(struct s_storage)); //clean up memory
p->amount = 0;
p->id = char_id;
p->type = TABLE_CART;
stmt = SqlStmt_Malloc(sql_handle);
if (stmt == NULL) {
@ -134,6 +146,7 @@ static bool cart_fromsql(uint32 char_id, struct s_storage* p)
return false;
}
// storage {`char_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`expire_time`/`bound`/`unique_id`/`card0`/`card1`/`card2`/`card3`/`option_id0`/`option_val0`/`option_parm0`/`option_id1`/`option_val1`/`option_parm1`/`option_id2`/`option_val2`/`option_parm2`/`option_id3`/`option_val3`/`option_parm3`/`option_id4`/`option_val4`/`option_parm4`}
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`, `unique_id`");
for( j = 0; j < MAX_SLOTS; ++j )
@ -167,6 +180,11 @@ static bool cart_fromsql(uint32 char_id, struct s_storage* p)
SqlStmt_BindColumn(stmt, 9, SQLDT_ULONGLONG, &tmp_item.unique_id, 0, NULL, NULL);
for( i = 0; i < MAX_SLOTS; ++i )
SqlStmt_BindColumn(stmt, 10+i, SQLDT_USHORT, &tmp_item.card[i], 0, NULL, NULL);
for( i = 0; i < MAX_ITEM_RDM_OPT; ++i ) {
SqlStmt_BindColumn(stmt, 10+MAX_SLOTS+i*3, SQLDT_SHORT, &tmp_item.option[i].id, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 11+MAX_SLOTS+i*3, SQLDT_SHORT, &tmp_item.option[i].value, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 12+MAX_SLOTS+i*3, SQLDT_CHAR, &tmp_item.option[i].param, 0, NULL, NULL);
}
for( i = 0; i < MAX_CART && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i )
memcpy(&p->u.items_cart[i], &tmp_item, sizeof(tmp_item));
@ -194,7 +212,8 @@ static bool storage_fromsql(uint32 account_id, struct s_storage* p)
struct item tmp_item;
memset(p, 0, sizeof(struct s_storage)); //clean up memory
p->amount = 0;
p->id = account_id;
p->type = TABLE_STORAGE;
stmt = SqlStmt_Malloc(sql_handle);
if (stmt == NULL) {
@ -202,10 +221,16 @@ static bool storage_fromsql(uint32 account_id, struct s_storage* p)
return false;
}
// storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`/`option_id0`/`option_val0`/`option_parm0`/`option_id1`/`option_val1`/`option_parm1`/`option_id2`/`option_val2`/`option_parm2`/`option_id3`/`option_val3`/`option_parm3`/`option_id4`/`option_val4`/`option_parm4`}
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`, `unique_id`");
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ", `card%d`", j);
for( i = 0; i < MAX_ITEM_RDM_OPT; ++i ) {
StringBuf_Printf(&buf, ", `option_id%d`", i);
StringBuf_Printf(&buf, ", `option_val%d`", i);
StringBuf_Printf(&buf, ", `option_parm%d`", i);
}
StringBuf_Printf(&buf, " FROM `%s` WHERE `account_id`=? ORDER BY `nameid` LIMIT %d", schema_config.storage_db, account_id, MAX_STORAGE);
if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
@ -230,6 +255,11 @@ static bool storage_fromsql(uint32 account_id, struct s_storage* p)
SqlStmt_BindColumn(stmt, 9, SQLDT_ULONGLONG, &tmp_item.unique_id, 0, NULL, NULL);
for( i = 0; i < MAX_SLOTS; ++i )
SqlStmt_BindColumn(stmt, 10+i, SQLDT_USHORT, &tmp_item.card[i], 0, NULL, NULL);
for( i = 0; i < MAX_ITEM_RDM_OPT; ++i ) {
SqlStmt_BindColumn(stmt, 10+MAX_SLOTS+i*3, SQLDT_SHORT, &tmp_item.option[i].id, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 11+MAX_SLOTS+i*3, SQLDT_SHORT, &tmp_item.option[i].value, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 12+MAX_SLOTS+i*3, SQLDT_CHAR, &tmp_item.option[i].param, 0, NULL, NULL);
}
for( i = 0; i < MAX_STORAGE && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i )
memcpy(&p->u.items_storage[i], &tmp_item, sizeof(tmp_item));
@ -269,7 +299,8 @@ bool guild_storage_fromsql(int guild_id, struct s_storage* p)
struct item tmp_item;
memset(p, 0, sizeof(struct s_storage)); //clean up memory
p->amount = 0;
p->id = guild_id;
p->type = TABLE_GUILD_STORAGE;
stmt = SqlStmt_Malloc(sql_handle);
if (stmt == NULL) {
@ -277,9 +308,9 @@ bool guild_storage_fromsql(int guild_id, struct s_storage* p)
return false;
}
// storage {`guild_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`/`option_id0`/`option_val0`/`option_parm0`/`option_id1`/`option_val1`/`option_parm1`/`option_id2`/`option_val2`/`option_parm2`/`option_id3`/`option_val3`/`option_parm3`/`option_id4`/`option_val4`/`option_parm4`}
// storage {`guild_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`expire_time`/`bound`/`unique_id`/`card0`/`card1`/`card2`/`card3`/`option_id0`/`option_val0`/`option_parm0`/`option_id1`/`option_val1`/`option_parm1`/`option_id2`/`option_val2`/`option_parm2`/`option_id3`/`option_val3`/`option_parm3`/`option_id4`/`option_val4`/`option_parm4`}
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`bound`,`unique_id`");
StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`,`bound`,`unique_id`");
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ",`card%d`", j);
for( j = 0; j < MAX_ITEM_RDM_OPT; ++j ) {
@ -306,11 +337,16 @@ bool guild_storage_fromsql(int guild_id, struct s_storage* p)
SqlStmt_BindColumn(stmt, 4, SQLDT_CHAR, &tmp_item.identify, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 5, SQLDT_CHAR, &tmp_item.refine, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 6, SQLDT_CHAR, &tmp_item.attribute, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 7, SQLDT_CHAR, &tmp_item.bound, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 8, SQLDT_ULONGLONG, &tmp_item.unique_id, 0, NULL, NULL);
tmp_item.expire_time = 0;
SqlStmt_BindColumn(stmt, 7, SQLDT_UINT, &tmp_item.expire_time, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 8, SQLDT_CHAR, &tmp_item.bound, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 9, SQLDT_ULONGLONG, &tmp_item.unique_id, 0, NULL, NULL);
for( i = 0; i < MAX_SLOTS; ++i )
SqlStmt_BindColumn(stmt, 9+i, SQLDT_USHORT, &tmp_item.card[i], 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 10+i, SQLDT_USHORT, &tmp_item.card[i], 0, NULL, NULL);
for( i = 0; i < MAX_ITEM_RDM_OPT; ++i ) {
SqlStmt_BindColumn(stmt, 10+MAX_SLOTS+i*3, SQLDT_SHORT, &tmp_item.option[i].id, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 11+MAX_SLOTS+i*3, SQLDT_SHORT, &tmp_item.option[i].value, 0, NULL, NULL);
SqlStmt_BindColumn(stmt, 12+MAX_SLOTS+i*3, SQLDT_CHAR, &tmp_item.option[i].param, 0, NULL, NULL);
}
for( i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i )
memcpy(&p->u.items_guild[i], &tmp_item, sizeof(tmp_item));

View File

@ -3099,7 +3099,7 @@ void intif_itembound_guild_retrieve(uint32 char_id,uint32 account_id,int guild_i
*/
void intif_parse_itembound_ack(int fd) {
int guild_id = RFIFOW(fd,6);
struct s_storage *gstor = guild2storage(guild_id);
struct s_storage *gstor = guild2storage2(guild_id);
if (gstor)
gstor->lock = false; //Unlock now that operation is completed
}