~ruther/NosSmooth

2ba067882c8dbeb0d2ed85cfaa07aef029de415d — František Boháček 3 years ago 75c12b9
fix: serialize in packet correctly
1 files changed, 21 insertions(+), 4 deletions(-)

M Core/NosSmooth.Core/Packets/Converters/InPacketSerializer.cs
M Core/NosSmooth.Core/Packets/Converters/InPacketSerializer.cs => Core/NosSmooth.Core/Packets/Converters/InPacketSerializer.cs +21 -4
@@ 5,6 5,7 @@
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Linq;
using NosCore.Packets.ServerPackets.Visibility;
using NosCore.Shared.Enumerations;
using Remora.Results;


@@ 45,9 46,25 @@ public class InPacketSerializer : SpecificPacketSerializer<InPacket>
        try
        {
            var deserializer = _packetSerializerProvider.ServerSerializer.Deserializer;
            var inPacket = (InPacket)deserializer.Deserialize(packetString);
            var splitted = packetString.Split(new char[] { ' ' }, 9).Skip(1).ToArray();

            if (!Enum.TryParse(splitted[0], out VisualType type))
            {
                return new ArgumentInvalidError(nameof(packetString), "The visual type is incorrect.");
            }

            var startAddress = type == VisualType.Player ? 3 : 2;
            var inPacket = new InPacket
            {
                VisualType = type,
                VNum = type != VisualType.Player ? long.Parse(splitted[1]) : null,
                Name = type == VisualType.Player ? splitted[1] : null,
                VisualId = long.Parse(splitted[startAddress]),
                PositionX = short.Parse(splitted[startAddress + 1]),
                PositionY = short.Parse(splitted[startAddress + 2]),
                Direction = byte.Parse(splitted[startAddress + 3])
            };

            var splitted = packetString.Split(new char[] { ' ' }, 8);
            switch (inPacket.VisualType)
            {
                case VisualType.Player:


@@ 56,11 73,11 @@ public class InPacketSerializer : SpecificPacketSerializer<InPacket>
                    break;
                case VisualType.Object:
                    inPacket.InItemSubPacket = (InItemSubPacket?)deserializer
                        .DeserializeHeaderlessIPacket(typeof(InItemSubPacket), splitted[7]);
                        .DeserializeHeaderlessIPacket(typeof(InItemSubPacket), splitted[6] + " " + splitted[7]);
                    break;
                default:
                    inPacket.InNonPlayerSubPacket = (InNonPlayerSubPacket?)deserializer
                        .DeserializeHeaderlessIPacket(typeof(InNonPlayerSubPacket), splitted[7]);
                        .DeserializeHeaderlessIPacket(typeof(InNonPlayerSubPacket), splitted[6] + " " + splitted[7]);
                    break;
            }


Do not follow this link