/// <summary>
        /// Parse all value to this class
        /// </summary>
        /// <param name="recv"></param>
        public bool Parse(byte[] recv)
        {
            ushort length = ByteTools.ToUInt16(ByteTools.SubBytes(recv, 0, 2), true);

            if (length != recv.Length)
            {
                return(false);
            }

            RequestVersion  = recv[2];
            ProtocolVersion = recv[3];
            EncodingVersion = recv[4];
            GameVersion     = BitConverter.ToInt32(ByteTools.SubBytes(recv, 5, 4));

            //because there are empty string we can not use StringSplitOptions.RemoveEmptyEntries
            string remainData = Encoding.ASCII.GetString(recv.Skip(9).ToArray());

            remainData.IndexOf('\0');
            DevGameName = remainData.Substring(0, remainData.IndexOf('\0'));
            remainData  = remainData.Substring(remainData.IndexOf('\0') + 1);
            GameName    = remainData.Substring(0, remainData.IndexOf('\0'));
            remainData  = remainData.Substring(remainData.IndexOf('\0') + 1);
            Challenge   = remainData.Substring(0, remainData.IndexOf('\0')).Substring(0, 8);

            if (remainData.Substring(0, remainData.IndexOf('\0')).Length > 8)
            {
                Filter = remainData.Substring(8, remainData.IndexOf('\0') - 8);
            }

            remainData = remainData.Substring(remainData.IndexOf('\0') + 1);
            Keys       = remainData.Substring(0, remainData.IndexOf('\0')).Split("\\", StringSplitOptions.RemoveEmptyEntries);
            remainData = remainData.Substring(remainData.IndexOf('\0') + 1);

            byte[] byteUpdateOptions = Encoding.ASCII.GetBytes(remainData.Substring(0, 4));
            //gamespy send this in big endian, we need to convert to little endian
            Array.Reverse(byteUpdateOptions);

            UpdateOption = (SBServerListUpdateOption)BitConverter.ToInt32(byteUpdateOptions);

            if ((UpdateOption & SBServerListUpdateOption.AlternateSourceIP) != 0)
            {
                SourceIP   = Encoding.ASCII.GetBytes(remainData.Substring(0, 4));
                remainData = remainData.Substring(7);
            }

            if ((UpdateOption & SBServerListUpdateOption.LimitResultCount) != 0)
            {
                MaxServers = ByteTools.ToInt32(remainData.Substring(0, 4), true);
            }

            return(true);
        }
示例#2
0
        public bool Parse(byte[] recv)
        {
            ushort length = ByteTools.ToUInt16(ByteTools.SubBytes(recv, 0, 2), true);

            if (length != recv.Length)
            {
                return(false);
            }

            byte[] ip   = ByteTools.SubBytes(recv, 3, 4);
            byte[] port = ByteTools.SubBytes(recv, 7, 2);

            IPEndPoint iPEnd = ByteTools.GetIPEndPoint(ip, port);

            TargetServerIP       = iPEnd.Address.ToString();
            TargetServerHostPort = iPEnd.Port.ToString();

            return(true);
        }
示例#3
0
        public bool Parse(byte[] recv)
        {
            ushort length = ByteTools.ToUInt16(ByteTools.SubBytes(recv, 0, 2), true);

            //if(recv.Length<length)
            //{
            //    return false;
            //}

            byte[] ip   = ByteTools.SubBytes(recv, 3, 4);
            byte[] port = ByteTools.SubBytes(recv, 7, 2);
            Array.Reverse(port);

            IPEndPoint iPEnd = ByteTools.GetIPEndPoint(ip, port);

            TargetServerIP       = iPEnd.Address.ToString();
            TargetServerHostPort = iPEnd.Port.ToString();

            return(true);
        }