Exemplo n.º 1
0
        /// <summary>
        /// this variant does only create outgoing commands and increments . incoming ones are created from a DataInputStream
        /// </summary>
        /// <param name="peer"></param>
        /// <param name="commandType"></param>
        /// <param name="payload"></param>
        /// <param name="channel"></param>
        internal NCommand(EnetPeer peer, byte commandType, byte[] payload, byte channel)
        {
            this.commandType      = commandType;
            this.commandFlags     = 1;
            this.commandChannelID = channel;
            this.Payload          = payload;
            this.Size             = 12;
            switch (this.commandType)
            {
            case 1:
                this.Size         = 20;
                this.commandFlags = 0;
                break;

            case 2:
            {
                this.Size       = 0x2c;
                this.Payload    = new byte[0x20];
                this.Payload[0] = 0;
                this.Payload[1] = 0;
                int mtuOffset = 2;
                Protocol.Serialize((short)peer.mtu, this.Payload, ref mtuOffset);
                this.Payload[4]    = 0;
                this.Payload[5]    = 0;
                this.Payload[6]    = 0x80;
                this.Payload[7]    = 0;
                this.Payload[11]   = peer.ChannelCount;
                this.Payload[15]   = 0;
                this.Payload[0x13] = 0;
                this.Payload[0x16] = 0x13;
                this.Payload[0x17] = 0x88;
                this.Payload[0x1b] = 2;
                this.Payload[0x1f] = 2;
                break;
            }

            case 4:
                this.Size = 12;
                if (peer.peerConnectionState != PeerBase.ConnectionStateValue.Connected)
                {
                    this.commandFlags = 2;
                }
                break;

            case 6:
                this.Size = 12 + payload.Length;
                break;

            case 7:
                this.Size         = 0x10 + payload.Length;
                this.commandFlags = 0;
                break;

            case 8:
                this.Size = 0x20 + payload.Length;
                break;
            }
        }
Exemplo n.º 2
0
 internal NConnect(EnetPeer npeer)
 {
     if (npeer.debugOut >= DebugLevel.ALL)
     {
         npeer.Listener.DebugReturn(DebugLevel.ALL, "NConnect().");
     }
     this.peer = npeer;
     this.sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
 }
Exemplo n.º 3
0
        internal static NCommand CreateAck(EnetPeer peer, NCommand commandToAck, int sentTime)
        {
            byte[] payload = new byte[8];
            int    offset  = 0;

            Protocol.Serialize(commandToAck.reliableSequenceNumber, payload, ref offset);
            Protocol.Serialize(sentTime, payload, ref offset);
            return(new NCommand(peer, 1, payload, commandToAck.commandChannelID));
        }
Exemplo n.º 4
0
        internal NCommand(EnetPeer peer, byte[] inBuff, ref int readingOffset)
        {
            this.commandType      = inBuff[readingOffset++];
            this.commandChannelID = inBuff[readingOffset++];
            this.commandFlags     = inBuff[readingOffset++];
            this.reservedByte     = inBuff[readingOffset++];
            Protocol.Deserialize(out this.Size, inBuff, ref readingOffset);
            Protocol.Deserialize(out this.reliableSequenceNumber, inBuff, ref readingOffset);
            peer.bytesIn += (long)this.Size;
            switch (this.commandType)
            {
            case 1:
                Protocol.Deserialize(out this.ackReceivedReliableSequenceNumber, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.ackReceivedSentTime, inBuff, ref readingOffset);
                break;

            case 3:
                short num;
                Protocol.Deserialize(out num, inBuff, ref readingOffset);
                readingOffset += 30;
                if ((int)peer.peerID == -1)
                {
                    peer.peerID = num;
                    break;
                }
                break;

            case 6:
                this.Payload = new byte[this.Size - 12];
                break;

            case 7:
                Protocol.Deserialize(out this.unreliableSequenceNumber, inBuff, ref readingOffset);
                this.Payload = new byte[this.Size - 16];
                break;

            case 8:
                Protocol.Deserialize(out this.startSequenceNumber, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.fragmentCount, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.fragmentNumber, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.totalLength, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.fragmentOffset, inBuff, ref readingOffset);
                this.Payload            = new byte[this.Size - 32];
                this.fragmentsRemaining = this.fragmentCount;
                break;
            }
            if (this.Payload == null)
            {
                return;
            }
            Buffer.BlockCopy((Array)inBuff, readingOffset, (Array)this.Payload, 0, this.Payload.Length);
            readingOffset += this.Payload.Length;
        }
