コード例 #1
0
ファイル: protocol.cpp プロジェクト: mvanderkolff/navi-misc
static void
enet_protocol_handle_send_unreliable (ENetHost * host, ENetPeer * peer, const ENetProtocol * command)
{
    ENetPacket * packet;

    if (command -> header.commandLength <= sizeof (ENetProtocolSendUnreliable) ||
        command -> header.channelID >= peer -> channelCount)
      return;

    packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendUnreliable),
                                 command -> header.commandLength - sizeof (ENetProtocolSendUnreliable),
                                 0);

    enet_peer_queue_incoming_command (peer, command, packet, 0);
}
コード例 #2
0
ファイル: protocol.c プロジェクト: wangeek/Egoboo
static void
enet_protocol_handle_send_reliable (ENetHost * host, ENetPeer * peer, const ENetProtocol * command)
{
    ENetPacket * packet;

    if (command -> header.commandLength <= sizeof (ENetProtocolSendReliable) ||
        command -> header.channelID >= peer -> channelCount ||
        peer -> state != ENET_PEER_STATE_CONNECTED)
      return;

    packet = enet_packet_create ((const enet_uint8 *) command + sizeof (ENetProtocolSendReliable),
                                 command -> header.commandLength - sizeof (ENetProtocolSendReliable),
                                 ENET_PACKET_FLAG_RELIABLE);

    enet_peer_queue_incoming_command (peer, command, packet, 0);
}
コード例 #3
0
ファイル: protocol.c プロジェクト: wangeek/Egoboo
static void
enet_protocol_handle_send_fragment (ENetHost * host, ENetPeer * peer, const ENetProtocol * command)
{
    enet_uint32 fragmentNumber,
           fragmentCount,
           fragmentOffset,
           fragmentLength,
           startSequenceNumber,
           totalLength;
    ENetChannel * channel;
    ENetListIterator currentCommand;
    ENetIncomingCommand * startCommand;

    if (command -> header.commandLength <= sizeof (ENetProtocolSendFragment) ||
        command -> header.channelID >= peer -> channelCount ||
        peer -> state != ENET_PEER_STATE_CONNECTED)
      return;

    startSequenceNumber = ENET_NET_TO_HOST_32 (command -> sendFragment.startSequenceNumber);
    fragmentNumber = ENET_NET_TO_HOST_32 (command -> sendFragment.fragmentNumber);
    fragmentCount = ENET_NET_TO_HOST_32 (command -> sendFragment.fragmentCount);
    fragmentOffset = ENET_NET_TO_HOST_32 (command -> sendFragment.fragmentOffset);
    totalLength = ENET_NET_TO_HOST_32 (command -> sendFragment.totalLength);
    fragmentLength = command -> header.commandLength - sizeof (ENetProtocolSendFragment);

    if (fragmentOffset >= totalLength ||
        fragmentOffset + fragmentLength > totalLength ||
        fragmentNumber >= fragmentCount)
      return;

    channel = & peer -> channels [command -> header.channelID];

    if (startSequenceNumber <= channel -> incomingReliableSequenceNumber)
      return;

    for (currentCommand = enet_list_previous (enet_list_end (& channel -> incomingReliableCommands));
         currentCommand != enet_list_end (& channel -> incomingReliableCommands);
         currentCommand = enet_list_previous (currentCommand))
    {
       startCommand = (ENetIncomingCommand *) currentCommand;

       if (startCommand -> command.header.command == ENET_PROTOCOL_COMMAND_SEND_FRAGMENT &&
           startCommand -> command.sendFragment.startSequenceNumber == startSequenceNumber)
         break;
    }

    if (currentCommand == enet_list_end (& channel -> incomingReliableCommands))
    {
       ENetProtocol hostCommand = * command;

       hostCommand.sendFragment.startSequenceNumber = startSequenceNumber;
       hostCommand.sendFragment.fragmentNumber = fragmentNumber;
       hostCommand.sendFragment.fragmentCount = fragmentCount;
       hostCommand.sendFragment.fragmentOffset = fragmentOffset;
       hostCommand.sendFragment.totalLength = totalLength;

       startCommand = enet_peer_queue_incoming_command (peer,
                                                        & hostCommand,
                                                        enet_packet_create (NULL, totalLength, ENET_PACKET_FLAG_RELIABLE),
                                                        fragmentCount);
    }
    else
    if (totalLength != startCommand -> packet -> dataLength ||
        fragmentCount != startCommand -> fragmentCount)
      return;

    if ((startCommand -> fragments [fragmentNumber / 32] & (1 << fragmentNumber)) == 0)
      -- startCommand -> fragmentsRemaining;

    startCommand -> fragments [fragmentNumber / 32] |= (1 << fragmentNumber);

    if (fragmentOffset + fragmentLength > startCommand -> packet -> dataLength)
      fragmentLength = startCommand -> packet -> dataLength - fragmentOffset;

    memcpy (startCommand -> packet -> data + fragmentOffset,
            (enet_uint8 *) command + sizeof (ENetProtocolSendFragment),
            fragmentLength);
}