summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/Network.cpp39
-rw-r--r--src/network/NetworkClient.cpp7
-rw-r--r--src/network/NetworkClient.hpp2
3 files changed, 11 insertions, 37 deletions
diff --git a/src/network/Network.cpp b/src/network/Network.cpp
index ac84494..b3b1e4b 100644
--- a/src/network/Network.cpp
+++ b/src/network/Network.cpp
@@ -57,8 +57,8 @@ Packet Network::ReceivePacket() {
}
Field fLen = FieldParser::Parse(VarInt, bufLen);
size_t packetLen = fLen.GetVarInt() + fLen.GetLength();
- if (packetLen > 1024 * 1024 * 30)
- std::cout << "OMG! SIZEOF PACKET IS " << packetLen << std::endl;
+ if (packetLen > 1024 * 1024 * 15)
+ LOG(WARNING)<<"OMG SIZEOF PACKAGE IS "<<packetLen;
if (packetLen < rec) {
return Packet(bufLen);
}
@@ -68,39 +68,12 @@ Packet Network::ReceivePacket() {
while (m_socket.receive(bufPack + dataLen, packetLen - dataLen, rec) == sf::Socket::Done && dataLen < packetLen) {
dataLen += rec;
}
- if (dataLen < packetLen)
- throw 93;
- else {
+ if (dataLen < packetLen) {
+ LOG(ERROR) << "Received data is "<<dataLen<<" but "<<packetLen<<" is promoted";
+ throw std::runtime_error("");
+ } else {
Packet p(bufPack);
delete[] bufPack;
return p;
}
-
- /*if (m_socket.receive(bufPack + rec, packetLen - rec, rec) != sf::Socket::Done) {
- delete[] bufPack;
- throw 93;
- }
- rec++;
- //Check for losted data
- int losted = 0;
- for (int i = packetLen - 2; i > 0; i--)
- if (bufPack[i] == 'N')
- losted++;
- if (losted > 100) {
- if (m_socket.receive(bufPack + rec, packetLen - rec, rec) != sf::Socket::Done) {
- throw 93;
- }
- std::cout << "Keep receiving!" << std::endl;
- }
- //One more time
- losted = 0;
- for (int i = packetLen - 2; i > 0; i--)
- if (bufPack[i] == 'N')
- losted++;
- if (losted > 100) {
- std::cout << "\x1b[31m" << "Losted " << losted << " bytes of " << packetLen << "\x1b[0m" << std::endl;
- delete[] bufPack;
- throw 93;
- }*/
- throw 94;
}
diff --git a/src/network/NetworkClient.cpp b/src/network/NetworkClient.cpp
index cbe705b..9916b10 100644
--- a/src/network/NetworkClient.cpp
+++ b/src/network/NetworkClient.cpp
@@ -1,7 +1,4 @@
#include "NetworkClient.hpp"
-#include "../packet/PacketParser.hpp"
-#include "../packet/PacketBuilder.hpp"
-#include <nlohmann/json.hpp>
ServerInfo NetworkClient::ServerPing(std::string address, unsigned short port) {
ServerInfo info;
@@ -62,8 +59,10 @@ NetworkClient::NetworkClient(std::string address, unsigned short port, std::stri
}
NetworkClient::~NetworkClient() {
+ LOG(INFO)<<"NC stopping...";
isContinue=false;
m_networkThread.join();
+ LOG(INFO)<<"NC is stopped";
}
Packet * NetworkClient::GetPacket() {
@@ -101,7 +100,7 @@ void NetworkClient::MainLoop() {
Update();
}
} catch (int e){
- std::cerr<<"NetworkClient exception: "<<e<<std::endl;
+ LOG(ERROR)<<"Catched exception in NC: "<<e;
}
}
diff --git a/src/network/NetworkClient.hpp b/src/network/NetworkClient.hpp
index a41b5f4..9f68e37 100644
--- a/src/network/NetworkClient.hpp
+++ b/src/network/NetworkClient.hpp
@@ -4,6 +4,8 @@
#include <thread>
#include <mutex>
#include "Network.hpp"
+#include "../packet/PacketParser.hpp"
+#include "../packet/PacketBuilder.hpp"
struct ServerInfo{
std::string version;