Ejemplo n.º 1
0
        public override Task QueryServer(ServerQueryState state)
        {
            switch (Settings.ServerQueryMode)
            {
            case ServerQueryMode.All: {
                if (state.Server.QueryMode == ServerQueryMode.Steam)
                {
                    return(sourceServersQuery.QueryServer(state));
                }
                if (state.Server.QueryMode == ServerQueryMode.Gamespy)
                {
                    return(gamespyServersQuery.QueryServer(state));
                }
                return(Task.WhenAll(sourceServersQuery.QueryServer(state), gamespyServersQuery.QueryServer(state)));
            }

            case ServerQueryMode.Gamespy:
                return(gamespyServersQuery.QueryServer(state));

            case ServerQueryMode.Steam:
                return(sourceServersQuery.QueryServer(state));

            default:
                throw new InvalidOperationException("Unknown server query: " + Settings.ServerQueryMode);
            }
        }
Ejemplo n.º 2
0
        public async Task <ServerQueryState> UpdateAsync(IPEndPoint endPoint = null)
        {
            IsUpdating = true;
            try {
                var state = new ServerQueryState(endPoint)
                {
                    Server = this
                };
                await _game.QueryServer(state).ConfigureAwait(false);

                return(state);
            } finally {
                IsUpdating = false;
            }
        }
        public async Task ServerInfo()
        {
            var mq      = new SourceMasterQuery("dayz");
            var servers = await mq.GetParsedServers(false, 200).ConfigureAwait(false);

            //TODO: not all servers returned will respond, allow timeout or verify good servers?
            servers = servers.OrderBy(x => Guid.NewGuid()).Take(3);
            foreach (var d in servers)
            {
                var split = d.Settings["address"].Split(':');
                var sq    = new SourceServerQuery(new ServerAddress(IPAddress.Parse(split[0]), Convert.ToInt32(split[1])),
                                                  "dayz", new SourceQueryParser());
                var state = new ServerQueryState {
                    Server = A.Fake <Server>()
                };
                await sq.UpdateAsync(state).ConfigureAwait(false);

                state.Exception.Should().BeNull();
                state.Success.Should().BeTrue();
            }
        }
        public ServerQueryResult ParsePackets(ServerQueryState state)
        {
            var receivedPackets = state.ReceivedPackets;
            if (receivedPackets.Count != state.MaxPackets)
                throw new Exception("Wrong number of packets");

            var settings = new Dictionary<string, string>();
            ParseSettings(settings, receivedPackets[0]);
            ParseRules(settings, receivedPackets[1]);

            return new SourceServerQueryResult(settings) {
                Players =
                    receivedPackets.Count == 3
                        ? ParsePlayers(state.Server, receivedPackets[2]).ToList()
                        : new List<Player>(),
                Ping = Convert.ToInt64(state.Pings.Average())
            };
        }
Ejemplo n.º 5
0
 public override Task QueryServer(ServerQueryState state)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
 public override Task QueryServer(ServerQueryState state) => serverQueryInfo.QueryServer(state);
Ejemplo n.º 7
0
 public abstract Task QueryServer(ServerQueryState state);
Ejemplo n.º 8
0
 public Task QueryServer(ServerQueryState state) => new GamespyServerQuery(state.Server.Address, Tag, new GamespyQueryParser())
 .UpdateAsync(state);
Ejemplo n.º 9
0
 public override Task QueryServer(ServerQueryState state) => queryHandler.QueryServer(state);