Example #1
0
        public void Encode_basic_ok()
        {
            var message = new ConnectionRequestAccepted();

            message.NoBatch            = true;
            message.systemAddress      = new IPEndPoint(IPAddress.Loopback, 19132);
            message.systemAddresses    = new IPEndPoint[20];
            message.systemAddresses[0] = new IPEndPoint(IPAddress.Loopback, 19132);
            message.incomingTimestamp  = 12345;
            message.serverTimestamp    = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond;

            for (int i = 1; i < 20; i++)
            {
                message.systemAddresses[i] = new IPEndPoint(IPAddress.Any, 19132);
            }


            var datagrams = Datagram.CreateDatagrams(message, 1664, new RakSession(null, null, IPEndPoint.Parse("127.0.0.1"), 1664));

            foreach (Datagram datagram in datagrams)
            {
                var  buffer = new byte[1600];
                long length = datagram.GetEncoded(ref buffer);
                Assert.AreNotEqual(length, buffer.Length);
            }
        }
        private Packet DecodePacketDecapsulated(Byte id, BinaryReaderBE reader)
        {
            Packet packet = null;

            switch ((PacketId)id)
            {
            case PacketId.ConnectedPing: packet = new ConnectedPing(); break;

            case PacketId.ConnectionRequest: packet = new ConnectionRequest(); break;

            case PacketId.ConnectionRequestAccepted: packet = new ConnectionRequestAccepted(); break;

            case PacketId.DisconnectionNotification: packet = new DisconnectionNotification(); break;

            default:
                packet = PacketConstructor(id);
                if (packet == null)
                {
                    throw new InvalidDataException("Unrecognized encapsulated packet ID");
                }
                break;
            }

            packet.Read(reader);
            return(packet);
        }
Example #3
0
        private void HandleConnectionRequestAccepted(ConnectionRequestAccepted message)
        {
            SendNewIncomingConnection();

            State = ConnectionState.Connected;

            CustomMessageHandler?.Connected();
        }
Example #4
0
        protected virtual void HandleConnectionRequest(ConnectionRequest message)
        {
            Log.DebugFormat("Connection request from: {0}", EndPoint.Address);

            var response = ConnectionRequestAccepted.CreateObject();

            response.NoBatch            = true;
            response.systemAddress      = new IPEndPoint(IPAddress.Loopback, 19132);
            response.systemAddresses    = new IPEndPoint[20];
            response.systemAddresses[0] = new IPEndPoint(IPAddress.Loopback, 19132);
            response.incomingTimestamp  = message.timestamp;
            response.serverTimestamp    = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond;

            for (int i = 1; i < 20; i++)
            {
                response.systemAddresses[i] = new IPEndPoint(IPAddress.Any, 19132);
            }

            SendPackage(response);
        }
Example #5
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;
            }
        private void HandleConnectionRequestAccepted(ConnectionRequestAccepted packet)
        {
            var ackReq = new NewIncomingConnection();

            SendEncapsulated(ackReq, EncapsulatedReliability.ReliableOrdered);
        }