Skip to content

Commit

Permalink
feat(gamestate): filter REQUEST_RAGDOLL_EVENT for player peds
Browse files Browse the repository at this point in the history
- allow the user to opt-in to completely disabling this event too
  • Loading branch information
AvarianKnight committed Oct 17, 2023
1 parent 4cc07c9 commit d040826
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,7 @@ class ServerGameState : public ServerGameStatePublic, public fx::IAttached<fx::S

private:
std::function<bool()> GetRequestControlEventHandler(const fx::ClientSharedPtr& client, net::Buffer&& buffer);
std::function<bool()> GetRagdollRequestEventHandler(const fx::ClientSharedPtr& client, net::Buffer&& buffer);

public:
fx::sync::SyncEntityPtr GetEntity(uint8_t playerId, uint16_t objectId);
Expand Down
46 changes: 46 additions & 0 deletions code/components/citizen-server-impl/src/state/ServerGameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ static std::shared_ptr<ConVar<int>> g_requestControlSettleVar;
static RequestControlFilterMode g_requestControlFilterState;
static int g_requestControlSettleDelay;

static std::shared_ptr<ConVar<bool>> g_enableRagdollRequestsVar;
static bool g_enableRagdollRequests;

static uint32_t MakeHandleUniqifierPair(uint16_t objectId, uint16_t uniqifier)
{
return ((uint32_t)objectId << 16) | (uint32_t)uniqifier;
Expand Down Expand Up @@ -6749,6 +6752,43 @@ std::function<bool()> fx::ServerGameState::GetRequestControlEventHandler(const f
#endif
}

std::function<bool()> fx::ServerGameState::GetRagdollRequestEventHandler(const fx::ClientSharedPtr& client, net::Buffer&& buffer)
{
const auto rejectSync = []
{
return false;
};

// users have opted-in to completely disabling REQUEST_RAGDOLL_EVENT
if (!g_enableRagdollRequests)
{
return rejectSync;
}

uint32_t pedNetId = 0;
rl::MessageBuffer msg;

if (ParseEvent(std::move(buffer), &msg))
{
bool success = msg.Read<uint32_t>(13, &pedNetId);
if (!success)
{
return rejectSync;
}
}

auto ped = this->GetEntity(0, pedNetId);
return [ped, client]
{
const bool callerIsOwner = ped->GetClient() == client;
if (ped->type == sync::NetObjEntityType::Player && !callerIsOwner)
{
return false;
}
return true;
};
}

std::function<bool()> fx::ServerGameState::GetGameEventHandler(const fx::ClientSharedPtr& client, const std::vector<uint16_t>& targetPlayers, net::Buffer&& buffer)
{
auto instance = m_instance;
Expand All @@ -6773,6 +6813,11 @@ std::function<bool()> fx::ServerGameState::GetGameEventHandler(const fx::ClientS
return GetRequestControlEventHandler(client, std::move(buffer));
}

if (eventType == RAGDOLL_REQUEST_EVENT)
{
return GetRagdollRequestEventHandler(client, std::move(buffer));
}

if(eventType == NETWORK_PLAY_SOUND_EVENT)
{
return []()
Expand Down Expand Up @@ -6869,6 +6914,7 @@ static InitFunction initFunction([]()
}

g_networkedSoundsEnabledVar = instance->AddVariable<bool>("sv_enableNetworkedSounds", ConVar_None, true, &g_networkedSoundsEnabled);
g_enableRagdollRequestsVar = instance->AddVariable<bool>("sv_enableRagdollRequests", ConVar_None, true, &g_enableRagdollRequests);

g_networkedPhoneExplosionsEnabledVar = instance->AddVariable<bool>("sv_enableNetworkedPhoneExplosions", ConVar_None, false, &g_networkedPhoneExplosionsEnabled);

Expand Down

0 comments on commit d040826

Please sign in to comment.