EXPERIMENTAL: Steam session improvements

1. Make sure that every call to steamcommunity has active session
2. Move whole userspace logic for session handling to ArchiWebHandler (and Bot)
3. Implement session caching and TTL so we won't send IsLoggedIn() on each ArchiWebHandler call
4. Instead of restarting whole steam account, just refresh the session via ArchiWebHandler instead
This commit is contained in:
JustArchi
2016-03-29 14:33:05 +02:00
parent 8fc39a44cd
commit d012255a21
5 changed files with 106 additions and 45 deletions

View File

@@ -187,6 +187,7 @@ namespace ArchiSteamFarm {
CallbackManager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);
CallbackManager.Subscribe<SteamUser.LoginKeyCallback>(OnLoginKey);
CallbackManager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
CallbackManager.Subscribe<SteamUser.WebAPIUserNonceCallback>(OnWebAPIUserNonce);
CallbackManager.Subscribe<ArchiHandler.NotificationsCallback>(OnNotifications);
CallbackManager.Subscribe<ArchiHandler.OfflineMessageCallback>(OnOfflineMessage);
@@ -261,12 +262,23 @@ namespace ArchiSteamFarm {
}
}
internal async Task RestartIfRunning() {
internal async Task<bool> RefreshSession() {
if (!SteamClient.IsConnected) {
return;
return false;
}
await Start().ConfigureAwait(false);
var userNonce = await SteamUser.RequestWebAPIUserNonce();
if (userNonce == null || userNonce.Result != EResult.OK || string.IsNullOrEmpty(userNonce.Nonce)) {
Start().Forget();
return false;
}
if (!ArchiWebHandler.Init(SteamClient, userNonce.Nonce, BotConfig.SteamParentalPIN)) {
Start().Forget();
return false;
}
return true;
}
internal async Task OnFarmingFinished(bool farmedSomething) {
@@ -1300,7 +1312,6 @@ namespace ArchiSteamFarm {
}
Logging.LogGenericInfo("Disconnected from Steam!", BotName);
ArchiWebHandler.OnDisconnected();
CardsFarmer.StopFarming().Forget();
// If we initiated disconnect, do not attempt to reconnect
@@ -1354,15 +1365,6 @@ namespace ArchiSteamFarm {
return;
}
for (byte i = 0; i < WebBrowser.MaxRetries && !ArchiWebHandler.IsInitialized; i++) {
await Utilities.SleepAsync(1000).ConfigureAwait(false);
}
if (!ArchiWebHandler.IsInitialized) {
Logging.LogGenericWarning("Reached timeout while waiting for ArchiWebHandler to initialize!");
return;
}
bool acceptedSomething = false;
foreach (KeyValue guestPass in callback.GuestPasses) {
ulong gid = guestPass["gid"].AsUnsignedLong();
@@ -1538,9 +1540,10 @@ namespace ArchiSteamFarm {
BotConfig.SteamParentalPIN = Program.GetUserInput(Program.EUserInputType.SteamParentalPIN, BotName);
}
if (!await ArchiWebHandler.Init(SteamClient, callback.WebAPIUserNonce, BotConfig.SteamParentalPIN).ConfigureAwait(false)) {
await RestartIfRunning().ConfigureAwait(false);
return;
if (!ArchiWebHandler.Init(SteamClient, callback.WebAPIUserNonce, BotConfig.SteamParentalPIN)) {
if (!await RefreshSession().ConfigureAwait(false)) {
return;
}
}
if (BotConfig.DismissInventoryNotifications) {
@@ -1624,6 +1627,12 @@ namespace ArchiSteamFarm {
}
}
private void OnWebAPIUserNonce(SteamUser.WebAPIUserNonceCallback callback) {
if (callback == null) {
return;
}
}
private async void OnNotifications(ArchiHandler.NotificationsCallback callback) {
if (callback == null || callback.Notifications == null) {
return;