Example #1
0
        /// <inheritdoc />
        public async Task <bool> TryHandleMessage(IProxiedMessageContext <GamePacketPayload, GamePacketPayload> context, NetworkIncomingMessage <GamePacketPayload> message)
        {
            NetworkOperationCode opCode = message.Payload.GetOperationCode();

            if (Logger.IsInfoEnabled)
            {
                Logger.Info($"Client Sent: {opCode}:{opCode:X}");
            }

            if (message.Payload is IPlayerMovementPayload <MovementInfo, MovementFlag, PackedGuid> payload)
            {
                //We should expect the payload to be a vanilla move info
                //Do NOT send guid. only server sends guid in 1.12.1
                CustomMovePacketProxy_Vanilla proxy = new CustomMovePacketProxy_Vanilla(opCode,
                                                                                        MoveInfoConverter.Convert(payload.MoveInfo) ?? throw new InvalidOperationException($"Failed to convert the move info."));

                //We use a custom overload that allows low level byte writing to the proxy
                //This feature was LITERALLY implemented exactly for this payload
                //I added it to GladNet as a hack but it may see use elsewhere for performance reasons.
                await context.ProxyConnection.WriteAsync(Serializer.Serialize(proxy));
            }
            else
            {
                throw new InvalidOperationException($"Recieved non-movement payload in movement handler. OpCode: {opCode} Type: {message.Payload.GetType().Name}");
            }

            return(true);
        }
Example #2
0
 /// <summary>
 /// Creates a metadata marker that defines the <see cref="NetworkOperationCode"/>
 /// for this packet.
 /// </summary>
 /// <param name="operationCode">The operation code.</param>
 public GamePayloadOperationCodeAttribute(NetworkOperationCode operationCode)
     : base((int)operationCode, typeof(GamePacketPayload))
 {
     if (!Enum.IsDefined(typeof(NetworkOperationCode), operationCode))
     {
         throw new ArgumentOutOfRangeException(nameof(operationCode), "Value should be defined in the NetworkOperationCode enum.");
     }
 }
        public PacketHandlerAttribute(NetworkOperationCode command)
        {
            if (!Enum.IsDefined(typeof(NetworkOperationCode), command))
            {
                throw new ArgumentOutOfRangeException($"Provided {nameof(command)} with value {(int)command} is not a defined {nameof(NetworkOperationCode)}.");
            }

            Command = command;
        }
Example #4
0
        /// <summary>
        /// Initializes a new packet header with a PacketSize of <see cref="PayloadSize"/> + 4 bytes.
        /// DO NOT provide the payloadsize with the opcode. Remove the opcode length from the payloadsize
        /// before providing it as a paremeters.
        /// The header
        /// </summary>
        /// <param name="payloadSize"></param>
        /// <param name="operationCode"></param>
        public OutgoingClientPacketHeader(int payloadSize, NetworkOperationCode operationCode)
        {
            if (!Enum.IsDefined(typeof(NetworkOperationCode), operationCode))
            {
                throw new ArgumentOutOfRangeException(nameof(operationCode), "Value should be defined in the NetworkOperationCode enum.");
            }

            OperationCode        = operationCode;
            SerializedPacketSize = (ushort)(payloadSize + 4);
        }
Example #5
0
        public IReadOnlyCollection <PacketCaptureTestEntry> BuildCaptureEntries(ExpansionType expacType, ISerializerService serializer, IEnumerable <Type> typesToRegister)
        {
            List <PacketCaptureTestEntry> testSource = new List <PacketCaptureTestEntry>(500);

            //Do file loading first because it could fail
            //Then we need to populate the input source for the tests.
            string testPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "PacketCaptures", expacType.ToString());

            //Get every folder
            foreach (string dir in Directory.GetDirectories(testPath))
            {
                //Each directory should fit the form of OpCode name
                //Even though the below is a Path with the directory if we pretend it's a file we can easily get the last part of the path
                //which represents the opcode
                NetworkOperationCode code  = (NetworkOperationCode)Enum.Parse(typeof(NetworkOperationCode), Path.GetFileNameWithoutExtension(dir));
                string[]             files = null;

                try
                {
                    files = Directory.GetFiles(Path.Combine(testPath, dir));
                }
                catch (Exception ee)
                {
                    throw new InvalidOperationException($"Failed to load File: {Path.Combine(testPath, dir)} Exception: {ee.Message} Stack: {ee.StackTrace}");
                }

                //Now we want to load each capture.
                foreach (var cap in files)
                {
                    string filePath = Path.Combine(testPath, dir, cap);
                    //Captures should have a guid on the end of them
                    Guid guid = Guid.Parse(cap.Split('_').Last());

                    try
                    {
                        byte[] bytes = File.ReadAllBytes(filePath);

                        testSource.Add(new PacketCaptureTestEntry(code, bytes, Path.GetFileName(cap)));
                    }
                    catch (Exception e)
                    {
                        throw new InvalidOperationException($"Failed to open File: {filePath} Exception: {e.Message}", e);
                    }
                }
            }

            typesToRegister
            .ToList()
            .ForEach(t => serializer.RegisterType(t));

            //This is kinda hacky but we compile here for test reasons
            serializer.Compile();

            return(testSource);
        }
        static Program()
        {
            try
            {
                //Do file loading first because it could fail
                //Then we need to populate the input source for the tests.
                string testPath = Path.Combine(Directory.GetCurrentDirectory(), "PacketCaptures");

                //Get every folder
                foreach (string dir in Directory.GetDirectories(testPath))
                {
                    //Each directory should fit the form of OpCode name
                    //Even though the below is a Path with the directory if we pretend it's a file we can easily get the last part of the path
                    //which represents the opcode
                    NetworkOperationCode code  = (NetworkOperationCode)Enum.Parse(typeof(NetworkOperationCode), Path.GetFileNameWithoutExtension(dir));
                    string[]             files = null;

                    try
                    {
                        files = Directory.GetFiles(Path.Combine(testPath, dir));
                    }
                    catch (Exception ee)
                    {
                        throw new InvalidOperationException($"Failed to load File: {Path.Combine(testPath, dir)} Exception: {ee.Message} Stack: {ee.StackTrace}");
                    }

                    //Now we want to load each capture.
                    foreach (var cap in files)
                    {
                        string filePath = Path.Combine(testPath, dir, cap);
                        //Captures should have a guid on the end of them
                        Guid guid = Guid.Parse(cap.Split('_').Last());

                        try
                        {
                            byte[] bytes = File.ReadAllBytes(filePath);

                            TestSource.Add(new PacketCaptureTestEntry(code, bytes, cap));
                        }
                        catch (Exception e)
                        {
                            throw new InvalidOperationException($"Failed to open File: {filePath} Exception: {e.Message}", e);
                        }
                    }

                    Serializer = new SerializerService();
                }
            }
            catch (Exception e)
            {
                string message = $"{e.Message} {e.StackTrace}";
                Console.WriteLine();
                throw new InvalidOperationException(message, e);
            }
        }
        //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));
        }
