Exemplo n.º 1
0
        public static PopupMenuData Parse(ref StackDataReader p)
        {
            ushort mode        = p.ReadUInt16BE();
            bool   isNewCliloc = mode >= 2;
            uint   serial      = p.ReadUInt32BE();
            byte   count       = p.ReadUInt8();

            PopupMenuItem[] items = new PopupMenuItem[count];

            for (int i = 0; i < count; i++)
            {
                ushort hue = 0xFFFF, replaced = 0;
                int    cliloc;
                ushort index, flags;

                if (isNewCliloc)
                {
                    cliloc = (int)p.ReadUInt32BE();
                    index  = p.ReadUInt16BE();
                    flags  = p.ReadUInt16BE();
                }
                else
                {
                    index  = p.ReadUInt16BE();
                    cliloc = p.ReadUInt16BE() + 3000000;
                    flags  = p.ReadUInt16BE();

                    if ((flags & 0x84) != 0)
                    {
                        p.Skip(2);
                    }

                    if ((flags & 0x40) != 0)
                    {
                        p.Skip(2);
                    }

                    if ((flags & 0x20) != 0)
                    {
                        replaced = (ushort)(p.ReadUInt16BE());
                    }
                }

                if ((flags & 0x01) != 0)
                {
                    hue = 0x0386;
                }

                items[i] = new PopupMenuItem
                           (
                    cliloc,
                    index,
                    hue,
                    replaced,
                    flags
                           );
            }

            return(new PopupMenuData(serial, items));
        }
Exemplo n.º 2
0
        public static ServerListEntry Create(ref StackDataReader p)
        {
            ServerListEntry entry = new ServerListEntry()
            {
                Index       = p.ReadUInt16BE(),
                Name        = p.ReadASCII(32, true),
                PercentFull = p.ReadUInt8(),
                Timezone    = p.ReadUInt8(),
                Address     = p.ReadUInt32BE()
            };

            // some server sends invalid ip.
            try
            {
                entry._ipAddress = new IPAddress
                                   (
                    new byte[]
                {
                    (byte)((entry.Address >> 24) & 0xFF),
                    (byte)((entry.Address >> 16) & 0xFF),
                    (byte)((entry.Address >> 8) & 0xFF),
                    (byte)(entry.Address & 0xFF)
                }
                                   );
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }

            entry._pinger.PingCompleted += entry.PingerOnPingCompleted;

            return(entry);
        }
Exemplo n.º 3
0
        public void HandleRelayServerPacket(ref StackDataReader p)
        {
            long   ip   = p.ReadUInt32LE(); // use LittleEndian here
            ushort port = p.ReadUInt16BE();
            uint   seed = p.ReadUInt32BE();

            NetClient.LoginSocket.Disconnect();
            EncryptionHelper.Initialize(false, seed, (ENCRYPTION_TYPE)Settings.GlobalSettings.Encryption);

            NetClient.Socket.Connect(new IPAddress(ip), port)
            .ContinueWith
            (
                t =>
            {
                if (!t.IsFaulted)
                {
                    NetClient.Socket.EnableCompression();

                    unsafe
                    {
                        Span <byte> b = stackalloc byte[4] {
                            (byte)(seed >> 24), (byte)(seed >> 16), (byte)(seed >> 8), (byte)seed
                        };
                        StackDataWriter writer = new StackDataWriter(b);
                        NetClient.Socket.Send(writer.AllocatedBuffer, writer.BytesWritten, true, true);
                        writer.Dispose();
                    }

                    NetClient.Socket.Send_SecondLogin(Account, Password, seed);
                }
            },
                TaskContinuationOptions.ExecuteSynchronously
            );
        }
