예제 #1
0
        unsafe public void Test_SocketObject_RemoveFirstPacket()
        {
            MockClient client = new MockClient(42, TestUserIP);

            string testusername1 = "foo";
            string testusername2 = "bar";
            string testpass      = "******";

            Assert.AreEqual(0u, client.SocketDataLength, "Data length should be zero after socket creation.");

            MockClient_80_Login packet1 = new MockClient_80_Login(client.Socket, testusername1, testpass);

            client.Enqueue(packet1);

            Assert.AreEqual(packet1.Length, client.SocketDataLength, "Socket should contain packet, datalength should equal packet length.");

            MockClient_80_Login packet2 = new MockClient_80_Login(client.Socket, testusername2, testpass);

            client.Enqueue(packet2);

            Assert.AreEqual(packet1.Length + packet2.Length, client.SocketDataLength, "Socket should contain 2 packet, datalength should equal sum of packet lengths.");

            Server.PacketEngine.SocketObject_RemoveFirstPacket(client.Socket, packet1.Length);

            Assert.AreEqual(packet2.Length, client.SocketDataLength, "Data length should be length of packet2 after packet1 removal.");

            Packet80_LoginRequest packetOut = client.ProcessOnly(packet2) as Packet80_LoginRequest;

            Assert.AreEqual(testusername2, packetOut.Username, "Couldn't verify username for packet2.");

            Server.PacketEngine.SocketObject_RemoveFirstPacket(client.Socket, packet2.Length);

            Assert.AreEqual(0u, client.SocketDataLength, "Data length should be zero after both packets removed.");
        }
예제 #2
0
        unsafe void TestFail(string username, string password, ALRReason expectedFailReason)
        {
            using (MockClient client = new MockClient(45, TestUserIP))
            {
                Assert.AreEqual(0u, client.SocketDataLength, "Data length should be zero");

                MockClient_80_Login packetIn = new MockClient_80_Login(client.Socket, username, password);
                client.Enqueue(packetIn);

                Assert.AreEqual(packetIn.Length, client.SocketDataLength, "Socket should contain packet, datalength should equal packet length.");

                try
                {
                    Packet80_LoginRequest packetOut = client.ProcessAndCheck(packetIn) as Packet80_LoginRequest;
                }
                catch (VerificationException ex)
                {
                    Assert.Fail(ex.Message);
                }

                Assert.AreEqual(0u, client.SocketDataLength, "Packet should have been removed.");

                MockServer_82_LoginDenied expectedPacketResponse = new MockServer_82_LoginDenied(expectedFailReason);
                string responce = ((MockPacketEngine)Server.PacketEngine).VerifySent(client, expectedPacketResponse.PacketData);
                Assert.IsTrue(string.IsNullOrEmpty(responce), "Failed to verify reject packet: {0}", responce);
            }
        }
예제 #3
0
        unsafe public void Packet00_CreateCharConstructorTest_FixSkills()
        {
            using (MockClient client = new MockClient(42, TestUserIP))
            {
                Assert.AreEqual(0u, client.SocketDataLength, "Data length should be zero");

                MockClient_00_CreateCharater packetIn = new MockClient_00_CreateCharater(client.Version);

                byte skill1 = 22;
                byte skill2 = 22;
                byte skill3 = 100;

                byte skill1Val = 24;
                byte skill2Val = 34;
                byte skill3val = 153;

                packetIn.StartX    = 23;
                packetIn.StartY    = 15;
                packetIn.StartZ    = 10;
                packetIn.Female    = 0;
                packetIn.Str       = 49;
                packetIn.Int       = 50;
                packetIn.Dex       = 25;
                packetIn.Skill1    = skill1;
                packetIn.Skill1val = skill1Val;
                packetIn.Skill2    = skill2;
                packetIn.Skill2val = skill2Val;
                packetIn.Skill3    = skill3;
                packetIn.Skill3val = skill3val;

                client.Enqueue(packetIn);

                Assert.AreEqual(packetIn.Length, client.SocketDataLength, "Socket should contain packet, datalength should equal packet length.");

                Packet00_CreateChar packetOut = client.ProcessOnly(packetIn) as Packet00_CreateChar;

                Assert.AreEqual(MockClient_00_CreateCharater.expectedLen, (uint)packetOut.Length, "Unexpected packet size.");

                Assert.AreNotEqual(packetOut.Skill1, packetOut.Skill2, "Skill1 and Skill2 should not be equal.");
                Assert.AreNotEqual(packetOut.Skill1, packetOut.Skill3, "Skill1 and Skill3 should not be equal.");
                Assert.AreNotEqual(packetOut.Skill2, packetOut.Skill3, "Skill2 and Skill3 should not be equal.");

                Assert.IsTrue(packetOut.Skill3 >= 0 && packetOut.Skill3 < Server.SkillsObject.SkillCount, "Skill3 is out of range: {0}", packetOut.Skill3);

                Assert.AreEqual(skill1Val, packetOut.Skill1val, "Skill1 value mismatch");
                Assert.AreEqual(skill2Val, packetOut.Skill2val, "Skill2 value mismatch");
                Assert.AreEqual(skill3val, packetOut.Skill3val, "Skill3 value mismatch");

                Assert.AreEqual(packetIn.Length, client.SocketDataLength, "Socket should still contain packet.");
            }
        }
