コード例 #1
0
        private static async Task UpdateServerInfo(ArmaServerInfoModel s, SteamApi api, bool inclRules)
        {
            s.GameTags = s.Tags == null ? null : GameTags.Parse(s.Tags);
            if (inclRules)
            {
                var rules = await api.GetServerRules(s.QueryEndPoint).ConfigureAwait(false);

                var mods = SourceQueryParser.GetList(rules, "modNames");
                s.SignatureList = SourceQueryParser.GetList(rules, "sigNames").ToHashSet();
                s.ModList       = mods.Select(x => new ServerModInfo {
                    Name = x
                }).ToList();
            }
        }
コード例 #2
0
        private static async Task <int> HandleAlt(ISteamSessionLocator locator, List <Tuple <string, string> > filter,
                                                  Action <ArmaServerInfoModel> act)
        {
            var api = new SteamApi(locator);

            var bc = new Subject <IPEndPoint>();

            var dq = new DirectQuerier();
            var t  = dq.Load(page => {
                foreach (var i in page)
                {
                    var r  = (SourceParseResult)i.Settings;
                    var s  = r.MapTo <ArmaServerInfoModel>();
                    s.Ping = i.Ping;
                    if (r.Rules != null)
                    {
                        try {
                            var rules       = SourceQueryParser.ParseRules(r.Rules);
                            var mods        = SourceQueryParser.GetList(rules, "modNames");
                            s.SignatureList = SourceQueryParser.GetList(rules, "sigNames").ToHashSet();
                            s.ModList       = mods.Select(x => new ServerModInfo {
                                Name = x
                            }).ToList();
                            s.ReceivedRules = true;
                        } catch (Exception ex) {
                            Console.WriteLine(ex);
                        }
                    }
                    act(s);
                }
            }, bc);

            var c2 = await api.GetServerInfo(locator.Session.AppId, x => {
                try {
                    var ip        = x.m_NetAdr.GetQueryAddressString().Split(':').First();
                    var ipAddress = IPAddress.Parse(ip);
                    bc.OnNext(new IPEndPoint(ipAddress, x.m_NetAdr.GetQueryPort()));
                } catch (Exception ex) {
                    Console.WriteLine(ex);
                }
            }, filter).ConfigureAwait(false);

            bc.OnCompleted();
            await t;

            return(c2);
        }