Commit 76e2b777 authored by Chen Bill's avatar Chen Bill

disconnect when the packet is too large

parent a4991d1b
......@@ -99,21 +99,19 @@ void DuelClient::StopClient(bool is_exiting) {
}
void DuelClient::ClientRead(bufferevent* bev, void* ctx) {
evbuffer* input = bufferevent_get_input(bev);
size_t len = evbuffer_get_length(input);
int len = evbuffer_get_length(input);
unsigned short packet_len = 0;
while(true) {
if(len < 2)
return;
evbuffer_copyout(input, &packet_len, 2);
if(len < (size_t)packet_len + 2)
return;
if (packet_len + 2 > SIZE_NETWORK_BUFFER) {
evbuffer_drain(input, packet_len + 2);
read_len = 0;
}
else {
read_len = evbuffer_remove(input, duel_client_read, packet_len + 2);
ClientEvent(bev, BEV_EVENT_ERROR, 0);
return;
}
if(len < packet_len + 2)
return;
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;
......
......@@ -117,21 +117,19 @@ void NetServer::ServerAcceptError(evconnlistener* listener, void* ctx) {
}
void NetServer::ServerEchoRead(bufferevent *bev, void *ctx) {
evbuffer* input = bufferevent_get_input(bev);
size_t len = evbuffer_get_length(input);
int len = evbuffer_get_length(input);
unsigned short packet_len = 0;
while(true) {
if(len < 2)
return;
evbuffer_copyout(input, &packet_len, 2);
if(len < (size_t)packet_len + 2)
return;
if (packet_len + 2 > SIZE_NETWORK_BUFFER) {
evbuffer_drain(input, packet_len + 2);
read_len = 0;
}
else {
read_len = evbuffer_remove(input, net_server_read, packet_len + 2);
ServerEchoEvent(bev, BEV_EVENT_ERROR, 0);
return;
}
if (len < packet_len + 2)
return;
read_len = evbuffer_remove(input, net_server_read, packet_len + 2);
if (read_len > 0)
HandleCTOSPacket(&users[bev], &net_server_read[2], read_len - 2);
len -= packet_len + 2;
......@@ -143,7 +141,8 @@ void NetServer::ServerEchoEvent(bufferevent* bev, short events, void* ctx) {
DuelMode* dm = dp->game;
if(dm)
dm->LeaveGame(dp);
else DisconnectPlayer(dp);
else
DisconnectPlayer(dp);
}
}
int NetServer::ServerThread() {
......
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