当前位置: 首页>>代码示例>>C++>>正文


C++ MessageBuffer::Write方法代码示例

本文整理汇总了C++中MessageBuffer::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageBuffer::Write方法的具体用法?C++ MessageBuffer::Write怎么用?C++ MessageBuffer::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MessageBuffer的用法示例。


在下文中一共展示了MessageBuffer::Write方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Update

bool WorldSocket::Update()
{

	EncryptablePacket* queued;
	MessageBuffer buffer;
	while (_bufferQueue.Dequeue(queued))
	{
		ServerPktHeader header(queued->size() + 2, queued->GetOpcode());
		if (queued->NeedsEncryption())
			_authCrypt.EncryptSend(header.header, header.getHeaderLength());

		if (buffer.GetRemainingSpace() < queued->size() + header.getHeaderLength())
		{
			QueuePacket(std::move(buffer));
			buffer.Resize(4096);
		}

		if (buffer.GetRemainingSpace() >= queued->size() + header.getHeaderLength())
		{
			buffer.Write(header.header, header.getHeaderLength());
			if (!queued->empty())
				buffer.Write(queued->contents(), queued->size());
		}
		else    // single packet larger than 4096 bytes
		{
			MessageBuffer packetBuffer(queued->size() + header.getHeaderLength());
			packetBuffer.Write(header.header, header.getHeaderLength());
			if (!queued->empty())
				packetBuffer.Write(queued->contents(), queued->size());

			QueuePacket(std::move(packetBuffer));
		}

		delete queued;
	}

	if (buffer.GetActiveSize() > 0)
		QueuePacket(std::move(buffer));

    if (!BaseSocket::Update())
        return false;

    
       
        if (_queryFuture.valid() && _queryFuture.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
        {
			auto callback = _queryCallback;
            _queryCallback = nullptr;
            callback(_queryFuture.get());
        }
    

    return true;
}
开发者ID:boom8866,项目名称:MaddieCore,代码行数:54,代码来源:WorldSocket.cpp

示例2: Start

void WorldSocket::Start()
{
    AsyncRead();

    MessageBuffer initializer;
    ServerPktHeader header(ServerConnectionInitialize.size(), 0);
    initializer.Write(header.header, header.getHeaderLength() - 2);
    initializer.Write(ServerConnectionInitialize.c_str(), ServerConnectionInitialize.length());

    std::unique_lock<std::mutex> dummy(_writeLock, std::defer_lock);
    QueuePacket(std::move(initializer), dummy);
}
开发者ID:BlackWolfsDen,项目名称:BW_Eluna_Trinity_Cata_4.3.4,代码行数:12,代码来源:WorldSocket.cpp

示例3: SendPacket

void AuthSession::SendPacket(ByteBuffer& packet)
{
    if (!IsOpen())
        return;

    if (!packet.empty())
    {
        MessageBuffer buffer;
        buffer.Write(packet.contents(), packet.size());
        QueuePacket(std::move(buffer));
    }
}
开发者ID:Cyph3r,项目名称:LordPsyanBots,代码行数:12,代码来源:AuthSession.cpp

示例4: SendPacket

void AuthSession::SendPacket(ByteBuffer& packet)
{
    if (!IsOpen())
        return;

    if (!packet.empty())
    {
        MessageBuffer buffer;
        buffer.Write(packet.contents(), packet.size());

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

        QueuePacket(std::move(buffer), guard);
    }
}
开发者ID:Exitare,项目名称:Testrealm-Core,代码行数:15,代码来源:AuthSession.cpp

示例5: WritePacketToBuffer

void WorldSocket::WritePacketToBuffer(WorldPacket const& packet, MessageBuffer& buffer)
{
    ServerPktHeader header;
    uint32 sizeOfHeader = SizeOfServerHeader[_authCrypt.IsInitialized()];
    uint32 opcode = packet.GetOpcode();
    uint32 packetSize = packet.size();

    // Reserve space for buffer
    uint8* headerPos = buffer.GetWritePointer();
    buffer.WriteCompleted(sizeOfHeader);

    if (packetSize > 0x400)
    {
        CompressedWorldPacket cmp;
        cmp.UncompressedSize = packetSize + 4;
        cmp.UncompressedAdler = adler32(adler32(0x9827D8F1, (Bytef*)&opcode, 4), packet.contents(), packetSize);

        // Reserve space for compression info - uncompressed size and checksums
        uint8* compressionInfo = buffer.GetWritePointer();
        buffer.WriteCompleted(sizeof(CompressedWorldPacket));

        uint32 compressedSize = CompressPacket(buffer.GetWritePointer(), packet);

        cmp.CompressedAdler = adler32(0x9827D8F1, buffer.GetWritePointer(), compressedSize);

        memcpy(compressionInfo, &cmp, sizeof(CompressedWorldPacket));
        buffer.WriteCompleted(compressedSize);
        packetSize = compressedSize + sizeof(CompressedWorldPacket);

        opcode = SMSG_COMPRESSED_PACKET;
    }
    else if (!packet.empty())
        buffer.Write(packet.contents(), packet.size());

    if (_authCrypt.IsInitialized())
    {
        header.Normal.Size = packetSize;
        header.Normal.Command = opcode;
        _authCrypt.EncryptSend((uint8*)&header, sizeOfHeader);
    }
    else
    {
        header.Setup.Size = packetSize + 4;
        header.Setup.Command = opcode;
    }

    memcpy(headerPos, &header, sizeOfHeader);
}
开发者ID:DrYaling,项目名称:eluna-wod,代码行数:48,代码来源:WorldSocket.cpp

示例6: EndianConvertReverse

void Battlenet::Session::SendResponse(uint32 token, uint32 status)
{
    Header header;
    header.set_token(token);
    header.set_status(status);
    header.set_service_id(0xFE);

    uint16 headerSize = header.ByteSize();
    EndianConvertReverse(headerSize);

    MessageBuffer packet;
    packet.Write(&headerSize, sizeof(headerSize));
    uint8* ptr = packet.GetWritePointer();
    packet.WriteCompleted(header.ByteSize());
    header.SerializeToArray(ptr, header.ByteSize());

    AsyncWrite(&packet);
}
开发者ID:Diyvol,项目名称:TrinityCore,代码行数:18,代码来源:Session.cpp

示例7: WritePacketToBuffer

void Socket::WritePacketToBuffer(Packet const& packet, MessageBuffer& buffer)
{
    ServerHeader header;
    uint32 sizeOfHeader = SizeOfServerHeader;
    uint32 opcode = packet.GetOpcode();
    uint32 packetSize = packet.size();

    // Reserve space for buffer
    uint8* headerPos = buffer.GetWritePointer();
    buffer.WriteCompleted(sizeOfHeader);

    if (!packet.empty())
        buffer.Write(packet.contents(), packet.size());

    header.Size = packetSize;
    header.Command = opcode;
    memcpy(headerPos, &header, sizeOfHeader);
}
开发者ID:ShipsInc,项目名称:ServerCPP,代码行数:18,代码来源:Socket.cpp

示例8: GetClientInfo

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);
}
开发者ID:TrueWoW,项目名称:TrinityCore,代码行数:22,代码来源:Session.cpp


注:本文中的MessageBuffer::Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。