mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-06-17 22:23:03 +00:00
implement size header for auth
This commit is contained in:
+17
-4
@@ -9,6 +9,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <algorithm>
|
||||||
#include "UnixCompat.h"
|
#include "UnixCompat.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -30,10 +31,22 @@ bool Send(SOCKET TCPSock,std::string Data){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string Rcv(SOCKET TCPSock){
|
std::string Rcv(SOCKET TCPSock){
|
||||||
char buf[6768];
|
uint32_t RealSize;
|
||||||
size_t len = 6768;
|
int64_t BytesRcv = recv(TCPSock, &RealSize, sizeof(RealSize), 0);
|
||||||
ZeroMemory(buf, len);
|
if (BytesRcv != sizeof(RealSize)) {
|
||||||
int64_t BytesRcv = recv(TCPSock, buf, len,0);
|
error(Sec("invalid packet (1)"));
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
// RealSize is big-endian, so we convert it to host endianness
|
||||||
|
RealSize = ntohl(RealSize);
|
||||||
|
if (RealSize > 7000) {
|
||||||
|
error(Sec("Larger than allowed TCP packet received"));
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
RealSize = std::min<uint32_t>(RealSize, 7000);
|
||||||
|
char buf[7000];
|
||||||
|
std::fill_n(buf, sizeof(buf), 0);
|
||||||
|
BytesRcv = recv(TCPSock, buf, RealSize, 0);
|
||||||
if (BytesRcv <= 0)return "";
|
if (BytesRcv <= 0)return "";
|
||||||
return std::string(buf);
|
return std::string(buf);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user