Given_connection_in_Initial_status_When_receives_2_part_login_seed_second_part_appended_to_LoginRequest_Then_connection_enters_ServerLogin_status()
        {
            var inputStream = new TestPullStream(new List <byte[]> {
                new byte[] { 0xef },
                new byte[] { 0x01, 0x38, 0xa8, 0xc0 },
                new byte[]
                {
                    0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x01,

                    0x80, 0x42, 0x75, 0x74, 0x68, 0x72, 0x6F, 0x6D, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4A,
                    0x46, 0x6B, 0x72, 0x34, 0x33, 0x21, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF
                },
            });

            int packetsReceived = 0;

            var connection = new UltimaClientConnection(UltimaClientConnectionStatus.Initial);

            connection.PacketReceived += (sender, packet) => packetsReceived++;

            connection.ReceiveBatch(inputStream, 1);
            inputStream.NextBatch();

            connection.ReceiveBatch(inputStream, 4);
            inputStream.NextBatch();

            connection.ReceiveBatch(inputStream, 78);
            inputStream.NextBatch();

            connection.Status.Should().Be(UltimaClientConnectionStatus.ServerLogin);
            packetsReceived.Should().Be(2);
        }
        public void Can_enter_Game_status_after_initial_sequence()
        {
            var inputStream = new TestPullStream(new List <byte[]>
            {
                FakePackets.InitialLoginSeed_Pre6060,
                FakePackets.InitialLoginRequest,
                FakePackets.ClientSpy,
                FakePackets.SelectServerRequest,
                FakePackets.LoginSeed,
                FakePackets.GameServerLoginRequest
            });

            var connection = new UltimaClientConnection(UltimaClientConnectionStatus.Initial);

            connection.ReceiveBatch(inputStream, inputStream.Length);
            inputStream.NextBatch();
            connection.ReceiveBatch(inputStream, inputStream.Length);
            inputStream.NextBatch();
            connection.ReceiveBatch(inputStream, inputStream.Length);
            inputStream.NextBatch();
            connection.ReceiveBatch(inputStream, inputStream.Length);
            inputStream.NextBatch();
            connection.ReceiveBatch(inputStream, inputStream.Length);
            inputStream.NextBatch();
            connection.ReceiveBatch(inputStream, inputStream.Length);

            connection.Status.Should().Be(UltimaClientConnectionStatus.Game);
        }
        public void Given_connection_in_GameLoign_status_When_receives_GameServerLoginRequest_Then_enters_Game_status()
        {
            var inputStream = new TestPullStream(new List <byte[]> {
                FakePackets.GameServerLoginRequest
            });

            var connection = new UltimaClientConnection(UltimaClientConnectionStatus.GameLogin);

            connection.ReceiveBatch(inputStream, inputStream.Length);

            connection.Status.Should().Be(UltimaClientConnectionStatus.Game);
        }
        Given_connection_in_PreGameLogin_status_When_receives_login_seed_Then_connection_enters_GameLogin_status()
        {
            var inpuStream = new TestPullStream(new List <byte[]> {
                FakePackets.LoginSeed
            });

            var connection = new UltimaClientConnection(UltimaClientConnectionStatus.PreGameLogin);

            connection.ReceiveBatch(inpuStream, inpuStream.Length);

            connection.Status.Should().Be(UltimaClientConnectionStatus.GameLogin);
        }
Exemple #5
0
        Given_connection_in_Initial_status_When_receives_login_seed_Then_connection_enters_ServerLogin_status()
        {
            var inputStream = new TestPullStream(new List <byte[]> {
                FakePackets.InitialLoginSeed_Pre6060
            });

            var connection = new UltimaClientConnection(UltimaClientConnectionStatus.Initial);

            connection.ReceiveBatch(inputStream, inputStream.Length);

            connection.Status.Should().Be(UltimaClientConnectionStatus.AfterInitialSeed);
        }
        Given_connection_in_ServerLogin_status_When_receives_SelectServerRequest_Then_enters_PreGameLogin_status()
        {
            var inputStream = new TestPullStream(new List <byte[]> {
                FakePackets.SelectServerRequest
            });

            var connection = new UltimaClientConnection(UltimaClientConnectionStatus.ServerLogin);

            connection.ReceiveBatch(inputStream);

            connection.Status.Should().Be(UltimaClientConnectionStatus.PreGameLogin);
        }
        public void Can_receive_two_consecutive_batches()
        {
            var inputStream = new TestPullStream(new List <byte[]>
            {
                FakePackets.InitialLoginSeed_Pre6060,
                FakePackets.InitialLoginRequest
            });

            var expectedPackets = new[]
            {
                new Packet(PacketDefinitions.LoginSeed.Id, FakePackets.InitialLoginSeed_Pre6060),
                new Packet(0x80, FakePackets.InitialLoginRequest)
            };

            var connection      = new UltimaClientConnection();
            var receivedPackets = new List <Packet>();

            connection.PacketReceived += (sender, packet) => receivedPackets.Add(packet);
            connection.ReceiveBatch(inputStream, inputStream.Length);
            inputStream.NextBatch();
            connection.ReceiveBatch(inputStream, inputStream.Length);

            expectedPackets.AreEqual(receivedPackets);
        }
        public void Can_receive_three_packets_in_one_batch()
        {
            var inputStream = new TestPullStream(new List <byte[]>
            {
                FakePackets.InitialLoginSeed_Pre6060
                .Concat(FakePackets.InitialLoginRequest)
                .Concat(FakePackets.SelectServerRequest).ToArray()
            });

            var expectedPackets = new[]
            {
                new Packet(PacketDefinitions.LoginSeed.Id, FakePackets.InitialLoginSeed_Pre6060),
                new Packet(0x80, FakePackets.InitialLoginRequest),
                new Packet(0xA0, FakePackets.SelectServerRequest)
            };

            var connection      = new UltimaClientConnection();
            var receivedPackets = new List <Packet>();

            connection.PacketReceived += (sender, packet) => receivedPackets.Add(packet);
            connection.ReceiveBatch(inputStream, inputStream.Length);

            expectedPackets.AreEqual(receivedPackets);
        }
        Given_connection_in_Initial_status_When_receives_3_part_login_seed_Then_connection_enters_ServerLogin_status()
        {
            var inputStream = new TestPullStream(new List <byte[]> {
                new byte[] { 0xef },
                new byte[] { 0x01, 0x38, 0xa8, 0xc0 },
                new byte[]
                {
                    0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x21, 0x00, 0x00, 0x00, 0x01,
                },
            });

            var connection = new UltimaClientConnection(UltimaClientConnectionStatus.Initial);

            connection.ReceiveBatch(inputStream, 1);
            inputStream.NextBatch();

            connection.ReceiveBatch(inputStream, 4);
            inputStream.NextBatch();

            connection.ReceiveBatch(inputStream, 16);

            connection.Status.Should().Be(UltimaClientConnectionStatus.AfterInitialSeed);
        }