protected override short?ToObject(string value, Type type, IConversionFactory factory)
        {
            if (value == "-1")
            {
                return(null);
            }

            return((short)factory.ToObject(value, typeof(short)));
        }
        protected override byte?ToObject(string value, Type type, IConversionFactory factory)
        {
            if (value == "-1" || value == "-")
            {
                return(null);
            }

            return((byte)factory.ToObject(value, typeof(byte)));
        }
Esempio n. 3
0
        protected override InPacket ToObject(string value, Type type, IConversionFactory factory)
        {
            string[] split = value.Split(' ');

            var entityType = (EntityType)Convert.ToInt32(split[0]);
            int startIndex = entityType == EntityType.PLAYER ? 3 : 2;

            var packet = new InPacket
            {
                EntityType = entityType,
                Name       = entityType == EntityType.PLAYER ? split[1] : string.Empty,
                Vnum       = entityType != EntityType.PLAYER ? Convert.ToInt32(split[1]) : 0,
                EntityId   = Convert.ToInt32(split[startIndex]),
                PositionX  = Convert.ToInt16(split[startIndex + 1]),
                PositionY  = Convert.ToInt16(split[startIndex + 2]),
                Direction  = entityType != EntityType.GROUND_ITEM ? Convert.ToByte(split[startIndex + 3]) : (byte)0
            };

            string content = string.Join(" ", split.Skip(startIndex + (entityType == EntityType.GROUND_ITEM ? 3 : 4)));

            switch (entityType)
            {
            case EntityType.MONSTER:
            case EntityType.NPC:
                packet.NpcSubPacket = (InNpcSubPacket)factory.ToObject(content, typeof(InNpcSubPacket));
                break;

            case EntityType.PLAYER:
                packet.PlayerSubPacket       = (InPlayerSubPacket)factory.ToObject(content, typeof(InPlayerSubPacket));
                packet.PlayerSubPacket.Level = byte.Parse(split.Skip(27).SkipWhile(x => x.Any(char.IsLetter)).Skip(5).First());
                break;

            case EntityType.GROUND_ITEM:
                packet.DropSubPacket = (InDropSubPacket)factory.ToObject(content, typeof(InDropSubPacket));
                break;

            default:
                throw new InvalidOperationException();
            }

            return(packet);
        }
Esempio n. 4
0
        protected override IList ToObject(string value, Type type, IConversionFactory factory)
        {
            Type generic  = type.GenericTypeArguments.FirstOrDefault();
            Type listType = typeof(List <>).MakeGenericType(type);
            var  list     = (IList)Activator.CreateInstance(listType);

            string[] values = value.Split(' ');

            foreach (string entry in values)
            {
                list.Add(factory.ToObject(entry, generic));
            }

            return(list);
        }
Esempio n. 5
0
        protected override Qnamli2Packet ToObject(string value, Type type, IConversionFactory factory)
        {
            var packet = new Qnamli2Packet();

            string[] splitted = value.Split(' ');

            packet.Command         = (string)factory.ToObject(splitted[1], typeof(string));
            packet.Type            = (Game18NConstString)factory.ToObject(splitted[2], typeof(Game18NConstString));
            packet.ParametersCount = (int)factory.ToObject(splitted[3], typeof(int));


            packet.Parameters = new string[packet.ParametersCount];
            for (int i = 0; i < packet.ParametersCount; i++)
            {
                if (i + 4 >= splitted.Length)
                {
                    break;
                }

                packet.Parameters[i] = splitted[i + 4];
            }

            return(packet);
        }
Esempio n. 6
0
        public IPacket Deserialize(string packet)
        {
            PacketOutput output     = _packetReader.Read(packet);
            CachedType   cachedType = _reflectionCache.GetCachedType(output.Header);

            if (string.IsNullOrEmpty(output.Header))
            {
                throw new InvalidOperationException("Failed to deserialize packet");
            }

            char firstChar = output.Header[0];

            if (firstChar == '$' || firstChar == '%')
            {
                string   name = output.Header.Remove(0);
                string[] args = output.Content.Split(' ');

                _logger.Debug($"[DESERIALIZER] Deserialized Command packet [Header: {firstChar} / Name {name}]");
                return(new CommandPacket
                {
                    Header = $"{firstChar}",
                    Content = output.Content,
                    Name = name,
                    Arguments = args
                });
            }

            if (cachedType == null)
            {
                _logger.Debug($"[DESERIALIZER] No type found in cache for header {output.Header}");
                return(new UnknownPacket
                {
                    Header = output.Header,
                    Content = packet
                });
            }

            var deserialized = (IPacket)_conversionFactory.ToObject(output.Content, cachedType.PacketType);

            deserialized.Header  = output.Header;
            deserialized.Content = output.Content;

            _logger.Debug($"[DESERIALIZER] {output.Header} successfully deserialized to {deserialized.GetType()}");
            return(deserialized);
        }
        protected override RaidPacket ToObject(string value, Type type, IConversionFactory factory)
        {
            string[] splitted = value.Split(' ');

            var packet = new RaidPacket
            {
                Type = RaidPacketType.Unknown
            };

            if (splitted[0] == "1")
            {
                if (splitted[1] == "0")
                {
                    packet.Type = RaidPacketType.Start;
                }

                if (splitted[1] == "1")
                {
                    packet.Type = RaidPacketType.Initialization;
                }
            }

            if (splitted[0] == "2")
            {
                if (splitted[1] == "-1")
                {
                    packet.Type = RaidPacketType.Left;
                }
                else
                {
                    packet.Type     = RaidPacketType.RaidLeader;
                    packet.LeaderId = (long)factory.ToObject(splitted[1], typeof(long));
                }
            }

            if (splitted[0] == "3")
            {
                packet.Type = RaidPacketType.PlayerHealths;
            }



            return(packet);
        }
Esempio n. 8
0
        protected override IList ToObject(string value, Type type, IConversionFactory factory)
        {
            Type generic  = type.GenericTypeArguments.FirstOrDefault();
            Type listType = typeof(List <>).MakeGenericType(type);
            var  list     = (IList)Activator.CreateInstance(listType);

            char separator = ' ';

            if (typeof(IPacket).IsAssignableFrom(generic))
            {
                separator = '^';
            }

            string[] values = value.Split(separator);
            foreach (string entry in values)
            {
                list.Add(factory.ToObject(entry, generic));
            }

            return(list);
        }