コード例 #1
0
        public void Read(ByteArrayStreamReader reader)
        {
            OperatingSystem = (OperatingSystem)reader.ReadUShort();

            Version = reader.ReadUShort();

            reader.ReadByte();

            Keys = new uint[]
            {
                reader.ReadUInt(),

                    reader.ReadUInt(),

                    reader.ReadUInt(),

                    reader.ReadUInt()
            };

            Gamemaster = reader.ReadBool();

            Account = reader.ReadString();

            Character = reader.ReadString();

            Password = reader.ReadString();
        }
コード例 #2
0
        public static HouseTile Load(ByteArrayFileTreeStream stream, ByteArrayStreamReader reader)
        {
            HouseTile houseTile = new HouseTile();

            houseTile.OffsetX = reader.ReadByte();

            houseTile.OffsetY = reader.ReadByte();

            houseTile.HouseId = reader.ReadUInt();

            while (true)
            {
                switch ((OtbmAttribute)reader.ReadByte())
                {
                case OtbmAttribute.Flags:

                    houseTile.Flags = (TileFlags)reader.ReadUInt();

                    break;

                case OtbmAttribute.ItemId:

                    houseTile.OpenTibiaItemId = reader.ReadUShort();

                    break;

                default:

                    stream.Seek(Origin.Current, -1);

                    if (stream.Child())
                    {
                        houseTile.items = new List <Item>();

                        while (true)
                        {
                            houseTile.items.Add(Item.Load(stream, reader));

                            if (!stream.Next())
                            {
                                break;
                            }
                        }
                    }
                    return(houseTile);
                }
            }
        }
コード例 #3
0
        public static OtbInfo Load(ByteArrayFileTreeStream stream, ByteArrayStreamReader reader)
        {
            OtbInfo otbInfo = new OtbInfo();

            stream.Seek(Origin.Current, 13);

            otbInfo.MajorVersion = (OtbVersion)reader.ReadUInt();

            otbInfo.MinorVersion = (TibiaVersion)reader.ReadUInt();

            otbInfo.Revision = reader.ReadUInt();

            otbInfo.CsdVersion = reader.ReadCsd();

            return(otbInfo);
        }
コード例 #4
0
ファイル: PicFile.cs プロジェクト: otbr/OpenTibia
        public static PicFile Load(string path)
        {
            using (ByteArrayFileStream stream = new ByteArrayFileStream(path))
            {
                ByteArrayStreamReader reader = new ByteArrayStreamReader(stream);

                PicFile file = new PicFile();

                file.signature = reader.ReadUInt();

                ushort images = reader.ReadUShort();

                file.images = new List <Image>(images);

                for (ushort imageId = 0; imageId < images; imageId++)
                {
                    Image image = Image.Load(stream, reader);

                    image.Id = imageId;

                    file.images.Add(image);
                }

                return(file);
            }
        }
コード例 #5
0
        public void Read(ByteArrayStreamReader reader)
        {
            OperatingSystem = (OperatingSystem)reader.ReadUShort();

            Version = reader.ReadUShort();

            TibiaDat = reader.ReadUInt();

            TibiaSpr = reader.ReadUInt();

            TibiaPic = reader.ReadUInt();

            reader.ReadByte();

            Keys = new uint[]
            {
                reader.ReadUInt(),

                    reader.ReadUInt(),

                    reader.ReadUInt(),

                    reader.ReadUInt()
            };

            Account = reader.ReadString();

            Password = reader.ReadString();
        }
コード例 #6
0
        public static OtbmInfo Load(ByteArrayFileTreeStream stream, ByteArrayStreamReader reader)
        {
            OtbmInfo otbmInfo = new OtbmInfo();

            stream.Seek(Origin.Current, 6);

            otbmInfo.OtbmVersion = (OtbmVersion)reader.ReadUInt();

            otbmInfo.Width = reader.ReadUShort();

            otbmInfo.Height = reader.ReadUShort();

            otbmInfo.MajorVersion = (OtbVersion)reader.ReadUInt();

            otbmInfo.MinorVersion = (TibiaVersion)reader.ReadUInt();

            return(otbmInfo);
        }
