Some clang-formatting

This commit is contained in:
Michael Cook (mackal) 2015-01-31 00:00:02 -05:00
parent a18cb6f61e
commit 0f1b504ed6

View File

@ -477,96 +477,106 @@ bool SharedDatabase::GetSharedBank(uint32 id, Inventory* inv, bool is_charid) {
return true; return true;
} }
// Overloaded: Retrieve character inventory based on character id // Overloaded: Retrieve character inventory based on character id
bool SharedDatabase::GetInventory(uint32 char_id, Inventory* inv) { bool SharedDatabase::GetInventory(uint32 char_id, Inventory *inv)
{
// Retrieve character inventory // Retrieve character inventory
std::string query = StringFormat("SELECT slotid, itemid, charges, color, augslot1, " std::string query =
"augslot2, augslot3, augslot4, augslot5, augslot6, instnodrop, custom_data, ornamenticon, ornamentidfile, ornament_hero_model " StringFormat("SELECT slotid, itemid, charges, color, augslot1, augslot2, augslot3, augslot4, augslot5, "
"FROM inventory WHERE charid = %i ORDER BY slotid", char_id); "augslot6, instnodrop, custom_data, ornamenticon, ornamentidfile, ornament_hero_model FROM "
auto results = QueryDatabase(query); "inventory WHERE charid = %i ORDER BY slotid",
if (!results.Success()) { char_id);
Log.Out(Logs::General, Logs::Error, "If you got an error related to the 'instnodrop' field, run the following SQL Queries:\nalter table inventory add instnodrop tinyint(1) unsigned default 0 not null;\n"); auto results = QueryDatabase(query);
return false; if (!results.Success()) {
} Log.Out(Logs::General, Logs::Error, "If you got an error related to the 'instnodrop' field, run the "
"following SQL Queries:\nalter table inventory add instnodrop "
"tinyint(1) unsigned default 0 not null;\n");
return false;
}
for (auto row = results.begin(); row != results.end(); ++row) { for (auto row = results.begin(); row != results.end(); ++row) {
int16 slot_id = atoi(row[0]); int16 slot_id = atoi(row[0]);
uint32 item_id = atoi(row[1]); uint32 item_id = atoi(row[1]);
uint16 charges = atoi(row[2]); uint16 charges = atoi(row[2]);
uint32 color = atoul(row[3]); uint32 color = atoul(row[3]);
uint32 aug[EmuConstants::ITEM_COMMON_SIZE]; uint32 aug[EmuConstants::ITEM_COMMON_SIZE];
aug[0] = (uint32)atoul(row[4]); aug[0] = (uint32)atoul(row[4]);
aug[1] = (uint32)atoul(row[5]); aug[1] = (uint32)atoul(row[5]);
aug[2] = (uint32)atoul(row[6]); aug[2] = (uint32)atoul(row[6]);
aug[3] = (uint32)atoul(row[7]); aug[3] = (uint32)atoul(row[7]);
aug[4] = (uint32)atoul(row[8]); aug[4] = (uint32)atoul(row[8]);
aug[5] = (uint32)atoul(row[9]); aug[5] = (uint32)atoul(row[9]);
bool instnodrop = (row[10] && (uint16)atoi(row[10]))? true: false; bool instnodrop = (row[10] && (uint16)atoi(row[10])) ? true : false;
uint32 ornament_icon = (uint32)atoul(row[12]); uint32 ornament_icon = (uint32)atoul(row[12]);
uint32 ornament_idfile = (uint32)atoul(row[13]); uint32 ornament_idfile = (uint32)atoul(row[13]);
uint32 ornament_hero_model = (uint32)atoul(row[14]); uint32 ornament_hero_model = (uint32)atoul(row[14]);
const Item_Struct* item = GetItem(item_id); const Item_Struct *item = GetItem(item_id);
if (!item) { if (!item) {
Log.Out(Logs::General, Logs::Error,"Warning: charid %i has an invalid item_id %i in inventory slot %i", char_id, item_id, slot_id); Log.Out(Logs::General, Logs::Error,
continue; "Warning: charid %i has an invalid item_id %i in inventory slot %i", char_id, item_id,
} slot_id);
continue;
}
int16 put_slot_id = INVALID_INDEX; int16 put_slot_id = INVALID_INDEX;
ItemInst* inst = CreateBaseItem(item, charges); ItemInst *inst = CreateBaseItem(item, charges);
if (inst == nullptr) if (inst == nullptr)
continue; continue;
if(row[11]) { if (row[11]) {
std::string data_str(row[11]); std::string data_str(row[11]);
std::string idAsString; std::string idAsString;
std::string value; std::string value;
bool use_id = true; bool use_id = true;
for(int i = 0; i < data_str.length(); ++i) { for (int i = 0; i < data_str.length(); ++i) {
if(data_str[i] == '^') { if (data_str[i] == '^') {
if(!use_id) { if (!use_id) {
inst->SetCustomData(idAsString, value); inst->SetCustomData(idAsString, value);
idAsString.clear(); idAsString.clear();
value.clear(); value.clear();
} }
use_id = !use_id; use_id = !use_id;
continue; continue;
} }
char v = data_str[i]; char v = data_str[i];
if(use_id) if (use_id)
idAsString.push_back(v); idAsString.push_back(v);
else else
value.push_back(v); value.push_back(v);
} }
} }
inst->SetOrnamentIcon(ornament_icon); inst->SetOrnamentIcon(ornament_icon);
inst->SetOrnamentationIDFile(ornament_idfile); inst->SetOrnamentationIDFile(ornament_idfile);
inst->SetOrnamentHeroModel(ornament_hero_model); inst->SetOrnamentHeroModel(ornament_hero_model);
if (instnodrop || (((slot_id >= EmuConstants::EQUIPMENT_BEGIN && slot_id <= EmuConstants::EQUIPMENT_END) || slot_id == MainPowerSource) && inst->GetItem()->Attuneable)) if (instnodrop ||
inst->SetAttuned(true); (((slot_id >= EmuConstants::EQUIPMENT_BEGIN && slot_id <= EmuConstants::EQUIPMENT_END) ||
slot_id == MainPowerSource) &&
inst->GetItem()->Attuneable))
inst->SetAttuned(true);
if (color > 0) if (color > 0)
inst->SetColor(color); inst->SetColor(color);
if(charges==0x7FFF) if (charges == 0x7FFF)
inst->SetCharges(-1); inst->SetCharges(-1);
else if (charges == 0 && inst->IsStackable()) // Stackable items need a minimum charge of 1 remain moveable. else if (charges == 0 &&
inst->IsStackable()) // Stackable items need a minimum charge of 1 remain moveable.
inst->SetCharges(1); inst->SetCharges(1);
else else
inst->SetCharges(charges); inst->SetCharges(charges);
if (item->ItemClass == ItemClassCommon) { if (item->ItemClass == ItemClassCommon) {
for (int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) { for (int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) {
@ -575,114 +585,116 @@ bool SharedDatabase::GetInventory(uint32 char_id, Inventory* inv) {
} }
} }
if (slot_id >= 8000 && slot_id <= 8999) if (slot_id >= 8000 && slot_id <= 8999) {
{ put_slot_id = inv->PushCursor(*inst);
put_slot_id = inv->PushCursor(*inst); } else if (slot_id >= 3111 && slot_id <= 3179) {
} // Admins: please report any occurrences of this error
else if (slot_id >= 3111 && slot_id <= 3179) Log.Out(Logs::General, Logs::Error, "Warning: Defunct location for item in inventory: "
{ "charid=%i, item_id=%i, slot_id=%i .. pushing to cursor...",
// Admins: please report any occurrences of this error char_id, item_id, slot_id);
Log.Out(Logs::General, Logs::Error, "Warning: Defunct location for item in inventory: charid=%i, item_id=%i, slot_id=%i .. pushing to cursor...", char_id, item_id, slot_id); put_slot_id = inv->PushCursor(*inst);
put_slot_id = inv->PushCursor(*inst); } else {
}
else
{
put_slot_id = inv->PutItem(slot_id, *inst); put_slot_id = inv->PutItem(slot_id, *inst);
} }
safe_delete(inst); safe_delete(inst);
// Save ptr to item in inventory // Save ptr to item in inventory
if (put_slot_id == INVALID_INDEX) { if (put_slot_id == INVALID_INDEX) {
Log.Out(Logs::General, Logs::Error, "Warning: Invalid slot_id for item in inventory: charid=%i, item_id=%i, slot_id=%i",char_id, item_id, slot_id); Log.Out(Logs::General, Logs::Error,
} "Warning: Invalid slot_id for item in inventory: charid=%i, item_id=%i, slot_id=%i",
} char_id, item_id, slot_id);
}
}
// Retrieve shared inventory // Retrieve shared inventory
return GetSharedBank(char_id, inv, true); return GetSharedBank(char_id, inv, true);
} }
// Overloaded: Retrieve character inventory based on account_id and character name // Overloaded: Retrieve character inventory based on account_id and character name
bool SharedDatabase::GetInventory(uint32 account_id, char* name, Inventory* inv) { bool SharedDatabase::GetInventory(uint32 account_id, char *name, Inventory *inv)
{
// Retrieve character inventory // Retrieve character inventory
std::string query = StringFormat("SELECT slotid, itemid, charges, color, augslot1, " std::string query =
"augslot2, augslot3, augslot4, augslot5, augslot6, instnodrop, custom_data, ornamenticon, ornamentidfile, ornament_hero_model " StringFormat("SELECT slotid, itemid, charges, color, augslot1, "
"FROM inventory INNER JOIN character_data ch " "augslot2, augslot3, augslot4, augslot5, augslot6, instnodrop, custom_data, ornamenticon, "
"ON ch.id = charid WHERE ch.name = '%s' AND ch.account_id = %i ORDER BY slotid", "ornamentidfile, ornament_hero_model "
name, account_id); "FROM inventory INNER JOIN character_data ch "
auto results = QueryDatabase(query); "ON ch.id = charid WHERE ch.name = '%s' AND ch.account_id = %i ORDER BY slotid",
if (!results.Success()){ name, account_id);
Log.Out(Logs::General, Logs::Error, "If you got an error related to the 'instnodrop' field, run the following SQL Queries:\nalter table inventory add instnodrop tinyint(1) unsigned default 0 not null;\n"); auto results = QueryDatabase(query);
return false; if (!results.Success()) {
Log.Out(Logs::General, Logs::Error, "If you got an error related to the 'instnodrop' field, run the "
"following SQL Queries:\nalter table inventory add instnodrop "
"tinyint(1) unsigned default 0 not null;\n");
return false;
} }
for (auto row = results.begin(); row != results.end(); ++row) {
int16 slot_id = atoi(row[0]);
uint32 item_id = atoi(row[1]);
int8 charges = atoi(row[2]);
uint32 color = atoul(row[3]);
for (auto row = results.begin(); row != results.end(); ++row) { uint32 aug[EmuConstants::ITEM_COMMON_SIZE];
int16 slot_id = atoi(row[0]); aug[0] = (uint32)atoi(row[4]);
uint32 item_id = atoi(row[1]); aug[1] = (uint32)atoi(row[5]);
int8 charges = atoi(row[2]); aug[2] = (uint32)atoi(row[6]);
uint32 color = atoul(row[3]); aug[3] = (uint32)atoi(row[7]);
aug[4] = (uint32)atoi(row[8]);
uint32 aug[EmuConstants::ITEM_COMMON_SIZE];
aug[0] = (uint32)atoi(row[4]);
aug[1] = (uint32)atoi(row[5]);
aug[2] = (uint32)atoi(row[6]);
aug[3] = (uint32)atoi(row[7]);
aug[4] = (uint32)atoi(row[8]);
aug[5] = (uint32)atoi(row[9]); aug[5] = (uint32)atoi(row[9]);
bool instnodrop = (row[10] && (uint16)atoi(row[10])) ? true : false; bool instnodrop = (row[10] && (uint16)atoi(row[10])) ? true : false;
uint32 ornament_icon = (uint32)atoul(row[12]); uint32 ornament_icon = (uint32)atoul(row[12]);
uint32 ornament_idfile = (uint32)atoul(row[13]); uint32 ornament_idfile = (uint32)atoul(row[13]);
uint32 ornament_hero_model = (uint32)atoul(row[14]); uint32 ornament_hero_model = (uint32)atoul(row[14]);
const Item_Struct* item = GetItem(item_id);
int16 put_slot_id = INVALID_INDEX;
if(!item)
continue;
ItemInst* inst = CreateBaseItem(item, charges); const Item_Struct *item = GetItem(item_id);
int16 put_slot_id = INVALID_INDEX;
if (!item)
continue;
ItemInst *inst = CreateBaseItem(item, charges);
if (inst == nullptr) if (inst == nullptr)
continue; continue;
inst->SetAttuned(instnodrop); inst->SetAttuned(instnodrop);
if(row[11]) { if (row[11]) {
std::string data_str(row[11]); std::string data_str(row[11]);
std::string idAsString; std::string idAsString;
std::string value; std::string value;
bool use_id = true; bool use_id = true;
for(int i = 0; i < data_str.length(); ++i) { for (int i = 0; i < data_str.length(); ++i) {
if(data_str[i] == '^') { if (data_str[i] == '^') {
if(!use_id) { if (!use_id) {
inst->SetCustomData(idAsString, value); inst->SetCustomData(idAsString, value);
idAsString.clear(); idAsString.clear();
value.clear(); value.clear();
} }
use_id = !use_id; use_id = !use_id;
continue; continue;
} }
char v = data_str[i]; char v = data_str[i];
if(use_id) if (use_id)
idAsString.push_back(v); idAsString.push_back(v);
else else
value.push_back(v); value.push_back(v);
}
}
}
}
inst->SetOrnamentIcon(ornament_icon); inst->SetOrnamentIcon(ornament_icon);
inst->SetOrnamentationIDFile(ornament_idfile); inst->SetOrnamentationIDFile(ornament_idfile);
inst->SetOrnamentHeroModel(ornament_hero_model); inst->SetOrnamentHeroModel(ornament_hero_model);
if (color > 0) if (color > 0)
inst->SetColor(color); inst->SetColor(color);
inst->SetCharges(charges); inst->SetCharges(charges);
if (item->ItemClass == ItemClassCommon) { if (item->ItemClass == ItemClassCommon) {
for (int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) { for (int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) {
@ -691,43 +703,44 @@ bool SharedDatabase::GetInventory(uint32 account_id, char* name, Inventory* inv)
} }
} }
if (slot_id>=8000 && slot_id <= 8999) if (slot_id >= 8000 && slot_id <= 8999)
put_slot_id = inv->PushCursor(*inst); put_slot_id = inv->PushCursor(*inst);
else else
put_slot_id = inv->PutItem(slot_id, *inst); put_slot_id = inv->PutItem(slot_id, *inst);
safe_delete(inst); safe_delete(inst);
// Save ptr to item in inventory // Save ptr to item in inventory
if (put_slot_id == INVALID_INDEX) if (put_slot_id == INVALID_INDEX)
Log.Out(Logs::General, Logs::Error, "Warning: Invalid slot_id for item in inventory: name=%s, acctid=%i, item_id=%i, slot_id=%i", name, account_id, item_id, slot_id); Log.Out(Logs::General, Logs::Error, "Warning: Invalid slot_id for item in inventory: name=%s, "
"acctid=%i, item_id=%i, slot_id=%i",
name, account_id, item_id, slot_id);
}
} // Retrieve shared inventory
// Retrieve shared inventory
return GetSharedBank(account_id, inv, false); return GetSharedBank(account_id, inv, false);
} }
void SharedDatabase::GetItemsCount(int32 &item_count, uint32 &max_id)
void SharedDatabase::GetItemsCount(int32 &item_count, uint32 &max_id) { {
item_count = -1; item_count = -1;
max_id = 0; max_id = 0;
const std::string query = "SELECT MAX(id), count(*) FROM items"; const std::string query = "SELECT MAX(id), count(*) FROM items";
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
if (!results.Success()) { if (!results.Success()) {
return; return;
} }
if (results.RowCount() == 0) if (results.RowCount() == 0)
return; return;
auto row = results.begin(); auto row = results.begin();
if(row[0]) if (row[0])
max_id = atoi(row[0]); max_id = atoi(row[0]);
if (row[1]) if (row[1])
item_count = atoi(row[1]); item_count = atoi(row[1]);
} }