示例#1
0
        public static void Test_Can_Serializer_Then_Deserialize_Most_Complex_Test_Possible()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            TestEnum[] arrayOne = new TestEnum[] { TestEnum.Zero, TestEnum.One };
            TestEnum[] arrayTwo = new TestEnum[3] {
                TestEnum.Two, TestEnum.One, TestEnum.Zero
            };
            BasicWireDataContract WireDataContractNested = new BasicWireDataContract(8);

            //act
            serializer.RegisterType <VeryComplexType>();
            serializer.Compile();

            byte[] bytes = serializer.Serialize(new VeryComplexType(6, WireDataContractNested, arrayOne, arrayTwo));
            Assert.NotNull(bytes);
            Assert.False(bytes.Length == 0);
            VeryComplexType message = serializer.Deserialize <VeryComplexType>(bytes);

            //assert
            Assert.NotNull(message);

            //check fields
            for (int i = 0; i < arrayOne.Length; i++)
            {
                Assert.AreEqual(arrayOne[i], message.testEnums[i], $"Failed for index {i}.");
            }

            for (int i = 0; i < arrayTwo.Length; i++)
            {
                Assert.AreEqual(arrayTwo[i], message.testEnumsAnother[i], $"Failed for index {i}.");
            }
        }
示例#2
0
 private static void NewMethod(Stopwatch watch, SerializerService serializer)
 {
     watch.Start();
     serializer.RegisterType <PlayerCharacterDataModel>();
     serializer.Compile();
     watch.Stop();
 }
示例#3
0
        public static void Test_Can_Deserialize_SeperatedCollection_Type()
        {
            Assert.Warn("TODO You must fix and reimplement seperated collection. It's not working fully as intended.");
            return;

            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestSeperatedCollection>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestSeperatedCollection("Hello meep56!", 123456, new[] { 55523, 90, 2445, 63432, 6969 }));
            TestSeperatedCollection deserialized = serializer.Deserialize <TestSeperatedCollection>(bytes);

            //assert
            Assert.NotNull(deserialized);
            Assert.NotNull(deserialized.IntsChars);

            Assert.AreEqual(5, deserialized.Size, "Expected the size to be the original collection size");
            Assert.AreEqual(5, deserialized.IntsChars.Length, $"Expected the length of the collection to be the original length");

            Assert.AreEqual("Hello meep56!", deserialized.TestString);
            Assert.AreEqual(123456, deserialized.AnotherValue);
        }
        public void Test_Can_Deserialize_ReadToEnd_String_Type()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <ReadToEndStringType>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new ReadToEndStringType(5, TestStrings));
            ReadToEndStringType deserializer = serializer.Deserialize <ReadToEndStringType>(bytes);

            Assert.NotNull(deserializer);
            Assert.IsNotEmpty(deserializer.Strings);
            Assert.AreEqual(5, deserializer.I);
            Assert.AreEqual(TestStrings.Length, deserializer.Strings.Length);

            //Check that there are null terminators
            Assert.AreEqual(TestStrings.Length, bytes.Skip(4).Count(b => b == 0));

            for (int i = 0; i < TestStrings.Length; i++)
            {
                Assert.AreEqual(TestStrings[i], deserializer.Strings[i]);
            }
        }
        public void Test_Can_Serialize_Then_Deserializer_AuthSessionChallengeEvent_Vanilla_Payload()
        {
            //arrange
            SerializerService otherService = new SerializerService();

            otherService.RegisterType <SessionAuthChallengeEvent>();

            SerializerService serializer = new SerializerService();

            serializer.RegisterType <SessionAuthChallengeEvent_Vanilla>();
            serializer.Compile();
            otherService.Compile();

            SerializerService lastserializer = new SerializerService();

            lastserializer.RegisterType <SessionAuthChallengeEvent_Vanilla>();
            lastserializer.Compile();

            //act
            byte[] bytes = lastserializer.Serialize(new SessionAuthChallengeEvent_Vanilla(new SessionAuthChallengeEventData(55, new byte[32])));
            SessionAuthChallengeEvent_Vanilla payload = serializer.Deserialize <SessionAuthChallengeEvent_Vanilla>(bytes);

            //assert
            Assert.NotNull(bytes);
        }
