コード例 #1
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();
        }
コード例 #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);
        }
コード例 #3
0
        public void Read_ASCII(string str, string result)
        {
            Span <byte> data = Encoding.ASCII.GetBytes(str);

            StackDataReader reader = new StackDataReader(data);

            string s = reader.ReadASCII();

            Assert.Equal(s, result);

            reader.Release();
        }
コード例 #4
0
        public void Read_More_Data_Than_Remains_ASCII(string str, int length)
        {
            Span <byte> data = Encoding.ASCII.GetBytes(str);

            StackDataReader reader = new StackDataReader(data);

            string s = reader.ReadASCII(length);

            Assert.Equal(str, s);

            reader.Release();
        }
コード例 #5
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();
        }
コード例 #6
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);
            }
        }
コード例 #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;
            }
        }