diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 4a28a5d4c..2a0279f3b 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -62,7 +62,7 @@ namespace ArchiSteamFarm { byte[] sessionKey = CryptoHelper.GenerateRandomBlock(32); // RSA encrypt it with the public key for the universe we're on - byte[] cryptedSessionKey = null; + byte[] cryptedSessionKey; using (RSACrypto rsa = new RSACrypto(KeyDictionary.GetPublicKey(steamClient.ConnectedUniverse))) { cryptedSessionKey = rsa.Encrypt(sessionKey); } @@ -368,7 +368,7 @@ namespace ArchiSteamFarm { {"partner", partnerID.ToString()}, {"tradeoffermessage", "Sent by ASF"}, {"json_tradeoffer", JsonConvert.SerializeObject(trade)}, - {"trade_offer_create_params", string.IsNullOrEmpty(token) ? "" : string.Format("{{ \"trade_offer_access_token\":\"{0}\" }}", token)} // TODO: This should be rewrote + {"trade_offer_create_params", string.IsNullOrEmpty(token) ? "" : $"{{\"trade_offer_access_token\":\"{token}\"}}"} }; HttpResponseMessage response = null; @@ -466,13 +466,20 @@ namespace ArchiSteamFarm { } foreach (string setCookieValue in setCookieValues) { - if (setCookieValue.Contains("steamparental=")) { - string setCookie = setCookieValue.Substring(setCookieValue.IndexOf("steamparental=") + 14); - setCookie = setCookie.Substring(0, setCookie.IndexOf(';')); - Cookie["steamparental"] = setCookie; - Logging.LogGenericInfo("Success!", Bot.BotName); - return; + if (!setCookieValue.Contains("steamparental=")) { + continue; } + + string setCookie = setCookieValue.Substring(setCookieValue.IndexOf("steamparental=", StringComparison.Ordinal) + 14); + + int index = setCookie.IndexOf(';'); + if (index > 0) { + setCookie = setCookie.Substring(0, index); + } + + Cookie["steamparental"] = setCookie; + Logging.LogGenericInfo("Success!", Bot.BotName); + return; } Logging.LogGenericWarning("Failed to unlock parental account!", Bot.BotName); diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index cc6218fe2..c7f80122e 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -66,14 +66,6 @@ namespace ArchiSteamFarm { private bool LoggedInElsewhere = false; private string AuthCode, TwoFactorAuth; - internal static string GetAnyBotName() { - foreach (string botName in Bots.Keys) { - return botName; - } - - return null; - } - internal static async Task RefreshCMs(uint cellID) { bool initialized = false; for (byte i = 0; i < 3 && !initialized; i++) { @@ -331,7 +323,7 @@ namespace ArchiSteamFarm { return ResponseRejoinChat(); case "!restart": Program.Restart(); - return "Done"; + return null; case "!status": return ResponseStatus(); case "!statusall": @@ -902,17 +894,16 @@ namespace ArchiSteamFarm { return; } - // TODO: I really need something better - if (steamID < 110300000000000000) { - SteamFriends.SendChatMessage(steamID, EChatEntryType.ChatMsg, message); - } else { + if (new SteamID(steamID).IsChatAccount) { SteamFriends.SendChatRoomMessage(steamID, EChatEntryType.ChatMsg, message); + } else { + SteamFriends.SendChatMessage(steamID, EChatEntryType.ChatMsg, message); } } - private bool LinkMobileAuthenticator() { + private void LinkMobileAuthenticator() { if (BotDatabase.SteamGuardAccount != null) { - return false; + return; } Logging.LogGenericInfo("Linking new ASF MobileAuthenticator...", BotName); @@ -925,7 +916,7 @@ namespace ArchiSteamFarm { break; default: Logging.LogGenericError("Unhandled situation: " + loginResult, BotName); - return false; + return; } } @@ -939,7 +930,7 @@ namespace ArchiSteamFarm { break; default: Logging.LogGenericError("Unhandled situation: " + linkResult, BotName); - return false; + return; } } @@ -949,12 +940,11 @@ namespace ArchiSteamFarm { if (finalizeResult != AuthenticatorLinker.FinalizeResult.Success) { Logging.LogGenericError("Unhandled situation: " + finalizeResult, BotName); DelinkMobileAuthenticator(); - return false; + return; } Logging.LogGenericInfo("Successfully linked ASF as new mobile authenticator for this account!", BotName); Program.GetUserInput(BotName, Program.EUserInputType.RevocationCode, BotDatabase.SteamGuardAccount.RevocationCode); - return true; } private bool DelinkMobileAuthenticator() { diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index 735f82875..a5943138e 100755 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Globalization; +using System.Linq; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -78,11 +79,7 @@ namespace ArchiSteamFarm { return 0; } - foreach (uint appID in gamesToFarm.Keys) { - return appID; - } - - return 0; + return gamesToFarm.Keys.FirstOrDefault(); } internal async Task SwitchToManualMode(bool manualMode) { @@ -109,7 +106,6 @@ namespace ArchiSteamFarm { } float maxHour = 0; - foreach (float hour in appIDs.Values) { if (hour > maxHour) { maxHour = hour; @@ -326,7 +322,7 @@ namespace ArchiSteamFarm { foreach (HtmlNode htmlNode in htmlNodeCollection) { string steamLink = htmlNode.GetAttributeValue("href", null); - if (steamLink == null) { + if (string.IsNullOrEmpty(steamLink)) { continue; } diff --git a/ArchiSteamFarm/GlobalConfig.cs b/ArchiSteamFarm/GlobalConfig.cs index 753d6e9d2..67a8f4254 100644 --- a/ArchiSteamFarm/GlobalConfig.cs +++ b/ArchiSteamFarm/GlobalConfig.cs @@ -45,7 +45,7 @@ namespace ArchiSteamFarm { internal bool AutoUpdates { get; private set; } = true; [JsonProperty(Required = Required.DisallowNull)] - internal EUpdateChannel UpdateChannel { get; private set; } = GlobalConfig.EUpdateChannel.Stable; + internal EUpdateChannel UpdateChannel { get; private set; } = EUpdateChannel.Stable; [JsonProperty(Required = Required.DisallowNull)] internal byte MaxFarmingTime { get; private set; } = 10; diff --git a/ArchiSteamFarm/GlobalDatabase.cs b/ArchiSteamFarm/GlobalDatabase.cs index 0834322d6..dfdf37d5a 100644 --- a/ArchiSteamFarm/GlobalDatabase.cs +++ b/ArchiSteamFarm/GlobalDatabase.cs @@ -23,7 +23,6 @@ */ using Newtonsoft.Json; -using SteamAuth; using System; using System.IO; diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index d7f386873..23818a91c 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -111,7 +111,7 @@ namespace ArchiSteamFarm { return; } - GitHub.ReleaseResponse releaseResponse = null; + GitHub.ReleaseResponse releaseResponse; if (GlobalConfig.UpdateChannel == GlobalConfig.EUpdateChannel.Stable) { try { releaseResponse = JsonConvert.DeserializeObject(response); @@ -143,8 +143,8 @@ namespace ArchiSteamFarm { Logging.LogGenericInfo("Local version: " + Version + " | Remote version: " + releaseResponse.Tag); - if (Version.CompareTo(releaseResponse.Tag) >= 0) { // If local version is the same or newer than remote version - // Set up a timer that will automatically update ASF on as-needed basis + if (string.Compare(Version, releaseResponse.Tag, StringComparison.Ordinal) >= 0) { // If local version is the same or newer than remote version + // Set up a timer that will automatically update ASF on as-needed basis if (GlobalConfig.AutoUpdates && AutoUpdatesTimer == null) { Logging.LogGenericInfo("ASF will automatically check for new versions every 24 hours"); AutoUpdatesTimer = new Timer( @@ -314,7 +314,7 @@ namespace ArchiSteamFarm { ConsoleIsBusy = false; } - return result.Trim(); // Get rid of all whitespace characters + return string.IsNullOrEmpty(result) ? null : result.Trim(); } internal static void OnBotShutdown() { diff --git a/ArchiSteamFarm/SteamItem.cs b/ArchiSteamFarm/SteamItem.cs index 3f6fcfbd9..6e3aa56e6 100644 --- a/ArchiSteamFarm/SteamItem.cs +++ b/ArchiSteamFarm/SteamItem.cs @@ -27,7 +27,6 @@ using Newtonsoft.Json; namespace ArchiSteamFarm { internal sealed class SteamItem { // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_Asset - [JsonProperty(Required = Required.DisallowNull)] internal string appid { get; set; } diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index 05888e70a..2fcdce43a 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -50,15 +50,17 @@ namespace ArchiSteamFarm { } internal async void CheckTrades() { - if (ParsingTasks < 2) { - ParsingTasks++; - - await Semaphore.WaitAsync().ConfigureAwait(false); - await ParseActiveTrades().ConfigureAwait(false); - Semaphore.Release(); - - ParsingTasks--; + if (ParsingTasks >= 2) { + return; } + + ParsingTasks++; + + await Semaphore.WaitAsync().ConfigureAwait(false); + await ParseActiveTrades().ConfigureAwait(false); + Semaphore.Release(); + + ParsingTasks--; } private async Task ParseActiveTrades() { diff --git a/ArchiSteamFarm/WCF.cs b/ArchiSteamFarm/WCF.cs index e2823addf..a4c1d5c17 100644 --- a/ArchiSteamFarm/WCF.cs +++ b/ArchiSteamFarm/WCF.cs @@ -23,6 +23,7 @@ */ using System; +using System.Linq; using System.ServiceModel; using System.ServiceModel.Channels; @@ -100,7 +101,7 @@ namespace ArchiSteamFarm { if (args.Length > 1) { // If we have args[1] provided, use given botName botName = args[1]; } else { // If not, just pick first one - botName = Bot.GetAnyBotName(); + botName = Bot.Bots.Keys.FirstOrDefault(); } if (string.IsNullOrEmpty(botName)) {