コード例 #1
0
        public void ReloadServerItem(IPEndPoint iPEndPoint, CancellationToken cancellationToken)
        {
            var dest = ServerItems;

            try
            {
                UiTask.Run(() => dest.Clear(), cancellationToken).Wait(cancellationToken);
            }

            catch (OperationCanceledException)
            {
                Trace.WriteLine("Reloading canceled");
                return;
            }

            var vo = _defaultServerRepository.GetServerInfo(new IPEndPoint(iPEndPoint.Address, iPEndPoint.Port + 1));

            if (cancellationToken.IsCancellationRequested || vo == null)
            {
                return;
            }
            var item = new ServerItem();

            AssignProperties(item, vo);

            UiTask.Run((dest2, item2) => dest2.Add(item2), dest, item).Wait(0);
        }
コード例 #2
0
        private void LoadingServerList(object loadingServerListContext)
        {
            var threadId = Thread.CurrentThread.ManagedThreadId;
            var state    = (LoadingServerListContext)loadingServerListContext;

            foreach (var dataItem in state.Ips)
            {
                if (state.Token.IsCancellationRequested)
                {
                    break;
                }

                var serverQueryEndpoint = new IPEndPoint(dataItem.Host, dataItem.QueryPort);

                if (LiveAction != null)
                {
                    LiveAction(this,
                               string.Format("{2,3} {0} {1}", BitConverter.ToString(dataItem.Host.GetAddressBytes()),
                                             BitConverter.ToString(BitConverter.GetBytes(dataItem.QueryPort)), threadId));
                }

                var vo = _defaultServerRepository.GetServerInfo(serverQueryEndpoint);

                if (state.Token.IsCancellationRequested)
                {
                    break;
                }

                var item = new ServerItem();
                if (vo != null)
                {
                    AssignProperties(item, vo);
                }
                else
                {
                    item.Name      = string.Format("{0}:{1}", serverQueryEndpoint.Address, serverQueryEndpoint.Port - 1);
                    item.Host      = serverQueryEndpoint.Address;
                    item.QueryPort = serverQueryEndpoint.Port;
                }

                state.ProgressValue++;
                state.Ping = item.Ping;

                var t = UiTask.Run((dest2, item2) => dest2.Add(item2), state.Dest, item);
            }
            state.Finished();
            Task.Delay(TimeSpan.FromSeconds(0.5))
            .ContinueWith((t, ctx) => ReloadThreads.Remove((LoadingServerListContext)ctx), state, UiTask.UiTaskScheduler)
            .Wait();
            //UiTask.Run(ctx => ReloadThreads.Remove(ctx), state).Wait();
        }
コード例 #3
0
        internal IServerItem[] AddServerItems(IEnumerable <string> hostQueryAddresses)
        {
            var result = new List <IServerItem>(hostQueryAddresses.Count());

            foreach (var hostQueryAddress in hostQueryAddresses)
            {
                var pos  = hostQueryAddress.IndexOf(':');
                var addr = hostQueryAddress.Substring(0, pos);
                var port = 0;
                int.TryParse(hostQueryAddress.Substring(pos + 1), out port);

                var serverItem = new ServerItem {
                    Host = IPAddress.Parse(addr), QueryPort = port, Name = addr
                };
                ServerItems.Add(serverItem);
                result.Add(serverItem);
            }
            return(result.ToArray());
        }
コード例 #4
0
        private void AssignProperties(ServerItem item, ISteamGameServer vo)
        {
            var keyWordsSplited = vo.Keywords.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
            var keyWords        = new Dictionary <string, string>(keyWordsSplited.Length);

            foreach (var s in keyWordsSplited)
            {
                var k = s.Substring(0, 1);
                if (!keyWords.ContainsKey(k))
                {
                    keyWords.Add(k, s.Substring(1));
                }
            }

            //serverItem1.Country = dataItem1.Country;
            item.Gamename           = vo.Gamename;
            item.Host               = vo.Host;
            item.Island             = vo.Map;
            item.Mission            = vo.Mission;
            item.Mode               = keyWords.FirstOrDefault(k => k.Key == "t").Value ?? string.Empty; //dataItem1.Mode;
            item.Modhashs           = vo.Modhashs;
            item.ModsText           = vo.Mods;
            item.Name               = vo.Name;
            item.CurrentPlayerCount = vo.CurrentPlayerCount;
            item.MaxPlayers         = vo.MaxPlayers;
            item.Port               = vo.Port;
            item.QueryPort          = vo.QueryPort;
            item.Signatures         = vo.Signatures;
            item.VerifySignatures   = vo.VerifySignatures;
            item.Version            = vo.Version;
            item.Passworded         = keyWords.FirstOrDefault(k => k.Key == "l").Value == "t"; //dataItem1.Passworded;
            item.Ping               = vo.Ping;
            if (vo.Players != null)
            {
                item.CurrentPlayersText = string.Join(", ", vo.Players.Select(p => p.Name).OrderBy(s => s));
                item.CurrentPlayers     = vo.Players.OrderBy(p => p.Name).ToArray();
            }
        }