mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 06:00:46 +00:00
Implement enhanced HeartBeat
The objective of this feature is to detect network malfunctions as well as SK2 connection issues early and initiate a reconnect as soon as possible, instead of relying on failures in SK2 code. This is because those failures are very usually coming too late, when connection was already lost for a dozen or more minutes behind, and it also increases likehood of getting weird SK2 freezes like the one in #318. Therefore, let's see how it works, it's possible that I'll revert it later when SK2 code improves or we find a better way to do that. The introduced overhead both CPU-wise and bandwidth-wise is negligible.
This commit is contained in:
@@ -68,7 +68,7 @@ namespace ArchiSteamFarm {
|
||||
private readonly SteamApps SteamApps;
|
||||
private readonly SteamFriends SteamFriends;
|
||||
private readonly SteamUser SteamUser;
|
||||
private readonly Timer AcceptConfirmationsTimer, SendItemsTimer;
|
||||
private readonly Timer AcceptConfirmationsTimer, HeartBeatTimer, SendItemsTimer;
|
||||
private readonly Trading Trading;
|
||||
|
||||
[JsonProperty]
|
||||
@@ -230,6 +230,13 @@ namespace ArchiSteamFarm {
|
||||
CardsFarmer = new CardsFarmer(this);
|
||||
Trading = new Trading(this);
|
||||
|
||||
HeartBeatTimer = new Timer(
|
||||
async e => await HeartBeat().ConfigureAwait(false),
|
||||
null,
|
||||
TimeSpan.FromMinutes(1), // Delay
|
||||
TimeSpan.FromMinutes(1) // Period
|
||||
);
|
||||
|
||||
if ((AcceptConfirmationsTimer == null) && (BotConfig.AcceptConfirmationsPeriod > 0)) {
|
||||
AcceptConfirmationsTimer = new Timer(
|
||||
async e => await AcceptConfirmations(true).ConfigureAwait(false),
|
||||
@@ -267,6 +274,7 @@ namespace ArchiSteamFarm {
|
||||
AcceptConfirmationsTimer?.Dispose();
|
||||
ArchiWebHandler?.Dispose();
|
||||
CardsFarmer?.Dispose();
|
||||
HeartBeatTimer?.Dispose();
|
||||
SendItemsTimer?.Dispose();
|
||||
Trading?.Dispose();
|
||||
}
|
||||
@@ -486,6 +494,23 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HeartBeat() {
|
||||
if (!SteamClient.IsConnected) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await SteamApps.PICSGetProductInfo(0, null);
|
||||
} catch {
|
||||
if (!SteamClient.IsConnected) {
|
||||
return;
|
||||
}
|
||||
|
||||
Logging.LogGenericWarning("Connection to Steam Network lost, reconnecting...", BotName);
|
||||
SteamClient.Connect();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Start() {
|
||||
if (!KeepRunning) {
|
||||
KeepRunning = true;
|
||||
|
||||
Reference in New Issue
Block a user