From a6e0c9ce9b6c468d0e622ffb5c05eba664ea4f47 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Tue, 17 Oct 2017 23:33:13 +0500 Subject: Refactored #include directives --- src/NetworkClient.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/NetworkClient.cpp') diff --git a/src/NetworkClient.cpp b/src/NetworkClient.cpp index 36c6912..38cb947 100644 --- a/src/NetworkClient.cpp +++ b/src/NetworkClient.cpp @@ -1,7 +1,11 @@ #include "NetworkClient.hpp" -NetworkClient::NetworkClient(std::string address, unsigned short port, std::string username) - : network(address, port) { +#include + +#include "Network.hpp" + +NetworkClient::NetworkClient(std::string address, unsigned short port, std::string username) { + network = std::make_unique(address, port); state = Handshaking; PacketHandshake handshake; @@ -9,18 +13,18 @@ NetworkClient::NetworkClient(std::string address, unsigned short port, std::stri handshake.serverAddress = address; handshake.serverPort = port; handshake.nextState = 2; - network.SendPacket(handshake); + network->SendPacket(handshake); state = Login; PacketLoginStart loginStart; loginStart.Username = username; - network.SendPacket(loginStart); + network->SendPacket(loginStart); - auto packet = network.ReceivePacket(Login); + auto packet = network->ReceivePacket(Login); while (!packet) - packet = network.ReceivePacket(Login); + packet = network->ReceivePacket(Login); if (packet->GetPacketId() == PacketNameLoginCB::SetCompression) { auto compPacket = std::static_pointer_cast(packet); @@ -28,7 +32,7 @@ NetworkClient::NetworkClient(std::string address, unsigned short port, std::stri compressionThreshold = compPacket->Threshold; packet.reset(); while (!packet) - packet = network.ReceivePacket(Login, compressionThreshold >= 0); + packet = network->ReceivePacket(Login, compressionThreshold >= 0); } auto response = std::static_pointer_cast(packet); @@ -60,11 +64,11 @@ void NetworkClient::SendPacket(std::shared_ptr packet) { void NetworkClient::UpdatePacket() { while (!toSend.empty()) { if (toSend.front() != nullptr) - network.SendPacket(*toSend.front(), compressionThreshold); + network->SendPacket(*toSend.front(), compressionThreshold); toSend.pop(); } - auto packet = network.ReceivePacket(state, compressionThreshold >= 0); + auto packet = network->ReceivePacket(state, compressionThreshold >= 0); if (packet.get() != nullptr) { if (packet->GetPacketId() != PacketNamePlayCB::KeepAliveCB) { toReceive.push(packet); @@ -73,7 +77,7 @@ void NetworkClient::UpdatePacket() { timeOfLastKeepAlivePacket = std::chrono::steady_clock::now(); auto packetKeepAlive = std::static_pointer_cast(packet); auto packetKeepAliveSB = std::make_shared(packetKeepAlive->KeepAliveId); - network.SendPacket(*packetKeepAliveSB, compressionThreshold); + network->SendPacket(*packetKeepAliveSB, compressionThreshold); } } using namespace std::chrono_literals; -- cgit v1.2.3