Ejemplo n.º 1
0
        private void OnTimer(object state)
        {
            if (Settings.Current.IRC.Enabled && !IRC.Instance.IsConnected)
            {
                Log.WriteWarn("Watchdog", "Forcing IRC reconnect.");

                IRC.Instance.Connect();
            }

            if (Steam.Instance.Client.IsConnected && Application.ChangelistTimer.Enabled)
            {
                AccountInfo.Sync();

                if (WebAuth.IsAuthorized)
                {
                    TaskManager.RunAsync(async() => await AccountInfo.RefreshAppsToIdle());
                }
                else
                {
                    WebAuth.AuthenticateUser();
                }
            }
            else if (DateTime.Now.Subtract(Connection.LastSuccessfulLogin).TotalMinutes >= 5.0)
            {
                Log.WriteWarn("Watchdog", "Forcing a Steam reconnect.");

                Connection.Reconnect(null, null);
            }
        }
Ejemplo n.º 2
0
        public async static Task RefreshAppsToIdle()
        {
            if (!Settings.Current.CanQueryStore)
            {
                return;
            }

            List <uint> newAppsToIdle;

            using (var handler = new HttpClientHandler())
                using (var client = new HttpClient(handler))
                {
                    handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
                    client.DefaultRequestHeaders.Add("Host", "steamdb.info");

                    var response = await client.GetAsync("https://localhost/api/GetNextAppIdToIdle/");

                    if (!response.IsSuccessStatusCode)
                    {
                        Log.WriteWarn("AccountInfo", $"GetNextAppIdToIdle returned {response.StatusCode}");

                        if (response.StatusCode == HttpStatusCode.Unauthorized)
                        {
                            await WebAuth.AuthenticateUser();
                        }

                        return;
                    }

                    var data = await response.Content.ReadAsStringAsync();

                    newAppsToIdle = JsonConvert.DeserializeObject <List <uint> >(data);
                }

            Log.WriteInfo("AccountInfo", $"{newAppsToIdle.Count} apps to idle: {string.Join(", ", newAppsToIdle)}");

            if (!AppsToIdle.SequenceEqual(newAppsToIdle))
            {
                AppsToIdle = newAppsToIdle;
                Sync();
            }
        }