コード例 #7
0
        public void Read(ByteArrayStreamReader reader)
        {
            OperatingSystem = (OperatingSystem)reader.ReadUShort();

            Version = reader.ReadUShort();

            TibiaDat = reader.ReadUInt();

            TibiaSpr = reader.ReadUInt();

            TibiaPic = reader.ReadUInt();

            reader.ReadByte();

            Keys = new uint[]
            {
                reader.ReadUInt(),

                    reader.ReadUInt(),

                    reader.ReadUInt(),

                    reader.ReadUInt()
            };

            Account = reader.ReadString();

            Password = reader.ReadString();

            LocaleId = reader.ReadByte();

            Locate = Encoding.Default.GetString(reader.ReadBytes(3));

            TotalRam = reader.ReadUShort();

            reader.ReadBytes(6);

            Cpu = Encoding.Default.GetString(reader.ReadBytes(9));

            reader.ReadBytes(2);

            CpuClock = reader.ReadUShort();

            CpuClock2 = reader.ReadUShort();

            reader.ReadBytes(4);

            Cpu = Encoding.Default.GetString(reader.ReadBytes(9));

            VideoRam = reader.ReadUShort();

            ResolutionHorizontal = reader.ReadUShort();

            ResolutionVertical = reader.ReadUShort();

            RefreshRate = reader.ReadByte();
        }
コード例 #8
0
        public void Read(ByteArrayStreamReader reader)
        {
            X = reader.ReadUShort();

            Y = reader.ReadUShort();

            Z = reader.ReadByte();

            ItemId = reader.ReadUShort();

            Index = reader.ReadByte();

            CreatureId = reader.ReadUInt();
        }
コード例 #9
0
ファイル: Town.cs プロジェクト: otbr/OpenTibia
        public static Town Load(ByteArrayFileTreeStream stream, ByteArrayStreamReader reader)
        {
            Town town = new Town();

            stream.Seek(Origin.Current, 1);

            town.Id = reader.ReadUInt();

            town.Name = reader.ReadString();

            town.Position = new Position(reader.ReadUShort(), reader.ReadUShort(), reader.ReadByte());

            return(town);
        }
コード例 #10
0
        protected override void OnReceived(byte[] body)
        {
            ByteArrayArrayStream stream = new ByteArrayArrayStream(body);

            ByteArrayStreamReader reader = new ByteArrayStreamReader(stream);

            try
            {
                if (Adler32.Generate(body, 4) == reader.ReadUInt())
                {
                    if (Keys == null)
                    {
                        Rsa.DecryptAndReplace(body, 21);
                    }

                    Command command = null;

                    switch (reader.ReadByte())
                    {
                    case 0x01:
                    {
                        var packet = server.PacketsFactory.Create <EnterGameIncomingPacket>(reader);

                        command = new EnterGameCommand(this, packet);
                    }
                    break;
                    }

                    if (command != null)
                    {
                        server.QueueForExecution(command);
                    }
                }
            }
            catch (Exception ex)
            {
                server.Logger.WriteLine(ex.ToString());
            }

            base.OnReceived(body);
        }
コード例 #11
0
        public static SprFile Load(string path)
        {
            using (ByteArrayFileStream stream = new ByteArrayFileStream(path))
            {
                ByteArrayStreamReader reader = new ByteArrayStreamReader(stream);

                SprFile file = new SprFile();

                file.signature = reader.ReadUInt();

                ushort sprites = reader.ReadUShort();

                file.sprites = new List <Sprite>(sprites);

                for (ushort spriteId = 1; spriteId <= sprites; spriteId++)
                {
                    int index = reader.ReadInt();

                    if (index > 0)
                    {
                        int returnIndex = stream.Position;

                        stream.Seek(Origin.Begin, index);

                        Sprite sprite = Sprite.Load(true, reader);

                        sprite.Id = spriteId;

                        file.sprites.Add(sprite);

                        stream.Seek(Origin.Begin, returnIndex);
                    }
                }

                return(file);
            }
        }