Example #8
0
        public OutPacket(NetworkOperationCode command, int emptyOffset = 0)
            : base()
        {
            this.Header = new ClientHeader(command, this);

            Buffer         = new MemoryStream();
            base.OutStream = Buffer;

            if (emptyOffset > 0)
            {
                Write(new byte[emptyOffset]);
            }
        }
        public bool isValid => (PacketSize + 2) >= HeaderSize;         //Is only valid if we have at least a header

        public OutgoingClientPacketHeader(int payloadSize, NetworkOperationCode operationCode)
        {
            if (!Enum.IsDefined(typeof(NetworkOperationCode), operationCode))
            {
                throw new ArgumentOutOfRangeException(nameof(operationCode), "Value should be defined in the NetworkOperationCode enum.");
            }

            OperationCode = operationCode;

            //Doesn't make much sense because the header is 6 bytes
            //This is how Jackpoz has it setup.
            PacketSize = (ushort)(payloadSize + 4);
        }
Example #10
0
        public static void Can_Deserialize_Captures_To_GamePacketPayloads(PacketCaptureTestEntry entry)
        {
            NetworkOperationCode originalOpCode = entry.OpCode;

            //TODO: Test compression another time.
            entry = RebuildEntryAsUncompressed(entry);

            Console.WriteLine($"Entry Decompressed/Real Size: {entry.BinaryData.Length} OpCode: {originalOpCode}");

            //arrange
            SerializerService serializer = Serializer;

            GamePacketPayload payload;

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            //act
            try
            {
                payload = serializer.Deserialize <GamePacketPayload>(entry.BinaryData);
            }
            catch (Exception e)
            {
                Assert.Fail($"Critical failure. Cannot deserialize File: {entry.FileName} FileSize: {entry.BinaryData.Length} \n\n Exception: {e.Message} Stack: {e.StackTrace}");
                return;
            }
            finally
            {
                stopwatch.Stop();
            }

            Console.WriteLine($"Serialization time in ms: {stopwatch.ElapsedMilliseconds}");

            foreach (ObjectUpdateBlock block in ((IObjectUpdatePayload)payload).UpdateBlocks.Items)
            {
                Console.WriteLine($"Encountered: {block.GetType().Name} Block Type: {block.UpdateType}");
            }


            //assert
            Assert.NotNull(payload, $"Resulting capture capture deserialization attempt null for File: {entry.FileName}");
            //We should have deserialized it. We want to make sure the opcode matches
            Assert.AreEqual(entry.OpCode, payload.GetOperationCode(), $"Mismatched {nameof(NetworkOperationCode)} on packet capture File: {entry.FileName}. Expected: {entry.OpCode} Was: {payload.GetOperationCode()}");
        }
Example #11
0
        public static void Can_Serialize_DeserializedDTO_To_Same_Binary_Representation(PacketCaptureTestEntry entry)
        {
            //arrange
            NetworkOperationCode originalOpCode = entry.OpCode;

            //TODO: Test compression another time.
            entry = RebuildEntryAsUncompressed(entry);
            Console.WriteLine($"Entry Decompressed/Real Size: {entry.BinaryData.Length} OpCode: {originalOpCode}");
            SerializerService serializer = Serializer;
            GamePacketPayload payload    = serializer.Deserialize <GamePacketPayload>(entry.BinaryData);

            //act
            byte[] serializedBytes = serializer.Serialize(payload);

            //assert
            Assert.AreEqual(entry.BinaryData.Length, serializedBytes.Length);

            for (int i = 0; i < entry.BinaryData.Length; i++)
            {
                Assert.AreEqual(entry.BinaryData[i], serializedBytes[i]);
            }
        }
 /// <inheritdoc />
 public PacketCaptureTestEntry(NetworkOperationCode opCode, byte[] binaryData, string fileName)
 {
     OpCode     = opCode;
     BinaryData = binaryData;
     FileName   = fileName;
 }
 /// <inheritdoc />
 public void Unlock(NetworkOperationCode operationCode)
 {
     //No matter the opcode we should release back
     LockingObject.Release(1);
 }
 /// <inheritdoc />
 public void Lock(NetworkOperationCode operationCode)
 {
     //No matter the opcode we should lock
     LockingObject.Wait();
 }
 /// <inheritdoc />
 public async Task LockAsync(NetworkOperationCode operationCode)
 {
     //No matter the opcode we should lock
     await LockingObject.WaitAsync();
 }
Example #16
0
 public PacketHandlerAttribute(NetworkOperationCode command)
 {
     Command = command;
 }
Example #17
0
 public OpcodeTriggerAction(NetworkOperationCode Opcode, Func <Packet, bool> PacketChecker, Action IntermediateAction = null)
     : base(TriggerActionType.Opcode, IntermediateAction)
 {
     this.Opcode        = Opcode;
     this.PacketChecker = PacketChecker;
 }