示例#6
0
        public void Test_Can_Serialize_Type_With_Complex_Array_Ignored_And_SendSize_Array_Succedding(int[] intArray)
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestComplexOptionalFieldWithDisable>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestComplexOptionalFieldWithDisable(intArray));
            TestComplexOptionalFieldWithDisable deserializerData = serializer.Deserialize <TestComplexOptionalFieldWithDisable>(bytes);

            //assert
            Assert.NotNull(bytes);
            Assert.True(bytes.Length != 0);

            //Check it's sizeof the element * length + the sendsize
            Assert.True(bytes.Length == intArray.Length * sizeof(int) + sizeof(int));

            Assert.NotNull(deserializerData);

            for (int i = 0; i < intArray.Length; i++)
            {
                Assert.AreEqual(intArray[i], deserializerData.TestInts[i]);
            }
        }
        public void Test_Can_Register_All_Concrete_Models(Type t)
        {
            //We have to do abit of a hack if it's a generic type
            //We need a closed generic. DBCs usually are generic if they have strings
            if (t.IsGenericTypeDefinition)
            {
                //TODO: Handle contraints better, causes throw and this is a hack to catch
                //TODO: Support closing multiple type arg generics
                //Assuming this can work, assuming all 1 generic param for now.
                try
                {
                    t = t.MakeGenericType(typeof(StringDBCReference));
                }
                catch (Exception e)
                {
                    Assert.Inconclusive($"Cannot test Type: {t.Name} because closed generic could not be made. Maybe caused by constaints. Error: {e.Message}");
                }
            }

            //arrange
            SerializerService serializer = new SerializerService();

            //assert
            Assert.DoesNotThrow(() => serializer.RegisterType(t));
            Assert.DoesNotThrow(() => serializer.Compile());

            Assert.True(serializer.isTypeRegistered(t), $"Failed to register Type: {t.Name}");
        }
示例#8
0
        private static async Task AsyncMain()
        {
            //While they're typing this let's build the serializer.
            Task serializerReady = Task.Factory.StartNew(() =>
            {
                serializer.RegisterType <AdtFile>();
                serializer.Compile();
            }, TaskCreationOptions.LongRunning);

            string adtName = Console.ReadLine();

            if (String.IsNullOrEmpty(adtName) || !File.Exists(adtName))
            {
                throw new ArgumentException($"No adt file named {adtName} found in the directory.");
            }

            byte[] bytes = File.ReadAllBytes(adtName);

            //wait for the serializer to compile
            await serializerReady;

            AdtFile adtFile = serializer.Deserialize <AdtFile>(bytes);

            foreach (var chunk in adtFile)
            {
                Console.WriteLine(chunk.ToString());
            }

            Console.ReadKey();
        }
        private static INetworkSerializationService BuildClientSerializer()
        {
            SerializerService serializer = new SerializerService();

            GamePacketMetadataMarker
            .SerializableTypes
            .Concat(GamePacketMetadataMarker.GamePacketPayloadTypes)
            .Where(t => t != typeof(SMSG_CONTACT_LIST_PAYLOAD) && t != typeof(SMSG_SPELL_GO_Payload))
            .ToList()
            .ForEach(t => serializer.RegisterType(t));

            //Register all unimplemented stubs
            foreach (Type t in GamePacketStubMetadataMarker.GamePacketPayloadStubTypes.Where(t => GamePacketMetadataMarker.UnimplementedOperationCodes.Value.Contains(t.GetCustomAttribute <GamePayloadOperationCodeAttribute>().OperationCode)))
            {
                serializer.RegisterType(t);
            }

            //Also the header types
            serializer.RegisterType <ServerPacketHeader>();
            serializer.RegisterType <OutgoingClientPacketHeader>();
            serializer.RegisterType <SMSG_CONTACT_LIST_DTO_PROXY>();
            serializer.RegisterType <SMSG_SPELL_GO_DTO_PROXY>();

            serializer.Compile();

            return(new FreecraftCoreGladNetSerializerAdapter(serializer));
        }
示例#10
0
        public void Test_Can_Link_PatchingUpOneDir()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.Link <PatchingInformationPayload, PSOBBPatchPacketPayloadServer>();
            serializer.Compile();
        }
