예제 #1
0
        public static BufferStream CreatePingBufferStream(OutgoingUDPPacketsHolder ReliableOutgoingHolder, IncomingUDPPacketsHolder ReliableIncomingHolder, OutgoingUDPPacketsHolder NonReliableOutgoingHolder, IncomingUDPPacketsHolder NonReliableIncomingHolder)
        {
            BufferStream buffer = Packet.CreatePingBufferStream((Constants.UDP.LAST_ACK_ID_SIZE + Constants.UDP.ACK_MASK_SIZE) * 2);

            uint ackMask = IncomingUDPPacketsHolder.GetAckMask(ReliableIncomingHolder, ReliableOutgoingHolder.AckMask);

            buffer.WriteUInt64(ReliableIncomingHolder.LastID);
            buffer.WriteUInt32(ackMask);

            ackMask = IncomingUDPPacketsHolder.GetAckMask(NonReliableIncomingHolder, NonReliableOutgoingHolder.AckMask);
            buffer.WriteUInt64(NonReliableIncomingHolder.LastID);
            buffer.WriteUInt32(ackMask);

            return(buffer);
        }
예제 #2
0
        public static OutgoingUDPPacket CreateOutgoingBufferStream(OutgoingUDPPacketsHolder OutgoingHolder, IncomingUDPPacketsHolder IncomingHolder, byte[] Buffer, uint Index, uint Length, uint MTU, bool IsReliable)
        {
            if (Constants.UDP.PACKET_HEADER_SIZE >= MTU)
            {
                throw new Exception("PACKET_HEADER_SIZE [" + Constants.UDP.PACKET_HEADER_SIZE + "] is greater than or equal to MTU [" + MTU + "]");
            }

            OutgoingHolder.IncreaseLastID();

            ulong id = OutgoingHolder.LastID;

            uint mtu = MTU - Constants.UDP.PACKET_HEADER_SIZE;

            ushort sliceCount = (ushort)Math.Ceiling(Length / (float)mtu);

            OutgoingUDPPacket packet = new OutgoingUDPPacket(id, sliceCount);

            uint ackMask = IncomingUDPPacketsHolder.GetAckMask(IncomingHolder, OutgoingHolder.AckMask);

            for (ushort i = 0; i < sliceCount; ++i)
            {
                uint index  = Index + (i * mtu);
                uint length = (uint)Math.Min(mtu, Length - (i * mtu));

                BufferStream buffer = Packet.CreateOutgoingBufferStream(Constants.UDP.PACKET_HEADER_SIZE + length);
                buffer.WriteUInt64(IncomingHolder.LastID);
                buffer.WriteUInt32(ackMask);
                buffer.WriteBool(IsReliable);
                buffer.WriteUInt64(id);
                buffer.WriteUInt16(sliceCount);
                buffer.WriteUInt16(i);
                buffer.WriteBytes(Buffer, index, length);

                packet.SetSliceBuffer(i, buffer);
            }

            OutgoingHolder.AddPacket(packet);

            return(packet);
        }