Skip to content

Commit a90b5ad

Browse files
committed
Further hardening
1 parent 1c74fdd commit a90b5ad

File tree

4 files changed

+31
-34
lines changed

4 files changed

+31
-34
lines changed

ArchiSteamFarm/ArchiWebHandler.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -342,19 +342,19 @@ internal async Task<Dictionary<uint, string>> GetOwnedGames() {
342342
XmlNode appNode = xmlNode.SelectSingleNode("appID");
343343
if (appNode == null) {
344344
Logging.LogNullError(nameof(appNode), Bot.BotName);
345-
continue;
345+
return null;
346346
}
347347

348348
uint appID;
349349
if (!uint.TryParse(appNode.InnerText, out appID)) {
350350
Logging.LogNullError(nameof(appID), Bot.BotName);
351-
continue;
351+
return null;
352352
}
353353

354354
XmlNode nameNode = xmlNode.SelectSingleNode("name");
355355
if (nameNode == null) {
356356
Logging.LogNullError(nameof(nameNode), Bot.BotName);
357-
continue;
357+
return null;
358358
}
359359

360360
result[appID] = nameNode.InnerText;
@@ -396,7 +396,7 @@ internal Dictionary<uint, string> GetOwnedGames(ulong steamID) {
396396
uint appID = (uint) game["appid"].AsUnsignedLong();
397397
if (appID == 0) {
398398
Logging.LogNullError(nameof(appID), Bot.BotName);
399-
continue;
399+
return null;
400400
}
401401

402402
result[appID] = game["name"].Value;
@@ -518,7 +518,7 @@ internal uint GetServerTime() {
518518
ulong classID = description["classid"].AsUnsignedLong();
519519
if (classID == 0) {
520520
Logging.LogNullError(nameof(classID), Bot.BotName);
521-
continue;
521+
return null;
522522
}
523523

524524
if (descriptions.ContainsKey(classID)) {
@@ -738,13 +738,13 @@ internal bool DeclineTradeOffer(ulong tradeID) {
738738
string classIDString = description["classid"].ToString();
739739
if (string.IsNullOrEmpty(classIDString)) {
740740
Logging.LogNullError(nameof(classIDString), Bot.BotName);
741-
continue;
741+
return null;
742742
}
743743

744744
ulong classID;
745745
if (!ulong.TryParse(classIDString, out classID) || (classID == 0)) {
746746
Logging.LogNullError(nameof(classID), Bot.BotName);
747-
continue;
747+
return null;
748748
}
749749

750750
if (descriptionMap.ContainsKey(classID)) {
@@ -762,12 +762,12 @@ internal bool DeclineTradeOffer(ulong tradeID) {
762762
string appIDString = description["appid"].ToString();
763763
if (string.IsNullOrEmpty(appIDString)) {
764764
Logging.LogNullError(nameof(appIDString), Bot.BotName);
765-
continue;
765+
return null;
766766
}
767767

768768
if (!uint.TryParse(appIDString, out appID)) {
769769
Logging.LogNullError(nameof(appID), Bot.BotName);
770-
continue;
770+
return null;
771771
}
772772
}
773773

@@ -794,12 +794,12 @@ internal bool DeclineTradeOffer(ulong tradeID) {
794794
steamItem = item.ToObject<Steam.Item>();
795795
} catch (JsonException e) {
796796
Logging.LogGenericException(e, Bot.BotName);
797-
continue;
797+
return null;
798798
}
799799

800800
if (steamItem == null) {
801801
Logging.LogNullError(nameof(steamItem), Bot.BotName);
802-
continue;
802+
return null;
803803
}
804804

805805
Tuple<uint, Steam.Item.EType> description;
@@ -817,13 +817,9 @@ internal bool DeclineTradeOffer(ulong tradeID) {
817817
}
818818

819819
uint nextPage;
820-
if (!uint.TryParse(jObject["more_start"].ToString(), out nextPage)) {
820+
if (!uint.TryParse(jObject["more_start"].ToString(), out nextPage) || (nextPage <= currentPage)) {
821821
Logging.LogNullError(nameof(nextPage), Bot.BotName);
822-
break;
823-
}
824-
825-
if (nextPage <= currentPage) {
826-
break;
822+
return null;
827823
}
828824

829825
currentPage = nextPage;

ArchiSteamFarm/Bot.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,8 @@ private async Task<string> ResponseAddLicense(ulong steamID, ICollection<uint> g
10981098
foreach (uint gameID in gameIDs) {
10991099
SteamApps.FreeLicenseCallback callback = await SteamApps.RequestFreeLicense(gameID);
11001100
if (callback == null) {
1101-
continue;
1101+
result.AppendLine("Result: Timeout!");
1102+
break;
11021103
}
11031104

11041105
result.AppendLine("Result: " + callback.Result + " | Granted apps: " + string.Join(", ", callback.GrantedApps) + " " + string.Join(", ", callback.GrantedPackages));
@@ -1128,14 +1129,14 @@ private static async Task<string> ResponseAddLicense(ulong steamID, string botNa
11281129
foreach (string game in gameIDs.Where(game => !string.IsNullOrEmpty(game))) {
11291130
uint gameID;
11301131
if (!uint.TryParse(game, out gameID)) {
1131-
continue;
1132+
return "Couldn't parse games list!";
11321133
}
11331134

11341135
gamesToRedeem.Add(gameID);
11351136
}
11361137

11371138
if (gamesToRedeem.Count == 0) {
1138-
return "Couldn't parse any games given!";
1139+
return "List of games is empty!";
11391140
}
11401141

11411142
return await bot.ResponseAddLicense(steamID, gamesToRedeem).ConfigureAwait(false);
@@ -1258,7 +1259,7 @@ private static async Task<string> ResponsePlay(ulong steamID, string botName, st
12581259
foreach (string game in gameIDs.Where(game => !string.IsNullOrEmpty(game))) {
12591260
uint gameID;
12601261
if (!uint.TryParse(game, out gameID)) {
1261-
continue;
1262+
return "Couldn't parse games list!";
12621263
}
12631264

12641265
gamesToPlay.Add(gameID);
@@ -1269,7 +1270,7 @@ private static async Task<string> ResponsePlay(ulong steamID, string botName, st
12691270
}
12701271

12711272
if (gamesToPlay.Count == 0) {
1272-
return "Couldn't parse any games given!";
1273+
return "List of games is empty!";
12731274
}
12741275

12751276
return await bot.ResponsePlay(steamID, gamesToPlay).ConfigureAwait(false);

ArchiSteamFarm/CardsFarmer.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,27 +299,27 @@ private void CheckPage(HtmlDocument htmlDocument) {
299299
string steamLink = farmingNode.GetAttributeValue("href", null);
300300
if (string.IsNullOrEmpty(steamLink)) {
301301
Logging.LogNullError(nameof(steamLink), Bot.BotName);
302-
continue;
302+
return;
303303
}
304304

305305
int index = steamLink.LastIndexOf('/');
306306
if (index < 0) {
307307
Logging.LogNullError(nameof(index), Bot.BotName);
308-
continue;
308+
return;
309309
}
310310

311311
index++;
312312
if (steamLink.Length <= index) {
313313
Logging.LogNullError(nameof(steamLink.Length), Bot.BotName);
314-
continue;
314+
return;
315315
}
316316

317317
steamLink = steamLink.Substring(index);
318318

319319
uint appID;
320320
if (!uint.TryParse(steamLink, out appID) || (appID == 0)) {
321321
Logging.LogNullError(nameof(appID), Bot.BotName);
322-
continue;
322+
return;
323323
}
324324

325325
if (GlobalConfig.GlobalBlacklist.Contains(appID) || Program.GlobalConfig.Blacklist.Contains(appID)) {
@@ -329,13 +329,13 @@ private void CheckPage(HtmlDocument htmlDocument) {
329329
HtmlNode timeNode = htmlNode.SelectSingleNode(".//div[@class='badge_title_stats_playtime']");
330330
if (timeNode == null) {
331331
Logging.LogNullError(nameof(timeNode), Bot.BotName);
332-
continue;
332+
return;
333333
}
334334

335335
string hoursString = timeNode.InnerText;
336336
if (string.IsNullOrEmpty(hoursString)) {
337337
Logging.LogNullError(nameof(hoursString), Bot.BotName);
338-
continue;
338+
return;
339339
}
340340

341341
float hours = 0;
@@ -344,7 +344,7 @@ private void CheckPage(HtmlDocument htmlDocument) {
344344
if (match.Success) {
345345
if (!float.TryParse(match.Value, NumberStyles.Number, CultureInfo.InvariantCulture, out hours)) {
346346
Logging.LogNullError(nameof(hours), Bot.BotName);
347-
continue;
347+
return;
348348
}
349349
}
350350

ArchiSteamFarm/MobileAuthenticator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,31 +187,31 @@ internal async Task<HashSet<Confirmation>> GetConfirmations() {
187187
string idString = confirmationNode.GetAttributeValue("data-confid", null);
188188
if (string.IsNullOrEmpty(idString)) {
189189
Logging.LogNullError(nameof(idString), Bot.BotName);
190-
continue;
190+
return null;
191191
}
192192

193193
uint id;
194194
if (!uint.TryParse(idString, out id) || (id == 0)) {
195195
Logging.LogNullError(nameof(id), Bot.BotName);
196-
continue;
196+
return null;
197197
}
198198

199199
string keyString = confirmationNode.GetAttributeValue("data-key", null);
200200
if (string.IsNullOrEmpty(keyString)) {
201201
Logging.LogNullError(nameof(keyString), Bot.BotName);
202-
continue;
202+
return null;
203203
}
204204

205205
ulong key;
206206
if (!ulong.TryParse(keyString, out key) || (key == 0)) {
207207
Logging.LogNullError(nameof(key), Bot.BotName);
208-
continue;
208+
return null;
209209
}
210210

211211
HtmlNode descriptionNode = confirmationNode.SelectSingleNode(".//div[@class='mobileconf_list_entry_description']/div");
212212
if (descriptionNode == null) {
213213
Logging.LogNullError(nameof(descriptionNode), Bot.BotName);
214-
continue;
214+
return null;
215215
}
216216

217217
Steam.ConfirmationDetails.EType type;

0 commit comments

Comments
 (0)