Exemplo n.º 5
0
        internal static NCommand CreateAck(EnetPeer peer, NCommand commandToAck, int sentTime)
        {
            byte[] numArray     = new byte[8];
            int    targetOffset = 0;

            Protocol.Serialize(commandToAck.reliableSequenceNumber, numArray, ref targetOffset);
            Protocol.Serialize(sentTime, numArray, ref targetOffset);
            return(new NCommand(peer, (byte)1, numArray, commandToAck.commandChannelID)
            {
                ackReceivedReliableSequenceNumber = commandToAck.reliableSequenceNumber,
                ackReceivedSentTime = sentTime
            });
        }
Exemplo n.º 6
0
        internal static NCommand CreateAck(EnetPeer peer, NCommand commandToAck, int sentTime)
        {
            byte[] array = new byte[8];
            int    num   = 0;

            Protocol.Serialize(commandToAck.reliableSequenceNumber, array, ref num);
            Protocol.Serialize(sentTime, array, ref num);
            return(new NCommand(peer, 1, array, commandToAck.commandChannelID)
            {
                ackReceivedReliableSequenceNumber = commandToAck.reliableSequenceNumber,
                ackReceivedSentTime = sentTime
            });
        }
Exemplo n.º 7
0
        internal NCommand(EnetPeer peer, byte commandType, StreamBuffer payload, byte channel)
        {
            this.commandType      = commandType;
            this.commandFlags     = 1;
            this.commandChannelID = channel;
            this.Payload          = payload;
            this.Size             = 12;
            switch (this.commandType)
            {
            case 3:
            case 5:
            case 9:
            case 10:
            case 12:
            case 13:
                break;

            case 2:
            {
                this.Size = 44;
                byte[] array = new byte[32]
                {
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0
                };
                int num = 2;
                Protocol.Serialize((short)peer.mtu, array, ref num);
                array[4]     = 0;
                array[5]     = 0;
                array[6]     = 128;
                array[7]     = 0;
                array[11]    = peer.ChannelCount;
                array[15]    = 0;
                array[19]    = 0;
                array[22]    = 19;
                array[23]    = 136;
                array[27]    = 2;
                array[31]    = 2;
                this.Payload = new StreamBuffer(array);
                break;
            }

            case 4:
                this.Size = 12;
                if (peer.peerConnectionState != ConnectionStateValue.Connected)
                {
                    this.commandFlags = 2;
                    if (peer.peerConnectionState == ConnectionStateValue.Zombie)
                    {
                        this.reservedByte = 2;
                    }
                }
                break;

            case 6:
                this.Size = 12 + payload.IntLength;
                break;

            case 14:
                this.Size         = 12 + payload.IntLength;
                this.commandFlags = 3;
                break;

            case 7:
                this.Size         = 16 + payload.IntLength;
                this.commandFlags = 0;
                break;

            case 11:
                this.Size         = 16 + payload.IntLength;
                this.commandFlags = 2;
                break;

            case 8:
                this.Size = 32 + payload.IntLength;
                break;

            case 15:
                this.Size         = 32 + payload.IntLength;
                this.commandFlags = 3;
                break;
            }
        }
