示例#1
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);
        }
示例#2
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));
        }
示例#3
0
        public void HandleErrorCode(ref StackDataReader p)
        {
            byte code = p.ReadUInt8();

            PopupMessage     = ServerErrorMessages.GetError(p[0], code);
            CurrentLoginStep = LoginSteps.PopUpMessage;
        }
示例#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();
        }
示例#5
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
            );
        }
示例#6
0
        public void UpdateCharacterList(ref StackDataReader p)
        {
            ParseCharacterList(ref p);

            if (CurrentLoginStep != LoginSteps.PopUpMessage)
            {
                PopupMessage = null;
            }
            CurrentLoginStep = LoginSteps.CharacterSelection;
            UIManager.GetGump <CharacterSelectionGump>()?.Dispose();

            _currentGump?.Dispose();

            UIManager.Add(_currentGump = new CharacterSelectionGump());
            if (!string.IsNullOrWhiteSpace(PopupMessage))
            {
                Gump g = null;
                g = new LoadingGump(PopupMessage, LoginButtons.OK, (but) => g.Dispose())
                {
                    IsModal = true
                };
                UIManager.Add(g);
                PopupMessage = null;
            }
        }
示例#7
0
        public void ServerListReceived(ref StackDataReader p)
        {
            byte   flags = p.ReadUInt8();
            ushort count = p.ReadUInt16BE();

            DisposeAllServerEntries();
            Servers = new ServerListEntry[count];

            for (ushort i = 0; i < count; i++)
            {
                Servers[i] = ServerListEntry.Create(ref p);
            }

            CurrentLoginStep = LoginSteps.ServerSelection;

            if (CanAutologin)
            {
                if (Servers.Length != 0)
                {
                    int index = GetServerIndexFromSettings();

                    SelectServer((byte)Servers[index].Index);
                }
            }
        }
示例#8
0
        private static void ReceiveZuluPacket(ref StackDataReader p)
        {
            byte type = p.ReadUInt8();

            switch (type)
            {
            case 0x1: HandleStatusUpdate(ref p);
                break;
            }
        }
示例#9
0
        public void Read_UTF8_Safe(string str, string result)
        {
            Span <byte> data = Encoding.UTF8.GetBytes(str);

            StackDataReader reader = new StackDataReader(data);

            string s = reader.ReadUTF8(true);

            Assert.Equal(s, result);

            reader.Release();
        }
示例#10
0
        private void ParseCharacterList(ref StackDataReader p)
        {
            int count = p.ReadUInt8();

            Characters = new string[count];

            for (ushort i = 0; i < count; i++)
            {
                Characters[i] = p.ReadASCII(30).TrimEnd('\0');

                p.Skip(30);
            }
        }
示例#11
0
        public void Read_ASCII_With_FixedLength(string str, string result)
        {
            Span <byte> data = Encoding.ASCII.GetBytes(str);

            StackDataReader reader = new StackDataReader(data);

            string s = reader.ReadASCII(str.Length);

            Assert.Equal(s, result);
            Assert.Equal(0, reader.Remaining);

            reader.Release();
        }
示例#12
0
        public void Read_UTF8_With_FixedLength_Safe(string str, string result)
        {
            Span <byte> data = Encoding.UTF8.GetBytes(str);

            StackDataReader reader = new StackDataReader(data);

            string s = reader.ReadUTF8(str.Length, true);

            Assert.Equal(s, result);
            Assert.Equal(0, reader.Remaining);

            reader.Release();
        }
示例#13
0
        public void Check_Data_Remaining_Unicode_BigEndian(string str, int remains)
        {
            Span <byte> data = Encoding.BigEndianUnicode.GetBytes(str);

            StackDataReader reader = new StackDataReader(data);

            reader.ReadUnicodeBE();
            Assert.Equal(remains, reader.Remaining);

            reader.ReadUnicodeBE();
            Assert.Equal(0, reader.Remaining);

            reader.Release();
        }
示例#14
0
        public void Check_Data_Remaining_FixedLength(string str, int remains)
        {
            Span <byte> data = Encoding.ASCII.GetBytes(str);

            StackDataReader reader = new StackDataReader(data);

            reader.ReadASCII(str.Length);
            Assert.Equal(reader.Remaining, remains);

            reader.ReadASCII(remains);
            Assert.Equal(0, reader.Remaining);

            reader.Release();
        }
示例#15
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();
            }
        }
示例#16
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;
            }
        }
        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;
            }
        }