Further HeartBeat() enhancements

This is another great idea I thought about - ArchiHandler already receives all packets from Steam Network, so why bother checking if steam client is still alive if we can make use of the time last message arrived, and send request only when needed.
Extra points for performance benefits for accounts receiving lots of packets, so mainly primary ones with lots of friends/groups
This commit is contained in:
JustArchi
2017-01-23 00:33:08 +01:00
parent 21fa824b60
commit 184029caab
2 changed files with 9 additions and 1 deletions

View File

@@ -37,6 +37,8 @@ namespace ArchiSteamFarm {
internal sealed class ArchiHandler : ClientMsgHandler {
internal const byte MaxGamesPlayedConcurrently = 32; // This is limit introduced by Steam Network
internal DateTime LastPacketReceived { get; private set; } = DateTime.MinValue;
private readonly ArchiLogger ArchiLogger;
internal ArchiHandler(ArchiLogger archiLogger) {
@@ -53,6 +55,8 @@ namespace ArchiSteamFarm {
return;
}
LastPacketReceived = DateTime.Now;
switch (packetMsg.MsgType) {
case EMsg.ClientFSOfflineMessageNotification:
HandleFSOfflineMessageNotification(packetMsg);

View File

@@ -48,6 +48,7 @@ namespace ArchiSteamFarm {
private const uint LoginID = GlobalConfig.DefaultWCFPort; // This must be the same for all ASF bots and all ASF processes
private const ushort MaxSteamMessageLength = 2048;
private const byte MaxTwoFactorCodeFailures = 3;
private const byte MinHeartBeatTTL = GlobalConfig.DefaultConnectionTimeout; // Assume client is responsive for at least that amount of seconds
internal static readonly ConcurrentDictionary<string, Bot> Bots = new ConcurrentDictionary<string, Bot>();
@@ -756,7 +757,10 @@ namespace ArchiSteamFarm {
}
try {
await SteamApps.PICSGetProductInfo(0, null);
if (DateTime.Now.Subtract(ArchiHandler.LastPacketReceived).TotalSeconds > MinHeartBeatTTL) {
await SteamApps.PICSGetProductInfo(0, null);
}
HeartBeatFailures = 0;
Statistics?.OnHeartBeat().Forget();
} catch {