LeviLamina
Loading...
Searching...
No Matches
NetworkSystem.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/common/SubClientId.h"
7#include "mc/deps/core/threading/Async.h"
8#include "mc/deps/core/utility/BinaryStream.h"
9#include "mc/deps/core/utility/NonOwnerPointer.h"
10#include "mc/deps/core/utility/pub_sub/Publisher.h"
11#include "mc/network/DevConnectionQuality.h"
12#include "mc/network/NetworkEnableDisableListener.h"
13#include "mc/network/NetworkSettingOptions.h"
14#include "mc/network/PacketGroupDefinition.h"
15#include "mc/network/RakNetConnector.h"
16#include "mc/network/RakPeerHelper.h"
17#include "mc/network/connection/DisconnectFailReason.h"
18#include "mc/platform/threading/Mutex.h"
19
20// auto generated forward declare list
21// clang-format off
22class AppPlatform;
23class IPacketObserver;
25class LocalConnector;
29class NetworkPeer;
32class Packet;
33class RemoteConnector;
34class Scheduler;
35class ServerLocator;
36class TaskGroup;
37class WeakEntityRef;
39namespace Bedrock::PubSub::ThreadModel { struct MultiThreaded; }
40namespace Json { class Value; }
41namespace cereal { struct ReflectionCtx; }
42// clang-format on
43
44class NetworkSystem : public ::RakNetConnector::ConnectionCallbacks,
46 public ::NetworkEnableDisableListener {
47public:
48 // NetworkSystem inner types declare
49 // clang-format off
50 struct Dependencies;
52 // clang-format on
53
54 // NetworkSystem inner types define
55 struct Dependencies {
56 public:
57 // member variables
58 // NOLINTBEGIN
59 ::ll::TypedStorage<8, 8, ::std::reference_wrapper<::Scheduler>> receiveThread;
60 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::RemoteConnector>> remoteConnector;
61 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::ServerLocator>> serverLocator;
62 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::AppPlatform>> appPlatform;
63 ::ll::TypedStorage<8, 24, ::Bedrock::NotNullNonOwnerPtr<::NetworkSessionOwner>> networkSessionOwner;
64 ::ll::TypedStorage<4, 20, ::NetworkSettingOptions> networkSettingOptions;
65 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::IPacketSerializationController>> serializationController;
66 // NOLINTEND
67
68 public:
69 // member functions
70 // NOLINTBEGIN
71 MCNAPI ~Dependencies();
72 // NOLINTEND
73
74 public:
75 // destructor thunk
76 // NOLINTBEGIN
77 MCNAPI void $dtor();
78 // NOLINTEND
79 };
80
81 struct IncomingPacketQueue {
82 public:
83 // member variables
84 // NOLINTBEGIN
85 ::ll::TypedStorage<8, 8, ::NetEventCallback&> mCallbacksObj;
86 ::ll::TypedStorage<8, 80, ::Bedrock::Threading::Mutex> mMutex;
87 // NOLINTEND
88
89 public:
90 // prevent constructor by default
91 IncomingPacketQueue& operator=(IncomingPacketQueue const&);
92 IncomingPacketQueue(IncomingPacketQueue const&);
93 IncomingPacketQueue();
94 };
95
96public:
97 // member variables
98 // NOLINTBEGIN
99 ::ll::TypedStorage<8, 24, ::Bedrock::NotNullNonOwnerPtr<::NetworkSessionOwner>> mNetworkSessionOwner;
100 ::ll::TypedStorage<8, 80, ::std::recursive_mutex> mConnectionsMutex;
101 ::ll::TypedStorage<8, 24, ::std::vector<::std::unique_ptr<::NetworkConnection>>> mConnections;
102 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::LocalConnector>> mLocalConnector;
103 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::PacketGroupDefinition::PacketGroupBuilder>> mPacketGroupBuilder;
104 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::RemoteConnector>> mRemoteConnector;
105 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::ServerLocator>> mServerLocator;
106 ::ll::TypedStorage<8, 8, uint64> mCurrentConnection;
107 ::ll::TypedStorage<8, 16, ::Bedrock::Threading::Async<void>> mReceiveTask;
108 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::TaskGroup>> mReceiveTaskGroup;
109 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::IPacketObserver>> mPacketObserver;
110 ::ll::TypedStorage<8, 8, ::Scheduler&> mMainThread;
111 ::ll::TypedStorage<8, 32, ::std::string> mReceiveBuffer;
112 ::ll::TypedStorage<8, 32, ::std::string> mSendBuffer;
113 ::ll::TypedStorage<8, 80, ::BinaryStream> mSendStream;
114 ::ll::TypedStorage<8, 32, ::std::unique_ptr<::NetworkSystem::IncomingPacketQueue>[4]> mIncomingPackets;
115 ::ll::TypedStorage<1, 1, bool> mUseIPv6Only;
116 ::ll::TypedStorage<2, 2, ushort> mDefaultGamePort;
117 ::ll::TypedStorage<2, 2, ushort> mDefaultGamePortv6;
118 ::ll::TypedStorage<1, 1, bool> mIsLanDiscoveryEnabled;
119 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::NetworkStatistics>> mNetworkStatistics;
120 ::ll::TypedStorage<1, 1, bool> mWebsocketsEnabled;
121 ::ll::TypedStorage<4, 20, ::NetworkSettingOptions> mNetworkSettingOptions;
122 ::ll::TypedStorage<1, 1, bool> mRawRecordingEnabled;
123 ::ll::TypedStorage<8, 8, ::gsl::not_null<::std::unique_ptr<::cereal::ReflectionCtx>>> mReflectionCtx;
124 ::ll::TypedStorage<8, 8, ::gsl::not_null<::std::unique_ptr<::IPacketSerializationController>>> mPacketOverrides;
125 ::ll::TypedStorage<
126 8,
127 8,
128 ::gsl::not_null<::std::unique_ptr<
129 ::Bedrock::PubSub::
131 mSessionSummaryPublisher;
132 // NOLINTEND
133
134public:
135 // prevent constructor by default
136 NetworkSystem& operator=(NetworkSystem const&);
137 NetworkSystem(NetworkSystem const&);
138 NetworkSystem();
139
140public:
141 LLNDAPI NetworkConnection* getConnectionFromId(NetworkIdentifier const& id);
142
143public:
144 // virtual functions
145 // NOLINTBEGIN
146 virtual bool useIPv4Only() const /*override*/;
147
148 virtual bool useIPv6Only() const /*override*/;
149
150 virtual ushort getDefaultGamePort() const /*override*/;
151
152 virtual ushort getDefaultGamePortv6() const /*override*/;
153
154 virtual ~NetworkSystem() /*override*/;
155
156 virtual void _onDisable() /*override*/;
157
158 virtual void _onEnable() /*override*/;
159
160 virtual bool
161 onNewIncomingConnection(::NetworkIdentifier const& id, ::std::shared_ptr<::NetworkPeer>&& peer) /*override*/;
162
163 virtual bool
164 onNewOutgoingConnection(::NetworkIdentifier const& id, ::std::shared_ptr<::NetworkPeer>&& peer) /*override*/;
165
166 virtual void onConnectionClosed(
167 ::NetworkIdentifier const& id,
168 ::Connection::DisconnectFailReason const discoReason,
169 ::std::string const& messageFromServer,
170 ::std::string const& messageBodyOverride,
171 bool skipDisconnectMessage,
172 ::Json::Value const& sessionSummary
173 ) /*override*/;
174
175 virtual void
176 onAllConnectionsClosed(::Connection::DisconnectFailReason discoReason, bool skipDisconnectMessage) /*override*/;
177
178 virtual void onAllRemoteConnectionsClosed(
179 ::Connection::DisconnectFailReason discoReason,
180 bool skipDisconnectMessage
181 ) /*override*/;
182
183 virtual void onOutgoingConnectionFailed(::Connection::DisconnectFailReason discoReason) /*override*/;
184
185 virtual void onWebsocketRequest(
186 ::std::string const& serverAddress,
187 ::std::string const& payload,
188 ::std::function<void()> errorCallback
189 ) /*override*/;
190 // NOLINTEND
191
192public:
193 // member functions
194 // NOLINTBEGIN
195 MCAPI explicit NetworkSystem(::NetworkSystem::Dependencies&& deps);
196
197 MCAPI void _sendInternal(::NetworkIdentifier const& id, ::Packet const& packet, ::std::string const& data);
198
199 MCAPI bool
200 _sortAndPacketizeEvents(::NetworkConnection& connection, ::std::chrono::steady_clock::time_point endTime);
201
202#ifdef LL_PLAT_C
203 MCAPI void closeConnection(
204 ::NetworkIdentifier const& id,
205 ::Connection::DisconnectFailReason discoReason,
206 ::std::string const& messageFromServer
207 );
208#endif
209
210 MCAPI void disconnect();
211
212 MCAPI void enableAsyncFlush(::NetworkIdentifier const& id);
213
214 MCAPI ::NetworkPeer* getPeerForUser(::NetworkIdentifier const& id);
215
216 MCAPI ::Bedrock::NotNullNonOwnerPtr<::RemoteConnector> getRemoteConnector();
217
218 MCAPI bool isServer() const;
219
220#ifdef LL_PLAT_C
221 MCAPI void registerClientInstance(::NetEventCallback& callback, ::SubClientId subID);
222#endif
223
224 MCAPI void runEvents(bool networkIsCritical);
225
226 MCAPI void send(::NetworkIdentifier const& id, ::Packet const& packet, ::SubClientId recipientSubId);
227
228 MCAPI void sendToMultiple(::std::vector<::NetworkIdentifierWithSubId> const& ids, ::Packet const& packet);
229
230 MCAPI void setDevConnectionQuality(::DevConnectionQuality quality);
231
232 MCAPI void update(::std::vector<::WeakEntityRef> const* userList);
233 // NOLINTEND
234
235public:
236 // constructor thunks
237 // NOLINTBEGIN
238 MCAPI void* $ctor(::NetworkSystem::Dependencies&& deps);
239 // NOLINTEND
240
241public:
242 // destructor thunk
243 // NOLINTBEGIN
244 MCAPI void $dtor();
245 // NOLINTEND
246
247public:
248 // virtual function thunks
249 // NOLINTBEGIN
250 MCFOLD bool $useIPv4Only() const;
251
252 MCAPI bool $useIPv6Only() const;
253
254 MCAPI ushort $getDefaultGamePort() const;
255
256 MCAPI ushort $getDefaultGamePortv6() const;
257
258 MCAPI void $_onDisable();
259
260 MCAPI void $_onEnable();
261
262 MCAPI bool $onNewIncomingConnection(::NetworkIdentifier const& id, ::std::shared_ptr<::NetworkPeer>&& peer);
263
264 MCAPI bool $onNewOutgoingConnection(::NetworkIdentifier const& id, ::std::shared_ptr<::NetworkPeer>&& peer);
265
266 MCAPI void $onConnectionClosed(
267 ::NetworkIdentifier const& id,
268 ::Connection::DisconnectFailReason const discoReason,
269 ::std::string const& messageFromServer,
270 ::std::string const& messageBodyOverride,
271 bool skipDisconnectMessage,
272 ::Json::Value const& sessionSummary
273 );
274
275 MCAPI void $onAllConnectionsClosed(::Connection::DisconnectFailReason discoReason, bool skipDisconnectMessage);
276
277 MCAPI void
278 $onAllRemoteConnectionsClosed(::Connection::DisconnectFailReason discoReason, bool skipDisconnectMessage);
279
280 MCAPI void $onOutgoingConnectionFailed(::Connection::DisconnectFailReason discoReason);
281
282 MCAPI void $onWebsocketRequest(
283 ::std::string const& serverAddress,
284 ::std::string const& payload,
285 ::std::function<void()> errorCallback
286 );
287
288
289 // NOLINTEND
290
291public:
292 // vftables
293 // NOLINTBEGIN
294 MCNAPI static void** $vftableForConnectionCallbacks();
295
296 MCNAPI static void** $vftableForIPSupportInterface();
297
299 // NOLINTEND
300};
Definition AppPlatform.h:91
Definition IPacketObserver.h:14
Definition IPacketSerializationController.h:9
Definition Value.h:16
Definition LocalConnector.h:18
Definition NetEventCallback.h:258
Definition NetworkConnection.h:30
Definition NetworkIdentifier.h:10
Definition NetworkPeer.h:8
Definition NetworkSessionOwner.h:9
Definition NetworkStatistics.h:23
static MCAPI void ** $vftableForIPSupportInterface()
static MCAPI void ** $vftableForNetworkEnableDisableListener()
static MCAPI void ** $vftableForConnectionCallbacks()
Definition Packet.h:28
Definition RakPeerHelper.h:35
Definition RemoteConnector.h:19
Definition Scheduler.h:14
Definition ServerLocator.h:17
Definition TaskGroup.h:57
Definition WeakEntityRef.h:14
STL namespace.
Definition MultiThreaded.h:12
Definition NetworkIdentifierWithSubId.h:10
Definition NetworkSystem.h:55
Definition NetworkSystem.h:81
Definition RakNetConnector.h:39
Definition ReflectionCtx.h:11