예제 #4
0
        unsafe public void Packet00_CreateCharConstructorTest_Normal()
        {
            using (MockClient client = new MockClient(42, TestUserIP))
            {
                client.Version = ClientVersion.v1_26_2.Version;

                Assert.AreEqual(0u, client.SocketDataLength, "Data length should be zero");

                MockClient_00_CreateCharater packetIn = new MockClient_00_CreateCharater(client.Version);

                packetIn.StartX    = 43;
                packetIn.StartY    = 75;
                packetIn.StartZ    = 0;
                packetIn.Female    = 1;
                packetIn.Str       = 49;
                packetIn.Int       = 50;
                packetIn.Dex       = 25;
                packetIn.Skill1    = 22;
                packetIn.Skill1val = 30;
                packetIn.Skill2    = 6;
                packetIn.Skill2val = 3;
                packetIn.Skill3    = 21;
                packetIn.Skill3val = 53;

                client.Enqueue(packetIn);

                Assert.AreEqual(MockClient_00_CreateCharater.v1_26_0len, client.SocketDataLength, "Socket should contain packet, datalength should equal packet length.");

                try
                {
                    ClientPacketSafe packetOut = client.ProcessAndCheck(packetIn);
                }
                catch (VerificationException ex)
                {
                    Assert.Fail(ex.Message);
                }

                Assert.AreEqual(MockClient_00_CreateCharater.expectedLen, client.SocketDataLength, "Socket should still contain packet, length should be {0}.", MockClient_00_CreateCharater.expectedLen);
            }
        }
예제 #5
0
        unsafe int TestSuccess(string username)
        {
            using (MockClient client = new MockClient(42, TestUserIP))
            {
                Assert.AreEqual(0u, client.SocketDataLength, "Data length should be zero");

                MockClient_80_Login packetIn = new MockClient_80_Login(client.Socket, username, TestUserPass);
                client.Enqueue(packetIn);

                Assert.AreEqual(packetIn.Length, client.SocketDataLength, "Socket should contain packet, datalength should equal packet length.");

                Packet80_LoginRequest packetOut = null;
                try
                {
                    packetOut = client.ProcessAndCheck(packetIn) as Packet80_LoginRequest;
                }
                catch (VerificationException ex)
                {
                    Assert.Fail(ex.Message);
                }

                Assert.AreEqual(packetIn.Length, client.SocketDataLength, "Socket should still contain packet, as login should have been accepted.");

                int  accountID;
                bool UsernameIsAccountID = int.TryParse(packetOut.Username, out accountID);

                Assert.IsTrue(UsernameIsAccountID, "Expected username to be an account id.");
                Assert.IsTrue(string.IsNullOrEmpty(packetOut.Password), "Password should be empty.");

                Account account = Accounting.Get(accountID);
                Assert.AreEqual(username, account.Username);

                bool passwordIsCorrect = account.Login(TestUserPass, TestUserIP);
                Assert.IsTrue(passwordIsCorrect, "Password didn't work.");

                return(accountID);
            }
        }