mirror of
https://github.com/mangosfour/server.git
synced 2025-12-16 22:37:02 +00:00
Added support for large server to client packets. SMSG_RESPOND_INSPECT_ACHIEVEMENTS and SMSG_ALL_ACHIEVEMENT_DATA have a good chance of reaching the old 32767 byte limit.
This commit is contained in:
parent
84f43e60ab
commit
0dbc77a628
3 changed files with 47 additions and 15 deletions
|
|
@ -52,8 +52,48 @@
|
||||||
|
|
||||||
struct ServerPktHeader
|
struct ServerPktHeader
|
||||||
{
|
{
|
||||||
uint16 size;
|
/**
|
||||||
uint16 cmd;
|
* size is the length of the payload _plus_ the length of the opcode
|
||||||
|
*/
|
||||||
|
ServerPktHeader(uint32 size, uint16 cmd) : size(size)
|
||||||
|
{
|
||||||
|
uint8 headerIndex=0;
|
||||||
|
if(isLargePacket())
|
||||||
|
{
|
||||||
|
sLog.outDebug("initializing large server to client packet. Size: %u, cmd: %u", size, cmd);
|
||||||
|
header= new uint8[5];
|
||||||
|
header[headerIndex++] = 0x80|(0xFF &(size>>16));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
header= new uint8[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
header[headerIndex++] = 0xFF &(size>>8);
|
||||||
|
header[headerIndex++] = 0xFF &size;
|
||||||
|
|
||||||
|
header[headerIndex++] = 0xFF & cmd;
|
||||||
|
header[headerIndex++] = 0xFF & (cmd>>8);
|
||||||
|
}
|
||||||
|
|
||||||
|
~ServerPktHeader()
|
||||||
|
{
|
||||||
|
delete[] header;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8 getHeaderLength()
|
||||||
|
{
|
||||||
|
// cmd = 2 bytes, size= 2||3bytes
|
||||||
|
return 2+(isLargePacket()?3:2);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isLargePacket()
|
||||||
|
{
|
||||||
|
return size > 0x7FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint32 size;
|
||||||
|
uint8 *header;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ClientPktHeader
|
struct ClientPktHeader
|
||||||
|
|
@ -961,23 +1001,17 @@ int WorldSocket::HandlePing (WorldPacket& recvPacket)
|
||||||
|
|
||||||
int WorldSocket::iSendPacket (const WorldPacket& pct)
|
int WorldSocket::iSendPacket (const WorldPacket& pct)
|
||||||
{
|
{
|
||||||
if (m_OutBuffer->space () < pct.size () + sizeof (ServerPktHeader))
|
ServerPktHeader header(pct.size()+2, pct.GetOpcode());
|
||||||
|
if (m_OutBuffer->space () < pct.size () + header.getHeaderLength())
|
||||||
{
|
{
|
||||||
errno = ENOBUFS;
|
errno = ENOBUFS;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerPktHeader header;
|
|
||||||
|
|
||||||
header.cmd = pct.GetOpcode ();
|
m_Crypt.EncryptSend ( header.header, header.getHeaderLength());
|
||||||
EndianConvert(header.cmd);
|
|
||||||
|
|
||||||
header.size = (uint16) pct.size () + 2;
|
if (m_OutBuffer->copy ((char*) header.header, header.getHeaderLength()) == -1)
|
||||||
EndianConvertReverse(header.size);
|
|
||||||
|
|
||||||
m_Crypt.EncryptSend ((uint8*) & header, sizeof (header));
|
|
||||||
|
|
||||||
if (m_OutBuffer->copy ((char*) & header, sizeof (header)) == -1)
|
|
||||||
ACE_ASSERT (false);
|
ACE_ASSERT (false);
|
||||||
|
|
||||||
if (!pct.empty ())
|
if (!pct.empty ())
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,8 @@ void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
|
||||||
void AuthCrypt::EncryptSend(uint8 *data, size_t len)
|
void AuthCrypt::EncryptSend(uint8 *data, size_t len)
|
||||||
{
|
{
|
||||||
if (!_initialized) return;
|
if (!_initialized) return;
|
||||||
if (len < CRYPTED_SEND_LEN) return;
|
|
||||||
|
|
||||||
for (size_t t = 0; t < CRYPTED_SEND_LEN; t++)
|
for (size_t t = 0; t < len; t++)
|
||||||
{
|
{
|
||||||
_send_i %= _key.size();
|
_send_i %= _key.size();
|
||||||
uint8 x = (data[t] ^ _key[_send_i]) + _send_j;
|
uint8 x = (data[t] ^ _key[_send_i]) + _send_j;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ class AuthCrypt
|
||||||
AuthCrypt();
|
AuthCrypt();
|
||||||
~AuthCrypt();
|
~AuthCrypt();
|
||||||
|
|
||||||
const static size_t CRYPTED_SEND_LEN = 4;
|
|
||||||
const static size_t CRYPTED_RECV_LEN = 6;
|
const static size_t CRYPTED_RECV_LEN = 6;
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue