From 6d1aef5ba39a7b16e8de7d5f25a6ecf53c97e71f Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sun, 24 Sep 2017 20:58:06 +0500 Subject: 2017-09-24 --- src/NetworkClient.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/NetworkClient.cpp') diff --git a/src/NetworkClient.cpp b/src/NetworkClient.cpp index 027eeb5..74d7804 100644 --- a/src/NetworkClient.cpp +++ b/src/NetworkClient.cpp @@ -16,13 +16,25 @@ NetworkClient::NetworkClient(std::string address, unsigned short port, std::stri loginStart.Username = "HelloOne"; network.SendPacket(loginStart); - auto response = std::static_pointer_cast(network.ReceivePacket(Login)); - while (!response) - response = std::static_pointer_cast(network.ReceivePacket(Login)); + auto packet = network.ReceivePacket(Login); + + while (!packet) + packet = network.ReceivePacket(Login); + + if (packet->GetPacketId() == PacketNameLoginCB::SetCompression) { + auto compPacket = std::static_pointer_cast(packet); + LOG(INFO) << "Compression threshold: " << compPacket->Threshold; + compressionThreshold = compPacket->Threshold; + packet.reset(); + while (!packet) + packet = network.ReceivePacket(Login, compressionThreshold >= 0); + } + + auto response = std::static_pointer_cast(packet); if (response->Username != username) { - throw std::logic_error("Received username is not sended username"); + throw std::logic_error("Received username is not sended username: "+response->Username+" != "+username); } state = Play; @@ -62,11 +74,11 @@ void NetworkClient::NetworkLoop() { toSendMutex.lock(); while (!toSend.empty()) { if (toSend.front() != nullptr) - network.SendPacket(*toSend.front()); + network.SendPacket(*toSend.front(), compressionThreshold); toSend.pop(); } toSendMutex.unlock(); - auto packet = network.ReceivePacket(state); + auto packet = network.ReceivePacket(state, compressionThreshold >= 0); if (packet.get() != nullptr) { if (packet->GetPacketId() != PacketNamePlayCB::KeepAliveCB) { toReceiveMutex.lock(); @@ -76,7 +88,7 @@ void NetworkClient::NetworkLoop() { timeOfLastKeepAlivePacket = std::chrono::steady_clock::now(); auto packetKeepAlive = std::static_pointer_cast(packet); auto packetKeepAliveSB = std::make_shared(packetKeepAlive->KeepAliveId); - network.SendPacket(*packetKeepAliveSB); + network.SendPacket(*packetKeepAliveSB, compressionThreshold); } } using namespace std::chrono_literals; -- cgit v1.2.3