mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
PlayerFlags.OnlySetByServer marks 22 flags. The client's flag component refuses to set them itself (LWOFlagComponent::SendMessage logs "Attempted to set a flag from the client side that can only be set from the server"), and none of the 205 client SetFlag messages in the live captures named one; the server set them. SetFlag::Handle set whatever flag the message named. The message is now dropped for those flags, with a debug log line. Flags already saved on a character are not touched. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
75 lines
2.5 KiB
C++
75 lines
2.5 KiB
C++
// A client SetFlag for a flag marked PlayerFlags.OnlySetByServer is ignored: the client's own flag component refuses
|
|
// to set these (LWOFlagComponent::SendMessage), and none of the 205 live client SetFlag messages named one.
|
|
#include "GameDependencies.h"
|
|
|
|
#include "CDClientDatabase.h"
|
|
#include "Character.h"
|
|
#include "Entity.h"
|
|
#include "MissionMessages.h"
|
|
#include "User.h"
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <memory>
|
|
|
|
namespace {
|
|
constexpr int32_t SERVER_ONLY_FLAG = 1110;
|
|
constexpr int32_t CLIENT_FLAG = 1111;
|
|
constexpr int32_t UNLISTED_FLAG = 1112;
|
|
}
|
|
|
|
class SetFlagServerOnlyTests : public GameDependenciesTest {
|
|
protected:
|
|
void SetUp() override {
|
|
SetUpDependencies();
|
|
CDClientDatabase::Connect(":memory:");
|
|
CDClientDatabase::ExecuteDML("CREATE TABLE PlayerFlags (id INTEGER, SessionOnly INTEGER, OnlySetByServer INTEGER, SessionZoneOnly INTEGER);");
|
|
CDClientDatabase::ExecuteDML("INSERT INTO PlayerFlags VALUES (1110, 0, 1, 0), (1111, 0, 0, 0);");
|
|
user = std::make_unique<User>(UNASSIGNED_SYSTEM_ADDRESS, "tester", "key");
|
|
character = std::make_unique<Character>(1, user.get());
|
|
entity = std::make_unique<Entity>(1, info);
|
|
entity->SetCharacter(character.get());
|
|
character->SetEntity(entity.get());
|
|
}
|
|
|
|
void TearDown() override {
|
|
entity->SetCharacter(nullptr);
|
|
entity.reset();
|
|
character.reset();
|
|
user.reset();
|
|
TearDownDependencies();
|
|
}
|
|
|
|
void ClientSetsFlag(const int32_t flag, const bool value) {
|
|
GameMessages::SetFlag setFlag;
|
|
setFlag.iFlagID = flag;
|
|
setFlag.bFlag = value;
|
|
setFlag.Handle(*entity, UNASSIGNED_SYSTEM_ADDRESS);
|
|
}
|
|
|
|
std::unique_ptr<User> user;
|
|
std::unique_ptr<Character> character;
|
|
std::unique_ptr<Entity> entity;
|
|
};
|
|
|
|
TEST_F(SetFlagServerOnlyTests, ClientCannotSetAServerOnlyFlag) {
|
|
ClientSetsFlag(SERVER_ONLY_FLAG, true);
|
|
EXPECT_FALSE(character->GetPlayerFlag(SERVER_ONLY_FLAG));
|
|
}
|
|
|
|
// A flag the server set stays set: the client cannot clear it either, and nothing saved is dropped
|
|
TEST_F(SetFlagServerOnlyTests, ClientCannotClearAServerOnlyFlag) {
|
|
character->SetPlayerFlag(SERVER_ONLY_FLAG, true);
|
|
ClientSetsFlag(SERVER_ONLY_FLAG, false);
|
|
EXPECT_TRUE(character->GetPlayerFlag(SERVER_ONLY_FLAG));
|
|
}
|
|
|
|
// Every other flag is set and cleared as before, with or without a PlayerFlags row
|
|
TEST_F(SetFlagServerOnlyTests, OtherFlagsAreStillSetByTheClient) {
|
|
for (const auto flag : { CLIENT_FLAG, UNLISTED_FLAG }) {
|
|
ClientSetsFlag(flag, true);
|
|
EXPECT_TRUE(character->GetPlayerFlag(flag));
|
|
ClientSetsFlag(flag, false);
|
|
EXPECT_FALSE(character->GetPlayerFlag(flag));
|
|
}
|
|
}
|