Skip to content

Commit

Permalink
send disable spectate RPC when it's incorrectly enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Oct 13, 2023
1 parent e2fdba7 commit 5dfb852
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Server/Source/player_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,19 @@ struct Player final : public IPlayer, public PoolIDProvider, public NoCopy

void setSpectating(bool spectating) override
{
NetCode::RPC::TogglePlayerSpectating togglePlayerSpectatingRPC;

// Reset internal player spectating data if ID is already set to a player
// Related issue: https://github.com/openmultiplayer/open.mp/issues/735
if (!spectating && spectateData_.spectateID != INVALID_PLAYER_ID)
// UPD: Also send player spectating RPC to disable it first in client internally
if (spectating && spectateData_.type == PlayerSpectateData::ESpectateType::Player && spectateData_.spectateID != INVALID_PLAYER_ID)
{
spectateData_.type = PlayerSpectateData::ESpectateType::None;
spectateData_.spectateID = INVALID_PLAYER_ID;
spectateData_.spectating = false;

togglePlayerSpectatingRPC.Enable = spectateData_.spectating;
PacketHelper::send(togglePlayerSpectatingRPC, *this);
}

if (spectating == spectateData_.spectating)
Expand Down Expand Up @@ -641,7 +647,6 @@ struct Player final : public IPlayer, public PoolIDProvider, public NoCopy
}

spectateData_.spectating = spectating;
NetCode::RPC::TogglePlayerSpectating togglePlayerSpectatingRPC;
togglePlayerSpectatingRPC.Enable = spectating;
PacketHelper::send(togglePlayerSpectatingRPC, *this);
}
Expand Down

0 comments on commit 5dfb852

Please sign in to comment.