mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-08 17:28:20 +00:00
chore: Use string to access SQLite columns (#1535)
* use string to access field name * Update DEVGMCommands.cpp * corrected column name * constexpr array include <array> Revert "constexpr array" This reverts commit 1492e8b1773ed5fbbe767c74466ca263178ecdd4. Revert "include <array>" This reverts commit 2b7a67e89ad673d420f496be97f9bc51fd2d5e59. include <array> constexpr array --------- Co-authored-by: jadebenn <jonahbenn@yahoo.com>
This commit is contained in:
parent
3a6123fe36
commit
5049f215ba
@ -536,13 +536,13 @@ void UserManager::LoginCharacter(const SystemAddress& sysAddr, uint32_t playerID
|
||||
uint32_t FindCharShirtID(uint32_t shirtColor, uint32_t shirtStyle) {
|
||||
try {
|
||||
auto stmt = CDClientDatabase::CreatePreppedStmt(
|
||||
"select obj.id from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == ? AND icc.color1 == ? AND icc.decal == ?"
|
||||
"select obj.id as objectId from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == ? AND icc.color1 == ? AND icc.decal == ?"
|
||||
);
|
||||
stmt.bind(1, "character create shirt");
|
||||
stmt.bind(2, static_cast<int>(shirtColor));
|
||||
stmt.bind(3, static_cast<int>(shirtStyle));
|
||||
auto tableData = stmt.execQuery();
|
||||
auto shirtLOT = tableData.getIntField(0, 4069);
|
||||
auto shirtLOT = tableData.getIntField("objectId", 4069);
|
||||
tableData.finalize();
|
||||
return shirtLOT;
|
||||
} catch (const std::exception& ex) {
|
||||
@ -555,12 +555,12 @@ uint32_t FindCharShirtID(uint32_t shirtColor, uint32_t shirtStyle) {
|
||||
uint32_t FindCharPantsID(uint32_t pantsColor) {
|
||||
try {
|
||||
auto stmt = CDClientDatabase::CreatePreppedStmt(
|
||||
"select obj.id from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == ? AND icc.color1 == ?"
|
||||
"select obj.id as objectId from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == ? AND icc.color1 == ?"
|
||||
);
|
||||
stmt.bind(1, "cc pants");
|
||||
stmt.bind(2, static_cast<int>(pantsColor));
|
||||
auto tableData = stmt.execQuery();
|
||||
auto pantsLOT = tableData.getIntField(0, 2508);
|
||||
auto pantsLOT = tableData.getIntField("objectId", 2508);
|
||||
tableData.finalize();
|
||||
return pantsLOT;
|
||||
} catch (const std::exception& ex) {
|
||||
|
@ -377,10 +377,10 @@ void Behavior::PlayFx(std::u16string type, const LWOOBJID target, const LWOOBJID
|
||||
return;
|
||||
}
|
||||
|
||||
const auto name = std::string(result.getStringField(0));
|
||||
const auto name = std::string(result.getStringField("effectName"));
|
||||
|
||||
if (type.empty()) {
|
||||
const auto typeResult = result.getStringField(1);
|
||||
const auto typeResult = result.getStringField("effectType");
|
||||
|
||||
type = GeneralUtils::ASCIIToUTF16(typeResult);
|
||||
|
||||
|
@ -47,11 +47,11 @@ void SwitchMultipleBehavior::Load() {
|
||||
auto result = query.execQuery();
|
||||
|
||||
while (!result.eof()) {
|
||||
const auto behavior_id = static_cast<uint32_t>(result.getFloatField(1));
|
||||
const auto behavior_id = static_cast<uint32_t>(result.getFloatField("behavior"));
|
||||
|
||||
auto* behavior = CreateBehavior(behavior_id);
|
||||
|
||||
auto value = result.getFloatField(2);
|
||||
auto value = result.getFloatField("value");
|
||||
|
||||
this->m_behaviors.emplace_back(value, behavior);
|
||||
|
||||
|
@ -45,20 +45,20 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id):
|
||||
auto componentResult = componentQuery.execQuery();
|
||||
|
||||
if (!componentResult.eof()) {
|
||||
if (!componentResult.fieldIsNull(0))
|
||||
m_AggroRadius = componentResult.getFloatField(0);
|
||||
if (!componentResult.fieldIsNull("aggroRadius"))
|
||||
m_AggroRadius = componentResult.getFloatField("aggroRadius");
|
||||
|
||||
if (!componentResult.fieldIsNull(1))
|
||||
m_TetherSpeed = componentResult.getFloatField(1);
|
||||
if (!componentResult.fieldIsNull("tetherSpeed"))
|
||||
m_TetherSpeed = componentResult.getFloatField("tetherSpeed");
|
||||
|
||||
if (!componentResult.fieldIsNull(2))
|
||||
m_PursuitSpeed = componentResult.getFloatField(2);
|
||||
if (!componentResult.fieldIsNull("pursuitSpeed"))
|
||||
m_PursuitSpeed = componentResult.getFloatField("pursuitSpeed");
|
||||
|
||||
if (!componentResult.fieldIsNull(3))
|
||||
m_SoftTetherRadius = componentResult.getFloatField(3);
|
||||
if (!componentResult.fieldIsNull("softTetherRadius"))
|
||||
m_SoftTetherRadius = componentResult.getFloatField("softTetherRadius");
|
||||
|
||||
if (!componentResult.fieldIsNull(4))
|
||||
m_HardTetherRadius = componentResult.getFloatField(4);
|
||||
if (!componentResult.fieldIsNull("hardTetherRadius"))
|
||||
m_HardTetherRadius = componentResult.getFloatField("hardTetherRadius");
|
||||
}
|
||||
|
||||
componentResult.finalize();
|
||||
@ -82,11 +82,11 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id):
|
||||
auto result = skillQuery.execQuery();
|
||||
|
||||
while (!result.eof()) {
|
||||
const auto skillId = static_cast<uint32_t>(result.getIntField(0));
|
||||
const auto skillId = static_cast<uint32_t>(result.getIntField("skillID"));
|
||||
|
||||
const auto abilityCooldown = static_cast<float>(result.getFloatField(1));
|
||||
const auto abilityCooldown = static_cast<float>(result.getFloatField("cooldown"));
|
||||
|
||||
const auto behaviorId = static_cast<uint32_t>(result.getIntField(2));
|
||||
const auto behaviorId = static_cast<uint32_t>(result.getIntField("behaviorID"));
|
||||
|
||||
auto* behavior = Behavior::CreateBehavior(behaviorId);
|
||||
|
||||
|
@ -450,7 +450,7 @@ const std::vector<BuffParameter>& BuffComponent::GetBuffParameters(int32_t buffI
|
||||
param.value = result.getFloatField("NumberValue");
|
||||
param.effectId = result.getIntField("EffectID");
|
||||
|
||||
if (!result.fieldIsNull(3)) {
|
||||
if (!result.fieldIsNull("StringValue")) {
|
||||
std::istringstream stream(result.getStringField("StringValue"));
|
||||
std::string token;
|
||||
|
||||
|
@ -389,9 +389,9 @@ void DestroyableComponent::AddFaction(const int32_t factionID, const bool ignore
|
||||
|
||||
if (result.eof()) return;
|
||||
|
||||
if (result.fieldIsNull(0)) return;
|
||||
if (result.fieldIsNull("enemyList")) return;
|
||||
|
||||
const auto* list_string = result.getStringField(0);
|
||||
const auto* list_string = result.getStringField("enemyList");
|
||||
|
||||
std::stringstream ss(list_string);
|
||||
std::string token;
|
||||
|
@ -1094,7 +1094,7 @@ void InventoryComponent::CheckItemSet(const LOT lot) {
|
||||
auto result = query.execQuery();
|
||||
|
||||
while (!result.eof()) {
|
||||
const auto id = result.getIntField(0);
|
||||
const auto id = result.getIntField("setID");
|
||||
|
||||
bool found = false;
|
||||
|
||||
|
@ -466,8 +466,8 @@ bool MissionComponent::RequiresItem(const LOT lot) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!result.fieldIsNull(0)) {
|
||||
const auto type = std::string(result.getStringField(0));
|
||||
if (!result.fieldIsNull("type")) {
|
||||
const auto type = std::string(result.getStringField("type"));
|
||||
|
||||
result.finalize();
|
||||
|
||||
|
@ -188,20 +188,20 @@ void PetComponent::OnUse(Entity* originator) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.fieldIsNull(0)) {
|
||||
if (result.fieldIsNull("ValidPiecesLXF")) {
|
||||
result.finalize();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
buildFile = std::string(result.getStringField(0));
|
||||
buildFile = std::string(result.getStringField("ValidPiecesLXF"));
|
||||
|
||||
PetPuzzleData data;
|
||||
data.buildFile = buildFile;
|
||||
data.puzzleModelLot = result.getIntField(1);
|
||||
data.timeLimit = result.getFloatField(2);
|
||||
data.numValidPieces = result.getIntField(3);
|
||||
data.imaginationCost = result.getIntField(4);
|
||||
data.puzzleModelLot = result.getIntField("PuzzleModelLot");
|
||||
data.timeLimit = result.getFloatField("Timelimit");
|
||||
data.numValidPieces = result.getIntField("NumValidPieces");
|
||||
data.imaginationCost = result.getIntField("imagCostPerBuild");
|
||||
if (data.timeLimit <= 0) data.timeLimit = 60;
|
||||
imaginationCost = data.imaginationCost;
|
||||
|
||||
|
@ -18,8 +18,8 @@ PossessableComponent::PossessableComponent(Entity* parent, uint32_t componentId)
|
||||
|
||||
// Should a result not exist for this default to attached visible
|
||||
if (!result.eof()) {
|
||||
m_PossessionType = static_cast<ePossessionType>(result.getIntField(0, 1)); // Default to Attached Visible
|
||||
m_DepossessOnHit = static_cast<bool>(result.getIntField(1, 0));
|
||||
m_PossessionType = static_cast<ePossessionType>(result.getIntField("possessionType", 1)); // Default to Attached Visible
|
||||
m_DepossessOnHit = static_cast<bool>(result.getIntField("depossessOnHit", 0));
|
||||
} else {
|
||||
m_PossessionType = ePossessionType::ATTACHED_VISIBLE;
|
||||
m_DepossessOnHit = false;
|
||||
|
@ -49,11 +49,11 @@ PropertyManagementComponent::PropertyManagementComponent(Entity* parent) : Compo
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (result.eof() || result.fieldIsNull(0)) {
|
||||
if (result.eof() || result.fieldIsNull("id")) {
|
||||
return;
|
||||
}
|
||||
|
||||
templateId = result.getIntField(0);
|
||||
templateId = result.getIntField("id");
|
||||
|
||||
auto propertyInfo = Database::Get()->GetPropertyInfo(zoneId, cloneId);
|
||||
|
||||
@ -105,7 +105,7 @@ std::vector<NiPoint3> PropertyManagementComponent::GetPaths() const {
|
||||
|
||||
std::vector<float> points;
|
||||
|
||||
std::istringstream stream(result.getStringField(0));
|
||||
std::istringstream stream(result.getStringField("path"));
|
||||
std::string token;
|
||||
|
||||
while (std::getline(stream, token, ' ')) {
|
||||
|
@ -117,7 +117,7 @@ void RenderComponent::PlayEffect(const int32_t effectId, const std::u16string& e
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (result.eof() || result.fieldIsNull(0)) {
|
||||
if (result.eof() || result.fieldIsNull("animation_length")) {
|
||||
result.finalize();
|
||||
|
||||
m_DurationCache[effectId] = 0;
|
||||
@ -127,7 +127,7 @@ void RenderComponent::PlayEffect(const int32_t effectId, const std::u16string& e
|
||||
return;
|
||||
}
|
||||
|
||||
effect.time = static_cast<float>(result.getFloatField(0));
|
||||
effect.time = static_cast<float>(result.getFloatField("animation_length"));
|
||||
|
||||
result.finalize();
|
||||
|
||||
|
@ -27,12 +27,12 @@ RocketLaunchpadControlComponent::RocketLaunchpadControlComponent(Entity* parent,
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (!result.eof() && !result.fieldIsNull(0)) {
|
||||
m_TargetZone = result.getIntField(0);
|
||||
m_DefaultZone = result.getIntField(1);
|
||||
m_TargetScene = result.getStringField(2);
|
||||
m_AltPrecondition = new PreconditionExpression(result.getStringField(3));
|
||||
m_AltLandingScene = result.getStringField(4);
|
||||
if (!result.eof() && !result.fieldIsNull("targetZone")) {
|
||||
m_TargetZone = result.getIntField("targetZone");
|
||||
m_DefaultZone = result.getIntField("defaultZoneID");
|
||||
m_TargetScene = result.getStringField("targetScene");
|
||||
m_AltPrecondition = new PreconditionExpression(result.getStringField("altLandingPrecondition"));
|
||||
m_AltLandingScene = result.getStringField("altLandingSpawnPointName");
|
||||
}
|
||||
|
||||
result.finalize();
|
||||
|
@ -99,7 +99,7 @@ void SkillComponent::SyncPlayerProjectile(const LWOOBJID projectileId, RakNet::B
|
||||
return;
|
||||
}
|
||||
|
||||
const auto behavior_id = static_cast<uint32_t>(result.getIntField(0));
|
||||
const auto behavior_id = static_cast<uint32_t>(result.getIntField("behaviorID"));
|
||||
|
||||
result.finalize();
|
||||
|
||||
@ -425,7 +425,7 @@ void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry)
|
||||
return;
|
||||
}
|
||||
|
||||
const auto behaviorId = static_cast<uint32_t>(result.getIntField(0));
|
||||
const auto behaviorId = static_cast<uint32_t>(result.getIntField("behaviorID"));
|
||||
|
||||
result.finalize();
|
||||
|
||||
|
@ -405,18 +405,18 @@ void Item::DisassembleModel(uint32_t numToDismantle) {
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (result.eof() || result.fieldIsNull(0)) {
|
||||
if (result.eof() || result.fieldIsNull("render_asset")) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string renderAsset = std::string(result.getStringField(0));
|
||||
std::string renderAsset = std::string(result.getStringField("render_asset"));
|
||||
|
||||
// normalize path slashes
|
||||
for (auto& c : renderAsset) {
|
||||
if (c == '\\') c = '/';
|
||||
}
|
||||
|
||||
std::string lxfmlFolderName = std::string(result.getStringField(1));
|
||||
std::string lxfmlFolderName = std::string(result.getStringField("LXFMLFolder"));
|
||||
if (!lxfmlFolderName.empty()) lxfmlFolderName.insert(0, "/");
|
||||
|
||||
std::vector<std::string> renderAssetSplit = GeneralUtils::SplitString(renderAsset, '/');
|
||||
|
@ -8,10 +8,13 @@
|
||||
#include "MissionComponent.h"
|
||||
#include "eMissionTaskType.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
#include "CDSkillBehaviorTable.h"
|
||||
|
||||
ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent) {
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
this->m_ID = id;
|
||||
this->m_InventoryComponent = inventoryComponent;
|
||||
|
||||
@ -27,14 +30,16 @@ ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto i = 0; i < 5; ++i) {
|
||||
if (result.fieldIsNull(i)) {
|
||||
constexpr std::array rowNames = { "skillSetWith2"sv, "skillSetWith3"sv, "skillSetWith4"sv, "skillSetWith5"sv, "skillSetWith6"sv };
|
||||
for (auto i = 0; i < rowNames.size(); ++i) {
|
||||
const auto rowName = rowNames[i];
|
||||
if (result.fieldIsNull(rowName.data())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto skillQuery = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT SkillID FROM ItemSetSkills WHERE SkillSetID = ?;");
|
||||
skillQuery.bind(1, result.getIntField(i));
|
||||
skillQuery.bind(1, result.getIntField(rowName.data()));
|
||||
|
||||
auto skillResult = skillQuery.execQuery();
|
||||
|
||||
@ -43,13 +48,13 @@ ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent) {
|
||||
}
|
||||
|
||||
while (!skillResult.eof()) {
|
||||
if (skillResult.fieldIsNull(0)) {
|
||||
if (skillResult.fieldIsNull("SkillID")) {
|
||||
skillResult.nextRow();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto skillId = skillResult.getIntField(0);
|
||||
const auto skillId = skillResult.getIntField("SkillID");
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
@ -75,7 +80,7 @@ ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string ids = result.getStringField(5);
|
||||
std::string ids = result.getStringField("itemIDs");
|
||||
|
||||
ids.erase(std::remove_if(ids.begin(), ids.end(), ::isspace), ids.end());
|
||||
|
||||
|
@ -33,10 +33,10 @@ Precondition::Precondition(const uint32_t condition) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->type = static_cast<PreconditionType>(result.fieldIsNull(0) ? 0 : result.getIntField(0));
|
||||
this->type = static_cast<PreconditionType>(result.fieldIsNull("type") ? 0 : result.getIntField("type"));
|
||||
|
||||
if (!result.fieldIsNull(1)) {
|
||||
std::istringstream stream(result.getStringField(1));
|
||||
if (!result.fieldIsNull("targetLOT")) {
|
||||
std::istringstream stream(result.getStringField("targetLOT"));
|
||||
std::string token;
|
||||
|
||||
while (std::getline(stream, token, ',')) {
|
||||
@ -45,7 +45,7 @@ Precondition::Precondition(const uint32_t condition) {
|
||||
}
|
||||
}
|
||||
|
||||
this->count = result.fieldIsNull(2) ? 1 : result.getIntField(2);
|
||||
this->count = result.fieldIsNull("targetCount") ? 1 : result.getIntField("targetCount");
|
||||
|
||||
result.finalize();
|
||||
}
|
||||
|
@ -704,7 +704,7 @@ namespace DEVGMCommands {
|
||||
auto tables = query.execQuery();
|
||||
|
||||
while (!tables.eof()) {
|
||||
std::string message = std::to_string(tables.getIntField(0)) + " - " + tables.getStringField(1);
|
||||
std::string message = std::to_string(tables.getIntField("id")) + " - " + tables.getStringField("name");
|
||||
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::UTF8ToUTF16(message, message.size()));
|
||||
tables.nextRow();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user