85 inline explicit NetCommand(CommandQueue* commandQueue) :
86 _g_commandQueue(commandQueue)
88 virtual ~NetCommand() =
default;
90 [[nodiscard]]
virtual NetCommandTypes getType()
const = 0;
91 [[nodiscard]] NetCommandResults update(TransmitPacketPtr& buffPacket,
92 IpAddress::Types addressType,
94 std::chrono::milliseconds deltaTime);
95 virtual void onReceive(std::unique_ptr<ProtocolPacket>& packet, IpAddress::Types addressType,
Client& client) = 0;
97 [[nodiscard]]
virtual std::chrono::milliseconds getTimeoutTarget()
const;
100 virtual void internalUpdate(TransmitPacketPtr& buffPacket,
101 IpAddress::Types addressType,
103 std::chrono::milliseconds deltaTime) = 0;
104 [[nodiscard]]
virtual NetCommandResults timeout(
Client& client);
108 void markAsSucceeded();
110 CommandQueue* _g_commandQueue{
nullptr};
113 std::chrono::milliseconds g_timeout{0};
114 NetCommandResults g_currentResultState{NetCommandResults::WORKING};
120 using NetCommand::NetCommand;
123 [[nodiscard]] NetCommandTypes getType()
const override {
return NetCommandTypes::DISCOVER_MTU; }
125 void internalUpdate(TransmitPacketPtr& buffPacket,
126 IpAddress::Types addressType,
128 std::chrono::milliseconds deltaTime)
override;
129 void onReceive(std::unique_ptr<ProtocolPacket>& packet, IpAddress::Types addressType,
Client& client)
override;
131 [[nodiscard]]
inline std::future<uint16_t> get_future() {
return this->g_promise.get_future(); }
133 [[nodiscard]]
inline std::chrono::milliseconds getTimeoutTarget()
const override {
return FGE_NET_MTU_TIMEOUT_MS; }
136 [[nodiscard]] NetCommandResults timeout(
Client& client)
override;
138 std::promise<uint16_t> g_promise;
139 uint16_t g_currentMTU{0};
140 uint16_t g_targetMTU{0};
141 uint16_t g_maximumMTU{0};
142 uint16_t g_intervalMTU{0};
143 std::size_t g_tryCount{0};
151 } g_state{States::ASKING};
157 using NetCommand::NetCommand;
160 void setVersioningString(std::string_view versioningString);
161 [[nodiscard]] std::string
const& getVersioningString()
const;
163 [[nodiscard]] NetCommandTypes getType()
const override {
return NetCommandTypes::CONNECT; }
165 void internalUpdate(TransmitPacketPtr& buffPacket,
166 IpAddress::Types addressType,
168 std::chrono::milliseconds deltaTime)
override;
169 void onReceive(std::unique_ptr<ProtocolPacket>& packet, IpAddress::Types addressType,
Client& client)
override;
171 [[nodiscard]]
inline std::future<bool> get_future() {
return this->g_promise.get_future(); }
173 [[nodiscard]]
inline std::chrono::milliseconds getTimeoutTarget()
const override
175 return FGE_NET_CONNECT_TIMEOUT_MS;
179 [[nodiscard]] NetCommandResults timeout(
Client& client)
override;
181 std::promise<bool> g_promise;
184 TRANSMIT_FGE_HANDSHAKE,
185 WAITING_FGE_HANDSHAKE,
188 WAITING_SERVER_FINAL_MTU,
194 } g_state{States::TRANSMIT_FGE_HANDSHAKE};
195 bool g_mtuTested{
false};
196 std::future<uint16_t> g_mtuFuture;
197 std::string g_versioningString;
203 using NetCommand::NetCommand;
206 [[nodiscard]] NetCommandTypes getType()
const override {
return NetCommandTypes::CONNECT_HANDLER; }
208 void internalUpdate(TransmitPacketPtr& buffPacket,
209 IpAddress::Types addressType,
211 std::chrono::milliseconds deltaTime)
override;
212 void onReceive(std::unique_ptr<ProtocolPacket>& packet, IpAddress::Types addressType,
Client& client)
override;
214 [[nodiscard]]
inline std::future<bool> get_future() {
return this->g_promise.get_future(); }
216 [[nodiscard]]
inline std::chrono::milliseconds getTimeoutTarget()
const override
218 return FGE_NET_CONNECT_TIMEOUT_MS;
222 [[nodiscard]] NetCommandResults timeout(
Client& client)
override;
224 std::promise<bool> g_promise;
230 WAITING_CLIENT_FINAL_MTU,
236 } g_state{States::LOOKUP_MTU};
238 std::future<uint16_t> g_mtuFuture;
245 using NetCommand::NetCommand;
248 [[nodiscard]] NetCommandTypes getType()
const override {
return NetCommandTypes::DISCONNECT; }
250 void internalUpdate(TransmitPacketPtr& buffPacket,
251 IpAddress::Types addressType,
253 std::chrono::milliseconds deltaTime)
override;
254 void onReceive(std::unique_ptr<ProtocolPacket>& packet, IpAddress::Types addressType,
Client& client)
override;
256 [[nodiscard]]
inline std::future<void> get_future() {
return this->g_promise.get_future(); }
258 [[nodiscard]]
inline std::chrono::milliseconds getTimeoutTarget()
const override
260 return FGE_NET_DISCONNECT_TIMEOUT_MS;
264 [[nodiscard]] NetCommandResults timeout(
Client& client)
override;
266 std::promise<void> g_promise;
267 bool g_transmitted{
false};