From 0f1b504ed6ff21fae47d35964279e1348bf70e5f Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Sat, 31 Jan 2015 00:00:02 -0500 Subject: [PATCH] Some clang-formatting --- common/shareddb.cpp | 319 +++++++++++++++++++++++--------------------- 1 file changed, 166 insertions(+), 153 deletions(-) diff --git a/common/shareddb.cpp b/common/shareddb.cpp index 969ca2d58..c25cc9e48 100644 --- a/common/shareddb.cpp +++ b/common/shareddb.cpp @@ -477,96 +477,106 @@ bool SharedDatabase::GetSharedBank(uint32 id, Inventory* inv, bool is_charid) { return true; } - // 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 - std::string query = StringFormat("SELECT slotid, itemid, charges, color, augslot1, " - "augslot2, augslot3, augslot4, augslot5, augslot6, instnodrop, custom_data, ornamenticon, ornamentidfile, ornament_hero_model " - "FROM inventory WHERE charid = %i ORDER BY slotid", char_id); - auto results = QueryDatabase(query); - 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; - } + std::string query = + StringFormat("SELECT slotid, itemid, charges, color, augslot1, augslot2, augslot3, augslot4, augslot5, " + "augslot6, instnodrop, custom_data, ornamenticon, ornamentidfile, ornament_hero_model FROM " + "inventory WHERE charid = %i ORDER BY slotid", + char_id); + auto results = QueryDatabase(query); + 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]); - uint16 charges = atoi(row[2]); - uint32 color = atoul(row[3]); + for (auto row = results.begin(); row != results.end(); ++row) { + int16 slot_id = atoi(row[0]); + uint32 item_id = atoi(row[1]); + uint16 charges = atoi(row[2]); + uint32 color = atoul(row[3]); - uint32 aug[EmuConstants::ITEM_COMMON_SIZE]; + uint32 aug[EmuConstants::ITEM_COMMON_SIZE]; - aug[0] = (uint32)atoul(row[4]); - aug[1] = (uint32)atoul(row[5]); - aug[2] = (uint32)atoul(row[6]); - aug[3] = (uint32)atoul(row[7]); - aug[4] = (uint32)atoul(row[8]); + aug[0] = (uint32)atoul(row[4]); + aug[1] = (uint32)atoul(row[5]); + aug[2] = (uint32)atoul(row[6]); + aug[3] = (uint32)atoul(row[7]); + aug[4] = (uint32)atoul(row[8]); 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_idfile = (uint32)atoul(row[13]); uint32 ornament_hero_model = (uint32)atoul(row[14]); - const Item_Struct* item = GetItem(item_id); + const Item_Struct *item = GetItem(item_id); - 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); - continue; - } + 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); + 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) continue; - if(row[11]) { - std::string data_str(row[11]); - std::string idAsString; - std::string value; - bool use_id = true; + if (row[11]) { + std::string data_str(row[11]); + 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(); - } + 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; - } + use_id = !use_id; + continue; + } - char v = data_str[i]; - if(use_id) - idAsString.push_back(v); - else - value.push_back(v); - } - } + char v = data_str[i]; + if (use_id) + idAsString.push_back(v); + else + value.push_back(v); + } + } inst->SetOrnamentIcon(ornament_icon); inst->SetOrnamentationIDFile(ornament_idfile); inst->SetOrnamentHeroModel(ornament_hero_model); - if (instnodrop || (((slot_id >= EmuConstants::EQUIPMENT_BEGIN && slot_id <= EmuConstants::EQUIPMENT_END) || slot_id == MainPowerSource) && inst->GetItem()->Attuneable)) - inst->SetAttuned(true); + if (instnodrop || + (((slot_id >= EmuConstants::EQUIPMENT_BEGIN && slot_id <= EmuConstants::EQUIPMENT_END) || + slot_id == MainPowerSource) && + inst->GetItem()->Attuneable)) + inst->SetAttuned(true); - if (color > 0) - inst->SetColor(color); + if (color > 0) + inst->SetColor(color); - if(charges==0x7FFF) - inst->SetCharges(-1); - else if (charges == 0 && inst->IsStackable()) // Stackable items need a minimum charge of 1 remain moveable. + if (charges == 0x7FFF) + inst->SetCharges(-1); + else if (charges == 0 && + inst->IsStackable()) // Stackable items need a minimum charge of 1 remain moveable. inst->SetCharges(1); else - inst->SetCharges(charges); + inst->SetCharges(charges); if (item->ItemClass == ItemClassCommon) { 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) - { - put_slot_id = inv->PushCursor(*inst); - } - else if (slot_id >= 3111 && slot_id <= 3179) - { - // Admins: please report any occurrences of this error - 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); - } - else - { + if (slot_id >= 8000 && slot_id <= 8999) { + put_slot_id = inv->PushCursor(*inst); + } else if (slot_id >= 3111 && slot_id <= 3179) { + // Admins: please report any occurrences of this error + 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); + } else { put_slot_id = inv->PutItem(slot_id, *inst); } - safe_delete(inst); + safe_delete(inst); - // Save ptr to item in inventory - 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); - } - } + // Save ptr to item in inventory + 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); + } + } - // Retrieve shared inventory + // Retrieve shared inventory return GetSharedBank(char_id, inv, true); } // 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 - std::string query = StringFormat("SELECT slotid, itemid, charges, color, augslot1, " - "augslot2, augslot3, augslot4, augslot5, augslot6, instnodrop, custom_data, ornamenticon, ornamentidfile, ornament_hero_model " - "FROM inventory INNER JOIN character_data ch " - "ON ch.id = charid WHERE ch.name = '%s' AND ch.account_id = %i ORDER BY slotid", - name, account_id); - auto results = QueryDatabase(query); - 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; + std::string query = + StringFormat("SELECT slotid, itemid, charges, color, augslot1, " + "augslot2, augslot3, augslot4, augslot5, augslot6, instnodrop, custom_data, ornamenticon, " + "ornamentidfile, ornament_hero_model " + "FROM inventory INNER JOIN character_data ch " + "ON ch.id = charid WHERE ch.name = '%s' AND ch.account_id = %i ORDER BY slotid", + name, account_id); + auto results = QueryDatabase(query); + 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) { - int16 slot_id = atoi(row[0]); - uint32 item_id = atoi(row[1]); - int8 charges = atoi(row[2]); - uint32 color = atoul(row[3]); - - 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]); + 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]); - 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_idfile = (uint32)atoul(row[13]); 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) continue; - inst->SetAttuned(instnodrop); + inst->SetAttuned(instnodrop); - if(row[11]) { - std::string data_str(row[11]); - std::string idAsString; - std::string value; - bool use_id = true; + if (row[11]) { + std::string data_str(row[11]); + 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(); - } + 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; - } + use_id = !use_id; + continue; + } - char v = data_str[i]; - if(use_id) - idAsString.push_back(v); - else - value.push_back(v); + char v = data_str[i]; + if (use_id) + idAsString.push_back(v); + else + value.push_back(v); + } + } - } - } - inst->SetOrnamentIcon(ornament_icon); inst->SetOrnamentationIDFile(ornament_idfile); inst->SetOrnamentHeroModel(ornament_hero_model); - if (color > 0) - inst->SetColor(color); + if (color > 0) + inst->SetColor(color); - inst->SetCharges(charges); + inst->SetCharges(charges); if (item->ItemClass == ItemClassCommon) { 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) - put_slot_id = inv->PushCursor(*inst); - else - put_slot_id = inv->PutItem(slot_id, *inst); + if (slot_id >= 8000 && slot_id <= 8999) + put_slot_id = inv->PushCursor(*inst); + else + put_slot_id = inv->PutItem(slot_id, *inst); - safe_delete(inst); + safe_delete(inst); - // Save ptr to item in inventory - 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); + // Save ptr to item in inventory + 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); + } - } - - // Retrieve shared inventory + // Retrieve shared inventory 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; max_id = 0; const std::string query = "SELECT MAX(id), count(*) FROM items"; auto results = QueryDatabase(query); if (!results.Success()) { - return; + return; } if (results.RowCount() == 0) - return; + return; - auto row = results.begin(); + auto row = results.begin(); - if(row[0]) - max_id = atoi(row[0]); + if (row[0]) + max_id = atoi(row[0]); - if (row[1]) + if (row[1]) item_count = atoi(row[1]); }