mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
LWOPropertyEntranceComponent::onRequestPropertyInfo sets the two flags of PropertyEntranceSync when the search text is part of the map's default property name / description, which the client shows for a property that has none of its own. Both were read and ignored, so a property without a name or description was never found by the text the player sees on it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
137 lines
5.8 KiB
C++
137 lines
5.8 KiB
C++
/**
|
|
* The property browser's list query (IProperty::GetProperties) on SQLite. Uses the database file that
|
|
* ChatHistorySqliteTests.cpp's environment creates and migrates.
|
|
*/
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <algorithm>
|
|
#include <memory>
|
|
#include <set>
|
|
|
|
#include "eGameMasterLevel.h"
|
|
#include "ePropertySortType.h"
|
|
#include "SQLiteDatabase.h"
|
|
|
|
namespace {
|
|
constexpr LWOOBJID P_ALICE = 1152921510000100001;
|
|
constexpr LWOOBJID P_ALICE_TWO = 1152921510000100002;
|
|
constexpr LWOOBJID P_BOB = 1152921510000100003;
|
|
constexpr LWOOBJID P_CAROL = 1152921510000100004;
|
|
constexpr LWOOBJID P_DAVE = 1152921510000100005;
|
|
constexpr LWOOBJID PROPERTY_BASE = 1152921510000200000;
|
|
constexpr uint32_t MAP = 1150;
|
|
|
|
// Alice and AliceTwo share an account; Bob is Alice's friend; Carol and Dave are strangers.
|
|
// Everybody owns a property on the map: Carol's is public and named, the others are private and unnamed.
|
|
class PropertyListSqlite : public ::testing::Test {
|
|
protected:
|
|
static inline std::unique_ptr<SQLiteDatabase> db;
|
|
|
|
static void SetUpTestSuite() {
|
|
db = std::make_unique<SQLiteDatabase>();
|
|
db->Connect();
|
|
db->InsertNewAccount("propAlice", "$2a$12$hash", eGameMasterLevel::CIVILIAN);
|
|
db->InsertNewAccount("propBob", "$2a$12$hash", eGameMasterLevel::CIVILIAN);
|
|
db->InsertNewAccount("propCarol", "$2a$12$hash", eGameMasterLevel::CIVILIAN);
|
|
db->InsertNewAccount("propDave", "$2a$12$hash", eGameMasterLevel::CIVILIAN);
|
|
const auto account = [](const char* name) { return db->GetAccountInfo(name)->id; };
|
|
const auto character = [](const std::string& name, const LWOOBJID id, const uint32_t accountId) {
|
|
db->InsertNewCharacter(ICharInfo::Info{ name, "", id, accountId, false, 0, static_cast<ePermissionMap>(0) });
|
|
};
|
|
character("PropAlice", P_ALICE, account("propAlice"));
|
|
character("PropAliceTwo", P_ALICE_TWO, account("propAlice"));
|
|
character("PropBob", P_BOB, account("propBob"));
|
|
character("PropCarol", P_CAROL, account("propCarol"));
|
|
character("PropDave", P_DAVE, account("propDave"));
|
|
db->AddFriend(P_ALICE, P_BOB);
|
|
|
|
uint32_t index = 0;
|
|
const auto property = [&index](const LWOOBJID owner, const std::string& name, const std::string& description, const int32_t privacy) {
|
|
IProperty::Info info{};
|
|
info.id = PROPERTY_BASE + ++index;
|
|
info.ownerId = owner;
|
|
info.cloneId = db->GetCharacterInfo(owner)->cloneId;
|
|
info.name = name;
|
|
info.description = description;
|
|
db->InsertNewProperty(info, 1, LWOZONEID(MAP, 0, info.cloneId));
|
|
db->SetPropertyPrivacy(info.id, privacy);
|
|
};
|
|
property(P_ALICE, "", "", 0);
|
|
property(P_ALICE_TWO, "", "", 0);
|
|
property(P_BOB, "", "", 0);
|
|
property(P_CAROL, "Carol's Keep", "A tall tower", 2);
|
|
property(P_DAVE, "", "", 2);
|
|
}
|
|
|
|
static void TearDownTestSuite() {
|
|
if (db) db->Destroy("PropertyListSqliteTests");
|
|
db.reset();
|
|
}
|
|
|
|
static IProperty::PropertyLookup Lookup(const ePropertySortType sort, const uint32_t minimumPrivacy, const std::string& search = "") {
|
|
IProperty::PropertyLookup lookup;
|
|
lookup.mapId = MAP;
|
|
lookup.searchString = search;
|
|
lookup.sortChoice = sort;
|
|
lookup.playerId = P_ALICE;
|
|
lookup.numResults = 12;
|
|
lookup.startIndex = 0;
|
|
lookup.playerSort = minimumPrivacy;
|
|
return lookup;
|
|
}
|
|
|
|
static std::set<LWOOBJID> Owners(const IProperty::PropertyEntranceResult& result) {
|
|
std::set<LWOOBJID> owners;
|
|
for (const auto& entry : result.entries) owners.insert(entry.ownerId);
|
|
EXPECT_EQ(owners.size(), result.entries.size());
|
|
EXPECT_EQ(result.totalEntriesMatchingQuery, static_cast<int32_t>(result.entries.size()));
|
|
return owners;
|
|
}
|
|
};
|
|
}
|
|
|
|
// Live friends lists held the friends' properties whatever their access type and the properties of the account's other
|
|
// characters, and never the player's own property or a stranger's.
|
|
TEST_F(PropertyListSqlite, FriendsListHoldsFriendsAndTheAccountsOtherCharacters) {
|
|
const auto owners = Owners(db->GetProperties(Lookup(SORT_TYPE_FRIENDS, 0)));
|
|
EXPECT_EQ(owners, (std::set<LWOOBJID>{ P_ALICE_TWO, P_BOB }));
|
|
}
|
|
|
|
// With a minimum access type the same query still filters (the caller passes 0 for the friends list)
|
|
TEST_F(PropertyListSqlite, FriendsListStillHonoursTheMinimumAccessType) {
|
|
EXPECT_TRUE(Owners(db->GetProperties(Lookup(SORT_TYPE_FRIENDS, 1))).empty());
|
|
}
|
|
|
|
// The other lists are unchanged: public properties only
|
|
TEST_F(PropertyListSqlite, PublicListsHoldPublicPropertiesOnly) {
|
|
EXPECT_EQ(Owners(db->GetProperties(Lookup(SORT_TYPE_RECENT, 2))), (std::set<LWOOBJID>{ P_CAROL, P_DAVE }));
|
|
EXPECT_EQ(Owners(db->GetProperties(Lookup(SORT_TYPE_REPUTATION, 2))), (std::set<LWOOBJID>{ 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<LWOOBJID>{ P_DAVE }));
|
|
|
|
lookup.includeNullName = false;
|
|
lookup.includeNullDescription = true;
|
|
EXPECT_EQ(Owners(db->GetProperties(lookup)), (std::set<LWOOBJID>{ P_DAVE }));
|
|
|
|
// A named property is still only found by its own text
|
|
lookup.searchString = "Keep";
|
|
EXPECT_EQ(Owners(db->GetProperties(lookup)), (std::set<LWOOBJID>{ P_CAROL, P_DAVE }));
|
|
lookup.includeNullDescription = false;
|
|
EXPECT_EQ(Owners(db->GetProperties(lookup)), (std::set<LWOOBJID>{ 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<LWOOBJID>{ P_ALICE_TWO, P_BOB }));
|
|
}
|