summaryrefslogtreecommitdiffstats
path: root/src/NetworkClient.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2017-09-24 17:58:06 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-01-13 03:39:32 +0100
commit6d1aef5ba39a7b16e8de7d5f25a6ecf53c97e71f (patch)
tree4055e47d4285d63e01a54b16650b2df6c382dc2c /src/NetworkClient.cpp
parent2017-09-23 (diff)
downloadAltCraft-6d1aef5ba39a7b16e8de7d5f25a6ecf53c97e71f.tar
AltCraft-6d1aef5ba39a7b16e8de7d5f25a6ecf53c97e71f.tar.gz
AltCraft-6d1aef5ba39a7b16e8de7d5f25a6ecf53c97e71f.tar.bz2
AltCraft-6d1aef5ba39a7b16e8de7d5f25a6ecf53c97e71f.tar.lz
AltCraft-6d1aef5ba39a7b16e8de7d5f25a6ecf53c97e71f.tar.xz
AltCraft-6d1aef5ba39a7b16e8de7d5f25a6ecf53c97e71f.tar.zst
AltCraft-6d1aef5ba39a7b16e8de7d5f25a6ecf53c97e71f.zip
Diffstat (limited to '')
-rw-r--r--src/NetworkClient.cpp26
1 files changed, 19 insertions, 7 deletions
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<PacketLoginSuccess>(network.ReceivePacket(Login));
- while (!response)
- response = std::static_pointer_cast<PacketLoginSuccess>(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<PacketSetCompression>(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<PacketLoginSuccess>(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<PacketKeepAliveCB>(packet);
auto packetKeepAliveSB = std::make_shared<PacketKeepAliveSB>(packetKeepAlive->KeepAliveId);
- network.SendPacket(*packetKeepAliveSB);
+ network.SendPacket(*packetKeepAliveSB, compressionThreshold);
}
}
using namespace std::chrono_literals;