Example #18
0
 public OpcodeTriggerAction(NetworkOperationCode Opcode, Action IntermediateAction = null)
     : base(TriggerActionType.Opcode, IntermediateAction)
 {
     this.Opcode = Opcode;
 }
Example #19
0
        static PacketCaptureGenericTests()
        {
            try
            {
                //Do file loading first because it could fail
                //Then we need to populate the input source for the tests.
                string testPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "PacketCaptures");

                //Get every folder
                foreach (string dir in Directory.GetDirectories(testPath))
                {
                    //Each directory should fit the form of OpCode name
                    //Even though the below is a Path with the directory if we pretend it's a file we can easily get the last part of the path
                    //which represents the opcode
                    NetworkOperationCode code  = (NetworkOperationCode)Enum.Parse(typeof(NetworkOperationCode), Path.GetFileNameWithoutExtension(dir));
                    string[]             files = null;

                    try
                    {
                        files = Directory.GetFiles(Path.Combine(testPath, dir));
                    }
                    catch (Exception ee)
                    {
                        throw new InvalidOperationException($"Failed to load File: {Path.Combine(testPath, dir)} Exception: {ee.Message} Stack: {ee.StackTrace}");
                    }

                    //Now we want to load each capture.
                    foreach (var cap in files)
                    {
                        string filePath = Path.Combine(testPath, dir, cap);
                        //Captures should have a guid on the end of them
                        Guid guid = Guid.Parse(cap.Split('_').Last());

                        try
                        {
                            byte[] bytes = File.ReadAllBytes(filePath);

                            TestSource.Add(new PacketCaptureTestEntry(code, bytes, cap));
                        }
                        catch (Exception e)
                        {
                            throw new InvalidOperationException($"Failed to open File: {filePath} Exception: {e.Message}", e);
                        }
                    }

                    Serializer = new SerializerService();

                    //TODO: Once we enable full custom type serializer support we won't need to register manually.
                    Serializer.RegisterType <PackedGuid>();
                    Serializer.RegisterType <UpdateFieldValueCollection>();

                    //We want to register all known packets and then PROXY_DTOs after
                    GamePacketMetadataMarker.SerializableTypes
                    .ToList()
                    .ForEach(t => Serializer.RegisterType(t));

                    //Then we want to register DTOs for unknown
                    GamePacketStubMetadataMarker.GamePacketPayloadStubTypes
                    .Where(t => GamePacketMetadataMarker.UnimplementedOperationCodes.Value.Contains(t.GetAttribute <GamePayloadOperationCodeAttribute>().OperationCode))
                    .ToList()
                    .ForEach(t => Serializer.RegisterType(t));

                    Serializer.Compile();
                }
            }
            catch (Exception e)
            {
                string message = $"{e.Message} {e.StackTrace}";
                Console.WriteLine();
                throw new InvalidOperationException(message, e);
            }
        }
Example #20
0
 public MovementPacket(NetworkOperationCode command)
     : base(command)
 {
     time = (uint)(DateTime.Now - Process.GetCurrentProcess().StartTime).TotalMilliseconds;
 }
