diff --git a/src/Console.cpp b/src/Console.cpp index 26e47e6..d1407be 100644 --- a/src/Console.cpp +++ b/src/Console.cpp @@ -17,6 +17,7 @@ typedef unsigned long DWORD, *PDWORD, *LPDWORD; #include #include #include +#include std::vector QConsoleOut; std::string CInputBuff; diff --git a/src/Enc.cpp b/src/Enc.cpp index de73730..c1ffd94 100644 --- a/src/Enc.cpp +++ b/src/Enc.cpp @@ -87,7 +87,7 @@ int Dec(int value,int d,int n){ #ifdef WIN32 int Handle(EXCEPTION_POINTERS *ep,char* Origin){ - Assert(false); + //Assert(false); std::stringstream R; R << Sec("Code : ") << std::hex << ep->ExceptionRecord->ExceptionCode diff --git a/src/Network/Auth.cpp b/src/Network/Auth.cpp index b87722f..5d3c637 100644 --- a/src/Network/Auth.cpp +++ b/src/Network/Auth.cpp @@ -255,7 +255,7 @@ void TCPServerMain(){ std::thread ID(Identify,client); ID.detach(); } catch (const std::exception& e) { - error(Sec("fatal: ") + std::string(e)); + error(Sec("fatal: ") + std::string(e.what())); } }while(client); diff --git a/src/Network/TCPHandler.cpp b/src/Network/TCPHandler.cpp index fd1067c..5c3d21d 100644 --- a/src/Network/TCPHandler.cpp +++ b/src/Network/TCPHandler.cpp @@ -13,19 +13,21 @@ void TCPSend(Client*c,const std::string&Data){ Assert(c); if(c == nullptr)return; // Size is BIG ENDIAN now, use only for header! - auto Size = htonl(int32_t(Data.size())); + //auto Size = htonl(int32_t(Data.size())); + ///TODO : BIG ENDIAN for other OS + int32_t Size, Sent, Temp; std::string Send(4,0); + Size = int32_t(Data.size()); memcpy(&Send[0],&Size,sizeof(Size)); Send += Data; - Size = int32_t(Send.size()); - int32_t Sent = 0,Temp; - + Sent = 0; + Size += 4; do { Temp = send(c->GetTCPSock(), &Send[Sent], Size - Sent, 0); if (Temp == 0) { if (c->GetStatus() > -1)c->SetStatus(-1); return; - } else if (Sent < 0) { + } else if (Temp < 0) { if (c->GetStatus() > -1)c->SetStatus(-1); closesocket(c->GetTCPSock()); return; @@ -55,15 +57,14 @@ bool CheckBytes(Client*c,int32_t BytesRcv){ void TCPRcv(Client*c){ Assert(c); - static thread_local int32_t Header,BytesRcv,Temp; + int32_t Header,BytesRcv,Temp; if(c == nullptr || c->GetStatus() < 0)return; #ifdef WIN32 BytesRcv = recv(c->GetTCPSock(), reinterpret_cast(&Header), sizeof(Header),0); #else BytesRcv = recv(c->GetTCPSock(), reinterpret_cast(&Header), sizeof(Header), 0); #endif - // convert back to host endianness - Header = ntohl(Header); + #ifdef DEBUG //debug(std::string(__func__) + Sec(": expecting ") + std::to_string(Header) + Sec(" bytes.")); #endif // DEBUG @@ -74,16 +75,15 @@ void TCPRcv(Client*c){ return; } // TODO: std::vector - char* Data = new char[Header]; - Assert(Data); + std::vector Data(Header); BytesRcv = 0; do{ - Temp = recv(c->GetTCPSock(), Data+BytesRcv, Header-BytesRcv,0); + Temp = recv(c->GetTCPSock(), &Data[BytesRcv], Header-BytesRcv,0); if(!CheckBytes(c,Temp)){ #ifdef DEBUG error(std::string(__func__) + Sec(": failed on CheckBytes in while(BytesRcv < Header)")); #endif // DEBUG - delete[] Data; + return; } #ifdef DEBUG @@ -94,11 +94,14 @@ void TCPRcv(Client*c){ #ifdef DEBUG //debug(std::string(__func__) + Sec(": finished recv with Temp: ") + std::to_string(Temp) + Sec(", BytesRcv: ") + std::to_string(BytesRcv)); #endif // DEBUG - std::string Ret = std::string(Data,Header); - delete[] Data; + std::string Ret(Data.data(),Header); + if (Ret.substr(0, 4) == "ABG:") { Ret = DeComp(Ret.substr(4)); } +#ifdef DEBUG + //debug("Parsing from " + c->GetName() + " -> " +std::to_string(Ret.size())); +#endif GParser(c,Ret); } diff --git a/src/Network/VehicleData.cpp b/src/Network/VehicleData.cpp index e5d5699..5ccec72 100644 --- a/src/Network/VehicleData.cpp +++ b/src/Network/VehicleData.cpp @@ -37,7 +37,6 @@ void UDPSend(Client* c, std::string Data) { return; sockaddr_in Addr = c->GetUDPAddr(); socklen_t AddrSize = sizeof(c->GetUDPAddr()); - Data = Data.substr(0, Data.find(char(0))); if (Data.length() > 400) { std::string CMP(Comp(Data)); Data = "ABG:" + CMP; @@ -100,7 +99,6 @@ int SplitID() { } void SendLarge(Client* c, std::string Data) { Assert(c); - Data = Data.substr(0, Data.find(char(0))); if (Data.length() > 400) { std::string CMP(Comp(Data)); Data = "ABG:" + CMP; @@ -174,7 +172,7 @@ std::string UDPRcvFromClient(sockaddr_in& client) { #endif // WIN32 return ""; } - return Ret; + return Ret.substr(0,Rcv); } SplitData* GetSplit(int SplitID) {