summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-21 22:14:19 +0200
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-08-21 22:14:19 +0200
commit42f93f6d3dceacfef0b54fb9dc778bbc00afea15 (patch)
tree2c931f85f2fb81165e07e85ae4301f2f17e39ff2
parentFixed uninitialized variable (diff)
downloadAltCraft-42f93f6d3dceacfef0b54fb9dc778bbc00afea15.tar
AltCraft-42f93f6d3dceacfef0b54fb9dc778bbc00afea15.tar.gz
AltCraft-42f93f6d3dceacfef0b54fb9dc778bbc00afea15.tar.bz2
AltCraft-42f93f6d3dceacfef0b54fb9dc778bbc00afea15.tar.lz
AltCraft-42f93f6d3dceacfef0b54fb9dc778bbc00afea15.tar.xz
AltCraft-42f93f6d3dceacfef0b54fb9dc778bbc00afea15.tar.zst
AltCraft-42f93f6d3dceacfef0b54fb9dc778bbc00afea15.zip
-rw-r--r--src/NetworkClient.cpp48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/NetworkClient.cpp b/src/NetworkClient.cpp
index e959faf..6273937 100644
--- a/src/NetworkClient.cpp
+++ b/src/NetworkClient.cpp
@@ -61,26 +61,30 @@ void NetworkClient::ExecNs() {
network->SendPacket(*packet,compressionThreshold);
});
- while (isRunning) {
- listener.HandleAllEvents();
-
- std::shared_ptr<Packet> packet = network->ReceivePacket(state, compressionThreshold >= 0);
- if (packet != nullptr) {
- if (packet->GetPacketId() != PacketNamePlayCB::KeepAliveCB) {
- PUSH_EVENT("ReceivedPacket", packet);
- }
- else {
- 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, compressionThreshold);
- }
- }
- using namespace std::chrono_literals;
- if (std::chrono::steady_clock::now() - timeOfLastKeepAlivePacket > 20s) {
- packet = std::make_shared<PacketDisconnectPlay>();
- std::static_pointer_cast<PacketDisconnectPlay>(packet)->Reason = "Timeout: server not respond";
- PUSH_EVENT("ReceivedPacket", packet);
- }
- }
+ try {
+ while (isRunning) {
+ listener.HandleAllEvents();
+
+ std::shared_ptr<Packet> packet = network->ReceivePacket(state, compressionThreshold >= 0);
+ if (packet != nullptr) {
+ if (packet->GetPacketId() != PacketNamePlayCB::KeepAliveCB) {
+ PUSH_EVENT("ReceivedPacket", packet);
+ }
+ else {
+ 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, compressionThreshold);
+ }
+ }
+ using namespace std::chrono_literals;
+ if (std::chrono::steady_clock::now() - timeOfLastKeepAlivePacket > 20s) {
+ packet = std::make_shared<PacketDisconnectPlay>();
+ std::static_pointer_cast<PacketDisconnectPlay>(packet)->Reason = "Timeout: server not respond";
+ PUSH_EVENT("ReceivedPacket", packet);
+ }
+ }
+ } catch (std::exception &e) {
+ PUSH_EVENT("NetworkClientException", std::string(e.what()));
+ }
} \ No newline at end of file