示例#11
0
        public void Test_Can_Register_PatchingLoginRequestPayload()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType(typeof(PatchingLoginRequestPayload));
            serializer.Compile();
        }
        public static void Test_Doesnt_Throw_On_Empty_Compile()
        {
            //arrange
            SerializerService service = new SerializerService();

            //assert
            Assert.DoesNotThrow(() => service.Compile());
        }
        public void Test_Can_Register_AddedSize_String_Type()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestAddedSizeStringType>();
            serializer.Compile();
        }
        public static void Test_Can_Register_Compression_Marked_Class()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestInt32ArrayCompression>();
            serializer.Compile();
        }
        public static void Test_Can_Register_AuthProofResponse()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <AuthPacketBaseTest>();
            serializer.Link <AuthLogonProofResponse, AuthPacketBaseTest>();

            serializer.Compile();
        }
        private static ISerializerService CreateNewSerializer()
        {
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <MapDatFormatGenericBodyModel <MapDataFormatObjectEntry> >();
            serializer.RegisterType <NRelSectionsChunkModel>();
            serializer.Compile();

            return(serializer);
        }
        //TODO: We should use seperate assemblies that can build the desired serializers
        private static INetworkSerializationService BuildServerSerializer()
        {
            SerializerService serializer = new SerializerService();

            //This is slightly complicated
            //But we need to register all the vanilla DTOs
            //but we should also register all the wotlk DTOs that we don't have vanilla DTOs for
            //This design will change in the future so that there is: wotlk, vanilla and shared libraries
            //But right now this is how we have to do it until then
            IReadOnlyCollection <NetworkOperationCode> codes     = VanillaGamePacketMetadataMarker.UnimplementedOperationCodes.Value;
            HashSet <NetworkOperationCode>             opcodeSet = new HashSet <NetworkOperationCode>();

            foreach (var opcode in codes)
            {
                opcodeSet.Add(opcode);
            }

            GamePacketStubMetadataMarker
            .GamePacketPayloadStubTypes
            .Where(t =>
            {
                NetworkOperationCode code = t.Attribute <GamePayloadOperationCodeAttribute>().OperationCode;

                //if it's not a vanilla or shared packet
                return(opcodeSet.Contains(code) && GamePacketMetadataMarker.UnimplementedOperationCodes.Value.Contains(code));
            })
            .Concat(GamePacketMetadataMarker.GamePacketPayloadTypes.Where(t => opcodeSet.Contains(t.Attribute <GamePayloadOperationCodeAttribute>().OperationCode)))
            .Concat(VanillaGamePacketMetadataMarker.VanillaGamePacketPayloadTypes)
            //TODO: Disable this when you need
            .Where(t => t != typeof(SMSG_CONTACT_LIST_PAYLOAD) && t != typeof(SMSG_SPELL_GO_Payload))
            .ToList()
            .ForEach(t =>
            {
                if (!(typeof(IUnimplementedGamePacketPayload).IsAssignableFrom(t)))
                {
                    Console.WriteLine($"Registering Type: {t.Name}");
                }

                serializer.RegisterType(t);
            });

            //Also the header types
            serializer.RegisterType <ServerPacketHeader>();
            serializer.RegisterType <OutgoingClientPacketHeader>();

            //TODO: Uncomment for dumping
            //serializer.RegisterType(typeof(SMSG_COMPRESSED_UPDATE_OBJECT_DTO_PROXY));
            //serializer.RegisterType(typeof(SMSG_UPDATE_OBJECT_DTO_PROXY));
            serializer.RegisterType <SMSG_CONTACT_LIST_DTO_PROXY>();
            serializer.RegisterType <SMSG_SPELL_GO_DTO_PROXY>();

            serializer.Compile();

            return(new FreecraftCoreGladNetSerializerAdapter(serializer));
        }
        public static void Test_Can_Serialize_Readonly_Property()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestWithReadonlyProperty>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestWithReadonlyProperty(5));
        }
        public static void Test_Cant_Polymorphic_Serialize_Null()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            //act
            serializer.RegisterType <WireDataContractTest>();
            serializer.Compile();

            Assert.Throws <InvalidOperationException>(() => serializer.Deserialize <WireDataContractTest>(serializer.Serialize(new WireDataContractTest(null, null))));
        }
示例#20
0
        public static void Test_Serializer_Can_Register_Most_Complex_Type_Possible()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            //act
            serializer.RegisterType <VeryComplexType>();
            serializer.Compile();

            //assert
            Assert.True(serializer.isTypeRegistered <VeryComplexType>());
        }
        public void Test_Can_Register_ReadToEnd_String_Type()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            //assert
            Assert.DoesNotThrow(() =>
            {
                serializer.RegisterType <ReadToEndStringType>();
                serializer.Compile();
            });
        }
示例#22
0
		public void Test_Can_Register_CustomClass_ReadToEnd()
		{
			//arrange
			SerializerService serializer = new SerializerService();

			//assert
			Assert.DoesNotThrow(() =>
			{
				serializer.RegisterType<ReadToEndCustomClassType>();
				serializer.Compile();
			});
		}
示例#23
0
        public void Test_No_Stack_Overflow_On_Deserializing_Unknown_Type()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            //don't register
            serializer.Compile();
            byte[] bytes = new byte[] { 55, 78 };

            //assert
            Assert.Throws <InvalidOperationException>(() => serializer.Deserialize <PSOBBPacketHeader>(bytes));
        }
示例#24
0
        public void Test_Can_Register_All_Concrete_Payloads(Type t)
        {
            //arrange
            SerializerService serializer = new SerializerService();

            //assert
            Assert.DoesNotThrow(() => serializer.RegisterType(t));
            serializer.Compile();

            Assert.True(serializer.isTypeRegistered(t), $"Failed to register Type: {t.Name}");
            Assert.True(serializer.isTypeRegistered(typeof(TPayloadBaseType)), $"Base packet type wasn't registered.");
        }
