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& reasonMessage,
170 bool skipDisconnectMessage,
171 ::Json::Value const& sessionSummary
172 ) /*override*/;
173
174 virtual void onAllConnectionsClosed(::Connection::DisconnectFailReason, ::std::string const&, bool) /*override*/;
175
176 virtual void
177 onAllRemoteConnectionsClosed(::Connection::DisconnectFailReason, ::std::string const&, bool) /*override*/;
178
179 virtual void onOutgoingConnectionFailed(
180 ::Connection::DisconnectFailReason discoReason,
181 ::std::string const& reasonMessage
182 ) /*override*/;
183
184 virtual void onWebsocketRequest(
185 ::std::string const& serverAddress,
186 ::std::string const& payload,
187 ::std::function<void()> errorCallback
188 ) /*override*/;
189 // NOLINTEND
190
191public:
192 // member functions
193 // NOLINTBEGIN
194 MCAPI explicit NetworkSystem(::NetworkSystem::Dependencies&& deps);
195
196 MCAPI void _sendInternal(::NetworkIdentifier const& id, ::Packet const& packet, ::std::string const& data);
197
198 MCAPI bool
199 _sortAndPacketizeEvents(::NetworkConnection& connection, ::std::chrono::steady_clock::time_point endTime);
200
201 MCAPI_C void closeConnection(
202 ::NetworkIdentifier const& id,
203 ::Connection::DisconnectFailReason discoReason,
204 ::std::string const& reasonMessage
205 );
206
207 MCAPI void disconnect();
208
209 MCAPI void enableAsyncFlush(::NetworkIdentifier const& id);
210
211 MCAPI ::NetworkPeer* getPeerForUser(::NetworkIdentifier const& id);
212
213 MCAPI ::Bedrock::NotNullNonOwnerPtr<::RemoteConnector> getRemoteConnector();
214
215 MCAPI bool isServer() const;
216
217 MCAPI_C void registerClientInstance(::NetEventCallback& callback, ::SubClientId subID);
218
219 MCAPI void runEvents(bool networkIsCritical);
220
221 MCAPI void send(::NetworkIdentifier const& id, ::Packet const& packet, ::SubClientId recipientSubId);
222
223 MCAPI void sendToMultiple(::std::vector<::NetworkIdentifierWithSubId> const& ids, ::Packet const& packet);
224
225 MCAPI void setDevConnectionQuality(::DevConnectionQuality quality);
226
227 MCAPI void update(::std::vector<::WeakEntityRef> const* userList);
228 // NOLINTEND
229
230public:
231 // constructor thunks
232 // NOLINTBEGIN
233 MCAPI void* $ctor(::NetworkSystem::Dependencies&& deps);
234 // NOLINTEND
235
236public:
237 // destructor thunk
238 // NOLINTBEGIN
239 MCAPI void $dtor();
240 // NOLINTEND
241
242public:
243 // virtual function thunks
244 // NOLINTBEGIN
245 MCFOLD bool $useIPv4Only() const;
246
247 MCAPI bool $useIPv6Only() const;
248
249 MCAPI ushort $getDefaultGamePort() const;
250
251 MCAPI ushort $getDefaultGamePortv6() const;
252
253 MCAPI void $_onDisable();
254
255 MCAPI void $_onEnable();
256
257 MCAPI bool $onNewIncomingConnection(::NetworkIdentifier const& id, ::std::shared_ptr<::NetworkPeer>&& peer);
258
259 MCAPI bool $onNewOutgoingConnection(::NetworkIdentifier const& id, ::std::shared_ptr<::NetworkPeer>&& peer);
260
261 MCAPI void $onConnectionClosed(
262 ::NetworkIdentifier const& id,
263 ::Connection::DisconnectFailReason const discoReason,
264 ::std::string const& reasonMessage,
265 bool skipDisconnectMessage,
266 ::Json::Value const& sessionSummary
267 );
268
269 MCAPI void
270 $onOutgoingConnectionFailed(::Connection::DisconnectFailReason discoReason, ::std::string const& reasonMessage);
271
272 MCAPI void $onWebsocketRequest(
273 ::std::string const& serverAddress,
274 ::std::string const& payload,
275 ::std::function<void()> errorCallback
276 );
277
278
279 // NOLINTEND
280
281public:
282 // vftables
283 // NOLINTBEGIN
284 MCNAPI static void** $vftableForConnectionCallbacks();
285
286 MCNAPI static void** $vftableForIPSupportInterface();
287
289 // NOLINTEND
290};
Definition AppPlatform.h:76
Definition IPacketObserver.h:14
Definition IPacketSerializationController.h:9
Definition Value.h:16
Definition LocalConnector.h:17
Definition NetEventCallback.h:245
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:19
Definition TaskGroup.h:53
Definition WeakEntityRef.h:14
STL namespace.
Definition NetworkIdentifierWithSubId.h:10
Definition NetworkSystem.h:55
Definition NetworkSystem.h:81
Definition RakNetConnector.h:39
Definition ReflectionCtx.h:11