From 6038faaa5fe4591949b4a853d8d9e00c374763b1 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Fri, 23 Dec 2016 03:37:29 +0100 Subject: [PATCH] I like my Steam account --- ArchiSteamFarm/SteamSaleEvent.cs | 7 +++++-- ArchiSteamFarm/Utilities.cs | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ArchiSteamFarm/SteamSaleEvent.cs b/ArchiSteamFarm/SteamSaleEvent.cs index 8674b5b1c..0b893fd86 100644 --- a/ArchiSteamFarm/SteamSaleEvent.cs +++ b/ArchiSteamFarm/SteamSaleEvent.cs @@ -118,8 +118,8 @@ namespace ArchiSteamFarm { Bot.ArchiLogger.LogGenericDebug("Getting SteamAwards page..."); HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetSteamAwardsPage().ConfigureAwait(false); - HtmlNode voteNode = htmlDocument?.DocumentNode.SelectSingleNode("//div[@class='vote_nomination ']"); - if (voteNode == null) { + HtmlNodeCollection voteNodes = htmlDocument?.DocumentNode.SelectNodes("//div[@class='vote_nomination ']"); + if (voteNodes == null) { // Event ended, error or likewise Bot.ArchiLogger.LogGenericDebug("Could not get SteamAwards page, returning"); return; @@ -150,6 +150,9 @@ namespace ArchiSteamFarm { return; } + // Random a game we'll actually vote for, we don't want to make GabeN angry by rigging votes... + HtmlNode voteNode = voteNodes[Utilities.RandomNext(voteNodes.Count)]; + string appIDText = voteNode.GetAttributeValue("data-vote-appid", null); if (string.IsNullOrEmpty(appIDText)) { Bot.ArchiLogger.LogNullError(nameof(appIDText)); diff --git a/ArchiSteamFarm/Utilities.cs b/ArchiSteamFarm/Utilities.cs index 8abb4ce1f..4449b1b9c 100644 --- a/ArchiSteamFarm/Utilities.cs +++ b/ArchiSteamFarm/Utilities.cs @@ -30,6 +30,8 @@ using System.Runtime.CompilerServices; namespace ArchiSteamFarm { internal static class Utilities { + private static readonly Random Random = new Random(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] [SuppressMessage("ReSharper", "UnusedParameter.Global")] internal static void Forget(this object obj) { } @@ -54,5 +56,20 @@ namespace ArchiSteamFarm { } internal static uint GetUnixTime() => (uint) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; + + internal static int RandomNext(int maxWithout) { + if (maxWithout <= 0) { + ASF.ArchiLogger.LogNullError(nameof(maxWithout)); + return -1; + } + + if (maxWithout == 1) { + return 0; + } + + lock (Random) { + return Random.Next(maxWithout); + } + } } } \ No newline at end of file