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); }
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); }