コード例 #12
0
        public static Item Load(ByteArrayFileTreeStream stream, ByteArrayStreamReader reader)
        {
            Item item = new Item();

            stream.Seek(Origin.Current, 1);

            item.OpenTibiaId = reader.ReadUShort();

            while (true)
            {
                switch ((OtbmAttribute)reader.ReadByte())
                {
                case OtbmAttribute.Count:

                    item.Count = reader.ReadByte();

                    break;

                case OtbmAttribute.ActionId:

                    item.ActionId = reader.ReadUShort();

                    break;

                case OtbmAttribute.UniqueId:

                    item.UniqueId = reader.ReadUShort();

                    break;

                case OtbmAttribute.Text:

                    item.Text = reader.ReadString();

                    break;

                case OtbmAttribute.WrittenDate:

                    item.WrittenDate = reader.ReadUInt();

                    break;

                case OtbmAttribute.WrittenBy:

                    item.WrittenBy = reader.ReadString();

                    break;

                case OtbmAttribute.SpecialDescription:

                    item.SpecialDescription = reader.ReadString();

                    break;

                case OtbmAttribute.RuneCharges:

                    item.RuneCharges = reader.ReadByte();

                    break;

                case OtbmAttribute.Charges:

                    item.Charges = reader.ReadUShort();

                    break;

                case OtbmAttribute.Duration:

                    item.Duration = reader.ReadUInt();

                    break;

                case OtbmAttribute.Decaying:

                    item.Decaying = reader.ReadByte();

                    break;

                case OtbmAttribute.DepotId:

                    item.DeportId = reader.ReadUShort();

                    break;

                case OtbmAttribute.HouseDoorId:

                    item.HouseDoorId = reader.ReadByte();

                    break;

                case OtbmAttribute.SleeperId:

                    item.SleeperId = reader.ReadUInt();

                    break;

                case OtbmAttribute.SleepStart:

                    item.SleepterStart = reader.ReadUInt();

                    break;

                case OtbmAttribute.TeleportDestination:

                    item.TeleportPosition = new Position(reader.ReadUShort(), reader.ReadUShort(), reader.ReadByte());

                    break;

                case OtbmAttribute.ContainerItems:

                    item.ContainerItems = reader.ReadUInt();

                    break;

                default:

                    stream.Seek(Origin.Current, -1);

                    if (stream.Child())
                    {
                        item.items = new List <Item>();

                        while (true)
                        {
                            item.items.Add(Item.Load(stream, reader));

                            if (!stream.Next())
                            {
                                break;
                            }
                        }
                    }
                    return(item);
                }
            }
        }
コード例 #13
0
        public static DatFile Load(string path)
        {
            using (ByteArrayFileStream stream = new ByteArrayFileStream(path))
            {
                ByteArrayStreamReader reader = new ByteArrayStreamReader(stream);

                DatFile file = new DatFile();

                file.signature = reader.ReadUInt();

                ushort items = reader.ReadUShort();

                ushort outfits = reader.ReadUShort();

                ushort effects = reader.ReadUShort();

                ushort projectiles = reader.ReadUShort();

                file.items = new List <Item>(items);

                for (ushort itemId = 100; itemId <= items; itemId++)
                {
                    Item item = Item.Load(reader);

                    item.TibiaId = itemId;

                    file.items.Add(item);
                }

                file.outfits = new List <Item>(outfits);

                for (ushort outfitId = 0; outfitId < outfits; outfitId++)
                {
                    Item item = Item.Load(reader);

                    item.TibiaId = outfitId;

                    file.outfits.Add(item);
                }

                file.effects = new List <Item>(effects);

                for (ushort effectId = 0; effectId < effects; effectId++)
                {
                    Item item = Item.Load(reader);

                    item.TibiaId = effectId;

                    file.effects.Add(item);
                }

                file.projectiles = new List <Item>(projectiles);

                for (ushort projectileId = 0; projectileId < projectiles; projectileId++)
                {
                    Item item = Item.Load(reader);

                    item.TibiaId = projectileId;

                    file.projectiles.Add(item);
                }

                return(file);
            }
        }
コード例 #14
0
 public void Read(ByteArrayStreamReader reader)
 {
     CreatureId = reader.ReadUInt();
 }