Exemplo n.º 4
0
        private static void HandleStatusUpdate(ref StackDataReader p)
        {
            if (World.Player == null)
            {
                return;
            }

            var serial = p.ReadUInt32BE(); // In-case we decide to send this packet to describe other mobiles

            World.Player.Hunger             = (short)p.ReadUInt16BE();
            World.Player.HealBonus          = (short)p.ReadUInt16BE();
            World.Player.MagicImmunity      = (short)p.ReadUInt16BE();
            World.Player.MagicReflect       = (short)p.ReadUInt16BE();
            World.Player.PhysicalProtection = (short)p.ReadUInt16BE();
            World.Player.PoisonProtection   = (short)p.ReadUInt16BE();
            World.Player.FireProtection     = (short)p.ReadUInt16BE();
            World.Player.WaterProtection    = (short)p.ReadUInt16BE();
            World.Player.AirProtection      = (short)p.ReadUInt16BE();
            World.Player.EarthProtection    = (short)p.ReadUInt16BE();
            World.Player.NecroProtection    = (short)p.ReadUInt16BE();
            World.Player.ShortTermMurders   = (short)p.ReadUInt16BE();
            World.Player.LongTermMurders    = (short)p.ReadUInt16BE();
            World.Player.DamageMin          = (short)p.ReadUInt16BE();
            World.Player.DamageMax          = (short)p.ReadUInt16BE();
        }
Exemplo n.º 5
0
        public void ReceiveCharacterList(ref StackDataReader p)
        {
            ParseCharacterList(ref p);
            ParseCities(ref p);

            World.ClientFeatures.SetFlags((CharacterListFlags)p.ReadUInt32BE());
            CurrentLoginStep = LoginSteps.CharacterSelection;

            uint charToSelect = 0;

            bool haveAnyCharacter = false;
            bool canLogin         = CanAutologin;

            if (_autoLogin)
            {
                _autoLogin = false;
            }

            string lastCharName = LastCharacterManager.GetLastCharacter(Account, World.ServerName);

            for (byte i = 0; i < Characters.Length; i++)
            {
                if (Characters[i].Length > 0)
                {
                    haveAnyCharacter = true;

                    if (Characters[i] == lastCharName)
                    {
                        charToSelect = i;

                        break;
                    }
                }
            }

            if (canLogin && haveAnyCharacter)
            {
                SelectCharacter(charToSelect);
            }
            else if (!haveAnyCharacter)
            {
                StartCharCreation();
            }
        }
Exemplo n.º 6
0
        public void ParsePacket(ref StackDataReader p)
        {
            byte code = p.ReadUInt8();

            bool add = false;

            switch (code)
            {
            case 1:
                add = true;
                goto case 2;

            case 2:
                byte count = p.ReadUInt8();

                if (count <= 1)
                {
                    Leader  = 0;
                    Inviter = 0;

                    for (int i = 0; i < PARTY_SIZE; i++)
                    {
                        if (Members[i] == null || Members[i].Serial == 0)
                        {
                            break;
                        }

                        BaseHealthBarGump gump = UIManager.GetGump <BaseHealthBarGump>(Members[i].Serial);


                        if (gump != null)
                        {
                            if (code == 2)
                            {
                                Members[i].Serial = 0;
                            }

                            gump.RequestUpdateContents();
                        }
                    }

                    Clear();

                    UIManager.GetGump <PartyGump>()?.RequestUpdateContents();

                    break;
                }

                Clear();

                uint to_remove = 0xFFFF_FFFF;

                if (!add)
                {
                    to_remove = p.ReadUInt32BE();

                    UIManager.GetGump <BaseHealthBarGump>(to_remove)?.RequestUpdateContents();
                }

                bool remove_all = !add && to_remove == World.Player;
                int  done       = 0;

                for (int i = 0; i < count; i++)
                {
                    uint serial = p.ReadUInt32BE();
                    bool remove = !add && serial == to_remove;

                    if (remove && serial == to_remove && i == 0)
                    {
                        remove_all = true;
                    }

                    if (!remove && !remove_all)
                    {
                        if (!Contains(serial))
                        {
                            Members[i] = new PartyMember(serial);
                        }

                        done++;
                    }

                    if (i == 0 && !remove && !remove_all)
                    {
                        Leader = serial;
                    }

                    BaseHealthBarGump gump = UIManager.GetGump <BaseHealthBarGump>(serial);

                    if (gump != null)
                    {
                        gump.RequestUpdateContents();
                    }
                    else
                    {
                        if (serial == World.Player)
                        {
                        }
                    }
                }

                if (done <= 1 && !add)
                {
                    for (int i = 0; i < PARTY_SIZE; i++)
                    {
                        if (Members[i] != null && SerialHelper.IsValid(Members[i].Serial))
                        {
                            uint serial = Members[i].Serial;

                            Members[i] = null;

                            UIManager.GetGump <BaseHealthBarGump>(serial)?.RequestUpdateContents();
                        }
                    }

                    Clear();
                }


                UIManager.GetGump <PartyGump>()?.RequestUpdateContents();

                break;

            case 3:
            case 4:
                uint   ser  = p.ReadUInt32BE();
                string name = p.ReadUnicodeBE();

                for (int i = 0; i < PARTY_SIZE; i++)
                {
                    if (Members[i] != null && Members[i].Serial == ser)
                    {
                        MessageManager.HandleMessage
                        (
                            null,
                            name,
                            Members[i].Name,
                            ProfileManager.CurrentProfile.PartyMessageHue,
                            MessageType.Party,
                            3,
                            TextType.GUILD_ALLY
                        );

                        break;
                    }
                }

                break;

            case 7:
                Inviter = p.ReadUInt32BE();

                if (ProfileManager.CurrentProfile.PartyInviteGump)
                {
                    UIManager.Add(new PartyInviteGump(Inviter));
                }

                break;
            }
        }
