diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index 568c5218d..5e29db3cb 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -231,7 +231,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { } if (!SignedInWithSteam) { - HttpStatusCode? signInWithSteam = await ArchiNet.SignInWithSteam(Bot).ConfigureAwait(false); + HttpStatusCode? signInWithSteam = await ArchiNet.SignInWithSteam(Bot, WebBrowser).ConfigureAwait(false); if (signInWithSteam == null) { // This is actually a network failure, so we'll stop sending heartbeats but not record it as valid check @@ -260,12 +260,16 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { // This is actually a network failure, so we'll stop sending heartbeats but not record it as valid check ShouldSendHeartBeats = false; + Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.ErrorObjectIsNull, nameof(response))); + return; } if (response.StatusCode.IsRedirectionCode()) { ShouldSendHeartBeats = false; + Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, response.StatusCode)); + if (response.FinalUri.Host != ArchiWebHandler.SteamCommunityURL.Host) { ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(response.FinalUri), response.FinalUri)); @@ -282,7 +286,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { // ArchiNet told us that we've sent a bad request, so the process should restart from the beginning at later time ShouldSendHeartBeats = false; - Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, response)); + Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, response.StatusCode)); switch (response.StatusCode) { case HttpStatusCode.Forbidden: @@ -363,6 +367,8 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { if (response.StatusCode.IsRedirectionCode()) { ShouldSendHeartBeats = false; + Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, response.StatusCode)); + if (response.FinalUri.Host != ArchiWebHandler.SteamCommunityURL.Host) { ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(response.FinalUri), response.FinalUri)); @@ -378,6 +384,8 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { if (response.StatusCode.IsClientErrorCode()) { ShouldSendHeartBeats = false; + Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, response.StatusCode)); + return; } @@ -526,7 +534,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { } if (response.Value.Users.IsEmpty) { - Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(response.Value.Users))); + Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(response.Value.Users))); return; } diff --git a/ArchiSteamFarm/Core/ArchiNet.cs b/ArchiSteamFarm/Core/ArchiNet.cs index 4449c8587..e7a40f4ac 100644 --- a/ArchiSteamFarm/Core/ArchiNet.cs +++ b/ArchiSteamFarm/Core/ArchiNet.cs @@ -74,8 +74,9 @@ internal static class ArchiNet { return badBots?.Contains(steamID); } - internal static async Task SignInWithSteam(Bot bot) { + internal static async Task SignInWithSteam(Bot bot, WebBrowser webBrowser) { ArgumentNullException.ThrowIfNull(bot); + ArgumentNullException.ThrowIfNull(webBrowser); if (!bot.IsConnectedAndLoggedOn) { return null; @@ -84,7 +85,7 @@ internal static class ArchiNet { // We expect data or redirection to Steam OpenID Uri authenticateRequest = new(URL, $"/Api/Steam/Authenticate?steamID={bot.SteamID}"); - ObjectResponse>? authenticateResponse = await bot.ArchiWebHandler.WebBrowser.UrlGetToJsonObject>(authenticateRequest, requestOptions: WebBrowser.ERequestOptions.ReturnRedirections | WebBrowser.ERequestOptions.ReturnClientErrors | WebBrowser.ERequestOptions.AllowInvalidBodyOnErrors).ConfigureAwait(false); + ObjectResponse>? authenticateResponse = await webBrowser.UrlGetToJsonObject>(authenticateRequest, requestOptions: WebBrowser.ERequestOptions.ReturnRedirections | WebBrowser.ERequestOptions.ReturnClientErrors | WebBrowser.ERequestOptions.AllowInvalidBodyOnErrors).ConfigureAwait(false); if (authenticateResponse == null) { return null; @@ -152,13 +153,20 @@ internal static class ArchiNet { data.Add(nonceContent, "nonce"); // Accept OpenID request presented and follow redirection back to the data we initially expected - authenticateResponse = await bot.ArchiWebHandler.WebBrowser.UrlPostToJsonObject, MultipartFormDataContent>(loginRequest, data: data, requestOptions: WebBrowser.ERequestOptions.ReturnClientErrors | WebBrowser.ERequestOptions.AllowInvalidBodyOnErrors).ConfigureAwait(false); + BasicResponse? loginResponse = await bot.ArchiWebHandler.WebBrowser.UrlPost(loginRequest, data: data, requestOptions: WebBrowser.ERequestOptions.ReturnRedirections).ConfigureAwait(false); + + if (loginResponse == null) { + return null; + } + + // We've got a final redirection, follow it and complete login procedure + authenticateResponse = await webBrowser.UrlGetToJsonObject>(loginResponse.FinalUri, requestOptions: WebBrowser.ERequestOptions.ReturnClientErrors | WebBrowser.ERequestOptions.AllowInvalidBodyOnErrors).ConfigureAwait(false); if (authenticateResponse == null) { return null; } - if (authenticateResponse.StatusCode.IsClientErrorCode()) { + if (!authenticateResponse.StatusCode.IsSuccessCode()) { return authenticateResponse.StatusCode; }