コード例 #15
0
        protected override void OnReceived(byte[] body)
        {
            ByteArrayArrayStream stream = new ByteArrayArrayStream(body);

            ByteArrayStreamReader reader = new ByteArrayStreamReader(stream);

            try
            {
                if (Adler32.Generate(body, 4) == reader.ReadUInt())
                {
                    if (Keys == null)
                    {
                        Rsa.DecryptAndReplace(body, 9);
                    }
                    else
                    {
                        Xtea.DecryptAndReplace(body, 4, 32, Keys);

                        stream.Seek(Origin.Current, 2);
                    }

                    Command command = null;

                    switch (reader.ReadByte())
                    {
                    case 0x0A:
                    {
                        var packet = server.PacketsFactory.Create <SelectedCharacterIncomingPacket>(reader);

                        command = new LogInCommand(this, packet);
                    }
                    break;

                    case 0x14:

                        command = new LogOutCommand(Client.Player);

                        break;

                    case 0x1E:

                        command = new PongCommand(Client.Player);

                        break;

                    case 0x64:
                    {
                        var packet = server.PacketsFactory.Create <WalkToIncomingPacket>(reader);

                        command = new WalkToKnownPathCommand(Client.Player, packet.MoveDirections);
                    }
                    break;

                    case 0x65:

                        command = new WalkCommand(Client.Player, MoveDirection.North);

                        break;

                    case 0x66:

                        command = new WalkCommand(Client.Player, MoveDirection.East);

                        break;

                    case 0x67:

                        command = new WalkCommand(Client.Player, MoveDirection.South);

                        break;

                    case 0x68:

                        command = new WalkCommand(Client.Player, MoveDirection.West);

                        break;

                    case 0x69:

                        command = new StopWalkCommand(Client.Player);

                        break;

                    case 0x6A:

                        command = new WalkCommand(Client.Player, MoveDirection.NorthEast);

                        break;

                    case 0x6B:

                        command = new WalkCommand(Client.Player, MoveDirection.SouthEast);

                        break;

                    case 0x6C:

                        command = new WalkCommand(Client.Player, MoveDirection.SouthWest);

                        break;

                    case 0x6D:

                        command = new WalkCommand(Client.Player, MoveDirection.NorthWest);

                        break;

                    case 0x6F:

                        command = new TurnCommand(Client.Player, Direction.North);

                        break;

                    case 0x70:

                        command = new TurnCommand(Client.Player, Direction.East);

                        break;

                    case 0x71:

                        command = new TurnCommand(Client.Player, Direction.South);

                        break;

                    case 0x72:

                        command = new TurnCommand(Client.Player, Direction.West);

                        break;

                    case 0x78:
                    {
                        var packet = server.PacketsFactory.Create <MoveItemIncomingPacket>(reader);

                        Position fromPosition = new Position(packet.FromX, packet.FromY, packet.FromZ);

                        Position toPosition = new Position(packet.ToX, packet.ToY, packet.ToZ);

                        if (fromPosition.IsContainer)
                        {
                            if (toPosition.IsContainer)
                            {
                                command = new MoveItemFromContainerToContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.FromItemId, toPosition.ContainerId, toPosition.ContainerIndex, packet.Count);
                            }
                            else if (toPosition.IsInventory)
                            {
                                command = new MoveItemFromContainerToInventoryCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.FromItemId, toPosition.InventoryIndex, packet.Count);
                            }
                            else
                            {
                                command = new MoveItemFromContainerToTileCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.FromItemId, toPosition, packet.Count);
                            }
                        }
                        else if (fromPosition.IsInventory)
                        {
                            if (toPosition.IsContainer)
                            {
                                command = new MoveItemFromInventoryToContainerCommand(Client.Player, fromPosition.InventoryIndex, packet.FromItemId, toPosition.ContainerId, toPosition.ContainerIndex, packet.Count);
                            }
                            else if (toPosition.IsInventory)
                            {
                                command = new MoveItemFromInventoryToInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.FromItemId, toPosition.InventoryIndex, packet.Count);
                            }
                            else
                            {
                                command = new MoveItemFromInventoryToTileCommand(Client.Player, fromPosition.InventoryIndex, packet.FromItemId, toPosition, packet.Count);
                            }
                        }
                        else
                        {
                            if (toPosition.IsContainer)
                            {
                                command = new MoveItemFromTileToContainerCommand(Client.Player, fromPosition, packet.FromIndex, packet.FromItemId, toPosition.ContainerId, toPosition.ContainerIndex, packet.Count);
                            }
                            else if (toPosition.IsInventory)
                            {
                                command = new MoveItemFromTileToInventoryCommand(Client.Player, fromPosition, packet.FromIndex, packet.FromItemId, toPosition.InventoryIndex, packet.Count);
                            }
                            else
                            {
                                command = new MoveItemFromTileToTileCommand(Client.Player, fromPosition, packet.FromIndex, packet.FromItemId, toPosition, packet.Count);
                            }
                        }
                    }
                    break;

                    case 0x79:
                    {
                        var packet = server.PacketsFactory.Create <LookItemNpcTradeIncommingPacket>(reader);

                        command = new LookFromNpcTradeCommand(Client.Player, packet.ItemId, packet.Type);
                    }
                    break;

                    case 0x7A:
                    {
                        var packet = server.PacketsFactory.Create <BuyNpcTradeIncommingPacket>(reader);

                        command = new BuyNpcTradeCommand(Client.Player, packet);
                    }
                    break;

                    case 0x7B:
                    {
                        var packet = server.PacketsFactory.Create <SellNpcTradeIncommingPacket>(reader);

                        command = new SellNpcTradeCommand(Client.Player, packet);
                    }
                    break;

                    case 0x7C:

                        command = new CloseNpcTradeCommand(Client.Player);

                        break;

                    case 0x7D:
                    {
                        var packet = server.PacketsFactory.Create <TradeWithIncommingPacket>(reader);

                        Position fromPosition = new Position(packet.X, packet.Y, packet.Z);

                        if (fromPosition.IsContainer)
                        {
                            command = new TradeWithFromContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.ItemId, packet.CreatureId);
                        }
                        else if (fromPosition.IsInventory)
                        {
                            command = new TradeWithFromInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.ItemId, packet.CreatureId);
                        }
                        else
                        {
                            command = new TradeWithFromTileCommand(Client.Player, fromPosition, packet.Index, packet.ItemId, packet.CreatureId);
                        }
                    }
                    break;

                    case 0x7E:
                    {
                        var packet = server.PacketsFactory.Create <LookItemTradeIncommingPacket>(reader);

                        command = new LookFromTradeCommand(Client.Player, packet.WindowId, packet.Index);
                    }
                    break;

                    case 0x7F:

                        command = new AcceptTradeCommand(Client.Player);

                        break;

                    case 0x80:

                        command = new CancelTradeCommand(Client.Player);

                        break;

                    case 0x82:
                    {
                        var packet = server.PacketsFactory.Create <UseItemIncomingPacket>(reader);

                        Position fromPosition = new Position(packet.X, packet.Y, packet.Z);

                        if (fromPosition.IsContainer)
                        {
                            command = new UseItemFromContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.ItemId, packet.ContainerId);
                        }
                        else if (fromPosition.IsInventory)
                        {
                            command = new UseItemFromInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.ItemId);
                        }
                        else
                        {
                            command = new UseItemFromTileCommand(Client.Player, fromPosition, packet.Index, packet.ItemId);
                        }
                    }
                    break;

                    case 0x83:
                    {
                        var packet = server.PacketsFactory.Create <UseItemWithItemIncomingPacket>(reader);

                        Position fromPosition = new Position(packet.FromX, packet.FromY, packet.FromZ);

                        Position toPosition = new Position(packet.ToX, packet.ToY, packet.ToZ);

                        if (fromPosition.IsContainer)
                        {
                            if (toPosition.IsContainer)
                            {
                                command = new UseItemWithItemFromContainerToContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.FromItemId, toPosition.ContainerId, toPosition.ContainerIndex, packet.ToItemId);
                            }
                            else if (toPosition.IsInventory)
                            {
                                command = new UseItemWithItemFromContainerToInventoryCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.FromItemId, toPosition.InventoryIndex, packet.ToItemId);
                            }
                            else
                            {
                                command = new UseItemWithItemFromContainerToTileCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.FromItemId, toPosition, packet.ToIndex, packet.ToItemId);
                            }
                        }
                        else if (fromPosition.IsInventory)
                        {
                            if (toPosition.IsContainer)
                            {
                                command = new UseItemWithItemFromInventoryToContainerCommand(Client.Player, fromPosition.InventoryIndex, packet.FromItemId, toPosition.ContainerId, toPosition.ContainerIndex, packet.ToItemId);
                            }
                            else if (toPosition.IsInventory)
                            {
                                command = new UseItemWithItemFromInventoryToInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.FromItemId, toPosition.InventoryIndex, packet.ToItemId);
                            }
                            else
                            {
                                command = new UseItemWithItemFromInventoryToTileCommand(Client.Player, fromPosition.InventoryIndex, packet.FromItemId, toPosition, packet.ToIndex, packet.ToItemId);
                            }
                        }
                        else
                        {
                            if (toPosition.IsContainer)
                            {
                                command = new UseItemWithItemFromTileToContainerCommand(Client.Player, fromPosition, packet.FromIndex, packet.FromItemId, toPosition.ContainerId, toPosition.ContainerIndex, packet.ToItemId);
                            }
                            else if (toPosition.IsInventory)
                            {
                                command = new UseItemWithItemFromTileToInventoryCommand(Client.Player, fromPosition, packet.FromIndex, packet.FromItemId, toPosition.InventoryIndex, packet.ToItemId);
                            }
                            else
                            {
                                command = new UseItemWithItemFromTileToTileCommand(Client.Player, fromPosition, packet.FromIndex, packet.FromItemId, toPosition, packet.ToIndex, packet.ToItemId);
                            }
                        }
                    }
                    break;

                    case 0x84:
                    {
                        var packet = server.PacketsFactory.Create <UseItemWithCreatureIncomingPacket>(reader);

                        Position fromPosition = new Position(packet.X, packet.Y, packet.Z);

                        if (fromPosition.IsContainer)
                        {
                            command = new UseItemWithCreatureFromContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.ItemId, packet.CreatureId);
                        }
                        else if (fromPosition.IsInventory)
                        {
                            command = new UseItemWithCreatureFromInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.ItemId, packet.CreatureId);
                        }
                        else
                        {
                            command = new UseItemWithCreatureFromTileCommand(Client.Player, fromPosition, packet.Index, packet.ItemId, packet.CreatureId);
                        }
                    }
                    break;

                    case 0x85:
                    {
                        var packet = server.PacketsFactory.Create <RotateItemIncomingPacket>(reader);

                        var fromPosition = new Position(packet.X, packet.Y, packet.Z);

                        if (fromPosition.IsContainer)
                        {
                            command = new RotateItemFromContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.ItemId);
                        }
                        else if (fromPosition.IsInventory)
                        {
                            command = new RotateItemFromInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.ItemId);
                        }
                        else
                        {
                            command = new RotateItemFromTileCommand(Client.Player, fromPosition, packet.Index, packet.ItemId);
                        }
                    }
                    break;

                    case 0x87:
                    {
                        var packet = server.PacketsFactory.Create <CloseContainerIncommingPacket>(reader);

                        command = new CloseContainerCommand(Client.Player, packet.ContainerId);
                    }
                    break;

                    case 0x88:
                    {
                        var packet = server.PacketsFactory.Create <OpenParentIncommingPacket>(reader);

                        command = new OpenParentContainerCommand(Client.Player, packet.ContainerId);
                    }
                    break;

                    case 0x8C:
                    {
                        var packet = server.PacketsFactory.Create <LookIncomingPacket>(reader);

                        var fromPosition = new Position(packet.X, packet.Y, packet.Z);

                        if (fromPosition.IsContainer)
                        {
                            command = new LookFromContainerCommand(Client.Player, fromPosition.ContainerId, fromPosition.ContainerIndex, packet.ItemId);
                        }
                        else if (fromPosition.IsInventory)
                        {
                            command = new LookFromInventoryCommand(Client.Player, fromPosition.InventoryIndex, packet.ItemId);
                        }
                        else
                        {
                            command = new LookFromTileCommand(Client.Player, fromPosition, packet.Index, packet.ItemId);
                        }
                    }
                    break;

                    case 0x96:
                    {
                        var packet = server.PacketsFactory.Create <TalkIncommingPacket>(reader);

                        switch (packet.TalkType)
                        {
                        case TalkType.Say:

                            command = new SayCommand(Client.Player, packet.Message);

                            break;

                        case TalkType.Whisper:

                            command = new WhisperCommand(Client.Player, packet.Message);

                            break;

                        case TalkType.Yell:

                            command = new YellCommand(Client.Player, packet.Message);

                            break;

                        case TalkType.Private:

                            command = new SendMessageToPlayerCommand(Client.Player, packet.Name, packet.Message);

                            break;

                        case TalkType.ChannelYellow:

                            command = new SendMessageToChannel(Client.Player, packet.ChannelId, packet.Message);

                            break;

                        case TalkType.ReportRuleViolationOpen:

                            command = new CreateReportRuleViolationCommand(Client.Player, packet.Message);

                            break;

                        case TalkType.ReportRuleViolationAnswer:

                            command = new AnswerInReportRuleViolationChannelCommand(Client.Player, packet.Name, packet.Message);

                            break;

                        case TalkType.ReportRuleViolationQuestion:

                            command = new AskInReportRuleViolationChannelCommand(Client.Player, packet.Message);

                            break;

                        case TalkType.Broadcast:

                            command = new BroadcastMessageCommand(Client.Player, packet.Message);

                            break;
                        }
                    }
                    break;

                    case 0x97:

                        command = new OpenNewChannelCommand(Client.Player);

                        break;

                    case 0x98:
                    {
                        var packet = server.PacketsFactory.Create <OpenedNewChannelIncomingPacket>(reader);

                        command = new OpenedNewChannelCommand(Client.Player, packet.ChannelId);
                    }
                    break;

                    case 0x99:
                    {
                        var packet = server.PacketsFactory.Create <CloseChannelIncommingPacket>(reader);

                        command = new CloseChannelCommand(Client.Player, packet.ChannelId);
                    }
                    break;

                    case 0x9A:
                    {
                        var packet = server.PacketsFactory.Create <OpenedPrivateChannelIncomingPacket>(reader);

                        command = new OpenedPrivateChannelCommand(Client.Player, packet.Name);
                    }
                    break;

                    case 0x9B:
                    {
                        var packet = server.PacketsFactory.Create <ProcessReportRuleViolationIncommingPacket>(reader);

                        command = new ProcessReportRuleViolationCommand(Client.Player, packet.Name);
                    }
                    break;

                    case 0x9C:
                    {
                        var packet = server.PacketsFactory.Create <CloseReportRuleViolationChannelAnswerIncommingPacket>(reader);

                        command = new CloseReportRuleViolationChannelAnswerCommand(Client.Player, packet.Name);
                    }
                    break;

                    case 0x9D:

                        command = new CloseReportRuleViolationChannelQuestionCommand(Client.Player);

                        break;

                    case 0x9E:

                        command = new CloseNpcsChannelCommand(Client.Player);

                        break;

                    case 0xA0:
                    {
                        var packet = server.PacketsFactory.Create <CombatControlsIncommingPacket>(reader);

                        command = new CombatControlsCommand(Client.Player, packet.FightMode, packet.ChaseMode, packet.SafeMode);
                    }
                    break;

                    case 0xA1:
                    {
                        var packet = server.PacketsFactory.Create <AttackIncommingPacket>(reader);

                        if (packet.CreatureId == 0)
                        {
                            command = new StopAttackCommand(Client.Player);
                        }
                        else
                        {
                            command = new StartAttackCommand(Client.Player, packet.CreatureId, packet.Nonce);
                        }
                    }
                    break;

                    case 0xA2:
                    {
                        var packet = server.PacketsFactory.Create <FollowIncommingPacket>(reader);

                        if (packet.CreatureId == 0)
                        {
                            command = new StopFollowCommand(Client.Player);
                        }
                        else
                        {
                            command = new StartFollowCommand(Client.Player, packet.CreatureId, packet.Nonce);
                        }
                    }
                    break;

                    case 0xA3:
                    {
                        var packet = server.PacketsFactory.Create <InviteToPartyIncomingPacket>(reader);

                        command = new InviteToPartyCommand(Client.Player, packet.CreatureId);
                    }
                    break;

                    case 0xA4:
                    {
                        var packet = server.PacketsFactory.Create <JoinPartyIncomingPacket>(reader);

                        command = new JoinPartyCommand(Client.Player, packet.CreatureId);
                    }
                    break;

                    case 0xA5:
                    {
                        var packet = server.PacketsFactory.Create <RevokePartyIncomingPacket>(reader);

                        command = new RevokePartyCommand(Client.Player, packet.CreatureId);
                    }
                    break;

                    case 0xA6:
                    {
                        var packet = server.PacketsFactory.Create <PassLeadershipToIncomingPacket>(reader);

                        command = new PassLeaderShipToCommand(Client.Player, packet.CreatureId);
                    }
                    break;

                    case 0xA7:

                        command = new LeavePartyCommand(Client.Player);

                        break;

                    case 0xA8:
                    {
                        var packet = server.PacketsFactory.Create <SharedExperienceIncomingPacket>(reader);

                        command = new SharedExperienceCommand(Client.Player, packet.Enabled);
                    }
                    break;

                    case 0xAA:

                        command = new OpenedMyPrivateChannelCommand(Client.Player);

                        break;

                    case 0xAB:
                    {
                        var packet = server.PacketsFactory.Create <InvitePlayerIncommingPacket>(reader);

                        command = new InvitePlayerCommand(Client.Player, packet.Name);
                    }
                    break;

                    case 0xAC:
                    {
                        var packet = server.PacketsFactory.Create <ExcludePlayerIncommingPacket>(reader);

                        command = new ExcludePlayerCommand(Client.Player, packet.Name);
                    }
                    break;

                    case 0xBE:

                        command = new StopCommand(Client.Player);

                        break;

                    case 0xD2:

                        command = new SelectOutfitCommand(Client.Player);

                        break;

                    case 0xD3:
                    {
                        var packet = server.PacketsFactory.Create <SelectedOutfitIncomingPacket>(reader);

                        command = new SelectedOutfitCommand(Client.Player, packet.Outfit);
                    }
                    break;

                    case 0xDC:
                    {
                        var packet = server.PacketsFactory.Create <AddVipIncommingPacket>(reader);

                        command = new AddVipCommand(Client.Player, packet.Name);
                    }
                    break;

                    case 0xDD:
                    {
                        var packet = server.PacketsFactory.Create <RemoveVipIncommingPacket>(reader);

                        command = new RemoveVipCommand(Client.Player, packet.CreatureId);
                    }
                    break;

                    case 0xE6:
                    {
                        var packet = server.PacketsFactory.Create <ReportBugIncomingPacket>(reader);

                        command = new ReportBugCommand(Client.Player, packet.Message);
                    }
                    break;

                    case 0xF0:

                        command = new OpenQuestsCommand(Client.Player);

                        break;

                    case 0xF1:
                    {
                        var packet = server.PacketsFactory.Create <OpenQuestIncomingPacket>(reader);

                        command = new OpenQuestCommand(Client.Player, packet.QuestId);
                    }
                    break;
                    }

                    if (command != null)
                    {
                        server.QueueForExecution(command);
                    }
                }
            }
            catch (Exception ex)
            {
                server.Logger.WriteLine(ex.ToString());
            }

            base.OnReceived(body);
        }
