Exemple #1
0
bool KOSocket::Send(Packet * pkt)
{
    if (!IsConnected() || pkt->size() + 1 > GetWriteBuffer().GetAllocatedSize())
        return false;

    bool r;

    uint8 opcode = pkt->GetOpcode();
    uint8 * out_stream = nullptr;
    uint16 len = (uint16)(pkt->size() + 1);

    if (isCryptoEnabled())
    {
        len += 5;

        out_stream = new uint8[len];

        *(uint16 *)&out_stream[0] = 0x1efc;
        *(uint16 *)&out_stream[2] = (uint16)(m_sequence); // this isn't actually incremented here
        out_stream[4] = 0;
        out_stream[5] = pkt->GetOpcode();

        if (pkt->size() > 0)
            memcpy(&out_stream[6], pkt->contents(), pkt->size());

        m_crypto.JvEncryptionFast(len, out_stream, out_stream);
    }
    else
    {
        out_stream = new uint8[len];
        out_stream[0] = pkt->GetOpcode();
        if (pkt->size() > 0)
            memcpy(&out_stream[1], pkt->contents(), pkt->size());
    }

    BurstBegin();

    if (GetWriteBuffer().GetSpace() < size_t(len + 6))
    {
        BurstEnd();
        Disconnect();
        return false;
    }

    r = BurstSend((const uint8*)"\xaa\x55", 2);
    if (r) r = BurstSend((const uint8*)&len, 2);
    if (r) r = BurstSend((const uint8*)out_stream, len);
    if (r) r = BurstSend((const uint8*)"\x55\xaa", 2);
    if (r) BurstPush();
    BurstEnd();

    delete [] out_stream;
    return r;
}
void WorldSocket::OutPacket(uint16 opcode, size_t len, const void* data)
{
	bool rv;
	if(opcode == 0 || !IsConnected())
		return;

	BurstBegin();

	// Encrypt the packet
	// First, create the header.
	ServerPktHeader Header;
	Header.cmd = opcode;
	Header.size = uint16(ntohs((u_short)len + 2));
    _crypt.EncryptFourSend((uint8*)&Header);

	// Pass the header to our send buffer
	rv = BurstSend((const uint8*)&Header, 4);

	// Pass the rest of the packet to our send buffer (if there is any)
	if(len > 0 && rv)
	{
		rv = BurstSend((const uint8*)data, (uint32)len);
	}

	if(rv) BurstPush();
	BurstEnd();
}
void VoiceChatClientSocket::SendPacket(WorldPacket* data)
{
	if( m_writeByteCount + 4 + data->size() > m_writeBufferSize )
	{
		printf("!!! VOICE CHAT CLIENT SOCKET OVERLOAD !!!\n");
		return;
	}
	uint16 opcode = data->GetOpcode();
	uint32 sz = data->size();
	bool rv;

	BurstBegin();
	rv = BurstSend((const uint8*)&opcode, 2);
	if(rv) BurstSend((const uint8*)&sz, 2);

	if( sz > 0 && rv )
	{
		rv = BurstSend((const uint8*)data->contents(), data->size());
	}

	printf("sent packet of %u bytes with op %u, buffer len is now %u\n", data->size(), data->GetOpcode(), m_writeByteCount);
	if( rv )
		BurstPush();


	BurstEnd();
}
void LogonCommClientSocket::SendPacket(WorldPacket * data)
{
	logonpacket header;
	bool rv;

	BurstBegin();

	header.opcode = data->GetOpcode();
	header.size   = uint32(ntohl((u_long)data->size()));

	if(use_crypto)
		_sendCrypto.Process((unsigned char*)&header, (unsigned char*)&header, 6);

	rv = BurstSend((const uint8*)&header, 6);

	if(data->size() > 0 && rv)
	{
		if(use_crypto)
			_sendCrypto.Process((unsigned char*)data->contents(), (unsigned char*)data->contents(), (unsigned int)data->size());

		rv = BurstSend((const uint8*)data->contents(), (uint32)data->size());
	}

	if(rv) BurstPush();
	BurstEnd();
}
void WSSocket::SendWoWPacket(Session * from, WorldPacket * pck)
{
	bool rv;
	size_t size1 = pck->size();
	uint16 opcode1 = pck->GetOpcode();
	size_t size2 = size1 + 10;
	uint32 opcode2 = ISMSG_WOW_PACKET;
	uint32 id = from->GetSessionId();
	if(!IsConnected())
		return;

	BurstBegin();

	// Pass the header to our send buffer
	BurstSend((const uint8*)&opcode2, 2);
	BurstSend((const uint8*)&size2, 4);
	BurstSend((const uint8*)&id, 4);
	BurstSend((const uint8*)&opcode1, 2);
	rv=BurstSend((const uint8*)&size1, 4);	

	// Pass the rest of the packet to our send buffer (if there is any)
	if(size1 > 0 && rv)
		rv = BurstSend(pck->contents(), uint32(size1));

	if(rv) BurstPush();
	BurstEnd();
}
void VoiceChatClientSocket::SendPacket(WorldPacket* data)
{
	//if((m_writeByteCount + len + 4) >= m_writeBufferSize)
	//if( GetWriteBuffer().GetSpace() < (len+4) )
	//if( m_writeByteCount + 4 + data->size() > m_writeBufferSize )
	if(	GetWriteBuffer().GetSpace() < (data->size()+4) )
	{
		Log.Error("VoiceChatHandler","!!! VOICE CHAT CLIENT SOCKET OVERLOAD !!!");
		return;
	}
	uint16 opcode = data->GetOpcode();
	uint32 sz = (uint32)data->size();
	bool rv;

	BurstBegin();
	rv = BurstSend((const uint8*)&opcode, 2);
	if(rv) BurstSend((const uint8*)&sz, 2);

	if( sz > 0 && rv )
	{
		rv = BurstSend((const uint8*)data->contents(), (uint32)data->size());
	}

	Log.Debug("VoiceChatHandler","sent packet of %u bytes with op %u, buffer len is now %u", data->size(), data->GetOpcode(), GetWriteBuffer().GetSize());
	if( rv )
		BurstPush();


	BurstEnd();
}
OUTPACKET_RESULT WorldSocket::_OutPacket(uint16 opcode, size_t len, const void* data)
{
    bool rv;
    if(!IsConnected())
        return OUTPACKET_RESULT_NOT_CONNECTED;

    BurstBegin();
    //if((m_writeByteCount + len + 4) >= m_writeBufferSize)
    if( GetWriteBuffer().GetSpace() < (len+4) )
    {
        BurstEnd();
        return OUTPACKET_RESULT_NO_ROOM_IN_BUFFER;
    }

    // Packet logger :)
    sWorldLog.LogPacket((uint32)len, opcode, (const uint8*)data, 1);

    // Encrypt the packet
    // First, create the header.
    ServerPktHeader Header;
#ifdef USING_BIG_ENDIAN
    Header.size = len + 2;
    Header.cmd = swap16(opcode);
#else
    Header.cmd = opcode;
    Header.size = ntohs((uint16)len + 2);
#endif
    _crypt.EncryptFourSend((uint8*)&Header);

    // Pass the header to our send buffer
    rv = BurstSend((const uint8*)&Header, 4);

    // Pass the rest of the packet to our send buffer (if there is any)
    if(len > 0 && rv)
    {
        rv = BurstSend((const uint8*)data, (uint32)len);
    }

    if(rv) BurstPush();
    BurstEnd();
    return rv ? OUTPACKET_RESULT_SUCCESS : OUTPACKET_RESULT_SOCKET_ERROR;
}
Exemple #8
0
bool Socket::Send(const uint8* Bytes, uint32 Size)
{
	bool rv;

	// This is really just a wrapper for all the burst stuff.
	BurstBegin();
	rv = BurstSend(Bytes, Size);
	if(rv)
		BurstPush();
	BurstEnd();

	return rv;
}
Exemple #9
0
OUTPACKET_RESULT WorldSocket::_OutPacket(uint16 opcode, size_t len, const void* data)
{
	bool rv;
	if(!IsConnected())
		return OUTPACKET_RESULT_NOT_CONNECTED;

	BurstBegin();
	if( writeBuffer.GetSpace() < (len+4) )
	{
		BurstEnd();
		return OUTPACKET_RESULT_NO_ROOM_IN_BUFFER;
	}

	// Packet logger :)
	sWorldLog.LogPacket((uint32)len, opcode, (const uint8*)data, 1);

	// Encrypt the packet
	// First, create the header.
	ServerPktHeader Header;
	Header.cmd = opcode;
	Header.size = ntohs((uint16)len + 2);
	_crypt.EncryptSend((uint8*)&Header, sizeof (ServerPktHeader));

	// Pass the header to our send buffer
	rv = BurstSend((const uint8*)&Header, 4);

	// Pass the rest of the packet to our send buffer (if there is any)
	if(len > 0 && rv)
	{
		rv = BurstSend((const uint8*)data, (uint32)len);
	}

	if(rv) BurstPush();
	BurstEnd();
	return rv ? OUTPACKET_RESULT_SUCCESS : OUTPACKET_RESULT_SOCKET_ERROR;
}
void WSClient::SendPacket(WorldPacket * data)
{
	bool rv;
	uint32 size = data->size();
	uint16 opcode = data->GetOpcode();
	if(!IsConnected())
		return;

	BurstBegin();

	// Pass the header to our send buffer
	rv = BurstSend((const uint8*)&opcode, 2);
	rv = BurstSend((const uint8*)&size, 4);

	// Pass the rest of the packet to our send buffer (if there is any)
	if(size > 0 && rv)
		rv = BurstSend((const uint8*)data->contents(), size);

	if(rv) BurstPush();
	BurstEnd();
}