示例#25
0
        public void Test_Can_Register_PatchingUpOneDir()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType(typeof(PatchingInformationPayload));
            serializer.RegisterType(typeof(PSOBBPatchPacketPayloadServer));
            serializer.RegisterType(typeof(PSOBBPatchPacketPayloadServer));
            serializer.RegisterType(typeof(PatchingInformationPayload));
            serializer.RegisterType(typeof(PSOBBPatchPacketPayloadServer));
            serializer.RegisterType(typeof(PatchingInformationPayload));
            serializer.Compile();
        }
示例#26
0
        public static void Test_String_Serializer_Serializes()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.Compile();

            //act
            string value = serializer.Deserialize <string>(serializer.Serialize("Hello!"));

            //assert
            Assert.AreEqual(value, "Hello!");
        }
示例#27
0
        private static async Task AsyncMain()
        {
            SerializerService serializer = new SerializerService();

            typeof(AuthLogonChallengeRequest).Assembly
            .GetTypes()
            .Where(t => typeof(AuthenticationServerPayload).IsAssignableFrom(t) || typeof(AuthenticationClientPayload).IsAssignableFrom(t))
            .ToList()
            .ForEach(t =>
            {
                serializer.RegisterType(t);
            });

            serializer.Compile();

            //The auth server is encryptionless and headerless
            IManagedNetworkClient <AuthenticationClientPayload, AuthenticationServerPayload> client = new DotNetTcpClientNetworkClient()
                                                                                                      .AddHeaderlessNetworkMessageReading(new FreecraftCoreGladNetSerializerAdapter(serializer))
                                                                                                      .For <AuthenticationServerPayload, AuthenticationClientPayload, IAuthenticationPayload>()
                                                                                                      .Build()
                                                                                                      .AsManaged(new ConsoleOutLogger("ConsoleLogger", LogLevel.All, true, false, false, null));

            if (!await client.ConnectAsync("127.0.0.1", 3724))
            {
                Console.WriteLine("Failed to connect");
            }

            await client.SendMessage(new AuthLogonChallengeRequest(ProtocolVersion.ProtocolVersionTwo, GameType.WoW, ExpansionType.WrathOfTheLichKing, 3, 5,
                                                                   ClientBuild.Wotlk_3_3_5a, PlatformType.x86, OperatingSystemType.Win, LocaleType.enUS,
                                                                   IPAddress.Parse("127.0.0.1"), "Glader"));

            while (true)
            {
                var response = (await client.ReadMessageAsync()).Payload;

                Console.WriteLine("Recieved payload");

                AuthenticationLogonChallengeResponseMessageHandler handler = new AuthenticationLogonChallengeResponseMessageHandler();

                if (response is AuthLogonChallengeResponse challengeResponse)
                {
                    Console.WriteLine($"Response: Valid: {challengeResponse.isValid} Result: {challengeResponse.Result} SRP: {challengeResponse.Challenge}");

                    await handler.HandleMessage(new DefaultPeerMessageContext <AuthenticationClientPayload>(client, client, new PayloadInterceptMessageSendService <AuthenticationClientPayload>(client, client)), challengeResponse);
                }
                else
                {
                    Console.WriteLine($"Recieved Payload of Type: {response.GetType().Name}");
                }
            }
        }
示例#28
0
		public void Test_Can_Serializer_ReadToEnd_String_Type()
		{
			//arrange
			SerializerService serializer = new SerializerService();
			serializer.RegisterType<ReadToEndCustomClassType>();
			serializer.Compile();

			//act
			byte[] bytes = serializer.Serialize(new ReadToEndCustomClassType(5, TestStrings.Select(t => new TestReadToEndCustomClass(t, 5)).ToArray()));

			Assert.NotNull(bytes);
			Assert.IsNotEmpty(bytes);
			Assert.True(bytes.Length > 4);
		}
示例#29
0
        public static void Test_Serializer_Can_Read_Write_Type_With_EnumString_Field()
        {
            //arrange
            SerializerService service = new SerializerService();

            service.RegisterType <WireDataContractWithStringEnum>();
            service.Compile();

            //act
            WireDataContractWithStringEnum testInstance = service.Deserialize <WireDataContractWithStringEnum>((service.Serialize <WireDataContractWithStringEnum>(new WireDataContractWithStringEnum(TestEnum.Something))));

            //assert
            Assert.AreEqual(testInstance.test, TestEnum.Something);
        }
        public static void Test_Can_Register_Type_With_Child_Types()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            //act
            serializer.RegisterType <WireDataContractTest>();
            serializer.Compile();

            //assert
            Assert.True(serializer.isTypeRegistered <WireDataContractTest>());
            Assert.True(serializer.isTypeRegistered <ChildTypeOne>());
            Assert.True(serializer.isTypeRegistered <BaseTypeField>());
        }