Example #21
0
 public static CompilationUnitSyntax BuildPayloadClassSyntax(string className, NetworkOperationCode code)
 {
     return(SyntaxFactory.CompilationUnit()
            .WithUsings
            (
                SyntaxFactory.List <UsingDirectiveSyntax>
                (
                    new UsingDirectiveSyntax[]
     {
         SyntaxFactory.UsingDirective
         (
             SyntaxFactory.IdentifierName(nameof(FreecraftCore))
         ),
         SyntaxFactory.UsingDirective
         (
             SyntaxFactory.QualifiedName
             (
                 SyntaxFactory.IdentifierName(nameof(FreecraftCore)),
                 SyntaxFactory.IdentifierName(nameof(Serializer))
             )
         )
     }
                )
            )
            .WithMembers
            (
                SyntaxFactory.SingletonList <MemberDeclarationSyntax>
                (
                    SyntaxFactory.ClassDeclaration(className)
                    .WithAttributeLists
                    (
                        SyntaxFactory.List <AttributeListSyntax>
                        (
                            new AttributeListSyntax[]
     {
         SyntaxFactory.AttributeList
         (
             SyntaxFactory.SingletonSeparatedList <AttributeSyntax>
             (
                 SyntaxFactory.Attribute
                 (
                     SyntaxFactory.IdentifierName(nameof(GamePayloadOperationCodeAttribute))
                 )
                 .WithArgumentList
                 (
                     SyntaxFactory.AttributeArgumentList
                     (
                         SyntaxFactory.SingletonSeparatedList <AttributeArgumentSyntax>
                         (
                             SyntaxFactory.AttributeArgument
                             (
                                 SyntaxFactory.MemberAccessExpression
                                 (
                                     SyntaxKind.SimpleMemberAccessExpression,
                                     SyntaxFactory.IdentifierName(nameof(NetworkOperationCode)),
                                     SyntaxFactory.IdentifierName(code.ToString())
                                 )
                             )
                         )
                     )
                 )
             )
         ),
         SyntaxFactory.AttributeList
         (
             SyntaxFactory.SingletonSeparatedList <AttributeSyntax>
             (
                 SyntaxFactory.Attribute
                 (
                     SyntaxFactory.IdentifierName(nameof(WireDataContractAttribute))
                 )
             )
         )
     }
                        )
                    )
                    .WithModifiers
                    (
                        SyntaxFactory.TokenList
                        (
                            new[]
     {
         SyntaxFactory.Token(SyntaxKind.PublicKeyword),
         SyntaxFactory.Token(SyntaxKind.SealedKeyword)
     }
                        )
                    )
                    .WithBaseList
                    (
                        SyntaxFactory.BaseList
                        (
                            SyntaxFactory.SeparatedList <BaseTypeSyntax>
                            (
                                new SyntaxNodeOrToken[]
     {
         SyntaxFactory.SimpleBaseType
         (
             SyntaxFactory.IdentifierName(nameof(GamePacketPayload))
         ),
         SyntaxFactory.Token(SyntaxKind.CommaToken),
         SyntaxFactory.SimpleBaseType
         (
             SyntaxFactory.IdentifierName(nameof(IUnimplementedGamePacketPayload))
         )
     }
                            )
                        )
                    )
                    .WithMembers
                    (
                        SyntaxFactory.List <MemberDeclarationSyntax>
                        (
                            new MemberDeclarationSyntax[]
     {
         SyntaxFactory.FieldDeclaration
         (
             SyntaxFactory.VariableDeclaration
             (
                 SyntaxFactory.ArrayType
                 (
                     SyntaxFactory.PredefinedType
                     (
                         SyntaxFactory.Token(SyntaxKind.ByteKeyword)
                     )
                 )
                 .WithRankSpecifiers
                 (
                     SyntaxFactory.SingletonList <ArrayRankSpecifierSyntax>
                     (
                         SyntaxFactory.ArrayRankSpecifier
                         (
                             SyntaxFactory.SingletonSeparatedList <ExpressionSyntax>
                             (
                                 SyntaxFactory.OmittedArraySizeExpression()
                             )
                         )
                     )
                 )
             )
             .WithVariables
             (
                 SyntaxFactory.SingletonSeparatedList <VariableDeclaratorSyntax>
                 (
                     SyntaxFactory.VariableDeclarator
                     (
                         SyntaxFactory.Identifier($"_{nameof(IUnimplementedGamePacketPayload.Data)}")
                     )
                 )
             )
         )
         .WithAttributeLists
         (
             SyntaxFactory.List <AttributeListSyntax>
             (
                 new AttributeListSyntax[]
         {
             SyntaxFactory.AttributeList
             (
                 SyntaxFactory.SingletonSeparatedList <AttributeSyntax>
                 (
                     SyntaxFactory.Attribute
                     (
                         SyntaxFactory.IdentifierName(nameof(ReadToEndAttribute))
                     )
                 )
             ),
             SyntaxFactory.AttributeList
             (
                 SyntaxFactory.SingletonSeparatedList <AttributeSyntax>
                 (
                     SyntaxFactory.Attribute
                     (
                         SyntaxFactory.IdentifierName(nameof(WireMemberAttribute))
                     )
                     .WithArgumentList
                     (
                         SyntaxFactory.AttributeArgumentList
                         (
                             SyntaxFactory.SingletonSeparatedList <AttributeArgumentSyntax>
                             (
                                 SyntaxFactory.AttributeArgument
                                 (
                                     SyntaxFactory.LiteralExpression
                                     (
                                         SyntaxKind.NumericLiteralExpression,
                                         SyntaxFactory.Literal(1)
                                     )
                                 )
                             )
                         )
                     )
                 )
             )
         }
             )
         )
         .WithModifiers
         (
             SyntaxFactory.TokenList
             (
                 SyntaxFactory.Token(SyntaxKind.PrivateKeyword)
             )
         ),
         SyntaxFactory.PropertyDeclaration
         (
             SyntaxFactory.ArrayType
             (
                 SyntaxFactory.PredefinedType
                 (
                     SyntaxFactory.Token(SyntaxKind.ByteKeyword)
                 )
             )
             .WithRankSpecifiers
             (
                 SyntaxFactory.SingletonList <ArrayRankSpecifierSyntax>
                 (
                     SyntaxFactory.ArrayRankSpecifier
                     (
                         SyntaxFactory.SingletonSeparatedList <ExpressionSyntax>
                         (
                             SyntaxFactory.OmittedArraySizeExpression()
                         )
                     )
                 )
             ),
             SyntaxFactory.Identifier(nameof(IUnimplementedGamePacketPayload.Data))
         )
         .WithModifiers
         (
             SyntaxFactory.TokenList
             (
                 SyntaxFactory.Token(SyntaxKind.PublicKeyword)
             )
         )
         .WithAccessorList
         (
             SyntaxFactory.AccessorList
             (
                 SyntaxFactory.List <AccessorDeclarationSyntax>
                 (
                     new AccessorDeclarationSyntax[]
         {
             SyntaxFactory.AccessorDeclaration
             (
                 SyntaxKind.GetAccessorDeclaration
             )
             .WithBody
             (
                 SyntaxFactory.Block
                 (
                     SyntaxFactory.SingletonList <StatementSyntax>
                     (
                         SyntaxFactory.ReturnStatement
                         (
                             SyntaxFactory.IdentifierName($"_{nameof(IUnimplementedGamePacketPayload.Data)}")
                         )
                     )
                 )
             ),
             SyntaxFactory.AccessorDeclaration
             (
                 SyntaxKind.SetAccessorDeclaration
             )
             .WithBody
             (
                 SyntaxFactory.Block
                 (
                     SyntaxFactory.SingletonList <StatementSyntax>
                     (
                         SyntaxFactory.ExpressionStatement
                         (
                             SyntaxFactory.AssignmentExpression
                             (
                                 SyntaxKind.SimpleAssignmentExpression,
                                 SyntaxFactory.IdentifierName($"_{nameof(IUnimplementedGamePacketPayload.Data)}"),
                                 SyntaxFactory.IdentifierName("value")
                             )
                         )
                     )
                 )
             )
         }
                 )
             )
         ),
         SyntaxFactory.ConstructorDeclaration
         (
             SyntaxFactory.Identifier(className)
         )
         .WithModifiers
         (
             SyntaxFactory.TokenList
             (
                 SyntaxFactory.Token(SyntaxKind.PublicKeyword)
             )
         )
         .WithBody
         (
             SyntaxFactory.Block()
         )
     }
                        )
                    )
                )
            )
            .NormalizeWhitespace());
 }
