diff --git a/dDatabase/GameDatabase/ITables/IProperty.h b/dDatabase/GameDatabase/ITables/IProperty.h index 5674024e1..c77e0fca0 100644 --- a/dDatabase/GameDatabase/ITables/IProperty.h +++ b/dDatabase/GameDatabase/ITables/IProperty.h @@ -34,6 +34,9 @@ public: uint32_t numResults{}; uint32_t startIndex{}; uint32_t playerSort{}; + // Also match properties with no name / no description of their own, whatever the search text + bool includeNullName{}; + bool includeNullDescription{}; }; struct PropertyEntranceResult { diff --git a/dDatabase/GameDatabase/MySQL/Tables/Property.cpp b/dDatabase/GameDatabase/MySQL/Tables/Property.cpp index 10664bad8..f640c50eb 100644 --- a/dDatabase/GameDatabase/MySQL/Tables/Property.cpp +++ b/dDatabase/GameDatabase/MySQL/Tables/Property.cpp @@ -25,6 +25,11 @@ IProperty::PropertyEntranceResult MySQLDatabase::GetProperties(const IProperty:: std::string query; PreparedStmtResultSet properties; + // The client sets these when the search text is part of the map's default property name / description, which it + // shows for a property with none of its own (LWOPropertyEntranceComponent::onRequestPropertyInfo) + const uint32_t includeNullName = params.includeNullName ? 1 : 0; + const uint32_t includeNullDescription = params.includeNullDescription ? 1 : 0; + if (params.sortChoice == SORT_TYPE_FEATURED || params.sortChoice == SORT_TYPE_FRIENDS) { query = R"QUERY( FROM properties as p @@ -35,6 +40,8 @@ IProperty::PropertyEntranceResult MySQLDatabase::GetProperties(const IProperty:: p.description LIKE ? OR p.name LIKE ? OR ci.name LIKE ? + OR (? != 0 AND p.name = '') + OR (? != 0 AND p.description = '') ) AND p.privacy_option >= ? AND ( @@ -62,6 +69,8 @@ IProperty::PropertyEntranceResult MySQLDatabase::GetProperties(const IProperty:: "%" + params.searchString + "%", "%" + params.searchString + "%", "%" + params.searchString + "%", + includeNullName, + includeNullDescription, params.playerSort, params.playerId, params.playerId, @@ -78,6 +87,8 @@ IProperty::PropertyEntranceResult MySQLDatabase::GetProperties(const IProperty:: "%" + params.searchString + "%", "%" + params.searchString + "%", "%" + params.searchString + "%", + includeNullName, + includeNullDescription, params.playerSort, params.playerId, params.playerId, @@ -99,6 +110,8 @@ IProperty::PropertyEntranceResult MySQLDatabase::GetProperties(const IProperty:: p.description LIKE ? OR p.name LIKE ? OR ci.name LIKE ? + OR (? != 0 AND p.name = '') + OR (? != 0 AND p.description = '') ) AND p.privacy_option >= ? ORDER BY p.reputation DESC, p.last_updated DESC @@ -113,6 +126,8 @@ IProperty::PropertyEntranceResult MySQLDatabase::GetProperties(const IProperty:: p.description LIKE ? OR p.name LIKE ? OR ci.name LIKE ? + OR (? != 0 AND p.name = '') + OR (? != 0 AND p.description = '') ) AND p.privacy_option >= ? ORDER BY p.last_updated DESC @@ -125,6 +140,8 @@ IProperty::PropertyEntranceResult MySQLDatabase::GetProperties(const IProperty:: "%" + params.searchString + "%", "%" + params.searchString + "%", "%" + params.searchString + "%", + includeNullName, + includeNullDescription, params.playerSort, params.numResults, params.startIndex @@ -136,6 +153,8 @@ IProperty::PropertyEntranceResult MySQLDatabase::GetProperties(const IProperty:: "%" + params.searchString + "%", "%" + params.searchString + "%", "%" + params.searchString + "%", + includeNullName, + includeNullDescription, params.playerSort ); if (count->next()) { diff --git a/dDatabase/GameDatabase/SQLite/Tables/Property.cpp b/dDatabase/GameDatabase/SQLite/Tables/Property.cpp index 839cf288b..035beda67 100644 --- a/dDatabase/GameDatabase/SQLite/Tables/Property.cpp +++ b/dDatabase/GameDatabase/SQLite/Tables/Property.cpp @@ -25,6 +25,11 @@ IProperty::PropertyEntranceResult SQLiteDatabase::GetProperties(const IProperty: std::string query; std::pair propertiesRes; + // The client sets these when the search text is part of the map's default property name / description, which it + // shows for a property with none of its own (LWOPropertyEntranceComponent::onRequestPropertyInfo) + const uint32_t includeNullName = params.includeNullName ? 1 : 0; + const uint32_t includeNullDescription = params.includeNullDescription ? 1 : 0; + if (params.sortChoice == SORT_TYPE_FEATURED || params.sortChoice == SORT_TYPE_FRIENDS) { query = R"QUERY( FROM properties as p @@ -35,6 +40,8 @@ IProperty::PropertyEntranceResult SQLiteDatabase::GetProperties(const IProperty: p.description LIKE ? OR p.name LIKE ? OR ci.name LIKE ? + OR (? != 0 AND p.name = '') + OR (? != 0 AND p.description = '') ) AND p.privacy_option >= ? AND ( @@ -62,6 +69,8 @@ IProperty::PropertyEntranceResult SQLiteDatabase::GetProperties(const IProperty: "%" + params.searchString + "%", "%" + params.searchString + "%", "%" + params.searchString + "%", + includeNullName, + includeNullDescription, params.playerSort, params.playerId, params.playerId, @@ -78,6 +87,8 @@ IProperty::PropertyEntranceResult SQLiteDatabase::GetProperties(const IProperty: "%" + params.searchString + "%", "%" + params.searchString + "%", "%" + params.searchString + "%", + includeNullName, + includeNullDescription, params.playerSort, params.playerId, params.playerId, @@ -99,6 +110,8 @@ IProperty::PropertyEntranceResult SQLiteDatabase::GetProperties(const IProperty: p.description LIKE ? OR p.name LIKE ? OR ci.name LIKE ? + OR (? != 0 AND p.name = '') + OR (? != 0 AND p.description = '') ) AND p.privacy_option >= ? ORDER BY p.reputation DESC, p.last_updated DESC @@ -113,6 +126,8 @@ IProperty::PropertyEntranceResult SQLiteDatabase::GetProperties(const IProperty: p.description LIKE ? OR p.name LIKE ? OR ci.name LIKE ? + OR (? != 0 AND p.name = '') + OR (? != 0 AND p.description = '') ) AND p.privacy_option >= ? ORDER BY p.last_updated DESC @@ -125,6 +140,8 @@ IProperty::PropertyEntranceResult SQLiteDatabase::GetProperties(const IProperty: "%" + params.searchString + "%", "%" + params.searchString + "%", "%" + params.searchString + "%", + includeNullName, + includeNullDescription, params.playerSort, params.numResults, params.startIndex @@ -136,6 +153,8 @@ IProperty::PropertyEntranceResult SQLiteDatabase::GetProperties(const IProperty: "%" + params.searchString + "%", "%" + params.searchString + "%", "%" + params.searchString + "%", + includeNullName, + includeNullDescription, params.playerSort ); if (!count.eof()) { diff --git a/dGame/dComponents/Property/PropertyEntranceComponent.cpp b/dGame/dComponents/Property/PropertyEntranceComponent.cpp index 214cc8ae1..8ad08c15b 100644 --- a/dGame/dComponents/Property/PropertyEntranceComponent.cpp +++ b/dGame/dComponents/Property/PropertyEntranceComponent.cpp @@ -154,6 +154,8 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl IProperty::PropertyLookup propertyLookup; propertyLookup.mapId = m_MapID; propertyLookup.searchString = filterText; + propertyLookup.includeNullName = includeNullAddress; + propertyLookup.includeNullDescription = includeNullDescription; propertyLookup.sortChoice = static_cast(sortMethod); // Live listed every property of the player's friends and of the account's other characters in the friends list, // whatever its access type (64 friend entries with accessType 0 in the captured replies); the client locks the diff --git a/tests/dDatabaseTests/PropertyListSqliteTests.cpp b/tests/dDatabaseTests/PropertyListSqliteTests.cpp index 820107749..e4f0db756 100644 --- a/tests/dDatabaseTests/PropertyListSqliteTests.cpp +++ b/tests/dDatabaseTests/PropertyListSqliteTests.cpp @@ -107,3 +107,30 @@ TEST_F(PropertyListSqlite, PublicListsHoldPublicPropertiesOnly) { EXPECT_EQ(Owners(db->GetProperties(Lookup(SORT_TYPE_RECENT, 2))), (std::set{ P_CAROL, P_DAVE })); EXPECT_EQ(Owners(db->GetProperties(Lookup(SORT_TYPE_REPUTATION, 2))), (std::set{ P_CAROL, P_DAVE })); } + +// The client shows the map's default name and description for a property with none of its own, and sets +// bIncludeNullAddress / bIncludeNullDescription when the search text is part of that default, so these are found. +TEST_F(PropertyListSqlite, SearchFindsUnnamedPropertiesWhenAskedTo) { + auto lookup = Lookup(SORT_TYPE_RECENT, 2, "Avant"); + EXPECT_TRUE(Owners(db->GetProperties(lookup)).empty()); + + lookup.includeNullName = true; + EXPECT_EQ(Owners(db->GetProperties(lookup)), (std::set{ P_DAVE })); + + lookup.includeNullName = false; + lookup.includeNullDescription = true; + EXPECT_EQ(Owners(db->GetProperties(lookup)), (std::set{ P_DAVE })); + + // A named property is still only found by its own text + lookup.searchString = "Keep"; + EXPECT_EQ(Owners(db->GetProperties(lookup)), (std::set{ P_CAROL, P_DAVE })); + lookup.includeNullDescription = false; + EXPECT_EQ(Owners(db->GetProperties(lookup)), (std::set{ P_CAROL })); +} + +TEST_F(PropertyListSqlite, FriendsSearchFindsUnnamedPropertiesWhenAskedTo) { + auto lookup = Lookup(SORT_TYPE_FRIENDS, 0, "Avant"); + EXPECT_TRUE(Owners(db->GetProperties(lookup)).empty()); + lookup.includeNullName = true; + EXPECT_EQ(Owners(db->GetProperties(lookup)), (std::set{ P_ALICE_TWO, P_BOB })); +}