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); } }
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) { AccountInfo.Sync(); } else if (DateTime.Now.Subtract(Connection.LastSuccessfulLogin).TotalMinutes >= 5.0) { IRC.Instance.SendOps("[Watchdog] Forcing a Steam reconnect."); Log.WriteWarn("Watchdog", "Forcing a Steam reconnect."); Connection.Reconnect(null, null); } if (DateTime.Now.Subtract(Steam.Instance.DepotProcessor.LastServerRefreshTime).TotalHours >= 2.0) { Log.WriteWarn("Watchdog", "Refreshing depot cdn servers"); TaskManager.RunAsync(Steam.Instance.DepotProcessor.UpdateContentServerList); } }
private void OnFreeLicenseCallback(SteamApps.FreeLicenseCallback callback) { JobManager.TryRemoveJob(callback.JobID); var packageIDs = callback.GrantedPackages; var appIDs = callback.GrantedApps; Log.WriteDebug("FreeLicense", "Received free license: {0} ({1} apps: {2}, {3} packages: {4})", callback.Result, appIDs.Count, string.Join(", ", appIDs), packageIDs.Count, string.Join(", ", packageIDs)); if (appIDs.Any()) { JobManager.AddJob(() => Steam.Instance.Apps.PICSGetAccessTokens(appIDs, Enumerable.Empty <uint>())); } if (packageIDs.Any()) { JobManager.AddJob(() => Steam.Instance.Apps.PICSGetProductInfo(Enumerable.Empty <uint>(), packageIDs)); TaskManager.RunAsync(() => { RefreshPackageNames(); foreach (var subID in packageIDs) { IRC.Instance.SendAnnounce("New free license granted: {0}{1}{2} -{3} {4}", Colors.BLUE, Steam.GetPackageName(subID), Colors.NORMAL, Colors.DARKBLUE, SteamDB.GetPackageURL(subID) ); } }); } }
public void PerformSync() { IEnumerable <uint> apps; IEnumerable <uint> packages; using (var db = Database.GetConnection()) { if (Settings.Current.FullRun == FullRunState.Enumerate) { var lastAppID = 50000 + db.ExecuteScalar <int>("SELECT `AppID` FROM `Apps` ORDER BY `AppID` DESC LIMIT 1"); var lastSubID = 10000 + db.ExecuteScalar <int>("SELECT `SubID` FROM `Subs` ORDER BY `SubID` DESC LIMIT 1"); // TODO: Tempo hack due to appid 2032727 if (lastAppID > 1000000) { lastAppID = 1000000; } Log.WriteInfo("Full Run", "Will enumerate {0} apps and {1} packages", lastAppID, lastSubID); // greatest code you've ever seen apps = Enumerable.Range(0, lastAppID).Select(i => (uint)i); packages = Enumerable.Range(0, lastSubID).Select(i => (uint)i); } else { Log.WriteInfo("Full Run", "Doing a full run on all apps and packages in the database."); apps = db.Query <uint>("SELECT `AppID` FROM `Apps` ORDER BY `AppID` DESC"); packages = db.Query <uint>("SELECT `SubID` FROM `Subs` ORDER BY `SubID` DESC"); } } TaskManager.RunAsync(() => RequestUpdateForList(apps, packages)); }
private void OnPICSChangesFullRun(SteamApps.PICSChangesCallback callback) { PreviousChangeNumber = 2; var apps = callback.AppChanges.Keys; var packages = callback.PackageChanges.Keys; TaskManager.RunAsync(() => RequestUpdateForList(apps, packages)); }
public static void Init() { ImportantApps = new Dictionary <uint, List <string> >(); ImportantSubs = new Dictionary <uint, byte>(); ReloadImportant(); TaskManager.RunAsync(async() => await KeyNameCache.Init()); ChangelistTimer = new Timer(); ChangelistTimer.Elapsed += Tick; ChangelistTimer.Interval = TimeSpan.FromSeconds(1).TotalMilliseconds; var thread = new Thread(Steam.Instance.Tick) { Name = "Steam" }; thread.Start(); var anonThread = new Thread(Steam.Anonymous.Tick) { Name = "SteamAnonymous" }; anonThread.Start(); Threads = new List <Thread> { thread, anonThread, }; if (Settings.IsFullRun) { return; } var commandHandler = new CommandHandler(); Steam.Instance.RegisterCommandHandlers(commandHandler); if (Settings.Current.IRC.Enabled) { RssReader = new RSS(); thread = new Thread(IRC.Instance.Connect) { Name = "IRC" }; thread.Start(); Threads.Add(thread); IRC.Instance.RegisterCommandHandlers(commandHandler); } }
private void OnLoggedOn(SteamUser.LoggedOnCallback callback) { if (callback.Result != EResult.OK) { return; } WebAPIUserNonce = callback.WebAPIUserNonce; TaskManager.RunAsync(() => AuthenticateUser()); }
private void OnFreeLicenseCallback(SteamApps.FreeLicenseCallback callback) { JobManager.TryRemoveJob(callback.JobID); var packageIDs = callback.GrantedPackages; var appIDs = callback.GrantedApps; Log.WriteDebug(nameof(FreeLicense), "Received free license: {0} ({1} apps: {2}, {3} packages: {4})", callback.Result, appIDs.Count, string.Join(", ", appIDs), packageIDs.Count, string.Join(", ", packageIDs)); if (appIDs.Count > 0) { JobManager.AddJob( () => Steam.Instance.Apps.PICSGetAccessTokens(appIDs, Enumerable.Empty <uint>()), new PICSTokens.RequestedTokens { Apps = appIDs.ToList() }); foreach (var appid in appIDs) { LocalConfig.Current.FreeLicensesToRequest.Remove(appid); } LocalConfig.Save(); } if (packageIDs.Count > 0) { JobManager.AddJob( () => Steam.Instance.Apps.PICSGetAccessTokens(Enumerable.Empty <uint>(), packageIDs), new PICSTokens.RequestedTokens { Packages = packageIDs.ToList() }); TaskManager.RunAsync(async() => { await RefreshPackageNames(); foreach (var subID in packageIDs) { IRC.Instance.SendAnnounce("New free license granted: {0}{1}{2} -{3} {4}", Colors.BLUE, Steam.GetPackageName(subID), Colors.NORMAL, Colors.DARKBLUE, SteamDB.GetPackageUrl(subID) ); } }); } }
public static void Init() { ImportantApps = new Dictionary <uint, List <string> >(); ImportantSubs = new Dictionary <uint, byte>(); ReloadImportant(); TaskManager.RunAsync(async() => await KeyNameCache.Init()); var thread = new Thread(Steam.Instance.Tick) { Name = "Steam" }; thread.Start(); Threads = new List <Thread> { thread, }; if (Settings.Current.BuiltInHttpServerPort > 0) { HttpServer = new HttpServer(Settings.Current.BuiltInHttpServerPort); } if (Settings.IsFullRun) { return; } var commandHandler = new CommandHandler(); Steam.Instance.RegisterCommandHandlers(commandHandler); if (Settings.Current.IRC.Enabled) { RssReader = new RSS(); thread = new Thread(IRC.Instance.Connect) { Name = "IRC" }; thread.Start(); Threads.Add(thread); IRC.Instance.RegisterCommandHandlers(commandHandler); } }
public void PerformSync() { PreviousChangeNumber = 2; List <uint> apps; List <uint> packages; using (var db = Database.Get()) { if (Settings.Current.FullRun == FullRunState.Enumerate) { // TODO: Remove WHERE when normal appids approach 2mil var lastAppID = 50000 + db.ExecuteScalar <int>("SELECT `AppID` FROM `Apps` WHERE `AppID` < 2000000 ORDER BY `AppID` DESC LIMIT 1"); var lastSubID = 10000 + db.ExecuteScalar <int>("SELECT `SubID` FROM `Subs` ORDER BY `SubID` DESC LIMIT 1"); Log.WriteInfo("Full Run", "Will enumerate {0} apps and {1} packages", lastAppID, lastSubID); // greatest code you've ever seen apps = Enumerable.Range(0, lastAppID).Reverse().Select(i => (uint)i).ToList(); packages = Enumerable.Range(0, lastSubID).Reverse().Select(i => (uint)i).ToList(); } else if (Settings.Current.FullRun == FullRunState.TokensOnly) { Log.WriteInfo("Full Run", $"Enumerating {PICSTokens.AppTokens.Count} apps and {PICSTokens.PackageTokens.Count} packages that have a token."); apps = PICSTokens.AppTokens.Keys.ToList(); packages = PICSTokens.PackageTokens.Keys.ToList(); } else { Log.WriteInfo("Full Run", "Doing a full run on all apps and packages in the database."); if (Settings.Current.FullRun == FullRunState.PackagesNormal) { apps = new List <uint>(); } else { apps = db.Query <uint>("(SELECT `AppID` FROM `Apps` ORDER BY `AppID` DESC) UNION DISTINCT (SELECT `AppID` FROM `SubsApps` WHERE `Type` = 'app') ORDER BY `AppID` DESC").ToList(); } packages = db.Query <uint>("SELECT `SubID` FROM `Subs` ORDER BY `SubID` DESC").ToList(); } } TaskManager.RunAsync(async() => await RequestUpdateForList(apps, packages)); }
public DepotProcessor(SteamClient client, CallbackManager manager) { UpdateScript = Path.Combine(Application.Path, "files", "update.sh"); CDNClient = new CDNClient(client); CDNServers = new List <CDNClient.Server> { new DnsEndPoint("valve500.steamcontent.com", 80) }; CDNClient.RequestTimeout = TimeSpan.FromSeconds(30); FileDownloader.SetCDNClient(CDNClient); manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn); TaskManager.RunAsync(UpdateContentServerList); }
private async void OnPICSChanges(SteamApps.PICSChangesCallback callback) { if (PreviousChangeNumber == callback.CurrentChangeNumber) { return; } var packageChangesCount = callback.PackageChanges.Count; var appChangesCount = callback.AppChanges.Count; Log.WriteInfo("PICSChanges", "Changelist {0} -> {1} ({2} apps, {3} packages)", PreviousChangeNumber, callback.CurrentChangeNumber, appChangesCount, packageChangesCount); LocalConfig.Current.ChangeNumber = PreviousChangeNumber = callback.CurrentChangeNumber; await HandleChangeNumbers(callback); if (appChangesCount == 0 && packageChangesCount == 0) { IRC.Instance.SendAnnounce("{0}»{1} Changelist {2}{3}{4} (empty)", Colors.RED, Colors.NORMAL, Colors.BLUE, PreviousChangeNumber, Colors.DARKGRAY); return; } // We don't care about waiting for separate database queries to finish, so don't await them #pragma warning disable 4014 if (appChangesCount > 0) { JobManager.AddJob(() => Steam.Instance.Apps.PICSGetAccessTokens(callback.AppChanges.Keys, Enumerable.Empty <uint>())); TaskManager.RunAsync(async() => await HandleApps(callback)); } if (packageChangesCount > 0) { JobManager.AddJob(() => Steam.Instance.Apps.PICSGetProductInfo(Enumerable.Empty <SteamApps.PICSRequest>(), callback.PackageChanges.Keys.Select(Utils.NewPICSRequest))); TaskManager.RunAsync(async() => await HandlePackages(callback)); TaskManager.RunAsync(async() => await HandlePackagesChangelists(callback)); } TaskManager.RunAsync(async() => await SendChangelistsToIRC(callback)); #pragma warning restore 4014 PrintImportants(callback); }
public override void HandleMsg(IPacketMsg packetMsg) { if (packetMsg.MsgType != EMsg.ClientItemAnnouncements) { return; } var response = new ClientMsgProtobuf <CMsgClientItemAnnouncements>(packetMsg); if (response.Body.count_new_items == 0) { return; } Log.WriteInfo("ClientItemAnnouncements", $"New items: {response.Body.count_new_items}"); TaskManager.RunAsync(async() => await AccountInfo.RefreshAppsToIdle()); }
private void OnPICSChanges(SteamApps.PICSChangesCallback callback) { if (PreviousChangeNumber == callback.CurrentChangeNumber) { return; } var packageChangesCount = callback.PackageChanges.Count; var appChangesCount = callback.AppChanges.Count; Log.WriteInfo("PICSChanges", "Changelist {0} -> {1} ({2} apps, {3} packages)", PreviousChangeNumber, callback.CurrentChangeNumber, appChangesCount, packageChangesCount); PreviousChangeNumber = callback.CurrentChangeNumber; HandleChangeNumbers(callback); if (appChangesCount == 0 && packageChangesCount == 0) { IRC.Instance.SendAnnounce("{0}»{1} Changelist {2}{3}{4} (empty)", Colors.RED, Colors.NORMAL, Colors.BLUE, PreviousChangeNumber, Colors.DARKGRAY); return; } if (appChangesCount > 0) { JobManager.AddJob(() => Steam.Instance.Apps.PICSGetAccessTokens(callback.AppChanges.Keys, Enumerable.Empty <uint>())); TaskManager.RunAsync(() => HandleApps(callback)); } if (packageChangesCount > 0) { JobManager.AddJob(() => Steam.Instance.Apps.PICSGetProductInfo(Enumerable.Empty <SteamApps.PICSRequest>(), callback.PackageChanges.Keys.Select(Utils.NewPICSRequest))); TaskManager.RunAsync(() => HandlePackages(callback)); TaskManager.RunAsync(() => HandlePackagesChangelists(callback)); } TaskManager.RunAsync(() => SendChangelistsToIRC(callback)); PrintImportants(callback); }
private void OnLoggedOn(SteamUser.LoggedOnCallback callback) { TaskManager.RunAsync(async() => await AuthenticateUser()); }
public static bool AuthenticateUser() { // 32 byte random blob of data var sessionKey = CryptoHelper.GenerateRandomBlock(32); byte[] encryptedSessionKey; // ... which is then encrypted with RSA using the Steam system's public key using (var rsa = new RSACrypto(KeyDictionary.GetPublicKey(Steam.Instance.Client.Universe))) { encryptedSessionKey = rsa.Encrypt(sessionKey); } // users hashed loginkey, AES encrypted with the sessionkey var encryptedLoginKey = CryptoHelper.SymmetricEncrypt(Encoding.ASCII.GetBytes(WebAPIUserNonce), sessionKey); using (dynamic userAuth = WebAPI.GetInterface("ISteamUserAuth")) { KeyValue result; try { result = userAuth.AuthenticateUser( steamid: Steam.Instance.Client.SteamID.ConvertToUInt64(), sessionkey: WebHelpers.UrlEncode(encryptedSessionKey), encrypted_loginkey: WebHelpers.UrlEncode(encryptedLoginKey), method: "POST", secure: true ); } catch (WebException e) { var response = (HttpWebResponse)e.Response; if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.Forbidden) { IsAuthorized = false; if (Steam.Instance.Client.IsConnected) { Steam.Instance.User.RequestWebAPIUserNonce(); } } Log.WriteWarn("WebAuth", "Failed to authenticate: {0}", e.Message); return(false); } File.WriteAllText(Path.Combine(Application.Path, "files", ".support", "cookie.txt"), $"steamLogin={result["token"].AsString()}; steamLoginSecure={result["tokensecure"].AsString()}"); Cookies = new CookieContainer(); Cookies.Add(new Cookie("steamLogin", result["token"].AsString(), "/", "store.steampowered.com")); Cookies.Add(new Cookie("steamLoginSecure", result["tokensecure"].AsString(), "/", "store.steampowered.com")); } IsAuthorized = true; Log.WriteInfo("WebAuth", "Authenticated"); TaskManager.RunAsync(async() => await AccountInfo.RefreshAppsToIdle()); return(true); }
private async void OnPICSChanges(SteamApps.PICSChangesCallback callback) { if (PreviousChangeNumber == callback.CurrentChangeNumber) { return; } Log.WriteInfo("PICSChanges", $"Changelist {PreviousChangeNumber} -> {callback.CurrentChangeNumber} ({callback.AppChanges.Count} apps, {callback.PackageChanges.Count} packages)"); LocalConfig.Current.ChangeNumber = PreviousChangeNumber = callback.CurrentChangeNumber; await HandleChangeNumbers(callback); if (callback.AppChanges.Count == 0 && callback.PackageChanges.Count == 0) { IRC.Instance.SendAnnounce("{0}»{1} Changelist {2}{3}{4} (empty)", Colors.RED, Colors.NORMAL, Colors.BLUE, PreviousChangeNumber, Colors.DARKGRAY); return; } const int appsPerJob = 50; if (callback.AppChanges.Count > appsPerJob) { foreach (var list in callback.AppChanges.Keys.Split(appsPerJob)) { JobManager.AddJob( () => Steam.Instance.Apps.PICSGetAccessTokens(list, Enumerable.Empty <uint>()), new PICSTokens.RequestedTokens { Apps = list.ToList() }); } } else if (callback.AppChanges.Count > 0) { JobManager.AddJob( () => Steam.Instance.Apps.PICSGetAccessTokens(callback.AppChanges.Keys, Enumerable.Empty <uint>()), new PICSTokens.RequestedTokens { Apps = callback.AppChanges.Keys.ToList() }); } if (callback.PackageChanges.Count > appsPerJob) { foreach (var list in callback.PackageChanges.Keys.Split(appsPerJob)) { JobManager.AddJob( () => Steam.Instance.Apps.PICSGetAccessTokens(Enumerable.Empty <uint>(), list), new PICSTokens.RequestedTokens { Packages = list.ToList() }); } } else if (callback.PackageChanges.Count > 0) { JobManager.AddJob( () => Steam.Instance.Apps.PICSGetAccessTokens(Enumerable.Empty <uint>(), callback.PackageChanges.Keys), new PICSTokens.RequestedTokens { Packages = callback.PackageChanges.Keys.ToList() }); } if (callback.AppChanges.Count > 0) { _ = TaskManager.RunAsync(async() => await HandleApps(callback)); } if (callback.PackageChanges.Count > 0) { _ = TaskManager.RunAsync(async() => await HandlePackages(callback)); _ = TaskManager.RunAsync(async() => await HandlePackagesChangelists(callback)); } _ = TaskManager.RunAsync(async() => await SendChangelistsToIRC(callback)); PrintImportants(callback); }
private void OnLoggedOn(SteamUser.LoggedOnCallback callback) { TaskManager.RunAsync(UpdateContentServerList); }