Example #22
0
 protected GamePacketPayload(NetworkOperationCode operationCode)
 {
     OperationCode = operationCode;
 }
 public static CompilationUnitSyntax BuildPayloadClassSyntax(string className, NetworkOperationCode code)
 {
     return(CompilationUnit()
            .WithUsings
            (
                List <UsingDirectiveSyntax>
                (
                    new UsingDirectiveSyntax[]
     {
         UsingDirective
         (
             IdentifierName("System")
         )
         .WithUsingKeyword
         (
             Token
             (
                 TriviaList(),
                 SyntaxKind.UsingKeyword,
                 TriviaList
                 (
                     Space
                 )
             )
         )
         .WithSemicolonToken
         (
             Token
             (
                 TriviaList(),
                 SyntaxKind.SemicolonToken,
                 TriviaList
                 (
                     CarriageReturnLineFeed
                 )
             )
         ),
         UsingDirective
         (
             QualifiedName
             (
                 IdentifierName("FreecraftCore"),
                 IdentifierName("Serializer")
             )
         )
         .WithUsingKeyword
         (
             Token
             (
                 TriviaList(),
                 SyntaxKind.UsingKeyword,
                 TriviaList
                 (
                     Space
                 )
             )
         )
         .WithSemicolonToken
         (
             Token
             (
                 TriviaList(),
                 SyntaxKind.SemicolonToken,
                 TriviaList
                 (
                     CarriageReturnLineFeed
                 )
             )
         )
     }
                )
            )
            .WithMembers
            (
                SingletonList <MemberDeclarationSyntax>
                (
                    NamespaceDeclaration
                    (
                        IdentifierName
                        (
                            Identifier
                            (
                                TriviaList(),
                                "FreecraftCore",
                                TriviaList
                                (
                                    CarriageReturnLineFeed
                                )
                            )
                        )
                    )
                    .WithNamespaceKeyword
                    (
                        Token
                        (
                            TriviaList
                            (
                                CarriageReturnLineFeed
                            ),
                            SyntaxKind.NamespaceKeyword,
                            TriviaList
                            (
                                Space
                            )
                        )
                    )
                    .WithOpenBraceToken
                    (
                        Token
                        (
                            TriviaList(),
                            SyntaxKind.OpenBraceToken,
                            TriviaList
                            (
                                CarriageReturnLineFeed
                            )
                        )
                    )
                    .WithMembers
                    (
                        SingletonList <MemberDeclarationSyntax>
                        (
                            ClassDeclaration
                            (
                                Identifier
                                (
                                    TriviaList(),
                                    className,
                                    TriviaList
                                    (
                                        Space
                                    )
                                )
                            )
                            .WithAttributeLists
                            (
                                List <AttributeListSyntax>
                                (
                                    new AttributeListSyntax[]
     {
         AttributeList
         (
             SingletonSeparatedList <AttributeSyntax>
             (
                 Attribute
                 (
                     IdentifierName(nameof(WireDataContractAttribute).Replace("Attribute", ""))
                 )
             )
         )
         .WithOpenBracketToken
         (
             Token
             (
                 TriviaList
                 (
                     new[]
         {
             Tab,
             Trivia
             (
                 DocumentationCommentTrivia
                 (
                     SyntaxKind.SingleLineDocumentationCommentTrivia,
                     List <XmlNodeSyntax>
                     (
                         new XmlNodeSyntax[]
             {
                 XmlText()
                 .WithTextTokens
                 (
                     TokenList
                     (
                         XmlTextLiteral
                         (
                             TriviaList
                             (
                                 DocumentationCommentExterior("///")
                             ),
                             " ",
                             " ",
                             TriviaList()
                         )
                     )
                 ),
                 XmlExampleElement
                 (
                     SingletonList <XmlNodeSyntax>
                     (
                         XmlText()
                         .WithTextTokens
                         (
                             TokenList
                             (
                                 new[]
                 {
                     XmlTextNewLine
                     (
                         TriviaList(),
                         Environment.NewLine,
                         Environment.NewLine,
                         TriviaList()
                     ),
                     XmlTextLiteral
                     (
                         TriviaList
                         (
                             DocumentationCommentExterior("	///")
                         ),
                         $" {code}:",
                         $" {code}:",
                         TriviaList()
                     ),
                     XmlTextNewLine
                     (
                         TriviaList(),
                         Environment.NewLine,
                         Environment.NewLine,
                         TriviaList()
                     ),
                     XmlTextLiteral
                     (
                         TriviaList
                         (
                             DocumentationCommentExterior("	///")
                         ),
                         " ",
                         " ",
                         TriviaList()
                     )
                 }
                             )
                         )
                     )
                 )
                 .WithStartTag
                 (
                     XmlElementStartTag
                     (
                         XmlName
                         (
                             Identifier("summary")
                         )
                     )
                 )
                 .WithEndTag
                 (
                     XmlElementEndTag
                     (
                         XmlName
                         (
                             Identifier("summary")
                         )
                     )
                 ),
                 XmlText()
                 .WithTextTokens
                 (
                     TokenList
                     (
                         XmlTextNewLine
                         (
                             TriviaList(),
                             Environment.NewLine,
                             Environment.NewLine,
                             TriviaList()
                         )
                     )
                 )
             }
                     )
                 )
             ),
             Tab
         }
                 ),
                 SyntaxKind.OpenBracketToken,
                 TriviaList()
             )
         )
         .WithCloseBracketToken
         (
             Token
             (
                 TriviaList(),
                 SyntaxKind.CloseBracketToken,
                 TriviaList
                 (
                     CarriageReturnLineFeed
                 )
             )
         ),
         AttributeList
         (
             SingletonSeparatedList <AttributeSyntax>
             (
                 Attribute
                 (
                     IdentifierName(nameof(GamePayloadOperationCodeAttribute).Replace("Attribute", ""))
                 )
                 .WithArgumentList
                 (
                     AttributeArgumentList
                     (
                         SingletonSeparatedList <AttributeArgumentSyntax>
                         (
                             AttributeArgument
                             (
                                 MemberAccessExpression
                                 (
                                     SyntaxKind.SimpleMemberAccessExpression,
                                     IdentifierName(nameof(NetworkOperationCode)),
                                     IdentifierName(code.ToString())
                                 )
                             )
                         )
                     )
                 )
             )
         )
         .WithOpenBracketToken
         (
             Token
             (
                 TriviaList
                 (
                     Tab
                 ),
                 SyntaxKind.OpenBracketToken,
                 TriviaList()
             )
         )
         .WithCloseBracketToken
         (
             Token
             (
                 TriviaList(),
                 SyntaxKind.CloseBracketToken,
                 TriviaList
                 (
                     CarriageReturnLineFeed
                 )
             )
         )
     }
                                )
                            )
                            .WithModifiers
                            (
                                TokenList
                                (
                                    new[]
     {
         Token
         (
             TriviaList
             (
                 Tab
             ),
             SyntaxKind.PublicKeyword,
             TriviaList
             (
                 Space
             )
         ),
         Token
         (
             TriviaList(),
             SyntaxKind.SealedKeyword,
             TriviaList
             (
                 Space
             )
         ),
         Token
         (
             TriviaList(),
             SyntaxKind.PartialKeyword,
             TriviaList
             (
                 Space
             )
         )
     }
                                )
                            )
                            .WithKeyword
                            (
                                Token
                                (
                                    TriviaList(),
                                    SyntaxKind.ClassKeyword,
                                    TriviaList
                                    (
                                        Space
                                    )
                                )
                            )
                            .WithBaseList
                            (
                                BaseList
                                (
                                    SingletonSeparatedList <BaseTypeSyntax>
                                    (
                                        SimpleBaseType
                                        (
                                            IdentifierName
                                            (
                                                Identifier
                                                (
                                                    TriviaList(),
                                                    nameof(GamePacketPayload),
                                                    TriviaList
                                                    (
                                                        CarriageReturnLineFeed
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                                .WithColonToken
                                (
                                    Token
                                    (
                                        TriviaList(),
                                        SyntaxKind.ColonToken,
                                        TriviaList
                                        (
                                            Space
                                        )
                                    )
                                )
                            )
                            .WithOpenBraceToken
                            (
                                Token
                                (
                                    TriviaList
                                    (
                                        Tab
                                    ),
                                    SyntaxKind.OpenBraceToken,
                                    TriviaList
                                    (
                                        CarriageReturnLineFeed
                                    )
                                )
                            )
                            .WithMembers
                            (
                                List <MemberDeclarationSyntax>
                                (
                                    new MemberDeclarationSyntax[]
     {
         PropertyDeclaration
         (
             ArrayType
             (
                 PredefinedType
                 (
                     Token(SyntaxKind.ByteKeyword)
                 )
             )
             .WithRankSpecifiers
             (
                 SingletonList <ArrayRankSpecifierSyntax>
                 (
                     ArrayRankSpecifier
                     (
                         SingletonSeparatedList <ExpressionSyntax>
                         (
                             OmittedArraySizeExpression()
                         )
                     )
                     .WithCloseBracketToken
                     (
                         Token
                         (
                             TriviaList(),
                             SyntaxKind.CloseBracketToken,
                             TriviaList
                             (
                                 Space
                             )
                         )
                     )
                 )
             ),
             Identifier
             (
                 TriviaList(),
                 "Contents",
                 TriviaList
                 (
                     Space
                 )
             )
         )
         .WithAttributeLists
         (
             List <AttributeListSyntax>
             (
                 new AttributeListSyntax[]
         {
             AttributeList
             (
                 SingletonSeparatedList <AttributeSyntax>
                 (
                     Attribute
                     (
                         IdentifierName(nameof(WireMemberAttribute).Replace("Attribute", ""))
                     )
                     .WithArgumentList
                     (
                         AttributeArgumentList
                         (
                             SingletonSeparatedList <AttributeArgumentSyntax>
                             (
                                 AttributeArgument
                                 (
                                     LiteralExpression
                                     (
                                         SyntaxKind.NumericLiteralExpression,
                                         Literal(1)
                                     )
                                 )
                             )
                         )
                     )
                 )
             )
             .WithOpenBracketToken
             (
                 Token
                 (
                     TriviaList
                     (
                         new[]
             {
                 Whitespace("		"),
                 Trivia
                 (
                     DocumentationCommentTrivia
                     (
                         SyntaxKind.SingleLineDocumentationCommentTrivia,
                         List <XmlNodeSyntax>
                         (
                             new XmlNodeSyntax[]
                 {
                     XmlText()
                     .WithTextTokens
                     (
                         TokenList
                         (
                             XmlTextLiteral
                             (
                                 TriviaList
                                 (
                                     DocumentationCommentExterior("///")
                                 ),
                                 " ",
                                 " ",
                                 TriviaList()
                             )
                         )
                     ),
                     XmlNullKeywordElement()
                     .WithName
                     (
                         XmlName
                         (
                             Identifier("inheritdoc")
                         )
                     )
                     .WithSlashGreaterThanToken
                     (
                         Token
                         (
                             TriviaList
                             (
                                 Space
                             ),
                             SyntaxKind.SlashGreaterThanToken,
                             TriviaList()
                         )
                     ),
                     XmlText()
                     .WithTextTokens
                     (
                         TokenList
                         (
                             XmlTextNewLine
                             (
                                 TriviaList(),
                                 Environment.NewLine,
                                 Environment.NewLine,
                                 TriviaList()
                             )
                         )
                     )
                 }
                         )
                     )
                 ),
                 Whitespace("		")
             }
                     ),
                     SyntaxKind.OpenBracketToken,
                     TriviaList()
                 )
             )
             .WithCloseBracketToken
             (
                 Token
                 (
                     TriviaList(),
                     SyntaxKind.CloseBracketToken,
                     TriviaList
                     (
                         CarriageReturnLineFeed
                     )
                 )
             ),
             AttributeList
             (
                 SingletonSeparatedList <AttributeSyntax>
                 (
                     Attribute
                     (
                         IdentifierName(nameof(ReadToEndAttribute).Replace("Attribute", ""))
                     )
                 )
             )
             .WithOpenBracketToken
             (
                 Token
                 (
                     TriviaList
                     (
                         Whitespace("		")
                     ),
                     SyntaxKind.OpenBracketToken,
                     TriviaList()
                 )
             )
             .WithCloseBracketToken
             (
                 Token
                 (
                     TriviaList(),
                     SyntaxKind.CloseBracketToken,
                     TriviaList
                     (
                         CarriageReturnLineFeed
                     )
                 )
             )
         }
             )
         )
         .WithModifiers
         (
             TokenList
             (
                 Token
                 (
                     TriviaList
                     (
                         Whitespace("		")
                     ),
                     SyntaxKind.PublicKeyword,
                     TriviaList
                     (
                         Space
                     )
                 )
             )
         )
         .WithAccessorList
         (
             AccessorList
             (
                 List <AccessorDeclarationSyntax>
                 (
                     new AccessorDeclarationSyntax[]
         {
             AccessorDeclaration
             (
                 SyntaxKind.GetAccessorDeclaration
             )
             .WithSemicolonToken
             (
                 Token
                 (
                     TriviaList(),
                     SyntaxKind.SemicolonToken,
                     TriviaList
                     (
                         Space
                     )
                 )
             ),
             AccessorDeclaration
             (
                 SyntaxKind.SetAccessorDeclaration
             )
             .WithModifiers
             (
                 TokenList
                 (
                     Token
                     (
                         TriviaList(),
                         SyntaxKind.InternalKeyword,
                         TriviaList
                         (
                             Space
                         )
                     )
                 )
             )
             .WithSemicolonToken
             (
                 Token
                 (
                     TriviaList(),
                     SyntaxKind.SemicolonToken,
                     TriviaList
                     (
                         Space
                     )
                 )
             )
         }
                 )
             )
             .WithOpenBraceToken
             (
                 Token
                 (
                     TriviaList(),
                     SyntaxKind.OpenBraceToken,
                     TriviaList
                     (
                         Space
                     )
                 )
             )
             .WithCloseBraceToken
             (
                 Token
                 (
                     TriviaList(),
                     SyntaxKind.CloseBraceToken,
                     TriviaList
                     (
                         CarriageReturnLineFeed
                     )
                 )
             )
         ),
         ConstructorDeclaration
         (
             Identifier(className)
         )
         .WithModifiers
         (
             TokenList
             (
                 Token
                 (
                     TriviaList
                     (
                         new[]
         {
             CarriageReturnLineFeed,
             Whitespace("		")
         }
                     ),
                     SyntaxKind.PublicKeyword,
                     TriviaList
                     (
                         Space
                     )
                 )
             )
         )
         .WithParameterList
         (
             ParameterList
             (
                 SingletonSeparatedList <ParameterSyntax>
                 (
                     Parameter
                     (
                         Identifier("contents")
                     )
                     .WithType
                     (
                         ArrayType
                         (
                             PredefinedType
                             (
                                 Token(SyntaxKind.ByteKeyword)
                             )
                         )
                         .WithRankSpecifiers
                         (
                             SingletonList <ArrayRankSpecifierSyntax>
                             (
                                 ArrayRankSpecifier
                                 (
                                     SingletonSeparatedList <ExpressionSyntax>
                                     (
                                         OmittedArraySizeExpression()
                                     )
                                 )
                                 .WithCloseBracketToken
                                 (
                                     Token
                                     (
                                         TriviaList(),
                                         SyntaxKind.CloseBracketToken,
                                         TriviaList
                                         (
                                             Space
                                         )
                                     )
                                 )
                             )
                         )
                     )
                 )
             )
             .WithCloseParenToken
             (
                 Token
                 (
                     TriviaList(),
                     SyntaxKind.CloseParenToken,
                     TriviaList
                     (
                         CarriageReturnLineFeed
                     )
                 )
             )
         )
         .WithInitializer
         (
             ConstructorInitializer
             (
                 SyntaxKind.ThisConstructorInitializer,
                 ArgumentList()
                 .WithCloseParenToken
                 (
                     Token
                     (
                         TriviaList(),
                         SyntaxKind.CloseParenToken,
                         TriviaList
                         (
                             CarriageReturnLineFeed
                         )
                     )
                 )
             )
             .WithColonToken
             (
                 Token
                 (
                     TriviaList
                     (
                         Whitespace("			")
                     ),
                     SyntaxKind.ColonToken,
                     TriviaList
                     (
                         Space
                     )
                 )
             )
         )
         .WithBody
         (
             Block
             (
                 SingletonList <StatementSyntax>
                 (
                     ExpressionStatement
                     (
                         AssignmentExpression
                         (
                             SyntaxKind.SimpleAssignmentExpression,
                             IdentifierName
                             (
                                 Identifier
                                 (
                                     TriviaList
                                     (
                                         Whitespace("			")
                                     ),
                                     "Contents",
                                     TriviaList
                                     (
                                         Space
                                     )
                                 )
                             ),
                             BinaryExpression
                             (
                                 SyntaxKind.CoalesceExpression,
                                 IdentifierName
                                 (
                                     Identifier
                                     (
                                         TriviaList(),
                                         "contents",
                                         TriviaList
                                         (
                                             Space
                                         )
                                     )
                                 ),
                                 ThrowExpression
                                 (
                                     ObjectCreationExpression
                                     (
                                         IdentifierName("ArgumentNullException")
                                     )
                                     .WithNewKeyword
                                     (
                                         Token
                                         (
                                             TriviaList(),
                                             SyntaxKind.NewKeyword,
                                             TriviaList
                                             (
                                                 Space
                                             )
                                         )
                                     )
                                     .WithArgumentList
                                     (
                                         ArgumentList
                                         (
                                             SingletonSeparatedList <ArgumentSyntax>
                                             (
                                                 Argument
                                                 (
                                                     InvocationExpression
                                                     (
                                                         IdentifierName
                                                         (
                                                             Identifier
                                                             (
                                                                 TriviaList(),
                                                                 SyntaxKind.NameOfKeyword,
                                                                 "nameof",
                                                                 "nameof",
                                                                 TriviaList()
                                                             )
                                                         )
                                                     )
                                                     .WithArgumentList
                                                     (
                                                         ArgumentList
                                                         (
                                                             SingletonSeparatedList <ArgumentSyntax>
                                                             (
                                                                 Argument
                                                                 (
                                                                     IdentifierName("contents")
                                                                 )
                                                             )
                                                         )
                                                     )
                                                 )
                                             )
                                         )
                                     )
                                 )
                                 .WithThrowKeyword
                                 (
                                     Token
                                     (
                                         TriviaList(),
                                         SyntaxKind.ThrowKeyword,
                                         TriviaList
                                         (
                                             Space
                                         )
                                     )
                                 )
                             )
                             .WithOperatorToken
                             (
                                 Token
                                 (
                                     TriviaList(),
                                     SyntaxKind.QuestionQuestionToken,
                                     TriviaList
                                     (
                                         Space
                                     )
                                 )
                             )
                         )
                         .WithOperatorToken
                         (
                             Token
                             (
                                 TriviaList(),
                                 SyntaxKind.EqualsToken,
                                 TriviaList
                                 (
                                     Space
                                 )
                             )
                         )
                     )
                     .WithSemicolonToken
                     (
                         Token
                         (
                             TriviaList(),
                             SyntaxKind.SemicolonToken,
                             TriviaList
                             (
                                 CarriageReturnLineFeed
                             )
                         )
                     )
                 )
             )
             .WithOpenBraceToken
             (
                 Token
                 (
                     TriviaList
                     (
                         Whitespace("		")
                     ),
                     SyntaxKind.OpenBraceToken,
                     TriviaList
                     (
                         CarriageReturnLineFeed
                     )
                 )
             )
             .WithCloseBraceToken
             (
                 Token
                 (
                     TriviaList
                     (
                         Whitespace("		")
                     ),
                     SyntaxKind.CloseBraceToken,
                     TriviaList
                     (
                         CarriageReturnLineFeed
                     )
                 )
             )
         ),
         ConstructorDeclaration
         (
             Identifier(className)
         )
         .WithModifiers
         (
             TokenList
             (
                 Token
                 (
                     TriviaList
                     (
                         new[]
         {
             CarriageReturnLineFeed,
             Whitespace("		")
         }
                     ),
                     SyntaxKind.PublicKeyword,
                     TriviaList
                     (
                         Space
                     )
                 )
             )
         )
         .WithParameterList
         (
             ParameterList()
             .WithCloseParenToken
             (
                 Token
                 (
                     TriviaList(),
                     SyntaxKind.CloseParenToken,
                     TriviaList
                     (
                         CarriageReturnLineFeed
                     )
                 )
             )
         )
         .WithInitializer
         (
             ConstructorInitializer
             (
                 SyntaxKind.BaseConstructorInitializer,
                 ArgumentList
                 (
                     SingletonSeparatedList <ArgumentSyntax>
                     (
                         Argument
                         (
                             MemberAccessExpression
                             (
                                 SyntaxKind.SimpleMemberAccessExpression,
                                 IdentifierName(nameof(NetworkOperationCode)),
                                 IdentifierName(code.ToString())
                             )
                         )
                     )
                 )
                 .WithCloseParenToken
                 (
                     Token
                     (
                         TriviaList(),
                         SyntaxKind.CloseParenToken,
                         TriviaList
                         (
                             CarriageReturnLineFeed
                         )
                     )
                 )
             )
             .WithColonToken
             (
                 Token
                 (
                     TriviaList
                     (
                         Whitespace("			")
                     ),
                     SyntaxKind.ColonToken,
                     TriviaList
                     (
                         Space
                     )
                 )
             )
         )
         .WithBody
         (
             Block()
             .WithOpenBraceToken
             (
                 Token
                 (
                     TriviaList
                     (
                         Whitespace("		")
                     ),
                     SyntaxKind.OpenBraceToken,
                     TriviaList
                     (
                         CarriageReturnLineFeed
                     )
                 )
             )
             .WithCloseBraceToken
             (
                 Token
                 (
                     TriviaList
                     (
                         new[]
         {
             CarriageReturnLineFeed,
             Whitespace("		")
         }
                     ),
                     SyntaxKind.CloseBraceToken,
                     TriviaList
                     (
                         CarriageReturnLineFeed
                     )
                 )
             )
         )
     }
                                )
                            )
                            .WithCloseBraceToken
                            (
                                Token
                                (
                                    TriviaList
                                    (
                                        Tab
                                    ),
                                    SyntaxKind.CloseBraceToken,
                                    TriviaList
                                    (
                                        CarriageReturnLineFeed
                                    )
                                )
                            )
                        )
                    )
                )
            ));
 }
Example #24
0
 /// <inheritdoc />
 public CustomMovePacketProxy_Vanilla(NetworkOperationCode opCode, MovementInfo_Vanilla moveInfo)
 {
     OpCode   = opCode;
     MoveInfo = moveInfo;
 }
 /// <inheritdoc />
 public Task LockAsync(NetworkOperationCode operationCode)
 {
     return(Task.CompletedTask);
 }
 /// <inheritdoc />
 public void Unlock(NetworkOperationCode operationCode)
 {
     //Do nothing, we don't lock with lockless
 }
Example #27
0
 public ClientHeader(NetworkOperationCode command, OutPacket packet)
 {
     this.Command = command;
     Packet       = packet;
 }
 /// <inheritdoc />
 public CustomMovePacketProxy(NetworkOperationCode opCode, [NotNull] PackedGuid moveGuid, [NotNull] MovementInfo moveInfo)
 {
     MoveGuid = moveGuid ?? throw new ArgumentNullException(nameof(moveGuid));
     OpCode   = opCode;
     MoveInfo = moveInfo ?? throw new ArgumentNullException(nameof(moveInfo));
 }