mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-05 23:36:23 +00:00
Minor fixes
This commit is contained in:
@@ -54,24 +54,43 @@ bool CheckBytes(Client*c,int32_t BytesRcv){
|
||||
|
||||
void TCPRcv(Client*c){
|
||||
Assert(c);
|
||||
static int32_t Header,BytesRcv,Temp;
|
||||
static thread_local int32_t Header,BytesRcv,Temp;
|
||||
if(c == nullptr || c->GetStatus() < 0)return;
|
||||
#ifdef WIN32
|
||||
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<char*>(&Header), sizeof(Header),0);
|
||||
#else
|
||||
BytesRcv = recv(c->GetTCPSock(), reinterpret_cast<void*>(&Header), sizeof(Header), 0);
|
||||
#endif
|
||||
if(!CheckBytes(c,BytesRcv))return;
|
||||
#ifdef DEBUG
|
||||
//debug(std::string(__func__) + Sec(": expecting ") + std::to_string(Header) + Sec(" bytes."));
|
||||
#endif // DEBUG
|
||||
if(!CheckBytes(c,BytesRcv)) {
|
||||
#ifdef DEBUG
|
||||
error(std::string(__func__) + Sec(": failed on CheckBytes"));
|
||||
#endif // DEBUG
|
||||
return;
|
||||
}
|
||||
// TODO: std::vector
|
||||
char* Data = new char[Header];
|
||||
Assert(Data);
|
||||
BytesRcv = 0;
|
||||
do{
|
||||
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
|
||||
//debug(std::string(__func__) + Sec(": Temp: ") + std::to_string(Temp) + Sec(", BytesRcv: ") + std::to_string(BytesRcv));
|
||||
#endif // DEBUG
|
||||
BytesRcv += Temp;
|
||||
}while(BytesRcv < Header);
|
||||
#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;
|
||||
if (Ret.substr(0, 4) == "ABG:") {
|
||||
|
||||
Reference in New Issue
Block a user