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

@ -13,3 +13,8 @@ void CDClientDatabase::Connect(const std::string& filename) {
CppSQLite3Query CDClientDatabase::ExecuteQuery(const std::string& query) { CppSQLite3Query CDClientDatabase::ExecuteQuery(const std::string& query) {
return conn->execQuery(query.c_str()); return conn->execQuery(query.c_str());
} }
//! Makes prepared statements
CppSQLite3Statement CDClientDatabase::CreatePreppedStmt(const std::string& query) {
return conn->compileStatement(query.c_str());
}

View File

@ -43,15 +43,7 @@ namespace CDClientDatabase {
//! Queries the CDClient and parses arguments //! Queries the CDClient and parses arguments
/*! /*!
\param query The query with formatted arguments \param query The query with formatted arguments
\return the results of the query \return prepared SQLite Statement
*/ */
// Due to the template, implementation must be in the header. CppSQLite3Statement CreatePreppedStmt(const std::string& query);
template <typename... Args>
CppSQLite3Query ExecuteQueryWithArgs(const std::string& query, Args... args) {
CppSQLite3Buffer sqlBuf;
sqlBuf.format(query.c_str(), args...);
std::string safe_query = (const char *) sqlBuf;
return ExecuteQuery(safe_query);
}
}; };

View File

@ -59,9 +59,11 @@ float CDBehaviorParameterTable::GetEntry(const uint32_t behaviorID, const std::s
} }
#ifndef CDCLIENT_CACHE_ALL #ifndef CDCLIENT_CACHE_ALL
auto tableData = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT parameterID, value FROM BehaviorParameter WHERE behaviorID = %u;", "SELECT parameterID, value FROM BehaviorParameter WHERE behaviorID = ?;");
behaviorID); query.bind(1, (int) behaviorID);
auto tableData = query.execQuery();
m_Entries.insert_or_assign(behaviorID, 0); m_Entries.insert_or_assign(behaviorID, 0);

View File

