From 126edee366be750c7acb718f0916dcd314617f5f Mon Sep 17 00:00:00 2001 From: Robbe Bryssinck Date: Tue, 22 Feb 2022 18:35:02 +0100 Subject: [PATCH] fix: health and death sync bug --- Code/client/Events/HealthChangeEvent.h | 3 ++- Code/server/GameServer.cpp | 5 +++-- Code/server/GameServer.h | 2 +- Code/server/Services/ActorValueService.cpp | 12 ++++-------- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Code/client/Events/HealthChangeEvent.h b/Code/client/Events/HealthChangeEvent.h index f653b072e..97e310790 100644 --- a/Code/client/Events/HealthChangeEvent.h +++ b/Code/client/Events/HealthChangeEvent.h @@ -6,7 +6,8 @@ struct HealthChangeEvent { HealthChangeEvent(uint32_t aHitteeId, float aDeltaHealth) : HitteeId(aHitteeId), DeltaHealth(aDeltaHealth) - {} + { + } uint32_t HitteeId; float DeltaHealth; diff --git a/Code/server/GameServer.cpp b/Code/server/GameServer.cpp index b7c62c2d3..c5c6b8c04 100644 --- a/Code/server/GameServer.cpp +++ b/Code/server/GameServer.cpp @@ -325,11 +325,12 @@ void GameServer::SendToLoaded(const ServerMessage& acServerMessage) const } } -void GameServer::SendToPlayers(const ServerMessage& acServerMessage) const +void GameServer::SendToPlayers(const ServerMessage& acServerMessage, const Player* apExcludeSender) const { for (auto pPlayer : m_pWorld->GetPlayerManager()) { - pPlayer->Send(acServerMessage); + if (pPlayer != apExcludeSender) + pPlayer->Send(acServerMessage); } } diff --git a/Code/server/GameServer.h b/Code/server/GameServer.h index f6dc80266..0e074296a 100644 --- a/Code/server/GameServer.h +++ b/Code/server/GameServer.h @@ -54,7 +54,7 @@ struct GameServer final : Server void Send(ConnectionId_t aConnectionId, const ServerMessage& acServerMessage) const; void Send(ConnectionId_t aConnectionId, const ServerAdminMessage& acServerMessage) const; void SendToLoaded(const ServerMessage& acServerMessage) const; - void SendToPlayers(const ServerMessage& acServerMessage) const; + void SendToPlayers(const ServerMessage& acServerMessage, const Player* apExcludeSender = nullptr) const; void SendToPlayersInRange(const ServerMessage& acServerMessage, const entt::entity acOrigin) const; const Info& GetInfo() const noexcept diff --git a/Code/server/Services/ActorValueService.cpp b/Code/server/Services/ActorValueService.cpp index dfcfcc769..eea3c3c3d 100644 --- a/Code/server/Services/ActorValueService.cpp +++ b/Code/server/Services/ActorValueService.cpp @@ -46,8 +46,7 @@ void ActorValueService::OnActorValueChanges(const PacketEvent(message.Id); - GameServer::Get()->SendToPlayersInRange(notify, cEntity); + GameServer::Get()->SendToPlayers(notify, acMessage.pPlayer); } void ActorValueService::OnActorMaxValueChanges(const PacketEvent& acMessage) const noexcept @@ -74,8 +73,7 @@ void ActorValueService::OnActorMaxValueChanges(const PacketEvent(message.Id); - GameServer::Get()->SendToPlayersInRange(notify, cEntity); + GameServer::Get()->SendToPlayers(notify, acMessage.pPlayer); } void ActorValueService::OnHealthChangeBroadcast(const PacketEvent& acMessage) const noexcept @@ -86,8 +84,7 @@ void ActorValueService::OnHealthChangeBroadcast(const PacketEvent(message.Id); - GameServer::Get()->SendToPlayersInRange(notify, cEntity); + GameServer::Get()->SendToPlayers(notify, acMessage.pPlayer); } void ActorValueService::OnDeathStateChange(const PacketEvent& acMessage) const noexcept @@ -110,7 +107,6 @@ void ActorValueService::OnDeathStateChange(const PacketEvent(message.Id); - GameServer::Get()->SendToPlayersInRange(notify, cEntity); + GameServer::Get()->SendToPlayers(notify, acMessage.pPlayer); }