我试图通过发送5,000
字节字符包boost::asio
。但我得到了错误:buffer overflow
。有没有办法自动提升拆分或我必须手动执行?
这是数据包代码:
char * CPlayerCharacter::getEnviPacket() //len 5824
{
char * buffer = new char[5824];
char xf[4];
char yf[4];
sprintf(xf, "%f", x);
sprintf(yf, "%f", y);
for(int i =0;i<5824;i++)
{
buffer[i] = 0x00;
}
buffer[0] = 5824 & 0xff;
buffer[1] = 5824 >> 8 & 0xff;
buffer[4] = 4; //minor id
buffer[6] = 1; //major id
buffer[8] = 1;
buffer[12] = id & 0xff;
buffer[13] = (id>>8) & 0xff;
buffer[14] = (id>>16) & 0xff;
buffer[15] = (id>>24) & 0xff;
buffer[20] = mapid;//map id
buffer[24] = 18;
buffer[28] = 0x0a;
buffer[29] = 0x0f;
buffer[30] = 0x16;
for(int i =0;i<4;i++)
{
buffer[5800+i] = xf[i];
buffer[5804+i] = yf[i];
}
buffer[5808] = 0x0c;
buffer[5813] = 0x9d;
buffer[5814] = 0x0f;
buffer[5815] = 0xbf;
buffer[5822] = 0x60;
buffer[5823] = 0x2a;
return buffer;
}
这是处理程序代码:
void CConnection::handle_enter_world(int packetlen)
{
Decryptor dec;
char buffer[packetlen];
boost::asio::async_read(socket_,
boost::asio::buffer(buffer, packetlen),
boost::bind(
&CConnection::nothing, shared_from_this()));
char * decrypted = decrypted = dec.decrypt((char*)&buffer, packetlen);
asynchronousSend(pl.characters[(int)decrypted[0]].getEnviPacket(), 5824);
}
这是 asynchronousSend 函数:
void CConnection::asynchronousSend(char * data, int len)
{
boost::asio::async_write(socket_, boost::asio::buffer(data, len), boost::bind(&CConnection::handle_write, shared_from_this()));
delete [] data;
}
谢谢。