VerifyInventory converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-10-04 13:32:01 -07:00
parent 95208eb24e
commit 2fbd170188

View File

@ -123,39 +123,36 @@ bool SharedDatabase::SaveCursor(uint32 char_id, std::list<ItemInst*>::const_iter
bool SharedDatabase::VerifyInventory(uint32 account_id, int16 slot_id, const ItemInst* inst) bool SharedDatabase::VerifyInventory(uint32 account_id, int16 slot_id, const ItemInst* inst)
{ {
char errbuf[MYSQL_ERRMSG_SIZE];
char* query = 0;
MYSQL_RES *result;
MYSQL_ROW row;
// Delete cursor items // Delete cursor items
if (!RunQuery(query, MakeAnyLenString(&query, std::string query = StringFormat("SELECT itemid, charges FROM sharedbank "
"SELECT itemid,charges FROM sharedbank "
"WHERE acctid = %d AND slotid = %d", "WHERE acctid = %d AND slotid = %d",
account_id, slot_id), errbuf, &result)) { account_id, slot_id);
LogFile->write(EQEMuLog::Error, "Error runing inventory verification query '%s': %s", query, errbuf); auto results = QueryDatabase(query);
safe_delete_array(query); if (!results.Success()) {
LogFile->write(EQEMuLog::Error, "Error runing inventory verification query '%s': %s", query.c_str(), results.ErrorMessage().c_str());
//returning true is less harmful in the face of a query error //returning true is less harmful in the face of a query error
return(true); return true;
} }
safe_delete_array(query);
row = mysql_fetch_row(result); if (results.RowCount() == 0)
bool found = false; return false;
if(row) {
auto row = results.begin();
uint32 id = atoi(row[0]); uint32 id = atoi(row[0]);
uint16 charges = atoi(row[1]); uint16 charges = atoi(row[1]);
uint16 expect_charges = 0; uint16 expect_charges = 0;
if(inst->GetCharges() >= 0) if(inst->GetCharges() >= 0)
expect_charges = inst->GetCharges(); expect_charges = inst->GetCharges();
else else
expect_charges = 0x7FFF; expect_charges = 0x7FFF;
if(id == inst->GetItem()->ID && charges == expect_charges) if(id != inst->GetItem()->ID || charges != expect_charges)
found = true; return false;
}
mysql_free_result(result); return true;
return(found);
} }
bool SharedDatabase::SaveInventory(uint32 char_id, const ItemInst* inst, int16 slot_id) { bool SharedDatabase::SaveInventory(uint32 char_id, const ItemInst* inst, int16 slot_id) {