more cleanup

This commit is contained in:
EmosewaMC 2022-03-28 20:51:15 -07:00
parent 965d4c7af0
commit 19e82a5150

View File

@ -84,6 +84,7 @@ PropertySelectQueryProperty PropertyEntranceComponent::SetPropertyValues(Propert
property.OwnerName = ownerName; property.OwnerName = ownerName;
property.Name = propertyName; property.Name = propertyName;
property.Description = propertyDescription; property.Description = propertyDescription;
// Reputation not updated for client side listing?
property.Reputation = reputation; property.Reputation = reputation;
property.IsBestFriend = isBFF; property.IsBestFriend = isBFF;
property.IsFriend = isFriend; property.IsFriend = isFriend;
@ -140,8 +141,10 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
std::vector<PropertySelectQueryProperty> entries {}; std::vector<PropertySelectQueryProperty> entries {};
PropertySelectQueryProperty playerEntry {}; PropertySelectQueryProperty playerEntry {};
auto* character = entity->GetCharacter();
auto character = entity->GetCharacter();
if (!character) return; if (!character) return;
// Player property goes in index 1 of the vector. This is how the client expects it. // Player property goes in index 1 of the vector. This is how the client expects it.
auto playerPropertyLookup = Database::CreatePreppedStmt("SELECT * FROM properties WHERE owner_id = ? AND zone_id = ?"); auto playerPropertyLookup = Database::CreatePreppedStmt("SELECT * FROM properties WHERE owner_id = ? AND zone_id = ?");
@ -167,19 +170,17 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
delete playerPropertyLookupResults; delete playerPropertyLookupResults;
playerPropertyLookupResults = nullptr; playerPropertyLookupResults = nullptr;
delete playerPropertyLookup; delete playerPropertyLookup;
playerPropertyLookup = nullptr; playerPropertyLookup = nullptr;
entries.push_back(playerEntry); entries.push_back(playerEntry);
sql::ResultSet* propertyEntry;
sql::PreparedStatement* propertyLookup;
const auto query = BuildQuery(entity, sortMethod); const auto query = BuildQuery(entity, sortMethod);
propertyLookup = Database::CreatePreppedStmt(query); auto propertyLookup = Database::CreatePreppedStmt(query);
const std::string searchString = "%" + filterText + "%"; const auto searchString = "%" + filterText + "%";
propertyLookup->setUInt(1, this->m_MapID); propertyLookup->setUInt(1, this->m_MapID);
propertyLookup->setString(2, searchString.c_str()); propertyLookup->setString(2, searchString.c_str());
propertyLookup->setString(3, searchString.c_str()); propertyLookup->setString(3, searchString.c_str());
@ -191,7 +192,7 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
Game::logger->Log("PropertyEntranceComponent", "Property query is \n%s\n. Entity is %s.\n", query.c_str(), entity->GetGMLevel() >= GAME_MASTER_LEVEL_LEAD_MODERATOR ? "a moderator" : "not a moderator"); Game::logger->Log("PropertyEntranceComponent", "Property query is \n%s\n. Entity is %s.\n", query.c_str(), entity->GetGMLevel() >= GAME_MASTER_LEVEL_LEAD_MODERATOR ? "a moderator" : "not a moderator");
propertyEntry = propertyLookup->executeQuery(); auto propertyEntry = propertyLookup->executeQuery();
while (propertyEntry->next()) while (propertyEntry->next())
{ {
@ -202,42 +203,52 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
const auto description = propertyEntry->getString(6).asStdString(); const auto description = propertyEntry->getString(6).asStdString();
const auto privacyOption = propertyEntry->getInt(9); const auto privacyOption = propertyEntry->getInt(9);
const auto modApproved = propertyEntry->getBoolean(10); const auto modApproved = propertyEntry->getBoolean(10);
const auto dateUpdated = propertyEntry->getInt(11); const auto dateLastUpdated = propertyEntry->getInt(11);
const auto reputation = propertyEntry->getUInt(14); const auto reputation = propertyEntry->getUInt(14);
PropertySelectQueryProperty entry {}; PropertySelectQueryProperty entry {};
auto* nameLookup = Database::CreatePreppedStmt("SELECT name FROM charinfo WHERE prop_clone_id = ?;"); std::string ownerName = "";
bool isOwned = true;
auto nameLookup = Database::CreatePreppedStmt("SELECT name FROM charinfo WHERE prop_clone_id = ?;");
nameLookup->setUInt64(1, cloneId); nameLookup->setUInt64(1, cloneId);
auto* nameResult = nameLookup->executeQuery(); auto nameResult = nameLookup->executeQuery();
if (!nameResult->next()) if (!nameResult->next()) {
{
delete nameLookup; delete nameLookup;
nameLookup = nullptr;
Game::logger->Log("PropertyEntranceComponent", "Failed to find property owner name for %llu!\n", cloneId); Game::logger->Log("PropertyEntranceComponent", "Failed to find property owner name for %llu!\n", cloneId);
continue; continue;
} }
else else {
{ isOwned = cloneId == character->GetPropertyCloneID();
entry.IsOwned = owner == entity->GetCharacter()->GetID(); ownerName = nameResult->getString(1).asStdString();
entry.OwnerName = nameResult->getString(1).asStdString();
} }
if (modApproved) delete nameResult;
{ nameResult = nullptr;
entry.Name = name;
entry.Description = description; delete nameLookup;
} nameLookup = nullptr;
std::string propertyName = "";
std::string propertyDescription = "";
propertyName = name;
propertyDescription = description;
bool isBestFriend = false;
bool isFriend = false;
// Convert owner char id to LWOOBJID // Convert owner char id to LWOOBJID
LWOOBJID ownerObjId = owner; LWOOBJID ownerObjId = owner;
ownerObjId = GeneralUtils::SetBit(ownerObjId, OBJECT_BIT_CHARACTER); ownerObjId = GeneralUtils::SetBit(ownerObjId, OBJECT_BIT_CHARACTER);
ownerObjId = GeneralUtils::SetBit(ownerObjId, OBJECT_BIT_PERSISTENT); ownerObjId = GeneralUtils::SetBit(ownerObjId, OBJECT_BIT_PERSISTENT);
// Query to get friend and best friend fields
auto friendCheck = Database::CreatePreppedStmt("SELECT best_friend FROM friends WHERE (player_id = ? AND friend_id = ?) OR (player_id = ? AND friend_id = ?)"); auto friendCheck = Database::CreatePreppedStmt("SELECT best_friend FROM friends WHERE (player_id = ? AND friend_id = ?) OR (player_id = ? AND friend_id = ?)");
friendCheck->setInt64(1, entity->GetObjectID()); friendCheck->setInt64(1, entity->GetObjectID());
@ -249,18 +260,29 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
// If we got a result than the two players are friends. // If we got a result than the two players are friends.
if (friendResult->next()) { if (friendResult->next()) {
entry.IsFriend = true; isFriend = true;
if (friendResult->getBoolean(1) == true) { if (friendResult->getBoolean(1) == true) {
entry.IsBestFriend = true; isBestFriend = true;
} else {
entry.IsBestFriend = false;
} }
} }
else {
entry.IsFriend = false;
entry.IsBestFriend = false;
}
delete friendCheck;
friendCheck = nullptr;
delete friendResult;
friendResult = nullptr;
bool isModeratorApproved = propertyEntry->getBoolean(10);
if (!isModeratorApproved && entity->GetGMLevel() >= GAME_MASTER_LEVEL_LEAD_MODERATOR) {
ownerName = "[AWAITING APPROVAL]";
propertyName = "[AWAITING APPROVAL]";
propertyDescription = "[AWAITING APPROVAL]";
entry.IsModeratorApproved = true;
}
bool isAlt = false;
// Query to determine whether this property is an alt of the entity.
auto isAltQuery = Database::CreatePreppedStmt("SELECT id FROM charinfo where account_id in (SELECT account_id from charinfo WHERE id = ?) AND id = ?;"); auto isAltQuery = Database::CreatePreppedStmt("SELECT id FROM charinfo where account_id in (SELECT account_id from charinfo WHERE id = ?) AND id = ?;");
isAltQuery->setInt(1, character->GetID()); isAltQuery->setInt(1, character->GetID());
@ -269,27 +291,25 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
auto isAltQueryResults = isAltQuery->executeQuery(); auto isAltQueryResults = isAltQuery->executeQuery();
if (isAltQueryResults->next()) { if (isAltQueryResults->next()) {
entry.IsAlt = true; isAlt = true;
} else {
entry.IsAlt = false;
} }
delete isAltQueryResults;
isAltQueryResults = nullptr;
delete isAltQuery; delete isAltQuery;
isAltQuery = nullptr; isAltQuery = nullptr;
entry.DateLastPublished = dateUpdated;
// Reputation not updated client side for listing? entry = SetPropertyValues(entry, cloneId, ownerName, propertyName, propertyDescription, reputation, isBestFriend, isFriend, isModeratorApproved, isAlt, isOwned, privacyOption, dateLastUpdated);
entry.Reputation = reputation;
entry.CloneId = cloneId;
entry.IsModeratorApproved = modApproved == true;
entry.AccessType = privacyOption;
// Client still reads performance cost as zero?
entry.PerformanceCost = 0;
entries.push_back(entry); entries.push_back(entry);
delete nameLookup;
} }
delete propertyEntry;
propertyEntry = nullptr;
delete propertyLookup; delete propertyLookup;
propertyLookup = nullptr;
propertyQueries[entity->GetObjectID()] = entries; propertyQueries[entity->GetObjectID()] = entries;