Пример #1
0
        private async Task WatchForOnlineDetails(Game.OnlineProperties online)
        {
            if (online.ServerHttpPort == null)
            {
                return;
            }
            var httpPort = online.ServerHttpPort.Value;

            string joinSecret = null, matchSecret = null;

            while (_presence?.IsDisposed == false)
            {
                try {
                    var data = await KunosApiProvider.GetInformationDirectAsync(online.ServerIp, online.ServerHttpPort.Value);

                    var currentSession = data.SessionTypes?.ArrayElementAtOrDefault(data.Session);
                    if (currentSession > 0)
                    {
                        _presence.Details = ((Game.SessionType)currentSession).GetDescription();
                    }

                    if (joinSecret == null)
                    {
                        var password = data.Password && OnlineServer.IncludePasswordToInviteLink ? online.Password : null;
                        joinSecret  = DiscordHandler.GetJoinSecret(online.ServerIp, httpPort, password);
                        matchSecret = DiscordHandler.GetMatchSecret(online.ServerIp, httpPort, password);
                    }

                    _presence.End   = DateTime.Now + TimeSpan.FromSeconds(data.TimeLeft - Math.Round(data.Timestamp / 1000d));
                    _presence.Party = new DiscordParty(data.Id)
                    {
                        Capacity    = data.Capacity,
                        Size        = data.Clients,
                        JoinSecret  = joinSecret,
                        MatchSecret = matchSecret,
                    };

                    _presence.ForceUpdate();
                } catch (Exception e) {
                    Logging.Warning(e.Message);
                }

                await Task.Delay(BuildInformation.IsDebugConfiguration? 3000 : 15000);
            }
        }