forked from citizenfx/fivem
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServerGameStatePublicInstance.cpp
More file actions
159 lines (120 loc) · 5.71 KB
/
ServerGameStatePublicInstance.cpp
File metadata and controls
159 lines (120 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "StdInc.h"
#include "ServerGameStatePublicInstance.h"
#include <NetBuffer.h>
#include <Client.h>
#include <GameServer.h>
#include <state/ServerGameStatePublic.h>
#include "GameStateNAck.h"
#include "GameStateAck.h"
class ServerGameStatePublicImpl : public fx::ServerGameStatePublic
{
public:
static inline std::optional<fx::ServerGameStatePublicInstance::ParseGameStatePacketData> parseGameStatePacketDataLastCall{};
static inline std::optional<fx::ServerGameStatePublicInstance::GameEventHandler> gameEventHandlerLastCall{};
static inline std::optional<fx::ServerGameStatePublicInstance::ArrayUpdateData> arrayUpdateLastCall{};
static inline std::optional<fx::ServerGameStatePublicInstance::GameStateNAckData> gameStateNAckLastCall{};
static inline std::optional<fx::ServerGameStatePublicInstance::GameStateAckData> gameStateAckLastCall{};
static inline std::function<bool()> gameEventHandler;
static inline std::optional<fx::ServerGameStatePublicInstance::SendObjectIdsData> getFreeObjectIdsLastCall{};
static inline std::vector<uint16_t> freeObjectIds{};
ServerGameStatePublicImpl() = default;
virtual ~ServerGameStatePublicImpl() = default;
void GetFreeObjectIds(const fx::ClientSharedPtr& client, uint8_t numIds, std::vector<uint16_t>& freeIds) override
{
getFreeObjectIdsLastCall.emplace(client, numIds);
freeIds = freeObjectIds;
}
fx::SyncStyle GetSyncStyle() override
{
return fx::SyncStyle::NAK;
}
fx::EntityLockdownMode GetEntityLockdownMode(const fx::ClientSharedPtr& client) override
{
return fx::EntityLockdownMode::Strict;
}
void ParseGameStatePacket(const fx::ClientSharedPtr& client, const net::packet::ClientRoute& packetData) override
{
parseGameStatePacketDataLastCall.emplace(client, std::vector<uint8_t>{packetData.data.GetValue().begin(), packetData.data.GetValue().end()});
}
void ForAllEntities(const std::function<void(fx::sync::Entity*)>& cb) override
{
}
bool SetEntityStateBag(uint8_t playerId, uint16_t objectId, std::function<std::shared_ptr<fx::StateBag>()> createStateBag) override
{
return false;
}
uint32_t GetClientRoutingBucket(const fx::ClientSharedPtr& client) override
{
return fx::AnyCast<uint32_t>(client->GetData("routingBucket"));
}
std::function<bool()> GetGameEventHandlerWithEvent(const fx::ClientSharedPtr& client, const std::vector<uint16_t>& targetPlayers, net::packet::ClientNetGameEventV2& netGameEvent) override
{
gameEventHandlerLastCall.emplace(client, targetPlayers, netGameEvent);
return gameEventHandler;
}
bool IsClientRelevantEntity(const fx::ClientSharedPtr& client, uint32_t objectId) override
{
// todo: add test for this
return true;
}
void HandleArrayUpdate(const fx::ClientSharedPtr& client, net::packet::ClientArrayUpdate& buffer) override
{
arrayUpdateLastCall.emplace(client, buffer.handler.GetValue(), buffer.index.GetValue(), std::vector<uint8_t>{ buffer.data.GetValue().begin(), buffer.data.GetValue().end() });
}
void HandleGameStateNAck(fx::ServerInstanceBase* instance, const fx::ClientSharedPtr& client, net::packet::ClientGameStateNAck& buffer) override
{
gameStateNAckLastCall.emplace(client, buffer.GetFlags(), buffer.GetFrameIndex(), buffer.GetFirstMissingFrame(), buffer.GetLastMissingFrame(), std::vector<net::packet::ClientGameStateNAck::IgnoreListEntry>{ buffer.GetIgnoreList().begin(), buffer.GetIgnoreList().end() }, std::vector<uint16_t>{ buffer.GetRecreateList().begin(), buffer.GetRecreateList().end() });
}
void HandleGameStateAck(fx::ServerInstanceBase* instance, const fx::ClientSharedPtr& client, net::packet::ClientGameStateAck& buffer) override
{
gameStateAckLastCall.emplace(client, buffer.GetFrameIndex(), std::vector<net::packet::ClientGameStateNAck::IgnoreListEntry>{ buffer.GetIgnoreList().begin(), buffer.GetIgnoreList().end() }, std::vector<uint16_t>{ buffer.GetRecreateList().begin(), buffer.GetRecreateList().end() });
}
bool GetStateBagStrictMode() const override
{
return false;
}
bool IsNetGameEventBlocked(uint32_t eventNameHash) override
{
return false;
}
};
fx::ServerGameStatePublic* fx::ServerGameStatePublicInstance::Create()
{
return new ServerGameStatePublicImpl();
}
void fx::ServerGameStatePublicInstance::SetClientRoutingBucket(const ClientSharedPtr& client, const uint32_t routingBucket)
{
client->SetData("routingBucket", routingBucket);
}
std::optional<fx::ServerGameStatePublicInstance::ParseGameStatePacketData>& fx::ServerGameStatePublicInstance::GetParseGameStatePacketDataLastCall()
{
return ServerGameStatePublicImpl::parseGameStatePacketDataLastCall;
}
std::optional<fx::ServerGameStatePublicInstance::GameEventHandler>& fx::ServerGameStatePublicInstance::GetGameEventHandlerLastCall()
{
return ServerGameStatePublicImpl::gameEventHandlerLastCall;
}
std::optional<fx::ServerGameStatePublicInstance::SendObjectIdsData>& fx::ServerGameStatePublicInstance::GetFreeObjectIdsLastCall()
{
return ServerGameStatePublicImpl::getFreeObjectIdsLastCall;
}
std::vector<uint16_t>& fx::ServerGameStatePublicInstance::GetFreeObjectIds()
{
return ServerGameStatePublicImpl::freeObjectIds;
}
std::optional<fx::ServerGameStatePublicInstance::ArrayUpdateData>& fx::ServerGameStatePublicInstance::GetArrayUpdateLastCall()
{
return ServerGameStatePublicImpl::arrayUpdateLastCall;
}
std::optional<fx::ServerGameStatePublicInstance::GameStateNAckData>& fx::ServerGameStatePublicInstance::GetGameStateNAckLastCall()
{
return ServerGameStatePublicImpl::gameStateNAckLastCall;
}
std::optional<fx::ServerGameStatePublicInstance::GameStateAckData>& fx::ServerGameStatePublicInstance::GetGameStateAckLastCall()
{
return ServerGameStatePublicImpl::gameStateAckLastCall;
}
std::function<bool()>& fx::ServerGameStatePublicInstance::GetGameEventHandler()
{
return ServerGameStatePublicImpl::gameEventHandler;
}