Exemplo n.º 7
0
        private void ParseCities(ref StackDataReader p)
        {
            byte count = p.ReadUInt8();

            Cities = new CityInfo[count];

            bool isNew = Client.Version >= ClientVersion.CV_70130;

            string[] descriptions = null;

            if (!isNew)
            {
                descriptions = ReadCityTextFile(count);
            }

            Point[] oldtowns =
            {
                new Point(105, 130), new Point(245,     90),
                new Point(165, 200), new Point(395,    160),
                new Point(200, 305), new Point(335,    250),
                new Point(160, 395), new Point(100,    250),
                new Point(270, 130), new Point(0xFFFF, 0xFFFF)
            };

            for (int i = 0; i < count; i++)
            {
                CityInfo cityInfo;

                if (isNew)
                {
                    byte   cityIndex       = p.ReadUInt8();
                    string cityName        = p.ReadASCII(32);
                    string cityBuilding    = p.ReadASCII(32);
                    ushort cityX           = (ushort)p.ReadUInt32BE();
                    ushort cityY           = (ushort)p.ReadUInt32BE();
                    sbyte  cityZ           = (sbyte)p.ReadUInt32BE();
                    uint   cityMapIndex    = p.ReadUInt32BE();
                    uint   cityDescription = p.ReadUInt32BE();
                    p.Skip(4);

                    cityInfo = new CityInfo
                               (
                        cityIndex,
                        cityName,
                        cityBuilding,
                        ClilocLoader.Instance.GetString((int)cityDescription),
                        cityX,
                        cityY,
                        cityZ,
                        cityMapIndex,
                        isNew
                               );
                }
                else
                {
                    byte   cityIndex    = p.ReadUInt8();
                    string cityName     = p.ReadASCII(31);
                    string cityBuilding = p.ReadASCII(31);

                    cityInfo = new CityInfo
                               (
                        cityIndex,
                        cityName,
                        cityBuilding,
                        descriptions != null ? descriptions[i] : string.Empty,
                        (ushort)oldtowns[i % oldtowns.Length].X,
                        (ushort)oldtowns[i % oldtowns.Length].Y,
                        0,
                        0,
                        isNew
                               );
                }

                Cities[i] = cityInfo;
            }
        }