コード例 #16
0
ファイル: Item.cs プロジェクト: otbr/OpenTibia
        public static Item Load(ByteArrayFileTreeStream stream, ByteArrayStreamReader reader)
        {
            Item item = new Item();

            item.Group = (ItemGroup)reader.ReadByte();

            item.Flags = (ItemFlags)reader.ReadUInt();

            while (true)
            {
                OtbAttribute attribute = (OtbAttribute)reader.ReadByte();

                stream.Seek(Origin.Current, 2);

                switch (attribute)
                {
                case OtbAttribute.OpenTibiaId:

                    item.OpenTibiaId = reader.ReadUShort();

                    break;

                case OtbAttribute.TibiaId:

                    item.TibiaId = reader.ReadUShort();

                    break;

                case OtbAttribute.Speed:

                    item.Speed = reader.ReadUShort();

                    break;

                case OtbAttribute.SpriteHash:

                    item.SpriteHash = reader.ReadBytes(16);

                    break;

                case OtbAttribute.MinimapColor:

                    item.MinimapColor = reader.ReadUShort();

                    break;

                case OtbAttribute.MaxReadWriteChars:

                    item.MaxReadWriteChars = reader.ReadUShort();

                    break;

                case OtbAttribute.MaxReadChars:

                    item.MaxReadChars = reader.ReadUShort();

                    break;

                case OtbAttribute.Light:

                    item.LightLevel = reader.ReadUShort();

                    item.LightColor = reader.ReadUShort();

                    break;

                case OtbAttribute.TopOrder:

                    item.TopOrder = (TopOrder)reader.ReadByte();

                    break;

                default:

                    stream.Seek(Origin.Current, -3);

                    return(item);
                }
            }
        }