mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 06:00:46 +00:00
Use new experimental delay everywhere
This commit is contained in:
@@ -210,9 +210,11 @@ namespace ArchiSteamFarm {
|
||||
return;
|
||||
}
|
||||
|
||||
SteamClient.Connect();
|
||||
IsRunning = true;
|
||||
|
||||
Program.LimitSteamRequests();
|
||||
SteamClient.Connect();
|
||||
|
||||
Task.Run(() => HandleCallbacks());
|
||||
}
|
||||
|
||||
@@ -368,7 +370,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
Logging.LogGenericWarning(BotName, "Disconnected from Steam, reconnecting...");
|
||||
await Utilities.SleepAsync(CallbackSleep).ConfigureAwait(false);
|
||||
await Program.LimitSteamRequestsAsync().ConfigureAwait(false);
|
||||
SteamClient.Connect();
|
||||
}
|
||||
|
||||
@@ -528,7 +530,6 @@ namespace ArchiSteamFarm {
|
||||
case EResult.TryAnotherCM:
|
||||
Logging.LogGenericWarning(BotName, "Unable to login to Steam: " + callback.Result + " / " + callback.ExtendedResult + ", retrying...");
|
||||
await Stop().ConfigureAwait(false);
|
||||
await Utilities.SleepAsync(CallbackSleep).ConfigureAwait(false);
|
||||
Start();
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace ArchiSteamFarm {
|
||||
private const string LatestGithubReleaseURL = "https://api.github.com/repos/JustArchi/ArchiSteamFarm/releases/latest";
|
||||
|
||||
internal static readonly object ConsoleLock = new object();
|
||||
private static readonly SemaphoreSlim SteamSemaphore = new SemaphoreSlim(1);
|
||||
private static readonly ManualResetEvent ShutdownResetEvent = new ManualResetEvent(false);
|
||||
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
|
||||
private static readonly string ExecutablePath = Assembly.Location;
|
||||
@@ -89,6 +90,18 @@ namespace ArchiSteamFarm {
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
internal static async Task LimitSteamRequestsAsync() {
|
||||
await SteamSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
await Utilities.SleepAsync(Utilities.GetRandomDelay() * 1000).ConfigureAwait(false); // We must add some delay to not get caught by Steam anty-DoS
|
||||
SteamSemaphore.Release();
|
||||
}
|
||||
|
||||
internal static void LimitSteamRequests() {
|
||||
SteamSemaphore.Wait();
|
||||
Thread.Sleep(Utilities.GetRandomDelay() * 1000); // We must add some delay to not get caught by Steam anty-DoS
|
||||
SteamSemaphore.Release();
|
||||
}
|
||||
|
||||
internal static string GetUserInput(string botLogin, EUserInputType userInputType) {
|
||||
string result;
|
||||
lock (ConsoleLock) {
|
||||
@@ -150,9 +163,8 @@ namespace ArchiSteamFarm {
|
||||
if (!bot.Enabled) {
|
||||
Logging.LogGenericInfo(botName, "Not starting this instance because it's disabled in config file");
|
||||
}
|
||||
Random random = new Random();
|
||||
int randomNumber = random.Next(5, 15); // pick random number between 5 and 15
|
||||
Thread.Sleep(randomNumber*1000); // Try to avoid spamming steam
|
||||
|
||||
LimitSteamRequests(); // We must add some delay to not get caught by Steam anty-DoS
|
||||
}
|
||||
|
||||
// Check if we got any bots running
|
||||
|
||||
@@ -35,10 +35,16 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ArchiSteamFarm {
|
||||
internal static class Utilities {
|
||||
private static readonly Random Random = new Random();
|
||||
|
||||
internal static async Task SleepAsync(int miliseconds) {
|
||||
await Task.Delay(miliseconds).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal static int GetRandomDelay() {
|
||||
return Random.Next(5, 16);
|
||||
}
|
||||
|
||||
internal static ulong OnlyNumbers(string inputString) {
|
||||
if (string.IsNullOrEmpty(inputString)) {
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user