Exemplo n.º 8
0
        internal NCommand(EnetPeer peer, byte[] inBuff, ref int readingOffset)
        {
            this.commandType      = inBuff[readingOffset++];
            this.commandChannelID = inBuff[readingOffset++];
            this.commandFlags     = inBuff[readingOffset++];
            this.reservedByte     = inBuff[readingOffset++];
            Protocol.Deserialize(out this.Size, inBuff, ref readingOffset);
            Protocol.Deserialize(out this.reliableSequenceNumber, inBuff, ref readingOffset);
            peer.bytesIn += this.Size;
            int num = 0;

            switch (this.commandType)
            {
            case 1:
            case 16:
                Protocol.Deserialize(out this.ackReceivedReliableSequenceNumber, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.ackReceivedSentTime, inBuff, ref readingOffset);
                break;

            case 6:
            case 14:
                num = this.Size - 12;
                break;

            case 7:
                Protocol.Deserialize(out this.unreliableSequenceNumber, inBuff, ref readingOffset);
                num = this.Size - 16;
                break;

            case 11:
                Protocol.Deserialize(out this.unsequencedGroupNumber, inBuff, ref readingOffset);
                num = this.Size - 16;
                break;

            case 8:
            case 15:
                Protocol.Deserialize(out this.startSequenceNumber, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.fragmentCount, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.fragmentNumber, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.totalLength, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.fragmentOffset, inBuff, ref readingOffset);
                num = this.Size - 32;
                this.fragmentsRemaining = this.fragmentCount;
                break;

            case 3:
            {
                short peerID = default(short);
                Protocol.Deserialize(out peerID, inBuff, ref readingOffset);
                readingOffset += 30;
                if (peer.peerID == -1 || peer.peerID == -2)
                {
                    peer.peerID = peerID;
                }
                break;
            }
            }
            if (num != 0)
            {
                StreamBuffer streamBuffer = PeerBase.MessageBufferPoolGet();
                streamBuffer.Write(inBuff, readingOffset, num);
                this.Payload             = streamBuffer;
                this.Payload.IntPosition = 0;
                readingOffset           += num;
            }
        }
Exemplo n.º 9
0
        }                            // Dummy constructor

        internal NCommand(EnetPeer peer, byte commandType, StreamBuffer payload, byte channel)
        {
        }                                                                                                 // 0x00000001806BC430-0x00000001806BC4A0
Exemplo n.º 10
0
        }                                                                                                 // 0x00000001806BC430-0x00000001806BC4A0

        internal NCommand(EnetPeer peer, byte[] inBuff, ref int readingOffset)
        {
        }                                                                                 // 0x00000001806BC4A0-0x00000001806BC500
Exemplo n.º 11
0
        }                                                                                                         // 0x00000001806BB190-0x00000001806BB310

        internal void Initialize(EnetPeer peer, byte commandType, StreamBuffer payload, byte channel)
        {
        }                                                                                                        // 0x00000001806BB390-0x00000001806BB790
Exemplo n.º 12
0
        }                                                                                                        // 0x00000001806BB390-0x00000001806BB790

        internal void Initialize(EnetPeer peer, byte[] inBuff, ref int readingOffset)
        {
        }                                                                                        // 0x00000001806BB790-0x00000001806BBBC0
Exemplo n.º 13
0
        internal NCommand(EnetPeer peer, byte commandType, byte[] payload, byte channel)
        {
            this.commandType      = commandType;
            this.commandFlags     = (byte)1;
            this.commandChannelID = channel;
            this.Payload          = payload;
            this.Size             = 12;
            switch (this.commandType)
            {
            case 1:
                this.Size         = 20;
                this.commandFlags = (byte)0;
                break;

            case 2:
                this.Size       = 44;
                this.Payload    = new byte[32];
                this.Payload[0] = (byte)0;
                this.Payload[1] = (byte)0;
                int targetOffset = 2;
                Protocol.Serialize((short)peer.mtu, this.Payload, ref targetOffset);
                this.Payload[4]  = (byte)0;
                this.Payload[5]  = (byte)0;
                this.Payload[6]  = (byte)128;
                this.Payload[7]  = (byte)0;
                this.Payload[11] = peer.ChannelCount;
                this.Payload[15] = (byte)0;
                this.Payload[19] = (byte)0;
                this.Payload[22] = (byte)19;
                this.Payload[23] = (byte)136;
                this.Payload[27] = (byte)2;
                this.Payload[31] = (byte)2;
                break;

            case 4:
                this.Size = 12;
                if (peer.peerConnectionState == PeerBase.ConnectionStateValue.Connected)
                {
                    break;
                }
                this.commandFlags = (byte)2;
                if (peer.peerConnectionState == PeerBase.ConnectionStateValue.Zombie)
                {
                    this.reservedByte = (byte)2;
                }
                break;

            case 6:
                this.Size = 12 + payload.Length;
                break;

            case 7:
                this.Size         = 16 + payload.Length;
                this.commandFlags = (byte)0;
                break;

            case 8:
                this.Size = 32 + payload.Length;
                break;
            }
        }
