mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-15 16:41:29 +00:00
GetSharedBank converted to QueryDatabase
This commit is contained in:
parent
4a3f94e688
commit
aa780ceb8c
@ -382,103 +382,98 @@ bool SharedDatabase::SetStartingItems(PlayerProfile_Struct* pp, Inventory* inv,
|
|||||||
|
|
||||||
// Retrieve shared bank inventory based on either account or character
|
// Retrieve shared bank inventory based on either account or character
|
||||||
bool SharedDatabase::GetSharedBank(uint32 id, Inventory* inv, bool is_charid) {
|
bool SharedDatabase::GetSharedBank(uint32 id, Inventory* inv, bool is_charid) {
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
std::string query;
|
||||||
char* query = 0;
|
|
||||||
uint32 len_query = 0;
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
if (is_charid) {
|
if (is_charid)
|
||||||
len_query = MakeAnyLenString(&query,
|
query = StringFormat("SELECT sb.slotid, sb.itemid, sb.charges, "
|
||||||
"SELECT sb.slotid,sb.itemid,sb.charges,sb.augslot1,sb.augslot2,sb.augslot3,sb.augslot4,sb.augslot5,sb.custom_data from sharedbank sb "
|
"sb.augslot1, sb.augslot2, sb.augslot3, "
|
||||||
"INNER JOIN character_data ch ON ch.account_id=sb.acctid "
|
"sb.augslot4, sb.augslot5, sb.custom_data "
|
||||||
"WHERE ch.id=%i", id);
|
"FROM sharedbank sb INNER JOIN character_data ch "
|
||||||
}
|
"ON ch.account_id=sb.acctid WHERE ch.id = %i", id);
|
||||||
else {
|
else
|
||||||
len_query = MakeAnyLenString(&query,
|
query = StringFormat("SELECT slotid, itemid, charges, "
|
||||||
"SELECT slotid,itemid,charges,augslot1,augslot2,augslot3,augslot4,augslot5,custom_data from sharedbank WHERE acctid=%i", id);
|
"augslot1, augslot2, augslot3, "
|
||||||
}
|
"augslot4, augslot5, custom_data "
|
||||||
|
"FROM sharedbank WHERE acctid=%i", id);
|
||||||
|
auto results = QueryDatabase(query);
|
||||||
|
if (!results.Success()) {
|
||||||
|
LogFile->write(EQEMuLog::Error, "Database::GetSharedBank(uint32 account_id): %s", results.ErrorMessage().c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (RunQuery(query, len_query, errbuf, &result)) {
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
while ((row = mysql_fetch_row(result))) {
|
int16 slot_id = (int16)atoi(row[0]);
|
||||||
int16 slot_id = (int16)atoi(row[0]);
|
uint32 item_id = (uint32)atoi(row[1]);
|
||||||
uint32 item_id = (uint32)atoi(row[1]);
|
int8 charges = (int8)atoi(row[2]);
|
||||||
int8 charges = (int8)atoi(row[2]);
|
|
||||||
uint32 aug[EmuConstants::ITEM_COMMON_SIZE];
|
|
||||||
aug[0] = (uint32)atoi(row[3]);
|
|
||||||
aug[1] = (uint32)atoi(row[4]);
|
|
||||||
aug[2] = (uint32)atoi(row[5]);
|
|
||||||
aug[3] = (uint32)atoi(row[6]);
|
|
||||||
aug[4] = (uint32)atoi(row[7]);
|
|
||||||
const Item_Struct* item = GetItem(item_id);
|
|
||||||
|
|
||||||
if (item) {
|
uint32 aug[EmuConstants::ITEM_COMMON_SIZE];
|
||||||
int16 put_slot_id = INVALID_INDEX;
|
aug[0] = (uint32)atoi(row[3]);
|
||||||
|
aug[1] = (uint32)atoi(row[4]);
|
||||||
|
aug[2] = (uint32)atoi(row[5]);
|
||||||
|
aug[3] = (uint32)atoi(row[6]);
|
||||||
|
aug[4] = (uint32)atoi(row[7]);
|
||||||
|
|
||||||
ItemInst* inst = CreateBaseItem(item, charges);
|
const Item_Struct* item = GetItem(item_id);
|
||||||
if (item->ItemClass == ItemClassCommon) {
|
|
||||||
for(int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) {
|
|
||||||
if (aug[i]) {
|
|
||||||
inst->PutAugment(this, i, aug[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(row[8]) {
|
|
||||||
std::string data_str(row[8]);
|
|
||||||
std::string id;
|
|
||||||
std::string value;
|
|
||||||
bool use_id = true;
|
|
||||||
|
|
||||||
for(int i = 0; i < data_str.length(); ++i) {
|
if (!item) {
|
||||||
if(data_str[i] == '^') {
|
LogFile->write(EQEMuLog::Error,
|
||||||
if(!use_id) {
|
|
||||||
inst->SetCustomData(id, value);
|
|
||||||
id.clear();
|
|
||||||
value.clear();
|
|
||||||
}
|
|
||||||
use_id = !use_id;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
char v = data_str[i];
|
|
||||||
if(use_id) {
|
|
||||||
id.push_back(v);
|
|
||||||
} else {
|
|
||||||
value.push_back(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
put_slot_id = inv->PutItem(slot_id, *inst);
|
|
||||||
safe_delete(inst);
|
|
||||||
|
|
||||||
// Save ptr to item in inventory
|
|
||||||
if (put_slot_id == INVALID_INDEX) {
|
|
||||||
LogFile->write(EQEMuLog::Error,
|
|
||||||
"Warning: Invalid slot_id for item in shared bank inventory: %s=%i, item_id=%i, slot_id=%i",
|
|
||||||
((is_charid==true) ? "charid" : "acctid"), id, item_id, slot_id);
|
|
||||||
|
|
||||||
if (is_charid)
|
|
||||||
SaveInventory(id, nullptr, slot_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LogFile->write(EQEMuLog::Error,
|
|
||||||
"Warning: %s %i has an invalid item_id %i in inventory slot %i",
|
"Warning: %s %i has an invalid item_id %i in inventory slot %i",
|
||||||
((is_charid==true) ? "charid" : "acctid"), id, item_id, slot_id);
|
((is_charid==true) ? "charid" : "acctid"), id, item_id, slot_id);
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
mysql_free_result(result);
|
int16 put_slot_id = INVALID_INDEX;
|
||||||
ret = true;
|
|
||||||
}
|
ItemInst* inst = CreateBaseItem(item, charges);
|
||||||
else {
|
if (item->ItemClass == ItemClassCommon) {
|
||||||
LogFile->write(EQEMuLog::Error, "Database::GetSharedBank(uint32 account_id): %s", errbuf);
|
for(int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) {
|
||||||
|
if (aug[i]) {
|
||||||
|
inst->PutAugment(this, i, aug[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!row[8])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::string data_str(row[8]);
|
||||||
|
std::string idAsString;
|
||||||
|
std::string value;
|
||||||
|
bool use_id = true;
|
||||||
|
|
||||||
|
for(int i = 0; i < data_str.length(); ++i) {
|
||||||
|
if(data_str[i] == '^') {
|
||||||
|
if(!use_id) {
|
||||||
|
inst->SetCustomData(idAsString, value);
|
||||||
|
idAsString.clear();
|
||||||
|
value.clear();
|
||||||
|
}
|
||||||
|
use_id = !use_id;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
char v = data_str[i];
|
||||||
|
if(use_id)
|
||||||
|
idAsString.push_back(v);
|
||||||
|
else
|
||||||
|
value.push_back(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
put_slot_id = inv->PutItem(slot_id, *inst);
|
||||||
|
safe_delete(inst);
|
||||||
|
|
||||||
|
// Save ptr to item in inventory
|
||||||
|
if (put_slot_id != INVALID_INDEX)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
LogFile->write(EQEMuLog::Error, "Warning: Invalid slot_id for item in shared bank inventory: %s=%i, item_id=%i, slot_id=%i",
|
||||||
|
((is_charid==true)? "charid": "acctid"), id, item_id, slot_id);
|
||||||
|
|
||||||
|
if (is_charid)
|
||||||
|
SaveInventory(id, nullptr, slot_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_delete_array(query);
|
return true;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user