mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
fix: player messages work on the player that sent them
SetTooltipFlag, SetLastCustomBuild, ModifyPlayerZoneStatistic and UpdatePlayerStatistic are only handled for the character of the player that sent them. ReportBug, ReportOffensiveModel and ReportOffensiveProperty report for the sender's own character, whatever object they name. RequestActivityExit is only handled for the player that sent it, and ZonePropertyModelRotated checks for the sender's player before using it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -64,8 +64,12 @@ namespace GameMessages {
|
||||
void RequestActivityExit::Handle(Entity& entity, const SystemAddress& sysAddr) {
|
||||
if (!bUserCancel) return;
|
||||
|
||||
// A player asks to leave the activity themselves
|
||||
auto* player = Game::entityManager->GetEntity(userID);
|
||||
if (!player) return;
|
||||
if (!player || !player->IsPlayer() || player->GetSystemAddress() != sysAddr) {
|
||||
LOG("Player %llu of an activity exit is not the player that sent it", userID);
|
||||
return;
|
||||
}
|
||||
entity.RequestActivityExit(&entity, userID, bUserCancel);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,8 +89,20 @@ namespace GameMessages {
|
||||
return true;
|
||||
}
|
||||
|
||||
// The client sends these for its own character: they are only handled for the character of the sender
|
||||
namespace {
|
||||
CharacterComponent* SendersCharacter(Entity& entity, const SystemAddress& sysAddr) {
|
||||
auto* const characterComponent = entity.GetComponent<CharacterComponent>();
|
||||
if (!characterComponent || characterComponent->GetSystemAddress() != sysAddr) {
|
||||
LOG("Object %llu is not the character of the player that sent a message for it", entity.GetObjectID());
|
||||
return nullptr;
|
||||
}
|
||||
return characterComponent;
|
||||
}
|
||||
}
|
||||
|
||||
void SetTooltipFlag::Handle(Entity& entity, const SystemAddress& sysAddr) {
|
||||
auto* const characterComponent = entity.GetComponent<CharacterComponent>();
|
||||
auto* const characterComponent = SendersCharacter(entity, sysAddr);
|
||||
if (characterComponent) characterComponent->SetTooltipFlag(iToolTip, bFlag);
|
||||
}
|
||||
|
||||
@@ -104,7 +116,7 @@ namespace GameMessages {
|
||||
}
|
||||
|
||||
void SetLastCustomBuild::Handle(Entity& entity, const SystemAddress& sysAddr) {
|
||||
auto* const characterComponent = entity.GetComponent<CharacterComponent>();
|
||||
auto* const characterComponent = SendersCharacter(entity, sysAddr);
|
||||
if (characterComponent) characterComponent->SetLastCustomBuild(tokenizedLOTList);
|
||||
}
|
||||
|
||||
@@ -157,7 +169,7 @@ namespace GameMessages {
|
||||
|
||||
void ModifyPlayerZoneStatistic::Handle(Entity& entity, const SystemAddress& sysAddr) {
|
||||
// Notify the character component that something's changed
|
||||
auto* characterComponent = entity.GetComponent<CharacterComponent>();
|
||||
auto* characterComponent = SendersCharacter(entity, sysAddr);
|
||||
if (characterComponent != nullptr) {
|
||||
characterComponent->HandleZoneStatisticsUpdate(zoneID, statName, statValue);
|
||||
}
|
||||
@@ -175,7 +187,7 @@ namespace GameMessages {
|
||||
}
|
||||
|
||||
void UpdatePlayerStatistic::Handle(Entity& entity, const SystemAddress& sysAddr) {
|
||||
auto* characterComponent = entity.GetComponent<CharacterComponent>();
|
||||
auto* characterComponent = SendersCharacter(entity, sysAddr);
|
||||
if (characterComponent != nullptr) {
|
||||
characterComponent->UpdatePlayerStatistic(static_cast<StatisticID>(updateID), static_cast<uint64_t>(std::max(updateValue, static_cast<int64_t>(0))), true);
|
||||
}
|
||||
@@ -226,12 +238,15 @@ namespace GameMessages {
|
||||
reportInfo.otherPlayer = otherPlayerID;
|
||||
reportInfo.selection = selection;
|
||||
|
||||
auto character = entity.GetCharacter();
|
||||
// From the sender's character
|
||||
auto* const reporter = PlayerManager::GetPlayer(sysAddr);
|
||||
if (!reporter) return;
|
||||
auto character = reporter->GetCharacter();
|
||||
if (character) reportInfo.characterId = character->GetID();
|
||||
|
||||
// Report Abuse about another player sends their ID here (and "0" otherwise); that's a player report, not a bug
|
||||
if (const auto reportedId = GeneralUtils::TryParse<LWOOBJID>(reportInfo.otherPlayer).value_or(LWOOBJID_EMPTY); reportedId != LWOOBJID_EMPTY) {
|
||||
PlayerReports::ReportPlayer(&entity, reportedId, reportInfo.body);
|
||||
PlayerReports::ReportPlayer(reporter, reportedId, reportInfo.body);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -519,8 +519,9 @@ namespace GameMessages {
|
||||
}
|
||||
|
||||
void ZonePropertyModelRotated::Handle(Entity& entity, const SystemAddress& sysAddr) {
|
||||
User* usr = UserManager::Instance()->GetUser(sysAddr);
|
||||
Game::entityManager->GetZoneControlEntity()->OnZonePropertyModelRotated(usr->GetLastUsedChar()->GetEntity());
|
||||
auto* const player = PlayerManager::GetPlayer(sysAddr);
|
||||
auto* const zoneControl = Game::entityManager->GetZoneControlEntity();
|
||||
if (player && zoneControl) zoneControl->OnZonePropertyModelRotated(player);
|
||||
}
|
||||
|
||||
void PlacePropertyModel::Serialize(RakNet::BitStream& bitStream) const {
|
||||
@@ -688,7 +689,9 @@ namespace GameMessages {
|
||||
}
|
||||
|
||||
void ReportOffensiveModel::Handle(Entity& entity, const SystemAddress& sysAddr) {
|
||||
PlayerReports::ReportOffensiveModel(&entity, description, offensiveObjectID);
|
||||
// Reported by the sender's character
|
||||
auto* const reporter = PlayerManager::GetPlayer(sysAddr);
|
||||
if (reporter) PlayerReports::ReportOffensiveModel(reporter, description, offensiveObjectID);
|
||||
}
|
||||
|
||||
void ReportOffensiveProperty::Serialize(RakNet::BitStream& bitStream) const {
|
||||
@@ -703,7 +706,8 @@ namespace GameMessages {
|
||||
}
|
||||
|
||||
void ReportOffensiveProperty::Handle(Entity& entity, const SystemAddress& sysAddr) {
|
||||
PlayerReports::ReportOffensiveProperty(&entity, description, propertyPlaqueObjectID);
|
||||
auto* const reporter = PlayerManager::GetPlayer(sysAddr);
|
||||
if (reporter) PlayerReports::ReportOffensiveProperty(reporter, description, propertyPlaqueObjectID);
|
||||
}
|
||||
|
||||
ControlBehaviors::ControlBehaviors() : NetGameMsg(MessageType::Game::CONTROL_BEHAVIORS) {}
|
||||
|
||||
Reference in New Issue
Block a user