mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-06 17:10:13 +00:00
Implement latest ArchiBoT HeartBeat() code
This commit is contained in:
@@ -99,10 +99,9 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
private Timer AcceptConfirmationsTimer;
|
private Timer AcceptConfirmationsTimer;
|
||||||
private string AuthCode;
|
private string AuthCode;
|
||||||
private Timer ConnectingTimeoutTimer;
|
private Timer ConnectionFailureTimer;
|
||||||
private Timer FamilySharingInactivityTimer;
|
private Timer FamilySharingInactivityTimer;
|
||||||
private bool FirstTradeSent;
|
private bool FirstTradeSent;
|
||||||
private byte HeartBeatFailures;
|
|
||||||
private EResult LastLogOnResult;
|
private EResult LastLogOnResult;
|
||||||
private ulong LibraryLockedBySteamID;
|
private ulong LibraryLockedBySteamID;
|
||||||
private bool LootingAllowed = true;
|
private bool LootingAllowed = true;
|
||||||
@@ -243,7 +242,7 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
// Those are objects that might be null and the check should be in-place
|
// Those are objects that might be null and the check should be in-place
|
||||||
AcceptConfirmationsTimer?.Dispose();
|
AcceptConfirmationsTimer?.Dispose();
|
||||||
ConnectingTimeoutTimer?.Dispose();
|
ConnectionFailureTimer?.Dispose();
|
||||||
FamilySharingInactivityTimer?.Dispose();
|
FamilySharingInactivityTimer?.Dispose();
|
||||||
SendItemsTimer?.Dispose();
|
SendItemsTimer?.Dispose();
|
||||||
Statistics?.Dispose();
|
Statistics?.Dispose();
|
||||||
@@ -650,16 +649,8 @@ namespace ArchiSteamFarm {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ConnectingTimeoutTimer == null) {
|
|
||||||
ConnectingTimeoutTimer = new Timer(
|
|
||||||
async e => await Connect().ConfigureAwait(false),
|
|
||||||
null,
|
|
||||||
TimeSpan.FromMinutes(1), // Delay
|
|
||||||
TimeSpan.FromMinutes(1) // Period
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ArchiLogger.LogGenericInfo(Strings.BotConnecting);
|
ArchiLogger.LogGenericInfo(Strings.BotConnecting);
|
||||||
|
InitConnectionFailureTimer();
|
||||||
SteamClient.Connect();
|
SteamClient.Connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -678,11 +669,7 @@ namespace ArchiSteamFarm {
|
|||||||
|
|
||||||
private void Disconnect() {
|
private void Disconnect() {
|
||||||
lock (SteamClient) {
|
lock (SteamClient) {
|
||||||
if (ConnectingTimeoutTimer != null) {
|
StopConnectionFailureTimer();
|
||||||
ConnectingTimeoutTimer.Dispose();
|
|
||||||
ConnectingTimeoutTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
SteamClient.Disconnect();
|
SteamClient.Disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -721,7 +708,7 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task HeartBeat() {
|
private async Task HeartBeat() {
|
||||||
if (!IsConnectedAndLoggedOn || (HeartBeatFailures == byte.MaxValue)) {
|
if (!IsConnectedAndLoggedOn) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -729,15 +716,7 @@ namespace ArchiSteamFarm {
|
|||||||
await SteamApps.PICSGetProductInfo(0, null);
|
await SteamApps.PICSGetProductInfo(0, null);
|
||||||
Statistics?.OnHeartBeat().Forget();
|
Statistics?.OnHeartBeat().Forget();
|
||||||
} catch {
|
} catch {
|
||||||
if (!IsConnectedAndLoggedOn || (HeartBeatFailures == byte.MaxValue)) {
|
if (!IsConnectedAndLoggedOn) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (++HeartBeatFailures >= 15) {
|
|
||||||
HeartBeatFailures = byte.MaxValue;
|
|
||||||
ArchiLogger.LogGenericError(Strings.BotHeartBeatFailed);
|
|
||||||
Destroy(true);
|
|
||||||
new Bot(BotName).Forget();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -933,16 +912,41 @@ namespace ArchiSteamFarm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void InitPermanentConnectionFailure() {
|
||||||
|
ArchiLogger.LogGenericError(Strings.BotHeartBeatFailed);
|
||||||
|
Destroy(true);
|
||||||
|
new Bot(BotName).Forget();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitConnectionFailureTimer() {
|
||||||
|
if (ConnectionFailureTimer != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectionFailureTimer = new Timer(
|
||||||
|
e => InitPermanentConnectionFailure(),
|
||||||
|
null,
|
||||||
|
TimeSpan.FromMinutes(2), // Delay
|
||||||
|
Timeout.InfiniteTimeSpan // Period
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopConnectionFailureTimer() {
|
||||||
|
if (ConnectionFailureTimer == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectionFailureTimer.Dispose();
|
||||||
|
ConnectionFailureTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnConnected(SteamClient.ConnectedCallback callback) {
|
private void OnConnected(SteamClient.ConnectedCallback callback) {
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
ArchiLogger.LogNullError(nameof(callback));
|
ArchiLogger.LogNullError(nameof(callback));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ConnectingTimeoutTimer != null) {
|
StopConnectionFailureTimer();
|
||||||
ConnectingTimeoutTimer.Dispose();
|
|
||||||
ConnectingTimeoutTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback.Result != EResult.OK) {
|
if (callback.Result != EResult.OK) {
|
||||||
ArchiLogger.LogGenericError(string.Format(Strings.BotUnableToConnect, callback.Result));
|
ArchiLogger.LogGenericError(string.Format(Strings.BotUnableToConnect, callback.Result));
|
||||||
@@ -999,6 +1003,8 @@ namespace ArchiSteamFarm {
|
|||||||
Username = BotConfig.SteamLogin
|
Username = BotConfig.SteamLogin
|
||||||
};
|
};
|
||||||
|
|
||||||
|
InitConnectionFailureTimer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SteamUser.LogOn(logOnDetails);
|
SteamUser.LogOn(logOnDetails);
|
||||||
} catch {
|
} catch {
|
||||||
@@ -1013,15 +1019,9 @@ namespace ArchiSteamFarm {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ConnectingTimeoutTimer != null) {
|
|
||||||
ConnectingTimeoutTimer.Dispose();
|
|
||||||
ConnectingTimeoutTimer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
HeartBeatFailures = 0;
|
|
||||||
|
|
||||||
EResult lastLogOnResult = LastLogOnResult;
|
EResult lastLogOnResult = LastLogOnResult;
|
||||||
LastLogOnResult = EResult.Invalid;
|
LastLogOnResult = EResult.Invalid;
|
||||||
|
StopConnectionFailureTimer();
|
||||||
|
|
||||||
ArchiLogger.LogGenericInfo(Strings.BotDisconnected);
|
ArchiLogger.LogGenericInfo(Strings.BotDisconnected);
|
||||||
|
|
||||||
@@ -1236,6 +1236,8 @@ namespace ArchiSteamFarm {
|
|||||||
// Keep LastLogOnResult for OnDisconnected()
|
// Keep LastLogOnResult for OnDisconnected()
|
||||||
LastLogOnResult = callback.Result;
|
LastLogOnResult = callback.Result;
|
||||||
|
|
||||||
|
StopConnectionFailureTimer();
|
||||||
|
|
||||||
switch (callback.Result) {
|
switch (callback.Result) {
|
||||||
case EResult.AccountLogonDenied:
|
case EResult.AccountLogonDenied:
|
||||||
AuthCode = Program.GetUserInput(ASF.EUserInputType.SteamGuard, BotName);
|
AuthCode = Program.GetUserInput(ASF.EUserInputType.SteamGuard, BotName);
|
||||||
|
|||||||
Reference in New Issue
Block a user