mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-17 01:05:28 +00:00
fix(skill): a start with a skill handle still in progress is dropped, as the client
LWOSkillComponent::msgStartSkill (0x00d45cb0) logs and ignores a StartSkill whose skill handle is still waiting on behavior syncs. The server ran it a second time: the hits, the imagination cost and the mission progress twice. Live captures hold 22 byte-identical StartSkill resends with the same handle a few packets apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "GeneralUtils.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
@@ -34,7 +35,18 @@ ProjectileSyncEntry::ProjectileSyncEntry() {
|
||||
|
||||
std::unordered_map<uint32_t, uint32_t> SkillComponent::m_skillBehaviorCache = {};
|
||||
|
||||
bool SkillComponent::IsSkillPending(const uint32_t skillUid) const {
|
||||
const auto [begin, end] = m_managedBehaviors.equal_range(skillUid);
|
||||
return std::any_of(begin, end, [](const auto& pair) { return pair.second && !pair.second->syncEntries.empty(); });
|
||||
}
|
||||
|
||||
bool SkillComponent::CastPlayerSkill(const uint32_t behaviorId, const uint32_t skillUid, RakNet::BitStream& bitStream, const LWOOBJID target, uint32_t skillID) {
|
||||
// A skill handle still waiting on syncs is taken: the client logs and drops a second start with it
|
||||
if (IsSkillPending(skillUid)) {
|
||||
LOG("StartSkill with existing skill handle %u for %llu", skillUid, m_Parent->GetObjectID());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* context = new BehaviorContext(this->m_Parent->GetObjectID());
|
||||
|
||||
context->caster = m_Parent->GetObjectID();
|
||||
|
||||
@@ -126,6 +126,11 @@ public:
|
||||
*/
|
||||
bool HasSkill(uint32_t skillUid) const { return m_managedBehaviors.contains(skillUid); }
|
||||
|
||||
/**
|
||||
* @return whether a skill with that handle still waits for the client to sync one of its behaviors
|
||||
*/
|
||||
bool IsSkillPending(uint32_t skillUid) const;
|
||||
|
||||
/**
|
||||
* Starts a player skill. Should only be called when the server receives a start skill message from the client.
|
||||
* @param behaviorId the root behavior ID of the skill
|
||||
|
||||
@@ -137,6 +137,10 @@ namespace GameMessages {
|
||||
Entity* entity = &entityRef;
|
||||
if (skillID == 1561 || skillID == 1562 || skillID == 1541) return;
|
||||
|
||||
// LWOSkillComponent::msgStartSkill (0x00d45cb0): a start with a skill handle still in progress is dropped
|
||||
const auto* const castingSkills = entity->GetComponent<SkillComponent>();
|
||||
if (castingSkills && castingSkills->IsSkillPending(uiSkillHandle)) return;
|
||||
|
||||
MissionComponent* comp = entity->GetComponent<MissionComponent>();
|
||||
if (comp) {
|
||||
comp->Progress(eMissionTaskType::USE_SKILL, skillID);
|
||||
|
||||
@@ -25,6 +25,7 @@ set(DCOMPONENTS_TESTS
|
||||
"UseItemResultTests.cpp"
|
||||
"LootMetricsTests.cpp"
|
||||
"SpawnerComponentTests.cpp"
|
||||
"SkillComponentTests.cpp"
|
||||
)
|
||||
|
||||
# Get the folder name and prepend it to the files above
|
||||
|
||||
62
tests/dGameTests/dComponentsTests/SkillComponentTests.cpp
Normal file
62
tests/dGameTests/dComponentsTests/SkillComponentTests.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "GameDependencies.h"
|
||||
|
||||
#include "Behavior.h"
|
||||
#include "BehaviorBranchContext.h"
|
||||
#include "BehaviorContext.h"
|
||||
#include "Entity.h"
|
||||
#include "SkillComponent.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace {
|
||||
// A behavior that waits for one client sync (handle 7) and counts the syncs it gets
|
||||
class WaitsForSync final : public Behavior {
|
||||
public:
|
||||
static constexpr uint32_t SYNC_HANDLE = 7;
|
||||
int syncs = 0;
|
||||
|
||||
explicit WaitsForSync(const uint32_t behaviorId) : Behavior(behaviorId) {}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) override {
|
||||
context->RegisterSyncBehavior(SYNC_HANDLE, this, branch, 10.0f);
|
||||
}
|
||||
|
||||
void Sync(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) override { ++syncs; }
|
||||
};
|
||||
}
|
||||
|
||||
class SkillComponentTests : public GameDependenciesTest {
|
||||
protected:
|
||||
static constexpr uint32_t BEHAVIOR_ID = 990001;
|
||||
WaitsForSync* behavior = nullptr;
|
||||
|
||||
void SetUp() override {
|
||||
SetUpDependencies();
|
||||
behavior = new WaitsForSync(BEHAVIOR_ID);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
Behavior::Cache.erase(BEHAVIOR_ID);
|
||||
delete behavior;
|
||||
TearDownDependencies();
|
||||
}
|
||||
};
|
||||
|
||||
// LWOSkillComponent::msgStartSkill (0x00d45cb0): a start whose skill handle still waits on syncs is logged and dropped;
|
||||
// once its behaviors are synced the handle can start a skill again.
|
||||
TEST_F(SkillComponentTests, StartWithAPendingSkillHandleIsDropped) {
|
||||
Entity caster(30, info);
|
||||
auto* const skills = caster.AddComponent<SkillComponent>(-1);
|
||||
RakNet::BitStream empty;
|
||||
|
||||
EXPECT_TRUE(skills->CastPlayerSkill(BEHAVIOR_ID, 5, empty, LWOOBJID_EMPTY));
|
||||
EXPECT_TRUE(skills->IsSkillPending(5));
|
||||
EXPECT_FALSE(skills->CastPlayerSkill(BEHAVIOR_ID, 5, empty, LWOOBJID_EMPTY));
|
||||
EXPECT_TRUE(skills->CastPlayerSkill(BEHAVIOR_ID, 6, empty, LWOOBJID_EMPTY)); // another handle is free
|
||||
|
||||
skills->SyncPlayerSkill(5, WaitsForSync::SYNC_HANDLE, empty);
|
||||
EXPECT_EQ(behavior->syncs, 1); // the dropped start registered no second sync
|
||||
EXPECT_FALSE(skills->IsSkillPending(5));
|
||||
EXPECT_TRUE(skills->CastPlayerSkill(BEHAVIOR_ID, 5, empty, LWOOBJID_EMPTY));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user