示例#1
0
        public IEnumerable <IGameServer> GetServersLazy(MasterServerRequest masterServerRequest)
        {
            var        packet       = 0;
            IPEndPoint lastEndPoint = null;

            using (var client = SteamAgent.GetUdpClient(_endpoint))
            {
                while (!masterServerRequest.MaximumPackets.HasValue || packet < masterServerRequest.MaximumPackets.Value)
                {
                    var request  = GetRequest(lastEndPoint, masterServerRequest.Region, masterServerRequest.Filters);
                    var response = AsyncHelper.RunSync(() => SteamAgent.RequestResponseAsync(client, request, IpEndPointLength));

                    packet++;

                    var packetEndPoints = ReadEndPointsFromPacket(response);
                    foreach (var endPoint in packetEndPoints)
                    {
                        if (endPoint.IsEmpty())
                        {
                            yield break;
                        }
                        yield return(new GameServer(endPoint));

                        lastEndPoint = endPoint;
                    }
                }
            }
        }
示例#2
0
        public async Task <IEnumerable <IGameServer> > GetServersAsync(MasterServerRequest masterServerRequest)
        {
            var endPoints = new List <IPEndPoint>();

            var packet = 0;

            using (var client = SteamAgent.GetUdpClient(_endpoint))
            {
                while (!masterServerRequest.MaximumPackets.HasValue || packet < masterServerRequest.MaximumPackets.Value)
                {
                    var request  = GetRequest(endPoints.LastOrDefault(), masterServerRequest.Region, masterServerRequest.Filters);
                    var response = await SteamAgent.RequestResponseAsync(client, request, IpEndPointLength);

                    packet++;

                    var packetEndPoints = ReadEndPointsFromPacket(response);
                    endPoints.AddRange(packetEndPoints);

                    if (endPoints.Last().IsEmpty())
                    {
                        break;
                    }
                }
            }

            return(endPoints.Take(endPoints.Count - 1).Select(e => new GameServer(e)));
        }
示例#3
0
        public async Task<IEnumerable<IGameServer>> GetServersAsync(MasterServerRequest masterServerRequest)
        {
            var endPoints = new List<IPEndPoint>();

            var packet = 0;
            using (var client = SteamAgent.GetUdpClient(_endpoint))
            {
                while (!masterServerRequest.MaximumPackets.HasValue || packet < masterServerRequest.MaximumPackets.Value)
                {
                    var request = GetRequest(endPoints.LastOrDefault(), masterServerRequest.Region, masterServerRequest.Filters);
                    var response = await SteamAgent.RequestResponseAsync(client, request, IpEndPointLength);

                    packet++;

                    var packetEndPoints = ReadEndPointsFromPacket(response);
                    endPoints.AddRange(packetEndPoints);

                    if (endPoints.Last().IsEmpty())
                    {
                        break;
                    }
                }
            }

            return endPoints.Take(endPoints.Count - 1).Select(e => new GameServer(e));
        }
示例#4
0
        public async Task BasicQuery()
        {
            var client = new MasterServer();

            var request = new MasterServerRequest(
                MasterServerRegion.Europe,
                Filter.GamedirIs("tf")
                )
            {
                MaximumPackets = 2,
                RequestTimeout = TimeSpan.FromSeconds(10)
            };

            var t = await client.GetServersAsync(request);
            var servers = t.ToList();

            Assert.IsTrue(servers.Any(), "No servers were returned");
        }
示例#5
0
        public async Task LogicalQuery()
        {
            var client = new MasterServer();

            var request = new MasterServerRequest(
                MasterServerRegion.Europe,
                Filter.GamedirIs("tf"),
                Filter.IsNotEmpty,
                Filter.IsNotFull,
                Filter.Nor(
                    Filter.NameMatches("*Valve*"),
                    Filter.NameMatches("*trade*")
                    )
                )
            {
                MaximumPackets = 1
            };

            var servers = (await client.GetServersAsync(request)).Take(100).ToList();
            Assert.IsTrue(servers.Any(), "No servers were returned");

            var infos = await Task.WhenAll(servers.Select(async x => new {Server = x, Info = await x.TryGetServerInfoAsync()}));



            foreach (var i in infos.Where(x => x.Info != null))
            {
                Assert.AreEqual("tf", i.Info.Gamedir, $"Unexpected gamedir {i.Server.EndPoint}; {i.Info.Gamedir}");

                Assert.That(i.Info.Players, Is.AtLeast(1), $"Unexpected empty server {i.Server.EndPoint}");
                Assert.That(i.Info.Players, Is.LessThan(i.Info.MaxPlayers), $"Unexpected full server {i.Server.EndPoint}");

                Assert.That(!i.Info.Name.Contains("Valve") && !i.Info.Name.Contains("trade"), $"Expected server name to contain neither 'Valve' or 'trade' - was [{i.Info.Name}].");

            }
        }