Exemplo n.º 14
0
        internal NCommand(EnetPeer peer, byte[] inBuff, ref int readingOffset)
        {
            int num = readingOffset;

            readingOffset    = num + 1;
            this.commandType = inBuff[num];
            num                   = readingOffset;
            readingOffset         = num + 1;
            this.commandChannelID = inBuff[num];
            num                   = readingOffset;
            readingOffset         = num + 1;
            this.commandFlags     = inBuff[num];
            num                   = readingOffset;
            readingOffset         = num + 1;
            this.reservedByte     = inBuff[num];
            Protocol.Deserialize(out this.Size, inBuff, ref readingOffset);
            Protocol.Deserialize(out this.reliableSequenceNumber, inBuff, ref readingOffset);
            peer.bytesIn += (long)this.Size;
            switch (this.commandType)
            {
            case 1:
                Protocol.Deserialize(out this.ackReceivedReliableSequenceNumber, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.ackReceivedSentTime, inBuff, ref readingOffset);
                break;

            case 3:
            {
                short peerID;
                Protocol.Deserialize(out peerID, inBuff, ref readingOffset);
                readingOffset += 30;
                bool flag = peer.peerID == -1;
                if (flag)
                {
                    peer.peerID = peerID;
                }
                break;
            }

            case 6:
                this.Payload = new byte[this.Size - 12];
                break;

            case 7:
                Protocol.Deserialize(out this.unreliableSequenceNumber, inBuff, ref readingOffset);
                this.Payload = new byte[this.Size - 16];
                break;

            case 8:
                Protocol.Deserialize(out this.startSequenceNumber, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.fragmentCount, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.fragmentNumber, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.totalLength, inBuff, ref readingOffset);
                Protocol.Deserialize(out this.fragmentOffset, inBuff, ref readingOffset);
                this.Payload            = new byte[this.Size - 32];
                this.fragmentsRemaining = this.fragmentCount;
                break;
            }
            bool flag2 = this.Payload != null;

            if (flag2)
            {
                Buffer.BlockCopy(inBuff, readingOffset, this.Payload, 0, this.Payload.Length);
                readingOffset += this.Payload.Length;
            }
        }
Exemplo n.º 15
0
        }                                // 0x00000001806BB0F0-0x00000001806BB160

        // Methods
        public NCommand Acquire(EnetPeer peer, byte[] inBuff, ref int readingOffset) => default;                 // 0x00000001806BAE40-0x00000001806BAFD0
Exemplo n.º 16
0
        internal NCommand(EnetPeer peer, byte commandType, byte[] payload, byte channel)
        {
            this.commandType      = commandType;
            this.commandFlags     = 1;
            this.commandChannelID = channel;
            this.Payload          = payload;
            this.Size             = 12;
            switch (this.commandType)
            {
            case 1:
                this.Size         = 20;
                this.commandFlags = 0;
                break;

            case 2:
            {
                this.Size       = 44;
                this.Payload    = new byte[32];
                this.Payload[0] = 0;
                this.Payload[1] = 0;
                int num = 2;
                Protocol.Serialize((short)peer.mtu, this.Payload, ref num);
                this.Payload[4]  = 0;
                this.Payload[5]  = 0;
                this.Payload[6]  = 128;
                this.Payload[7]  = 0;
                this.Payload[11] = peer.ChannelCount;
                this.Payload[15] = 0;
                this.Payload[19] = 0;
                this.Payload[22] = 19;
                this.Payload[23] = 136;
                this.Payload[27] = 2;
                this.Payload[31] = 2;
                break;
            }

            case 4:
            {
                this.Size = 12;
                bool flag = peer.peerConnectionState != PeerBase.ConnectionStateValue.Connected;
                if (flag)
                {
                    this.commandFlags = 2;
                    bool flag2 = peer.peerConnectionState == PeerBase.ConnectionStateValue.Zombie;
                    if (flag2)
                    {
                        this.reservedByte = 2;
                    }
                }
                break;
            }

            case 6:
                this.Size = 12 + payload.Length;
                break;

            case 7:
                this.Size         = 16 + payload.Length;
                this.commandFlags = 0;
                break;

            case 8:
                this.Size = 32 + payload.Length;
                break;
            }
        }
Exemplo n.º 17
0
 public NCommand Acquire(EnetPeer peer, byte[] inBuff, ref int readingOffset) => default;                 // 0x00000001806BAE40-0x00000001806BAFD0
 public NCommand Acquire(EnetPeer peer, byte commandType, StreamBuffer payload, byte channel) => default; // 0x00000001806BAC90-0x00000001806BAE40