@ -276,9 +276,11 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId)
} }
BehaviorTemplates Behavior::GetBehaviorTemplate(const uint32_t behaviorId) { BehaviorTemplates Behavior::GetBehaviorTemplate(const uint32_t behaviorId) {
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT templateID FROM BehaviorTemplate WHERE behaviorID = %u;", "SELECT templateID FROM BehaviorTemplate WHERE behaviorID = ?;");
behaviorId); query.bind(1, (int) behaviorId);
auto result = query.execQuery();
// Make sure we do not proceed if we are trying to load an invalid behavior // Make sure we do not proceed if we are trying to load an invalid behavior
if (result.eof()) if (result.eof())
@ -349,18 +351,24 @@ void Behavior::PlayFx(std::u16string type, const LWOOBJID target, const LWOOBJID
} }
} }
// The SQlite result object becomes invalid if the query object leaves scope.
// So both queries are defined before the if statement
CppSQLite3Query result; CppSQLite3Query result;
if (!type.empty()) auto typeQuery = CDClientDatabase::CreatePreppedStmt(
{ "SELECT effectName FROM BehaviorEffect WHERE effectType = ? AND effectID = ?;");
result = CDClientDatabase::ExecuteQueryWithArgs(
"SELECT effectName FROM BehaviorEffect WHERE effectType = %Q AND effectID = %u;", auto idQuery = CDClientDatabase::CreatePreppedStmt(
typeString.c_str(), effectId); "SELECT effectName, effectType FROM BehaviorEffect WHERE effectID = ?;");
}
else if (!type.empty()) {
{ typeQuery.bind(1, typeString.c_str());
result = CDClientDatabase::ExecuteQueryWithArgs( typeQuery.bind(2, (int) effectId);
"SELECT effectName, effectType FROM BehaviorEffect WHERE effectID = %u;",
effectId); result = typeQuery.execQuery();
} else {
idQuery.bind(1, (int) effectId);
result = idQuery.execQuery();
} }
if (result.eof() || result.fieldIsNull(0)) if (result.eof() || result.fieldIsNull(0))
@ -406,9 +414,11 @@ Behavior::Behavior(const uint32_t behaviorId)
this->m_templateId = BehaviorTemplates::BEHAVIOR_EMPTY; this->m_templateId = BehaviorTemplates::BEHAVIOR_EMPTY;
} }
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT templateID, effectID, effectHandle FROM BehaviorTemplate WHERE behaviorID = %u;", "SELECT templateID, effectID, effectHandle FROM BehaviorTemplate WHERE behaviorID = ?;");
behaviorId); query.bind(1, (int) behaviorId);
auto result = query.execQuery();
// Make sure we do not proceed if we are trying to load an invalid behavior // Make sure we do not proceed if we are trying to load an invalid behavior
if (result.eof()) if (result.eof())
@ -481,9 +491,11 @@ std::map<std::string, float> Behavior::GetParameterNames() const
{ {
std::map<std::string, float> parameters; std::map<std::string, float> parameters;
auto tableData = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT parameterID, value FROM BehaviorParameter WHERE behaviorID = %u;", "SELECT parameterID, value FROM BehaviorParameter WHERE behaviorID = ?;");
this->m_behaviorId); query.bind(1, (int) this->m_behaviorId);
auto tableData = query.execQuery();
while (!tableData.eof()) while (!tableData.eof())
{ {

View File

@ -40,12 +40,14 @@ void SwitchMultipleBehavior::Calculate(BehaviorContext* context, RakNet::BitStre
} }
void SwitchMultipleBehavior::Load() { void SwitchMultipleBehavior::Load() {
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT replace(bP1.parameterID, 'behavior ', '') as key, bP1.value as behavior, " "SELECT replace(bP1.parameterID, 'behavior ', '') as key, bP1.value as behavior, "
"(select bP2.value FROM BehaviorParameter bP2 WHERE bP2.behaviorID = %u AND bP2.parameterID LIKE 'value %' " "(select bP2.value FROM BehaviorParameter bP2 WHERE bP2.behaviorID = ?1 AND bP2.parameterID LIKE 'value %' "
"AND replace(bP1.parameterID, 'behavior ', '') = replace(bP2.parameterID, 'value ', '')) as value " "AND replace(bP1.parameterID, 'behavior ', '') = replace(bP2.parameterID, 'value ', '')) as value "
"FROM BehaviorParameter bP1 WHERE bP1.behaviorID = %u AND bP1.parameterID LIKE 'behavior %';", "FROM BehaviorParameter bP1 WHERE bP1.behaviorID = ?1 AND bP1.parameterID LIKE 'behavior %';");
this->m_behaviorId, this->m_behaviorId); query.bind(1, (int) this->m_behaviorId);
auto result = query.execQuery();
while (!result.eof()) { while (!result.eof()) {
const auto behavior_id = static_cast<uint32_t>(result.getFloatField(1)); const auto behavior_id = static_cast<uint32_t>(result.getFloatField(1));

View File

@ -35,9 +35,11 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id)
m_SoftTimer = 5.0f; m_SoftTimer = 5.0f;
//Grab the aggro information from BaseCombatAI: //Grab the aggro information from BaseCombatAI:
auto componentResult = CDClientDatabase::ExecuteQueryWithArgs( auto componentQuery = CDClientDatabase::CreatePreppedStmt(
"SELECT aggroRadius, tetherSpeed, pursuitSpeed, softTetherRadius, hardTetherRadius FROM BaseCombatAIComponent WHERE id = %u;", "SELECT aggroRadius, tetherSpeed, pursuitSpeed, softTetherRadius, hardTetherRadius FROM BaseCombatAIComponent WHERE id = ?;");
id); componentQuery.bind(1, (int) id);
auto componentResult = componentQuery.execQuery();
if (!componentResult.eof()) if (!componentResult.eof())
{ {
@ -62,9 +64,11 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id)
/* /*
* Find skills * Find skills
*/ */
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto skillQuery = CDClientDatabase::CreatePreppedStmt(
"SELECT skillID, cooldown, behaviorID FROM SkillBehavior WHERE skillID IN (SELECT skillID FROM ObjectSkills WHERE objectTemplate = %d);", "SELECT skillID, cooldown, behaviorID FROM SkillBehavior WHERE skillID IN (SELECT skillID FROM ObjectSkills WHERE objectTemplate = ?);");
parent->GetLOT()); skillQuery.bind(1, (int) parent->GetLOT());
auto result = skillQuery.execQuery();
while (!result.eof()) { while (!result.eof()) {
const auto skillId = static_cast<uint32_t>(result.getIntField(0)); const auto skillId = static_cast<uint32_t>(result.getIntField(0));

View File

@ -371,10 +371,12 @@ const std::vector<BuffParameter>& BuffComponent::GetBuffParameters(int32_t buffI
return pair->second; return pair->second;
} }
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT * FROM BuffParameters WHERE BuffID = %d;", "SELECT * FROM BuffParameters WHERE BuffID = ?;");
buffId); query.bind(1, (int) buffId);
auto result = query.execQuery();
std::vector<BuffParameter> parameters {}; std::vector<BuffParameter> parameters {};
while (!result.eof()) while (!result.eof())

View File

@ -373,8 +373,11 @@ void DestroyableComponent::AddFaction(const int32_t factionID, const bool ignore
m_FactionIDs.push_back(factionID); m_FactionIDs.push_back(factionID);
m_DirtyHealth = true; m_DirtyHealth = true;
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT enemyList FROM Factions WHERE faction = %d;", factionID); "SELECT enemyList FROM Factions WHERE faction = ?;");
query.bind(1, (int) factionID);
auto result = query.execQuery();
if (result.eof()) return; if (result.eof()) return;

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

View File

@ -450,8 +450,11 @@ const std::vector<uint32_t>& MissionComponent::QueryAchievements(MissionTaskType
} }
bool MissionComponent::RequiresItem(const LOT lot) { bool MissionComponent::RequiresItem(const LOT lot) {
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT type FROM Objects WHERE id = %d;", lot); "SELECT type FROM Objects WHERE id = ?;");
query.bind(1, (int) lot);
auto result = query.execQuery();
if (result.eof()) { if (result.eof()) {
return false; return false;

View File

@ -167,9 +167,11 @@ void PetComponent::OnUse(Entity* originator)
std::string buildFile; std::string buildFile;
if (cached == buildCache.end()) { if (cached == buildCache.end()) {
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT ValidPiecesLXF, PuzzleModelLot, Timelimit, NumValidPieces, imagCostPerBuild FROM TamingBuildPuzzles WHERE NPCLot = %d;", "SELECT ValidPiecesLXF, PuzzleModelLot, Timelimit, NumValidPieces, imagCostPerBuild FROM TamingBuildPuzzles WHERE NPCLot = ?;");
m_Parent->GetLOT()); query.bind(1, (int) m_Parent->GetLOT());
auto result = query.execQuery();
if (result.eof()) if (result.eof())
{ {

View File

@ -40,9 +40,11 @@ PropertyManagementComponent::PropertyManagementComponent(Entity* parent) : Compo
const auto zoneId = worldId.GetMapID(); const auto zoneId = worldId.GetMapID();
const auto cloneId = worldId.GetCloneID(); const auto cloneId = worldId.GetCloneID();
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT id FROM PropertyTemplate WHERE mapID = %d;", "SELECT id FROM PropertyTemplate WHERE mapID = ?;");
(int) zoneId); query.bind(1, (int) zoneId);
auto result = query.execQuery();
if (result.eof() || result.fieldIsNull(0)) if (result.eof() || result.fieldIsNull(0))
{ {
@ -96,9 +98,11 @@ std::vector<NiPoint3> PropertyManagementComponent::GetPaths() const
{ {
const auto zoneId = dZoneManager::Instance()->GetZone()->GetWorldID(); const auto zoneId = dZoneManager::Instance()->GetZone()->GetWorldID();
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT path FROM PropertyTemplate WHERE mapID = %u;", "SELECT path FROM PropertyTemplate WHERE mapID = ?;");
zoneId); query.bind(1, (int) zoneId);
auto result = query.execQuery();
std::vector<NiPoint3> paths {}; std::vector<NiPoint3> paths {};

View File

@ -199,9 +199,13 @@ void RenderComponent::PlayEffect(const int32_t effectId, const std::u16string& e
} }
const std::string effectType_str = GeneralUtils::UTF16ToWTF8(effectType); const std::string effectType_str = GeneralUtils::UTF16ToWTF8(effectType);
auto result = CDClientDatabase::ExecuteQueryWithArgs(
"SELECT animation_length FROM Animations WHERE animation_type IN (SELECT animationName FROM BehaviorEffect WHERE effectID = %d AND effectType = %Q);", auto query = CDClientDatabase::CreatePreppedStmt(
effectId, effectType_str.c_str()); "SELECT animation_length FROM Animations WHERE animation_type IN (SELECT animationName FROM BehaviorEffect WHERE effectID = ? AND effectType = ?);");
query.bind(1, effectId);
query.bind(2, effectType_str.c_str());
auto result = query.execQuery();
if (result.eof() || result.fieldIsNull(0)) { if (result.eof() || result.fieldIsNull(0)) {
result.finalize(); result.finalize();

View File

@ -18,10 +18,12 @@
#include "PacketUtils.h" #include "PacketUtils.h"
RocketLaunchpadControlComponent::RocketLaunchpadControlComponent(Entity* parent, int rocketId) : Component(parent) { RocketLaunchpadControlComponent::RocketLaunchpadControlComponent(Entity* parent, int rocketId) : Component(parent) {
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT targetZone, defaultZoneID, targetScene, altLandingPrecondition, altLandingSpawnPointName FROM RocketLaunchpadControlComponent WHERE id = %d;", "SELECT targetZone, defaultZoneID, targetScene, altLandingPrecondition, altLandingSpawnPointName FROM RocketLaunchpadControlComponent WHERE id = ?;");
rocketId); query.bind(1, rocketId);
auto result = query.execQuery();
if (!result.eof() && !result.fieldIsNull(0)) if (!result.eof() && !result.fieldIsNull(0))
{ {
m_TargetZone = result.getIntField(0); m_TargetZone = result.getIntField(0);

View File

@ -86,9 +86,11 @@ void SkillComponent::SyncPlayerProjectile(const LWOOBJID projectileId, RakNet::B
const auto sync_entry = this->m_managedProjectiles.at(index); const auto sync_entry = this->m_managedProjectiles.at(index);
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT behaviorID FROM SkillBehavior WHERE skillID = (SELECT skillID FROM ObjectSkills WHERE objectTemplate = %d);", "SELECT behaviorID FROM SkillBehavior WHERE skillID = (SELECT skillID FROM ObjectSkills WHERE objectTemplate = ?);");
sync_entry.lot); query.bind(1, (int) sync_entry.lot);
auto result = query.execQuery();
if (result.eof()) { if (result.eof()) {
Game::logger->Log("SkillComponent", "Failed to find skill id for (%i)!\n", sync_entry.lot); Game::logger->Log("SkillComponent", "Failed to find skill id for (%i)!\n", sync_entry.lot);
@ -434,9 +436,10 @@ void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry)
return; return;
} }
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT behaviorID FROM SkillBehavior WHERE skillID = (SELECT skillID FROM ObjectSkills WHERE objectTemplate = %d);", "SELECT behaviorID FROM SkillBehavior WHERE skillID = (SELECT skillID FROM ObjectSkills WHERE objectTemplate = ?);");
entry.lot); query.bind(1, (int) entry.lot);
auto result = query.execQuery();
if (result.eof()) { if (result.eof()) {
Game::logger->Log("SkillComponent", "Failed to find skill id for (%i)!\n", entry.lot); Game::logger->Log("SkillComponent", "Failed to find skill id for (%i)!\n", entry.lot);

View File

@ -2509,9 +2509,11 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent
const auto zoneId = worldId.GetMapID(); const auto zoneId = worldId.GetMapID();
const auto cloneId = worldId.GetCloneID(); const auto cloneId = worldId.GetCloneID();
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT id FROM PropertyTemplate WHERE mapID = %d;", "SELECT id FROM PropertyTemplate WHERE mapID = ?;");
(int) zoneId); query.bind(1, (int) zoneId);
auto result = query.execQuery();
if (result.eof() || result.fieldIsNull(0)) { if (result.eof() || result.fieldIsNull(0)) {
return; return;

View File

@ -386,9 +386,11 @@ void Item::DisassembleModel()
const auto componentId = table->GetByIDAndType(GetLot(), COMPONENT_TYPE_RENDER); const auto componentId = table->GetByIDAndType(GetLot(), COMPONENT_TYPE_RENDER);
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT render_asset FROM RenderComponent WHERE id = %d;", "SELECT render_asset FROM RenderComponent WHERE id = ?;");
componentId); query.bind(1, (int) componentId);
auto result = query.execQuery();
if (result.eof()) if (result.eof())
{ {

View File

@ -15,9 +15,11 @@ ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent)
this->m_PassiveAbilities = ItemSetPassiveAbility::FindAbilities(id, m_InventoryComponent->GetParent(), this); this->m_PassiveAbilities = ItemSetPassiveAbility::FindAbilities(id, m_InventoryComponent->GetParent(), this);
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT skillSetWith2, skillSetWith3, skillSetWith4, skillSetWith5, skillSetWith6, itemIDs FROM ItemSets WHERE setID = %u;", "SELECT skillSetWith2, skillSetWith3, skillSetWith4, skillSetWith5, skillSetWith6, itemIDs FROM ItemSets WHERE setID = ?;");
id); query.bind(1, (int) id);
auto result = query.execQuery();
if (result.eof()) if (result.eof())
{ {
@ -31,9 +33,11 @@ ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent)
continue; continue;
} }
auto skillResult = CDClientDatabase::ExecuteQueryWithArgs( auto skillQuery = CDClientDatabase::CreatePreppedStmt(
"SELECT SkillID FROM ItemSetSkills WHERE SkillSetID = %d;", "SELECT SkillID FROM ItemSetSkills WHERE SkillSetID = ?;");
result.getIntField(i)); skillQuery.bind(1, result.getIntField(i));
auto skillResult = skillQuery.execQuery();
if (skillResult.eof()) if (skillResult.eof())
{ {

View File

@ -16,9 +16,11 @@
std::map<uint32_t, Precondition*> Preconditions::cache = {}; std::map<uint32_t, Precondition*> Preconditions::cache = {};
Precondition::Precondition(const uint32_t condition) { Precondition::Precondition(const uint32_t condition) {
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT type, targetLOT, targetCount FROM Preconditions WHERE id = %u;", "SELECT type, targetLOT, targetCount FROM Preconditions WHERE id = ?;");
condition); query.bind(1, (int) condition);
auto result = query.execQuery();
if (result.eof()) if (result.eof())
{ {

View File

@ -1243,11 +1243,13 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
} }
if (chatCommand == "lookup" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() == 1) { if (chatCommand == "lookup" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() == 1) {
std::string query = "%" + args[0] + "%"; auto query = CDClientDatabase::CreatePreppedStmt(
const char* query_cstr = query.c_str(); "SELECT `id`, `name` FROM `Objects` WHERE `displayName` LIKE ?1 OR `name` LIKE ?1 OR `description` LIKE ?1 LIMIT 50");
auto tables = CDClientDatabase::ExecuteQueryWithArgs(
"SELECT `id`, `name` FROM `Objects` WHERE `displayName` LIKE %Q OR `name` LIKE %Q OR `description` LIKE %Q LIMIT 50", const std::string query_text = "%" + args[0] + "%";
query_cstr, query_cstr, query_cstr); query.bind(1, query_text.c_str());
auto tables = query.execQuery();
while (!tables.eof()) { while (!tables.eof()) {
std::string message = std::to_string(tables.getIntField(0)) + " - " + tables.getStringField(1); std::string message = std::to_string(tables.getIntField(0)) + " - " + tables.getStringField(1);

View File

@ -1059,9 +1059,11 @@ void HandlePacket(Packet* packet) {
const auto zoneId = Game::server->GetZoneID(); const auto zoneId = Game::server->GetZoneID();
const auto cloneId = g_CloneID; const auto cloneId = g_CloneID;
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT id FROM PropertyTemplate WHERE mapID = %u;", "SELECT id FROM PropertyTemplate WHERE mapID = ?;");
zoneId); query.bind(1, (int) zoneId);
auto result = query.execQuery();
if (result.eof() || result.fieldIsNull(0)) { if (result.eof() || result.fieldIsNull(0)) {
Game::logger->Log("WorldServer", "No property templates found for zone %d, not sending BBB\n", zoneId); Game::logger->Log("WorldServer", "No property templates found for zone %d, not sending BBB\n", zoneId);

View File

@ -26,9 +26,11 @@ void dZoneManager::Initialize(const LWOZONEID& zoneID) {
LOT zoneControlTemplate = 2365; LOT zoneControlTemplate = 2365;
auto result = CDClientDatabase::ExecuteQueryWithArgs( auto query = CDClientDatabase::CreatePreppedStmt(
"SELECT zoneControlTemplate, ghostdistance_min, ghostdistance FROM ZoneTable WHERE zoneID = %d;", "SELECT zoneControlTemplate, ghostdistance_min, ghostdistance FROM ZoneTable WHERE zoneID = ?;");
(int) zoneID.GetMapID()); query.bind(1, (int) zoneID.GetMapID());
auto result = query.execQuery();
if (!result.eof()) { if (!result.eof()) {
zoneControlTemplate = result.getIntField("zoneControlTemplate", 2365); zoneControlTemplate = result.getIntField("zoneControlTemplate", 2365);