Comply with Xiphoseer required changes.

Remove the CDClientDatabase::ExecuteQueryWithArgs() function and replace 
it with CDClientDatabase::CreatePreppedStmt().

This prevents a developer from accidently using %s, or incorrectly 
passing std::string, and causing a silent error.
This commit is contained in:
TheMatt2
2022-01-12 22:48:27 -05:00
parent e5f7d164cb
commit 3de3932503
22 changed files with 247 additions and 189 deletions

View File

@@ -50,18 +50,18 @@ InventoryComponent::InventoryComponent(Entity* parent, tinyxml2::XMLDocument* do
auto items = inventoryComponentTable->Query([=](const CDInventoryComponent entry) { return entry.id == componentId; });
auto slot = 0u;
for (const auto& item : items)
{
if (!item.equip || !Inventory::IsValidItem(item.itemid))
{
continue;
}
const LWOOBJID id = ObjectIDManager::Instance()->GenerateObjectID();
const auto& info = Inventory::FindItemComponent(item.itemid);
UpdateSlot(info.equipLocation, { id, static_cast<LOT>(item.itemid), item.count, slot++ });
}
}
@@ -86,7 +86,7 @@ Inventory* InventoryComponent::GetInventory(const eInventoryType type)
case eInventoryType::VAULT_ITEMS:
size = 40u;
break;
default:
break;
}
@@ -173,7 +173,7 @@ void InventoryComponent::AddItem(
auto* missions = static_cast<MissionComponent*>(this->m_Parent->GetComponent(COMPONENT_TYPE_MISSION));
auto* inventory = GetInventory(inventoryType);
if (!config.empty() || bound)
{
const auto slot = inventory->FindEmptySlot();
@@ -184,7 +184,7 @@ void InventoryComponent::AddItem(
return;
}
auto* item = new Item(lot, inventory, slot, count, config, parent, showFlyingLoot, isModMoveAndEquip, subKey, bound);
if (missions != nullptr && !IsTransferInventory(inventoryType))
@@ -196,7 +196,7 @@ void InventoryComponent::AddItem(
}
const auto info = Inventory::FindItemComponent(lot);
auto left = count;
int32_t outOfSpace = 0;
@@ -211,7 +211,7 @@ void InventoryComponent::AddItem(
{
stack = 1;
}
auto* existing = FindItemByLot(lot, inventoryType);
if (existing != nullptr)
@@ -235,7 +235,7 @@ void InventoryComponent::AddItem(
const auto size = std::min(left, stack);
left -= size;
int32_t slot;
if (preferredSlot != -1 && inventory->IsSlotEmpty(preferredSlot))
@@ -248,7 +248,7 @@ void InventoryComponent::AddItem(
{
slot = inventory->FindEmptySlot();
}
if (slot == -1)
{
auto* player = dynamic_cast<Player*>(GetParent());
@@ -271,9 +271,9 @@ void InventoryComponent::AddItem(
{
GameMessages::SendDropClientLoot(this->m_Parent, this->m_Parent->GetObjectID(), lot, 0, this->m_Parent->GetPosition(), 1);
}
break;
default:
break;
}
@@ -323,7 +323,7 @@ void InventoryComponent::RemoveItem(const LOT lot, const uint32_t count, eInvent
{
break;
}
const auto delta = std::min<uint32_t>(left, item->GetCount());
item->SetCount(item->GetCount() - delta);
@@ -338,11 +338,11 @@ void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType in
{
return;
}
auto* origin = item->GetInventory();
const auto lot = item->GetLot();
if (item->GetConfig().empty() && !item->GetBound() || (item->GetBound() && item->GetInfo().isBOP))
{
auto left = std::min<uint32_t>(count, origin->GetLotCount(lot));
@@ -380,7 +380,7 @@ void InventoryComponent::MoveItemToInventory(Item* item, const eInventoryType in
{
config.push_back(data->Copy());
}
const auto delta = std::min<uint32_t>(item->GetCount(), count);
AddItem(lot, delta, inventory, config, LWOOBJID_EMPTY, showFlyingLot, isModMoveAndEquip, LWOOBJID_EMPTY, origin->GetType(), 0, item->GetBound(), preferredSlot);
@@ -438,7 +438,7 @@ Item* InventoryComponent::FindItemByLot(const LOT lot, eInventoryType inventoryT
return inventory->FindItemByLot(lot, ignoreEquipped, ignoreBound);
}
Item* InventoryComponent::FindItemBySubKey(LWOOBJID id, eInventoryType inventoryType)
Item* InventoryComponent::FindItemBySubKey(LWOOBJID id, eInventoryType inventoryType)
{
if (inventoryType == INVALID)
{
@@ -597,7 +597,7 @@ void InventoryComponent::LoadXml(tinyxml2::XMLDocument* document)
unsigned int count;
bool bound;
LWOOBJID subKey = LWOOBJID_EMPTY;
itemElement->QueryAttribute("id", &id);
itemElement->QueryAttribute("l", &lot);
itemElement->QueryAttribute("eq", &equipped);
@@ -608,23 +608,23 @@ void InventoryComponent::LoadXml(tinyxml2::XMLDocument* document)
// Begin custom xml
auto parent = LWOOBJID_EMPTY;
itemElement->QueryAttribute("parent", &parent);
// End custom xml
std::vector<LDFBaseData*> config;
auto* extraInfo = itemElement->FirstChildElement("x");
if (extraInfo)
{
std::string modInfo = extraInfo->Attribute("ma");
LDFBaseData* moduleAssembly = new LDFData<std::u16string>(u"assemblyPartLOTs", GeneralUtils::ASCIIToUTF16(modInfo.substr(2, modInfo.size() - 1)));
config.push_back(moduleAssembly);
}
const auto* item = new Item(id, lot, inventory, slot, count, bound, config, parent, subKey);
if (equipped)
@@ -702,7 +702,7 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument* document)
bags->LinkEndChild(bag);
}
auto* items = inventoryElement->FirstChildElement("items");
if (items == nullptr)
@@ -756,10 +756,10 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument* document)
itemElement->LinkEndChild(extraInfo);
}
bagElement->LinkEndChild(itemElement);
}
items->LinkEndChild(bagElement);
}
}
@@ -769,13 +769,13 @@ void InventoryComponent::Serialize(RakNet::BitStream* outBitStream, const bool b
if (bIsInitialUpdate || m_Dirty)
{
outBitStream->Write(true);
outBitStream->Write<uint32_t>(m_Equipped.size());
for (const auto& pair : m_Equipped)
{
const auto item = pair.second;
if (bIsInitialUpdate)
{
AddItemSkills(item.lot);
@@ -783,19 +783,19 @@ void InventoryComponent::Serialize(RakNet::BitStream* outBitStream, const bool b
outBitStream->Write(item.id);
outBitStream->Write(item.lot);
outBitStream->Write0();
outBitStream->Write(item.count > 0);
if (item.count > 0) outBitStream->Write(item.count);
outBitStream->Write(item.slot != 0);
if (item.slot != 0) outBitStream->Write<uint16_t>(item.slot);
outBitStream->Write0();
outBitStream->Write0(); //TODO: This is supposed to be true and write the assemblyPartLOTs when they're present.
outBitStream->Write1();
}
@@ -805,7 +805,7 @@ void InventoryComponent::Serialize(RakNet::BitStream* outBitStream, const bool b
{
outBitStream->Write(false);
}
outBitStream->Write(false);
}
@@ -814,7 +814,7 @@ void InventoryComponent::ResetFlags()
m_Dirty = false;
}
void InventoryComponent::Update(float deltaTime)
void InventoryComponent::Update(float deltaTime)
{
for (auto* set : m_Itemsets)
{
@@ -843,7 +843,7 @@ void InventoryComponent::UpdateSlot(const std::string& location, EquippedItem it
UnEquipItem(old);
}
}
m_Equipped.insert_or_assign(location, item);
m_Dirty = true;
@@ -855,14 +855,14 @@ void InventoryComponent::RemoveSlot(const std::string& location)
{
return;
}
m_Equipped.erase(location);
m_Dirty = true;
}
void InventoryComponent::EquipItem(Item* item, const bool skipChecks)
{
{
if (!Inventory::IsValidItem(item->GetLot()))
{
return;
@@ -908,7 +908,7 @@ void InventoryComponent::EquipItem(Item* item, const bool skipChecks)
const auto building = character->GetBuildMode();
const auto type = static_cast<eItemType>(item->GetInfo().itemType);
if (item->GetLot() == 8092 && m_Parent->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER)
{
EntityInfo info {};
@@ -976,7 +976,7 @@ void InventoryComponent::EquipItem(Item* item, const bool skipChecks)
{
return;
}
if (type == ITEM_TYPE_LOOT_MODEL || type == ITEM_TYPE_VEHICLE)
{
return;
@@ -995,12 +995,12 @@ void InventoryComponent::EquipItem(Item* item, const bool skipChecks)
const auto lot = item->GetLot();
CheckItemSet(lot);
for (auto* set : m_Itemsets)
{
set->OnEquip(lot);
}
if (lot == 1727) GameMessages::SendSetJetpackMode(m_Parent, false, true, false);
if (lot == 7292) GameMessages::SendSetJetpackMode(m_Parent, true, true, false);
if (lot == 14442) GameMessages::SendSetJetpackMode(m_Parent, false, true, true);
@@ -1011,11 +1011,11 @@ void InventoryComponent::EquipItem(Item* item, const bool skipChecks)
}
GenerateProxies(item);
UpdateSlot(item->GetInfo().equipLocation, { item->GetId(), item->GetLot(), item->GetCount(), item->GetSlot() });
ApplyBuff(item->GetLot());
AddItemSkills(item->GetLot());
EntityManager::Instance()->SerializeEntity(m_Parent);
@@ -1029,7 +1029,7 @@ void InventoryComponent::UnEquipItem(Item* item)
}
const auto lot = item->GetLot();
if (!Inventory::IsValidItem(lot))
{
return;
@@ -1047,11 +1047,11 @@ void InventoryComponent::UnEquipItem(Item* item)
if (lot == 14442) GameMessages::SendSetJetpackMode(m_Parent, false, false, true);
RemoveBuff(item->GetLot());
RemoveItemSkills(item->GetLot());
RemoveSlot(item->GetInfo().equipLocation);
PurgeProxies(item);
EntityManager::Instance()->SerializeEntity(m_Parent);
@@ -1069,7 +1069,7 @@ void InventoryComponent::ApplyBuff(const LOT lot) const
const auto buffs = FindBuffs(lot, true);
for (const auto buff : buffs)
{
{
SkillComponent::HandleUnmanaged(buff, m_Parent->GetObjectID());
}
}
@@ -1142,10 +1142,13 @@ void InventoryComponent::CheckItemSet(const LOT lot) {
return;
}
std::cout << "INVENTORY CHECK" << std::endl;
auto result = CDClientDatabase::ExecuteQueryWithArgs(
"SELECT setID FROM ItemSets WHERE itemIDs LIKE '%%%d%%';",
lot);
const std::string lot_query = "%" + std::to_string(lot) + "%";
auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT setID FROM ItemSets WHERE itemIDs LIKE ?;");
query.bind(1, lot_query.c_str());
auto result = query.execQuery();
while (!result.eof()) {
const auto id = result.getIntField(0);
@@ -1173,11 +1176,11 @@ void InventoryComponent::CheckItemSet(const LOT lot) {
}
m_ItemSetsChecked.push_back(lot);
result.finalize();
}
void InventoryComponent::SetConsumable(LOT lot)
void InventoryComponent::SetConsumable(LOT lot)
{
m_Consumable = lot;
}
@@ -1197,13 +1200,13 @@ void InventoryComponent::AddItemSkills(const LOT lot)
{
return;
}
const auto index = m_Skills.find(slot);
if (index != m_Skills.end())
{
const auto old = index->second;
GameMessages::SendRemoveSkill(m_Parent, old);
}
@@ -1213,7 +1216,7 @@ void InventoryComponent::AddItemSkills(const LOT lot)
{
return;
}
GameMessages::SendAddSkill(m_Parent, skill, static_cast<int>(slot));
m_Skills.insert_or_assign(slot, skill);
@@ -1222,14 +1225,14 @@ void InventoryComponent::AddItemSkills(const LOT lot)
void InventoryComponent::RemoveItemSkills(const LOT lot)
{
const auto info = Inventory::FindItemComponent(lot);
const auto slot = FindBehaviorSlot(static_cast<eItemType>(info.itemType));
if (slot == BehaviorSlot::Invalid)
{
return;
}
const auto index = m_Skills.find(slot);
if (index == m_Skills.end())
@@ -1242,7 +1245,7 @@ void InventoryComponent::RemoveItemSkills(const LOT lot)
GameMessages::SendRemoveSkill(m_Parent, old);
m_Skills.erase(slot);
if (slot == BehaviorSlot::Primary)
{
m_Skills.insert_or_assign(BehaviorSlot::Primary, 1);
@@ -1251,7 +1254,7 @@ void InventoryComponent::RemoveItemSkills(const LOT lot)
}
}
void InventoryComponent::TriggerPassiveAbility(PassiveAbilityTrigger trigger)
void InventoryComponent::TriggerPassiveAbility(PassiveAbilityTrigger trigger)
{
for (auto* set : m_Itemsets)
{
@@ -1278,7 +1281,7 @@ bool InventoryComponent::HasAnyPassive(const std::vector<ItemSetPassiveAbilityID
return false;
}
void InventoryComponent::DespawnPet()
void InventoryComponent::DespawnPet()
{
auto* current = PetComponent::GetActivePet(m_Parent->GetObjectID());
@@ -1288,7 +1291,7 @@ void InventoryComponent::DespawnPet()
}
}
void InventoryComponent::SpawnPet(Item* item)
void InventoryComponent::SpawnPet(Item* item)
{
auto* current = PetComponent::GetActivePet(m_Parent->GetObjectID());
@@ -1307,11 +1310,11 @@ void InventoryComponent::SpawnPet(Item* item)
info.pos = m_Parent->GetPosition();
info.rot = NiQuaternion::IDENTITY;
info.spawnerID = m_Parent->GetObjectID();
auto* pet = EntityManager::Instance()->CreateEntity(info);
auto* petComponent = pet->GetComponent<PetComponent>();
if (petComponent != nullptr)
{
petComponent->Activate(item);
@@ -1320,7 +1323,7 @@ void InventoryComponent::SpawnPet(Item* item)
EntityManager::Instance()->ConstructEntity(pet);
}
void InventoryComponent::SetDatabasePet(LWOOBJID id, const DatabasePet& data)
void InventoryComponent::SetDatabasePet(LWOOBJID id, const DatabasePet& data)
{
m_Pets.insert_or_assign(id, data);
}
@@ -1341,7 +1344,7 @@ bool InventoryComponent::IsPet(LWOOBJID id) const
return pair != m_Pets.end();
}
void InventoryComponent::RemoveDatabasePet(LWOOBJID id)
void InventoryComponent::RemoveDatabasePet(LWOOBJID id)
{
m_Pets.erase(id);
}
@@ -1364,7 +1367,7 @@ BehaviorSlot InventoryComponent::FindBehaviorSlot(const eItemType type)
}
}
bool InventoryComponent::IsTransferInventory(eInventoryType type)
bool InventoryComponent::IsTransferInventory(eInventoryType type)
{
return type == VENDOR_BUYBACK || type == VAULT_ITEMS || type == VAULT_MODELS || type == TEMP_ITEMS || type == TEMP_MODELS;
}
@@ -1415,12 +1418,12 @@ std::vector<uint32_t> InventoryComponent::FindBuffs(const LOT lot, bool castOnEq
continue;
}
if (missions != nullptr && castOnEquip)
{
missions->Progress(MissionTaskType::MISSION_TASK_TYPE_SKILL, result.skillID);
}
buffs.push_back(static_cast<uint32_t>(entry.behaviorID));
}
}
@@ -1428,18 +1431,18 @@ std::vector<uint32_t> InventoryComponent::FindBuffs(const LOT lot, bool castOnEq
return buffs;
}
void InventoryComponent::SetNPCItems(const std::vector<LOT>& items)
void InventoryComponent::SetNPCItems(const std::vector<LOT>& items)
{
m_Equipped.clear();
auto slot = 0u;
for (const auto& item : items)
{
const LWOOBJID id = ObjectIDManager::Instance()->GenerateObjectID();
const auto& info = Inventory::FindItemComponent(item);
UpdateSlot(info.equipLocation, { id, static_cast<LOT>(item), 1, slot++ }, true);
}
@@ -1474,9 +1477,9 @@ std::vector<Item*> InventoryComponent::GenerateProxies(Item* parent)
{
return proxies;
}
subItems.erase(std::remove_if(subItems.begin(), subItems.end(), ::isspace), subItems.end());
std::stringstream stream(subItems);
std::string segment;
std::vector<uint32_t> lots;
@@ -1491,7 +1494,7 @@ std::vector<Item*> InventoryComponent::GenerateProxies(Item* parent)
{
Game::logger->Log("InventoryComponent", "Failed to parse proxy (%s): (%s)!\n", segment.c_str(), exception.what());
}
}
}
for (const auto lot : lots)
{
@@ -1508,7 +1511,7 @@ std::vector<Item*> InventoryComponent::GenerateProxies(Item* parent)
proxies.push_back(proxy);
}
return proxies;
}
@@ -1517,7 +1520,7 @@ std::vector<Item*> InventoryComponent::FindProxies(const LWOOBJID parent)
auto* inventory = GetInventory(ITEM_SETS);
std::vector<Item*> proxies;
for (const auto& pair : inventory->GetItems())
{
auto* item = pair.second;
@@ -1559,7 +1562,7 @@ bool InventoryComponent::IsParentValid(Item* root)
}
const auto id = root->GetId();
for (const auto& pair : m_Inventories)
{
const auto items = pair.second->GetItems();
@@ -1581,7 +1584,7 @@ bool InventoryComponent::IsParentValid(Item* root)
void InventoryComponent::CheckProxyIntegrity()
{
std::vector<Item*> dead;
for (const auto& pair : m_Inventories)
{
const auto& items = pair.second->GetItems();
@@ -1596,7 +1599,7 @@ void InventoryComponent::CheckProxyIntegrity()
{
continue;
}
if (IsValidProxy(parent))
{
continue;
@@ -1621,7 +1624,7 @@ void InventoryComponent::CheckProxyIntegrity()
for (const auto& candidate : items)
{
auto* item = candidate.second;
const auto parent = item->GetParent();
if (parent != LWOOBJID_EMPTY)
@@ -1653,7 +1656,7 @@ void InventoryComponent::CheckProxyIntegrity()
void InventoryComponent::PurgeProxies(Item* item)
{
const auto root = item->GetParent();
if (root != LWOOBJID_EMPTY)
{
item = FindItemById(root);
@@ -1662,7 +1665,7 @@ void InventoryComponent::PurgeProxies(Item* item)
{
UnEquipItem(item);
}
return;
}
@@ -1676,7 +1679,7 @@ void InventoryComponent::PurgeProxies(Item* item)
}
}
void InventoryComponent::LoadPetXml(tinyxml2::XMLDocument* document)
void InventoryComponent::LoadPetXml(tinyxml2::XMLDocument* document)
{
auto* petInventoryElement = document->FirstChildElement("obj")->FirstChildElement("pet");
@@ -1694,7 +1697,7 @@ void InventoryComponent::LoadPetXml(tinyxml2::XMLDocument* document)
LWOOBJID id;
LOT lot;
int32_t moderationStatus;
petElement->QueryAttribute("id", &id);
petElement->QueryAttribute("l", &lot);
petElement->QueryAttribute("m", &moderationStatus);
@@ -1711,7 +1714,7 @@ void InventoryComponent::LoadPetXml(tinyxml2::XMLDocument* document)
}
}
void InventoryComponent::UpdatePetXml(tinyxml2::XMLDocument* document)
void InventoryComponent::UpdatePetXml(tinyxml2::XMLDocument* document)
{
auto* petInventoryElement = document->FirstChildElement("obj")->FirstChildElement("pet");
@@ -1733,8 +1736,7 @@ void InventoryComponent::UpdatePetXml(tinyxml2::XMLDocument* document)
petElement->SetAttribute("m", pet.second.moderationState);
petElement->SetAttribute("n", pet.second.name.c_str());
petElement->SetAttribute("t", 0);
petInventoryElement->LinkEndChild(petElement);
}
}