From 184029caab9a412094d6e55328953e71e5819e75 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Mon, 23 Jan 2017 00:33:08 +0100 Subject: [PATCH] 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 --- ArchiSteamFarm/ArchiHandler.cs | 4 ++++ ArchiSteamFarm/Bot.cs | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ArchiSteamFarm/ArchiHandler.cs b/ArchiSteamFarm/ArchiHandler.cs index 173c030b2..4b666419f 100644 --- a/ArchiSteamFarm/ArchiHandler.cs +++ b/ArchiSteamFarm/ArchiHandler.cs @@ -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); diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index b6cebcdf7..42823d3e9 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -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 Bots = new ConcurrentDictionary(); @@ -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 {