Skip to content

Commit f5e0451

Browse files
committed
feat(gamestate/server): add blockedEvents system
This add 2 commands to block individual net game events
1 parent 60beca6 commit f5e0451

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

code/components/citizen-server-impl/include/state/ServerGameState.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,7 @@ class ServerGameState : public ServerGameStatePublic, public fx::IAttached<fx::S
14761476
bool ValidateEntity(EntityLockdownMode entityLockdownMode, const fx::sync::SyncEntityPtr& entity);
14771477

14781478
public:
1479+
std::unordered_set<uint32_t> blockedEvents;
14791480
std::function<bool()> GetGameEventHandler(const fx::ClientSharedPtr& client, const std::vector<uint16_t>& targetPlayers, net::Buffer&& buffer);
14801481

14811482
private:

code/components/citizen-server-impl/src/state/ServerGameState.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4644,6 +4644,21 @@ void ServerGameState::AttachToObject(fx::ServerInstanceBase* instance)
46444644

46454645
console::Printf("net", "---------------- END OBJECT ID DUMP ----------------\n");
46464646
});
4647+
4648+
// event is either eventNameHash for msgNetGameEventV2, or eventId when using v1
4649+
static auto blockNetGameEvent = instance->AddCommand("block_net_game_event", [this](uint32_t event)
4650+
{
4651+
auto& blockedEvents = this->blockedEvents;
4652+
if (blockedEvents.find(event) != blockedEvents.end())
4653+
return;
4654+
blockedEvents.insert(event);
4655+
});
4656+
4657+
static auto allowNetGameEvent = instance->AddCommand("allow_net_game_event", [this](uint32_t event)
4658+
{
4659+
auto& blockedEvents = this->blockedEvents;
4660+
blockedEvents.erase(event);
4661+
});
46474662
}
46484663
}
46494664

@@ -7512,6 +7527,15 @@ std::function<bool()> fx::ServerGameState::GetGameEventHandler(const fx::ClientS
75127527
}
75137528
#endif
75147529

7530+
// This checks for event id rather than eventNameHash for compatibility until msgNetGameEventV2 is ready
7531+
if (blockedEvents.find(eventType) != blockedEvents.end())
7532+
{
7533+
return []()
7534+
{
7535+
return false;
7536+
};
7537+
}
7538+
75157539
// RDR3 remaps eventType on the client (netEventMgr_MapEventId)
75167540

75177541
#if defined(STATE_FIVE) || defined(STATE_RDR3)
@@ -7640,7 +7664,15 @@ std::function<bool()> fx::ServerGameState::GetGameEventHandlerWithEvent(const fx
76407664
auto instance = m_instance;
76417665

76427666
const bool isReply = netGameEvent.isReply;
7643-
const uint32_t eventNameHash = netGameEvent.eventNameHash;
7667+
const uint32_t eventNameHash = netGameEvent.eventNameHash;
7668+
7669+
if (blockedEvents.find(eventNameHash) != blockedEvents.end())
7670+
{
7671+
return []()
7672+
{
7673+
return false;
7674+
};
7675+
}
76447676

76457677
#if defined(STATE_FIVE) || defined(STATE_RDR3)
76467678
#ifdef STATE_FIVE

0 commit comments

Comments
 (0)