Example #1
0
void Battlenet::Session::AsyncWrite(ServerPacket* packet)
{
    if (!IsOpen())
    {
        delete packet;
        return;
    }

    TC_LOG_DEBUG("session.packets", "%s Sending %s", GetClientInfo().c_str(), PacketToStringHelper(packet).c_str());

    packet->Write();

    EncryptableBuffer* buffer = new EncryptableBuffer();
    buffer->Buffer.Write(packet->GetData(), packet->GetSize());
    buffer->Encrypt = _crypt.IsInitialized();
    delete packet;

    _bufferQueue.Enqueue(buffer);
}
Example #2
0
void Battlenet::Session::AsyncWrite(ServerPacket* packet)
{
    if (!IsOpen())
    {
        delete packet;
        return;
    }

    TC_LOG_DEBUG("session.packets", "%s Sending %s", GetClientInfo().c_str(), PacketToStringHelper(packet).c_str());

    packet->Write();

    MessageBuffer buffer;
    buffer.Write(packet->GetData(), packet->GetSize());
    delete packet;

    std::unique_lock<std::mutex> guard(_writeLock);

    _crypt.EncryptSend(buffer.GetReadPointer(), buffer.GetActiveSize());

    QueuePacket(std::move(buffer), guard);
}
Example #3
0
void Battlenet::Session::ReadHandler()
{
    BitStream stream(std::move(GetReadBuffer()));
    _crypt.DecryptRecv(stream.GetBuffer(), stream.GetSize());

    while (!stream.IsRead())
    {
        try
        {
            PacketHeader header;
            header.Opcode = stream.Read<uint32>(6);
            if (stream.Read<bool>(1))
                header.Channel = stream.Read<int32>(4);

            if (header.Channel != AUTHENTICATION && (header.Channel != CONNECTION || header.Opcode != Connection::CMSG_PING) && !_authed)
            {
                TC_LOG_DEBUG("session.packets", "%s Received not allowed %s. Client has not authed yet.", GetClientInfo().c_str(), header.ToString().c_str());
                CloseSocket();
                return;
            }

            if (ClientPacket* packet = sPacketManager.CreateClientPacket(header, stream))
            {
                if (sPacketManager.IsHandled(header))
                    TC_LOG_DEBUG("session.packets", "%s Received %s", GetClientInfo().c_str(), PacketToStringHelper(packet).c_str());

                packet->CallHandler(this);
                delete packet;
            }
            else if (sPacketManager.GetClientPacketName(header))
            {
                LogUnhandledPacket(header);
                break;
            }
            else
            {
                TC_LOG_DEBUG("session.packets", "%s Received unknown %s", GetClientInfo().c_str(), header.ToString().c_str());
                break;
            }

            stream.AlignToNextByte();
        }
        catch (BitStreamPositionException const& e)
        {
            TC_LOG_ERROR("session.packets", "%s Exception thrown during packet processing %s", GetClientInfo().c_str(), e.what());
            CloseSocket();
            return;
        }
    }

    GetReadBuffer().Resize(size_t(BufferSizes::Read));
    AsyncRead();
}