Exemplo n.º 1
0
        public ServerInfoResult GetServerInfoSync(GetServerInfoSettings settings)
        {
            var localEndPoint = new IPEndPoint(IPAddress.Any, 0);

            using (var client = new UdpClient(localEndPoint))
            {
                client.Client.ReceiveTimeout = settings.ReceiveTimeout;
                client.Client.SendTimeout    = settings.SendTimeout;

                client.Connect(EndPoint);
                var requestPacket = new List <byte>();
                requestPacket.AddRange(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF });
                requestPacket.Add(0x54);
                requestPacket.AddRange(Encoding.ASCII.GetBytes("Source Engine Query"));
                requestPacket.Add(0x00);
                var requestData = requestPacket.ToArray();
                client.Send(requestData, requestData.Length);
                var data = client.Receive(ref localEndPoint);
                return(ServerInfoResult.Parse(data));
            }
        }
Exemplo n.º 2
0
        public static ServerInfoResult Parse(byte[] data)
        {
            var parser = new ResponseParser(data);
            parser.CurrentPosition += 5; //Header
            var result = new ServerInfoResult();
            result.Protocol = parser.GetByte();
            result.Name = parser.GetStringToTermination();
            result.Map = parser.GetStringToTermination();
            result.Folder = parser.GetStringToTermination();
            result.Game = parser.GetStringToTermination();
            result.ID = parser.GetShort();
            result.Players = parser.GetByte();
            result.MaxPlayers = parser.GetByte();
            result.Bots = parser.GetByte();
            result.ServerType = parser.GetStringOfByte();
            result.Environment = parser.GetStringOfByte();
            result.Visibility = parser.GetByte();
            result.VAC = parser.GetByte();
            result.Version = parser.GetStringToTermination();

            //get EDF
            uint edf = parser.GetByte();

            if ((edf & 0x80) != 0) //has port number
            {
                result.Port = parser.GetShort();
            }

            return result;
        }