summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2020-07-30 01:46:07 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2020-07-30 01:46:07 +0200
commitf561980fecbfcda4d2ee2fafbe01991a974ca141 (patch)
tree3463c1f5ba88c651d041b63c18ef3e8165104951
parentNetwork usage optimization (diff)
downloadAltCraft-f561980fecbfcda4d2ee2fafbe01991a974ca141.tar
AltCraft-f561980fecbfcda4d2ee2fafbe01991a974ca141.tar.gz
AltCraft-f561980fecbfcda4d2ee2fafbe01991a974ca141.tar.bz2
AltCraft-f561980fecbfcda4d2ee2fafbe01991a974ca141.tar.lz
AltCraft-f561980fecbfcda4d2ee2fafbe01991a974ca141.tar.xz
AltCraft-f561980fecbfcda4d2ee2fafbe01991a974ca141.tar.zst
AltCraft-f561980fecbfcda4d2ee2fafbe01991a974ca141.zip
Diffstat (limited to '')
-rw-r--r--src/NetworkClient.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/NetworkClient.cpp b/src/NetworkClient.cpp
index 6273937..ee79fb9 100644
--- a/src/NetworkClient.cpp
+++ b/src/NetworkClient.cpp
@@ -24,17 +24,29 @@ NetworkClient::NetworkClient(std::string address, unsigned short port, std::stri
auto packet = network->ReceivePacket(Login);
- while (!packet)
- packet = network->ReceivePacket(Login);
+ for (int i = 0; i < 10 && !packet; i++)
+ packet = network->ReceivePacket(Login);
+ if (!packet)
+ throw std::runtime_error("Server not answered after LoginStart");
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);
+ for (int i = 0; i < 10 && !packet; i++)
+ packet = network->ReceivePacket(Login, compressionThreshold >= 0);
+ if (!packet)
+ throw std::runtime_error("Server not answered after SetCompression");
}
+ else if (packet->GetPacketId() == PacketNameLoginCB::Disconnect) {
+ auto disconnectPacket = std::static_pointer_cast<PacketDisconnect>(packet);
+ LOG(INFO) << "Server not allowed connection: " << disconnectPacket->Reason;
+ throw std::runtime_error(disconnectPacket->Reason);
+ }
+ else if (packet->GetPacketId() != PacketNameLoginCB::LoginSuccess) {
+ throw std::runtime_error("Unexpected packet type: " + std::to_string(packet->GetPacketId()));
+ }
auto response = std::static_pointer_cast<PacketLoginSuccess>(packet);