public void GroupTest()
        {
            // login, create character, start game
            FakeNetworkClient clientA = HandlerTestHelper.InitializeTestEnvironment();
            FakeNetworkClient clientB = HandlerTestHelper.CreateFakeNetworkClient();

            Thread.Sleep(1000);

            // client A asks client B for group
            PJoinPacket pjoinPacketRequest = new PJoinPacket()
            {
                CharacterId = clientB.Session.Character.CharacterId,
                RequestType = GroupRequestType.Invited
            };

            clientA.ReceivePacket(pjoinPacketRequest);
            HandlerTestHelper.WaitForPackets(clientA, 1);

            // client B accepts group request
            PJoinPacket pjoinPacketAccept = new PJoinPacket()
            {
                CharacterId = clientA.Session.Character.CharacterId,
                RequestType = GroupRequestType.Accepted
            };

            clientB.ReceivePacket(pjoinPacketAccept);
            HandlerTestHelper.WaitForPackets(clientA, 1);

            // check if group has been created successfully
            Assert.IsNotNull(clientA.Session.Character.Group);
            Assert.IsNotNull(clientB.Session.Character.Group);
            Assert.AreEqual(2, clientA.Session.Character.Group.CharacterCount);
        }
Esempio n. 2
0
        public void TestCharacterOption()
        {
            // login, create character, start game
            FakeNetworkClient client = HandlerTestHelper.InitializeTestEnvironment();

            CharacterOptionPacket optionPacket = new CharacterOptionPacket {
                IsActive = false, Option = CharacterOption.FamilyRequestBlocked
            };

            // check family request
            client.ReceivePacket(optionPacket);
            string msgPacket = HandlerTestHelper.WaitForPacket(client, "msg");

            Assert.IsTrue(client.Session.Character.FamilyRequestBlocked);

            HandlerTestHelper.ShutdownTestingEnvironment();
            Assert.Pass();
        }
Esempio n. 3
0
        public static FakeNetworkClient CreateFakeNetworkClient()
        {
            FakeNetworkClient client = new FakeNetworkClient();

            _sessionManager.AddSession(client);

            long       id      = ServerManager.RandomNumber(0, 999999);
            AccountDTO account = new AccountDTO
            {
                AccountId   = id,
                Authority   = AuthorityType.Admin,
                LastSession = 12345,
                Name        = "test" + id,
                Password    = "******"
            };

            DAOFactory.AccountDAO.InsertOrUpdate(ref account);

            // register for account login
            ServerCommunicationClient.Instance.HubProxy.Invoke("RegisterAccountLogin", account.Name, 12345);

            // OpenNosEntryPoint -> LoadCharacterList
            client.ReceivePacket("12345");
            client.ReceivePacket(account.Name);
            client.ReceivePacket("test");

            string clistStart = WaitForPacket(client);

            string clistEnd = WaitForPacket(client);

            // creation of character
            client.ReceivePacket($"Char_NEW {account.Name} 2 1 0 9");

            List <string> clistAfterCreate = WaitForPackets(client, 3);
            CListPacket   cListPacket      = PacketFactory.Deserialize <CListPacket>(clistAfterCreate[1]);

            // select character
            client.ReceivePacket($"select {cListPacket.Slot}");
            string okPacket = WaitForPacket(client);

            // start game
            client.ReceivePacket("game_start");
            List <string> gameStartPacketsFirstPart  = WaitForPackets(client, "p_clear");
            List <string> gameStartPacketsSecondPart = WaitForPackets(client, "p_clear");

            // wait 100 milliseconds to be sure initialization has been finished
            Thread.Sleep(100);

            return(client);
        }
Esempio n. 4
0
        public void TestWalkMove()
        {
            // login, create character, start game
            FakeNetworkClient client = HandlerTestHelper.InitializeTestEnvironment();

            WalkPacket walkPacket = new WalkPacket {
                Speed = 11, XCoordinate = 89, YCoordinate = 126
            };

            // send walkpacket to client
            client.ReceivePacket(walkPacket);

            string     mvPacket   = HandlerTestHelper.WaitForPacket(client, "mv");
            MovePacket movePacket = PacketFactory.Deserialize <MovePacket>(mvPacket);

            Assert.AreEqual(walkPacket.XCoordinate, movePacket.PositionX);
            Assert.AreEqual(walkPacket.YCoordinate, movePacket.PositionY);
            Assert.AreEqual(walkPacket.Speed, movePacket.Speed);

            HandlerTestHelper.ShutdownTestingEnvironment();
            Assert.Pass();
        }
Esempio n. 5
0
        public static FakeNetworkClient InitializeTestEnvironment()
        {
            System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");

            // initialize Logger
            Logger.InitializeLogger(LogManager.GetLogger(typeof(BasicPacketHandlerTest)));

            // create server entities (this values would have been imported)
            CreateServerItems();
            CreateServerMaps();
            CreateServerSkills();

            // initialize servermanager
            ServerManager.Initialize();

            // initialize WCF
            ServiceFactory.Instance.Initialize();

            // register mappings for items
            DAOFactory.InventoryDAO.RegisterMapping(typeof(SpecialistInstance));
            DAOFactory.InventoryDAO.RegisterMapping(typeof(WearableInstance));
            DAOFactory.InventoryDAO.RegisterMapping(typeof(UsableInstance));
            DAOFactory.InventoryDAO.InitializeMapper(typeof(ItemInstance));

            // initialize PacketSerialization
            PacketFactory.Initialize <WalkPacket>();

            // initialize new manager
            _sessionManager = new NetworkManager <TestEncryption>("127.0.0.1", 1234, typeof(CharacterScreenPacketHandler), typeof(TestEncryption), true);
            FakeNetworkClient client = new FakeNetworkClient();

            _sessionManager.AddSession(client);

            AccountDTO account = new AccountDTO()
            {
                AccountId   = 1,
                Authority   = AuthorityType.Admin,
                LastSession = 12345,
                Name        = "test",
                Password    = "******"
            };

            DAOFactory.AccountDAO.InsertOrUpdate(ref account);

            // register for account login
            ServiceFactory.Instance.CommunicationService.RegisterAccountLogin("test", 12345);

            // OpenNosEntryPoint -> LoadCharacterList
            client.ReceivePacket("12345");
            client.ReceivePacket("test");
            client.ReceivePacket("test");

            string clistStart = WaitForPacket(client);

            string clistEnd = WaitForPacket(client);

            // creation of character
            client.ReceivePacket("Char_NEW Test 2 1 0 9");

            List <string> clistAfterCreate = WaitForPackets(client, 3);
            CListPacket   cListPacket      = PacketFactory.Serialize <CListPacket>(clistAfterCreate[1]);

            // select character
            client.ReceivePacket($"select {cListPacket.Slot}");
            string okPacket = WaitForPacket(client);

            // start game
            client.ReceivePacket("game_start");
            List <string> gameStartPacketsFirstPart  = WaitForPackets(client, "p_clear");
            List <string> gameStartPacketsSecondPart = WaitForPackets(client, "p_clear");

            return(client);
        }