Ejemplo n.º 1
0
        public ServerRulesResult GetServerRulesSync(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, 0x56 });
                requestPacket.AddRange(BitConverter.GetBytes(-1));
                client.Send(requestPacket.ToArray(), requestPacket.ToArray().Length);
                byte[] responseData = client.Receive(ref localEndpoint);
                requestPacket.Clear();
                requestPacket.AddRange(new Byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0x56 });
                requestPacket.AddRange(responseData.Skip(5).Take(4));
                client.Send(requestPacket.ToArray(), requestPacket.ToArray().Length);
                responseData = client.Receive(ref localEndpoint);
                return(ServerRulesResult.Parse(responseData));
            }
        }
Ejemplo n.º 2
0
        public async Task <ServerRulesResult> GetServerRules()
        {
            using (var client = new UdpClient(new IPEndPoint(IPAddress.Any, 0)))
            {
                client.Connect(EndPoint);
                var requestPacket = new List <byte>();
                requestPacket.AddRange(new Byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0x56 });
                requestPacket.AddRange(BitConverter.GetBytes(-1));
                await client.SendAsync(requestPacket.ToArray(), requestPacket.ToArray().Length);

                UdpReceiveResult response = await client.ReceiveAsync();

                List <byte> responseData = response.Buffer.ToList();
                requestPacket.Clear();
                requestPacket.AddRange(new Byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0x56 });
                requestPacket.AddRange(responseData.GetRange(5, 4));
                await client.SendAsync(requestPacket.ToArray(), requestPacket.ToArray().Length);

                response = await client.ReceiveAsync();

                return(ServerRulesResult.Parse(response.Buffer));
            }
        }