Esempio n. 1
0
        public RakNetPacket ReceivePacket()
        {
            IPEndPoint endPoint = null;

            byte[]       buffer = Receive(ref endPoint);
            RakNetPacket packet = PacketIdentifier.GetPacketFormId(buffer[0]);

            packet.SetBuffer(buffer);
            packet.EndPoint = endPoint;
            DownloadBytes  += (uint)buffer.Length;

            try
            {
                packet.DecodeHeader();
                packet.DecodePayload();
            }
            catch (Exception e)
            {
                throw new PacketDecodeException(e.Message, e);
            }

            new SocketPacketReceiveEventArgs(this, packet, DownloadBytes)
            .Invoke(this, ReceivePacketEvent);

            return(packet);
        }
Esempio n. 2
0
        public async Task <RakNetPacket> ReceivePacketAsync()
        {
            UdpReceiveResult result = await ReceiveAsync();

            byte[]       buffer = result.Buffer;
            RakNetPacket packet = PacketIdentifier.GetPacketFormId(buffer[0]);

            packet.SetBuffer(buffer);
            packet.EndPoint = result.RemoteEndPoint;
            DownloadBytes  += (uint)result.Buffer.Length;

            try
            {
                packet.DecodeHeader();
                packet.DecodePayload();
            }
            catch (Exception e)
            {
                throw new PacketDecodeException(e.Message, e);
            }

            new SocketPacketReceiveEventArgs(this, packet, DownloadBytes)
            .Invoke(this, ReceivePacketEvent);

            return(packet);
        }
Esempio n. 3
0
        public void HandleConnectedPacket(EncapsulatedPacket packet)
        {
            byte[]       buffer = packet.Payload;
            RakNetPacket pk     = Server.Socket.PacketIdentifier.GetPacketFormId(buffer[0]);

            pk.EndPoint = PeerEndPoint;
            pk.SetBuffer(buffer);

            pk.DecodeHeader();
            pk.DecodePayload();

            if (pk is ConnectionRequest connectionRequest && State == RakNetPeerState.Connected)
            {
                ConnectionRequestAccepted accepted = new ConnectionRequestAccepted();
                accepted.PeerAddress     = PeerEndPoint;
                accepted.ClientTimestamp = connectionRequest.Timestamp;
                accepted.ServerTimestamp = TimeSpan.FromMilliseconds(Environment.TickCount);
                accepted.EndPoint        = PeerEndPoint;
                SendEncapsulatedPacket(accepted, Reliability.Unreliable, 0);

                State = RakNetPeerState.Handshaking;
            }