Commit 5485940f authored by Chen Bill's avatar Chen Bill

DuelClient: discard too large packet

parent 9a55d543
...@@ -20,6 +20,7 @@ bool DuelClient::is_host = false; ...@@ -20,6 +20,7 @@ bool DuelClient::is_host = false;
event_base* DuelClient::client_base = 0; event_base* DuelClient::client_base = 0;
bufferevent* DuelClient::client_bev = 0; bufferevent* DuelClient::client_bev = 0;
unsigned char DuelClient::duel_client_read[SIZE_NETWORK_BUFFER]; unsigned char DuelClient::duel_client_read[SIZE_NETWORK_BUFFER];
int DuelClient::read_len = 0;
unsigned char DuelClient::duel_client_write[SIZE_NETWORK_BUFFER]; unsigned char DuelClient::duel_client_write[SIZE_NETWORK_BUFFER];
bool DuelClient::is_closing = false; bool DuelClient::is_closing = false;
bool DuelClient::is_swapping = false; bool DuelClient::is_swapping = false;
...@@ -106,9 +107,15 @@ void DuelClient::ClientRead(bufferevent* bev, void* ctx) { ...@@ -106,9 +107,15 @@ void DuelClient::ClientRead(bufferevent* bev, void* ctx) {
evbuffer_copyout(input, &packet_len, 2); evbuffer_copyout(input, &packet_len, 2);
if(len < (size_t)packet_len + 2) if(len < (size_t)packet_len + 2)
return; return;
evbuffer_remove(input, duel_client_read, packet_len + 2); if (packet_len + 2 > SIZE_NETWORK_BUFFER) {
if(packet_len) evbuffer_drain(input, packet_len + 2);
HandleSTOCPacketLan(&duel_client_read[2], packet_len); read_len = 0;
}
else {
read_len = evbuffer_remove(input, duel_client_read, packet_len + 2);
}
if (read_len > 0)
HandleSTOCPacketLan(&duel_client_read[2], read_len - 2);
len -= packet_len + 2; len -= packet_len + 2;
} }
} }
......
...@@ -27,6 +27,7 @@ private: ...@@ -27,6 +27,7 @@ private:
static event_base* client_base; static event_base* client_base;
static bufferevent* client_bev; static bufferevent* client_bev;
static unsigned char duel_client_read[SIZE_NETWORK_BUFFER]; static unsigned char duel_client_read[SIZE_NETWORK_BUFFER];
static int read_len;
static unsigned char duel_client_write[SIZE_NETWORK_BUFFER]; static unsigned char duel_client_write[SIZE_NETWORK_BUFFER];
static bool is_closing; static bool is_closing;
static bool is_swapping; static bool is_swapping;
...@@ -62,7 +63,7 @@ public: ...@@ -62,7 +63,7 @@ public:
auto p = duel_client_write; auto p = duel_client_write;
int blen = sizeof(ST); int blen = sizeof(ST);
if (blen > MAX_DATA_SIZE) if (blen > MAX_DATA_SIZE)
blen = MAX_DATA_SIZE; return;
BufferIO::WriteInt16(p, (short)(1 + blen)); BufferIO::WriteInt16(p, (short)(1 + blen));
BufferIO::WriteInt8(p, proto); BufferIO::WriteInt8(p, proto);
memcpy(p, &st, blen); memcpy(p, &st, blen);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment