mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2025-12-19 15:58:39 +00:00
Add GiftsLimiterDelay
This commit is contained in:
@@ -45,6 +45,7 @@ namespace ArchiSteamFarm {
|
|||||||
internal static readonly Dictionary<string, Bot> Bots = new Dictionary<string, Bot>();
|
internal static readonly Dictionary<string, Bot> Bots = new Dictionary<string, Bot>();
|
||||||
|
|
||||||
private static readonly uint LoginID = MsgClientLogon.ObfuscationMask; // This must be the same for all ASF bots and all ASF processes
|
private static readonly uint LoginID = MsgClientLogon.ObfuscationMask; // This must be the same for all ASF bots and all ASF processes
|
||||||
|
private static readonly SemaphoreSlim GiftsSemaphore = new SemaphoreSlim(1);
|
||||||
private static readonly SemaphoreSlim LoginSemaphore = new SemaphoreSlim(1);
|
private static readonly SemaphoreSlim LoginSemaphore = new SemaphoreSlim(1);
|
||||||
|
|
||||||
internal readonly string BotName;
|
internal readonly string BotName;
|
||||||
@@ -84,7 +85,7 @@ namespace ArchiSteamFarm {
|
|||||||
initialized = true;
|
initialized = true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logging.LogGenericException(e);
|
Logging.LogGenericException(e);
|
||||||
await Utilities.SleepAsync(1000).ConfigureAwait(false);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,10 +114,18 @@ namespace ArchiSteamFarm {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async Task LimitGiftsRequestsAsync() {
|
||||||
|
await GiftsSemaphore.WaitAsync().ConfigureAwait(false);
|
||||||
|
Task.Run(async () => {
|
||||||
|
await Task.Delay(Program.GlobalConfig.GiftsLimiterDelay * 1000).ConfigureAwait(false);
|
||||||
|
GiftsSemaphore.Release();
|
||||||
|
}).Forget();
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task LimitLoginRequestsAsync() {
|
private static async Task LimitLoginRequestsAsync() {
|
||||||
await LoginSemaphore.WaitAsync().ConfigureAwait(false);
|
await LoginSemaphore.WaitAsync().ConfigureAwait(false);
|
||||||
Task.Run(async () => {
|
Task.Run(async () => {
|
||||||
await Utilities.SleepAsync(Program.GlobalConfig.LoginLimiterDelay * 1000).ConfigureAwait(false);
|
await Task.Delay(Program.GlobalConfig.LoginLimiterDelay * 1000).ConfigureAwait(false);
|
||||||
LoginSemaphore.Release();
|
LoginSemaphore.Release();
|
||||||
}).Forget();
|
}).Forget();
|
||||||
}
|
}
|
||||||
@@ -812,7 +821,7 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
// Schedule the task after some time so user can receive response
|
// Schedule the task after some time so user can receive response
|
||||||
Task.Run(async () => {
|
Task.Run(async () => {
|
||||||
await Utilities.SleepAsync(1000).ConfigureAwait(false);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
Program.Exit();
|
Program.Exit();
|
||||||
}).Forget();
|
}).Forget();
|
||||||
|
|
||||||
@@ -1014,7 +1023,7 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
// Schedule the task after some time so user can receive response
|
// Schedule the task after some time so user can receive response
|
||||||
Task.Run(async () => {
|
Task.Run(async () => {
|
||||||
await Utilities.SleepAsync(1000).ConfigureAwait(false);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
Program.Restart();
|
Program.Restart();
|
||||||
}).Forget();
|
}).Forget();
|
||||||
|
|
||||||
@@ -1532,7 +1541,7 @@ namespace ArchiSteamFarm {
|
|||||||
Logging.LogGenericInfo("Removed expired login key", BotName);
|
Logging.LogGenericInfo("Removed expired login key", BotName);
|
||||||
} else { // If we didn't use login key, InvalidPassword usually means we got captcha or other network-based throttling
|
} else { // If we didn't use login key, InvalidPassword usually means we got captcha or other network-based throttling
|
||||||
Logging.LogGenericInfo("Will retry after 25 minutes...", BotName);
|
Logging.LogGenericInfo("Will retry after 25 minutes...", BotName);
|
||||||
await Utilities.SleepAsync(25 * 60 * 1000).ConfigureAwait(false); // Captcha disappears after around 20 minutes, so we make it 25
|
await Task.Delay(25 * 60 * 1000).ConfigureAwait(false); // Captcha disappears after around 20 minutes, so we make it 25
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1577,7 +1586,10 @@ namespace ArchiSteamFarm {
|
|||||||
bool acceptedSomething = false;
|
bool acceptedSomething = false;
|
||||||
foreach (ulong gid in callback.GuestPasses.Select(guestPass => guestPass["gid"].AsUnsignedLong()).Where(gid => (gid != 0) && !HandledGifts.Contains(gid))) {
|
foreach (ulong gid in callback.GuestPasses.Select(guestPass => guestPass["gid"].AsUnsignedLong()).Where(gid => (gid != 0) && !HandledGifts.Contains(gid))) {
|
||||||
HandledGifts.Add(gid);
|
HandledGifts.Add(gid);
|
||||||
|
|
||||||
Logging.LogGenericInfo("Accepting gift: " + gid + "...", BotName);
|
Logging.LogGenericInfo("Accepting gift: " + gid + "...", BotName);
|
||||||
|
await LimitGiftsRequestsAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
if (await ArchiWebHandler.AcceptGift(gid).ConfigureAwait(false)) {
|
if (await ArchiWebHandler.AcceptGift(gid).ConfigureAwait(false)) {
|
||||||
acceptedSomething = true;
|
acceptedSomething = true;
|
||||||
Logging.LogGenericInfo("Success!", BotName);
|
Logging.LogGenericInfo("Success!", BotName);
|
||||||
@@ -1796,7 +1808,7 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
Trading.CheckTrades().Forget();
|
Trading.CheckTrades().Forget();
|
||||||
|
|
||||||
await Utilities.SleepAsync(1000).ConfigureAwait(false); // Wait a second for eventual PlayingSessionStateCallback
|
await Task.Delay(1000).ConfigureAwait(false); // Wait a second for eventual PlayingSessionStateCallback
|
||||||
CardsFarmer.StartFarming().Forget();
|
CardsFarmer.StartFarming().Forget();
|
||||||
break;
|
break;
|
||||||
case EResult.NoConnection:
|
case EResult.NoConnection:
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
Logging.LogGenericInfo("Waiting for reaction...", Bot.BotName);
|
Logging.LogGenericInfo("Waiting for reaction...", Bot.BotName);
|
||||||
for (byte i = 0; (i < 5) && NowFarming; i++) {
|
for (byte i = 0; (i < 5) && NowFarming; i++) {
|
||||||
await Utilities.SleepAsync(1000).ConfigureAwait(false);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NowFarming) {
|
if (NowFarming) {
|
||||||
|
|||||||
@@ -86,6 +86,9 @@ namespace ArchiSteamFarm {
|
|||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
internal byte InventoryLimiterDelay { get; private set; } = 3;
|
internal byte InventoryLimiterDelay { get; private set; } = 3;
|
||||||
|
|
||||||
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
|
internal byte GiftsLimiterDelay { get; private set; } = 1;
|
||||||
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
internal bool ForceHttp { get; private set; } = false;
|
internal bool ForceHttp { get; private set; } = false;
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ namespace ArchiSteamFarm {
|
|||||||
// We booted successfully so we can now remove old exe file
|
// We booted successfully so we can now remove old exe file
|
||||||
if (File.Exists(oldExeFile)) {
|
if (File.Exists(oldExeFile)) {
|
||||||
// It's entirely possible that old process is still running, allow at least a second before trying to remove the file
|
// It's entirely possible that old process is still running, allow at least a second before trying to remove the file
|
||||||
await Utilities.SleepAsync(1000).ConfigureAwait(false);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File.Delete(oldExeFile);
|
File.Delete(oldExeFile);
|
||||||
@@ -172,7 +172,7 @@ namespace ArchiSteamFarm {
|
|||||||
if (!updateOverride && !GlobalConfig.AutoUpdates) {
|
if (!updateOverride && !GlobalConfig.AutoUpdates) {
|
||||||
Logging.LogGenericInfo("New version is available!");
|
Logging.LogGenericInfo("New version is available!");
|
||||||
Logging.LogGenericInfo("Consider updating yourself!");
|
Logging.LogGenericInfo("Consider updating yourself!");
|
||||||
await Utilities.SleepAsync(5000).ConfigureAwait(false);
|
await Task.Delay(5000).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,11 +248,11 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
if (GlobalConfig.AutoRestart) {
|
if (GlobalConfig.AutoRestart) {
|
||||||
Logging.LogGenericInfo("Restarting...");
|
Logging.LogGenericInfo("Restarting...");
|
||||||
await Utilities.SleepAsync(5000).ConfigureAwait(false);
|
await Task.Delay(5000).ConfigureAwait(false);
|
||||||
Restart();
|
Restart();
|
||||||
} else {
|
} else {
|
||||||
Logging.LogGenericInfo("Exiting...");
|
Logging.LogGenericInfo("Exiting...");
|
||||||
await Utilities.SleepAsync(5000).ConfigureAwait(false);
|
await Task.Delay(5000).ConfigureAwait(false);
|
||||||
Exit();
|
Exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,14 +53,5 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal static uint GetUnixTime() => (uint) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
internal static uint GetUnixTime() => (uint) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||||
|
|
||||||
internal static Task SleepAsync(int miliseconds) {
|
|
||||||
if (miliseconds >= 0) {
|
|
||||||
return Task.Delay(miliseconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
Logging.LogNullError(nameof(miliseconds));
|
|
||||||
return Task.FromResult(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"FarmingDelay": 15,
|
"FarmingDelay": 15,
|
||||||
"LoginLimiterDelay": 10,
|
"LoginLimiterDelay": 10,
|
||||||
"InventoryLimiterDelay": 3,
|
"InventoryLimiterDelay": 3,
|
||||||
|
"GiftsLimiterDelay": 1,
|
||||||
"ForceHttp": false,
|
"ForceHttp": false,
|
||||||
"HttpTimeout": 60,
|
"HttpTimeout": 60,
|
||||||
"WCFHostname": "localhost",
|
"WCFHostname": "localhost",
|
||||||
|
|||||||
@@ -86,6 +86,9 @@ namespace ConfigGenerator {
|
|||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public byte InventoryLimiterDelay { get; set; } = 3;
|
public byte InventoryLimiterDelay { get; set; } = 3;
|
||||||
|
|
||||||
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
|
public byte GiftsLimiterDelay { get; set; } = 1;
|
||||||
|
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public bool ForceHttp { get; set; } = false;
|
public bool ForceHttp { get; set; } = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user