From a90b5adaf5d60bf9be17c3e3c475eabf98a6f258 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Wed, 29 Jun 2016 20:33:52 +0200 Subject: [PATCH] Further hardening --- ArchiSteamFarm/ArchiWebHandler.cs | 30 ++++++++++++--------------- ArchiSteamFarm/Bot.cs | 11 +++++----- ArchiSteamFarm/CardsFarmer.cs | 14 ++++++------- ArchiSteamFarm/MobileAuthenticator.cs | 10 ++++----- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index a4026db3c..020351348 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -342,19 +342,19 @@ namespace ArchiSteamFarm { XmlNode appNode = xmlNode.SelectSingleNode("appID"); if (appNode == null) { Logging.LogNullError(nameof(appNode), Bot.BotName); - continue; + return null; } uint appID; if (!uint.TryParse(appNode.InnerText, out appID)) { Logging.LogNullError(nameof(appID), Bot.BotName); - continue; + return null; } XmlNode nameNode = xmlNode.SelectSingleNode("name"); if (nameNode == null) { Logging.LogNullError(nameof(nameNode), Bot.BotName); - continue; + return null; } result[appID] = nameNode.InnerText; @@ -396,7 +396,7 @@ namespace ArchiSteamFarm { uint appID = (uint) game["appid"].AsUnsignedLong(); if (appID == 0) { Logging.LogNullError(nameof(appID), Bot.BotName); - continue; + return null; } result[appID] = game["name"].Value; @@ -518,7 +518,7 @@ namespace ArchiSteamFarm { ulong classID = description["classid"].AsUnsignedLong(); if (classID == 0) { Logging.LogNullError(nameof(classID), Bot.BotName); - continue; + return null; } if (descriptions.ContainsKey(classID)) { @@ -738,13 +738,13 @@ namespace ArchiSteamFarm { string classIDString = description["classid"].ToString(); if (string.IsNullOrEmpty(classIDString)) { Logging.LogNullError(nameof(classIDString), Bot.BotName); - continue; + return null; } ulong classID; if (!ulong.TryParse(classIDString, out classID) || (classID == 0)) { Logging.LogNullError(nameof(classID), Bot.BotName); - continue; + return null; } if (descriptionMap.ContainsKey(classID)) { @@ -762,12 +762,12 @@ namespace ArchiSteamFarm { string appIDString = description["appid"].ToString(); if (string.IsNullOrEmpty(appIDString)) { Logging.LogNullError(nameof(appIDString), Bot.BotName); - continue; + return null; } if (!uint.TryParse(appIDString, out appID)) { Logging.LogNullError(nameof(appID), Bot.BotName); - continue; + return null; } } @@ -794,12 +794,12 @@ namespace ArchiSteamFarm { steamItem = item.ToObject(); } catch (JsonException e) { Logging.LogGenericException(e, Bot.BotName); - continue; + return null; } if (steamItem == null) { Logging.LogNullError(nameof(steamItem), Bot.BotName); - continue; + return null; } Tuple description; @@ -817,13 +817,9 @@ namespace ArchiSteamFarm { } uint nextPage; - if (!uint.TryParse(jObject["more_start"].ToString(), out nextPage)) { + if (!uint.TryParse(jObject["more_start"].ToString(), out nextPage) || (nextPage <= currentPage)) { Logging.LogNullError(nameof(nextPage), Bot.BotName); - break; - } - - if (nextPage <= currentPage) { - break; + return null; } currentPage = nextPage; diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 324605e68..f18aab7df 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -1098,7 +1098,8 @@ namespace ArchiSteamFarm { foreach (uint gameID in gameIDs) { SteamApps.FreeLicenseCallback callback = await SteamApps.RequestFreeLicense(gameID); if (callback == null) { - continue; + result.AppendLine("Result: Timeout!"); + break; } result.AppendLine("Result: " + callback.Result + " | Granted apps: " + string.Join(", ", callback.GrantedApps) + " " + string.Join(", ", callback.GrantedPackages)); @@ -1128,14 +1129,14 @@ namespace ArchiSteamFarm { foreach (string game in gameIDs.Where(game => !string.IsNullOrEmpty(game))) { uint gameID; if (!uint.TryParse(game, out gameID)) { - continue; + return "Couldn't parse games list!"; } gamesToRedeem.Add(gameID); } if (gamesToRedeem.Count == 0) { - return "Couldn't parse any games given!"; + return "List of games is empty!"; } return await bot.ResponseAddLicense(steamID, gamesToRedeem).ConfigureAwait(false); @@ -1258,7 +1259,7 @@ namespace ArchiSteamFarm { foreach (string game in gameIDs.Where(game => !string.IsNullOrEmpty(game))) { uint gameID; if (!uint.TryParse(game, out gameID)) { - continue; + return "Couldn't parse games list!"; } gamesToPlay.Add(gameID); @@ -1269,7 +1270,7 @@ namespace ArchiSteamFarm { } if (gamesToPlay.Count == 0) { - return "Couldn't parse any games given!"; + return "List of games is empty!"; } return await bot.ResponsePlay(steamID, gamesToPlay).ConfigureAwait(false); diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index 8148a8813..2a67b7c45 100755 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -299,19 +299,19 @@ namespace ArchiSteamFarm { string steamLink = farmingNode.GetAttributeValue("href", null); if (string.IsNullOrEmpty(steamLink)) { Logging.LogNullError(nameof(steamLink), Bot.BotName); - continue; + return; } int index = steamLink.LastIndexOf('/'); if (index < 0) { Logging.LogNullError(nameof(index), Bot.BotName); - continue; + return; } index++; if (steamLink.Length <= index) { Logging.LogNullError(nameof(steamLink.Length), Bot.BotName); - continue; + return; } steamLink = steamLink.Substring(index); @@ -319,7 +319,7 @@ namespace ArchiSteamFarm { uint appID; if (!uint.TryParse(steamLink, out appID) || (appID == 0)) { Logging.LogNullError(nameof(appID), Bot.BotName); - continue; + return; } if (GlobalConfig.GlobalBlacklist.Contains(appID) || Program.GlobalConfig.Blacklist.Contains(appID)) { @@ -329,13 +329,13 @@ namespace ArchiSteamFarm { HtmlNode timeNode = htmlNode.SelectSingleNode(".//div[@class='badge_title_stats_playtime']"); if (timeNode == null) { Logging.LogNullError(nameof(timeNode), Bot.BotName); - continue; + return; } string hoursString = timeNode.InnerText; if (string.IsNullOrEmpty(hoursString)) { Logging.LogNullError(nameof(hoursString), Bot.BotName); - continue; + return; } float hours = 0; @@ -344,7 +344,7 @@ namespace ArchiSteamFarm { if (match.Success) { if (!float.TryParse(match.Value, NumberStyles.Number, CultureInfo.InvariantCulture, out hours)) { Logging.LogNullError(nameof(hours), Bot.BotName); - continue; + return; } } diff --git a/ArchiSteamFarm/MobileAuthenticator.cs b/ArchiSteamFarm/MobileAuthenticator.cs index 33d66b865..dce937e66 100644 --- a/ArchiSteamFarm/MobileAuthenticator.cs +++ b/ArchiSteamFarm/MobileAuthenticator.cs @@ -187,31 +187,31 @@ namespace ArchiSteamFarm { string idString = confirmationNode.GetAttributeValue("data-confid", null); if (string.IsNullOrEmpty(idString)) { Logging.LogNullError(nameof(idString), Bot.BotName); - continue; + return null; } uint id; if (!uint.TryParse(idString, out id) || (id == 0)) { Logging.LogNullError(nameof(id), Bot.BotName); - continue; + return null; } string keyString = confirmationNode.GetAttributeValue("data-key", null); if (string.IsNullOrEmpty(keyString)) { Logging.LogNullError(nameof(keyString), Bot.BotName); - continue; + return null; } ulong key; if (!ulong.TryParse(keyString, out key) || (key == 0)) { Logging.LogNullError(nameof(key), Bot.BotName); - continue; + return null; } HtmlNode descriptionNode = confirmationNode.SelectSingleNode(".//div[@class='mobileconf_list_entry_description']/div"); if (descriptionNode == null) { Logging.LogNullError(nameof(descriptionNode), Bot.BotName); - continue; + return null; } Steam.ConfirmationDetails.EType type;