mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 06:00:46 +00:00
Improve requests utilizing absolute profile URL
In very rare case it's possible that this request could be executed when we don't have SteamID initialized.
This commit is contained in:
@@ -120,7 +120,18 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
internal async Task<bool> ChangePrivacySettings(Steam.UserPrivacy userPrivacy) {
|
||||
string request = GetAbsoluteProfileURL() + "/ajaxsetprivacy";
|
||||
if (userPrivacy == null) {
|
||||
Bot.ArchiLogger.LogNullError(nameof(userPrivacy));
|
||||
return false;
|
||||
}
|
||||
|
||||
string profileURL = await GetAbsoluteProfileURL().ConfigureAwait(false);
|
||||
if (string.IsNullOrEmpty(profileURL)) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
return false;
|
||||
}
|
||||
|
||||
string request = profileURL + "/ajaxsetprivacy";
|
||||
|
||||
// Extra entry for sessionID
|
||||
Dictionary<string, string> data = new Dictionary<string, string>(3) {
|
||||
@@ -1102,7 +1113,13 @@ namespace ArchiSteamFarm {
|
||||
return false;
|
||||
}
|
||||
|
||||
string request = GetAbsoluteProfileURL() + "/ajaxunpackbooster";
|
||||
string profileURL = await GetAbsoluteProfileURL().ConfigureAwait(false);
|
||||
if (string.IsNullOrEmpty(profileURL)) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
return false;
|
||||
}
|
||||
|
||||
string request = profileURL + "/ajaxunpackbooster";
|
||||
|
||||
// Extra entry for sessionID
|
||||
Dictionary<string, string> data = new Dictionary<string, string>(3) {
|
||||
@@ -1114,7 +1131,20 @@ namespace ArchiSteamFarm {
|
||||
return response?.Result == EResult.OK;
|
||||
}
|
||||
|
||||
private string GetAbsoluteProfileURL() => !string.IsNullOrEmpty(VanityURL) ? "/id/" + VanityURL : "/profiles/" + SteamID;
|
||||
private async Task<string> GetAbsoluteProfileURL() {
|
||||
if (SteamID == 0) {
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return string.IsNullOrEmpty(VanityURL) ? "/profiles/" + SteamID : "/id/" + VanityURL;
|
||||
}
|
||||
|
||||
private async Task<string> GetApiKey() {
|
||||
if (CachedApiKey != null) {
|
||||
@@ -1328,13 +1358,19 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsProfileUri(Uri uri) {
|
||||
private async Task<bool> IsProfileUri(Uri uri) {
|
||||
if (uri == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(uri));
|
||||
return false;
|
||||
}
|
||||
|
||||
return uri.AbsolutePath.Equals(GetAbsoluteProfileURL());
|
||||
string profileURL = await GetAbsoluteProfileURL().ConfigureAwait(false);
|
||||
if (string.IsNullOrEmpty(profileURL)) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
return false;
|
||||
}
|
||||
|
||||
return uri.AbsolutePath.Equals(profileURL);
|
||||
}
|
||||
|
||||
private static bool IsSessionExpiredUri(Uri uri) {
|
||||
@@ -1487,7 +1523,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
// Under special brain-damaged circumstances, Steam might just return our own profile as a response to the request, for absolutely no reason whatsoever - just try again in this case
|
||||
if (IsProfileUri(response.FinalUri)) {
|
||||
if (await IsProfileUri(response.FinalUri).ConfigureAwait(false)) {
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.WarningWorkaroundTriggered, nameof(IsProfileUri)));
|
||||
return await UnlockParentalAccountForService(serviceURL, parentalPin, --maxTries).ConfigureAwait(false);
|
||||
}
|
||||
@@ -1511,14 +1547,16 @@ namespace ArchiSteamFarm {
|
||||
await SessionSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
SessionSemaphore.Release();
|
||||
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return null;
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
WebBrowser.HtmlDocumentResponse response = await WebLimitRequest(host, async () => await WebBrowser.UrlGetToHtmlDocument(host + request).ConfigureAwait(false)).ConfigureAwait(false);
|
||||
@@ -1537,7 +1575,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
// Under special brain-damaged circumstances, Steam might just return our own profile as a response to the request, for absolutely no reason whatsoever - just try again in this case
|
||||
if (IsProfileUri(response.FinalUri)) {
|
||||
if (await IsProfileUri(response.FinalUri).ConfigureAwait(false)) {
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.WarningWorkaroundTriggered, nameof(IsProfileUri)));
|
||||
return await UrlGetToHtmlDocumentWithSession(host, request, --maxTries).ConfigureAwait(false);
|
||||
}
|
||||
@@ -1561,14 +1599,16 @@ namespace ArchiSteamFarm {
|
||||
await SessionSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
SessionSemaphore.Release();
|
||||
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return default;
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
WebBrowser.ObjectResponse<T> response = await WebLimitRequest(host, async () => await WebBrowser.UrlGetToJsonObject<T>(host + request).ConfigureAwait(false)).ConfigureAwait(false);
|
||||
@@ -1587,7 +1627,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
// Under special brain-damaged circumstances, Steam might just return our own profile as a response to the request, for absolutely no reason whatsoever - just try again in this case
|
||||
if (IsProfileUri(response.FinalUri)) {
|
||||
if (await IsProfileUri(response.FinalUri).ConfigureAwait(false)) {
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.WarningWorkaroundTriggered, nameof(IsProfileUri)));
|
||||
return await UrlGetToJsonObjectWithSession<T>(host, request, --maxTries).ConfigureAwait(false);
|
||||
}
|
||||
@@ -1611,14 +1651,16 @@ namespace ArchiSteamFarm {
|
||||
await SessionSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
SessionSemaphore.Release();
|
||||
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return null;
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
WebBrowser.XmlDocumentResponse response = await WebLimitRequest(host, async () => await WebBrowser.UrlGetToXmlDocument(host + request).ConfigureAwait(false)).ConfigureAwait(false);
|
||||
@@ -1637,7 +1679,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
// Under special brain-damaged circumstances, Steam might just return our own profile as a response to the request, for absolutely no reason whatsoever - just try again in this case
|
||||
if (IsProfileUri(response.FinalUri)) {
|
||||
if (await IsProfileUri(response.FinalUri).ConfigureAwait(false)) {
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.WarningWorkaroundTriggered, nameof(IsProfileUri)));
|
||||
return await UrlGetToXmlDocumentWithSession(host, request, --maxTries).ConfigureAwait(false);
|
||||
}
|
||||
@@ -1661,14 +1703,16 @@ namespace ArchiSteamFarm {
|
||||
await SessionSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
SessionSemaphore.Release();
|
||||
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return false;
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
WebBrowser.BasicResponse response = await WebLimitRequest(host, async () => await WebBrowser.UrlHead(host + request).ConfigureAwait(false)).ConfigureAwait(false);
|
||||
@@ -1687,7 +1731,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
// Under special brain-damaged circumstances, Steam might just return our own profile as a response to the request, for absolutely no reason whatsoever - just try again in this case
|
||||
if (IsProfileUri(response.FinalUri)) {
|
||||
if (await IsProfileUri(response.FinalUri).ConfigureAwait(false)) {
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.WarningWorkaroundTriggered, nameof(IsProfileUri)));
|
||||
return await UrlHeadWithSession(host, request, --maxTries).ConfigureAwait(false);
|
||||
}
|
||||
@@ -1711,14 +1755,16 @@ namespace ArchiSteamFarm {
|
||||
await SessionSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
SessionSemaphore.Release();
|
||||
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return null;
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (session != ESession.None) {
|
||||
@@ -1766,7 +1812,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
// Under special brain-damaged circumstances, Steam might just return our own profile as a response to the request, for absolutely no reason whatsoever - just try again in this case
|
||||
if (IsProfileUri(response.FinalUri)) {
|
||||
if (await IsProfileUri(response.FinalUri).ConfigureAwait(false)) {
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.WarningWorkaroundTriggered, nameof(IsProfileUri)));
|
||||
return await UrlPostToHtmlDocumentWithSession(host, request, data, referer, session, --maxTries).ConfigureAwait(false);
|
||||
}
|
||||
@@ -1790,14 +1836,16 @@ namespace ArchiSteamFarm {
|
||||
await SessionSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
SessionSemaphore.Release();
|
||||
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return null;
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (session != ESession.None) {
|
||||
@@ -1845,7 +1893,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
// Under special brain-damaged circumstances, Steam might just return our own profile as a response to the request, for absolutely no reason whatsoever - just try again in this case
|
||||
if (IsProfileUri(response.FinalUri)) {
|
||||
if (await IsProfileUri(response.FinalUri).ConfigureAwait(false)) {
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.WarningWorkaroundTriggered, nameof(IsProfileUri)));
|
||||
return await UrlPostToJsonObjectWithSession<T>(host, request, data, referer, session, --maxTries).ConfigureAwait(false);
|
||||
}
|
||||
@@ -1869,14 +1917,16 @@ namespace ArchiSteamFarm {
|
||||
await SessionSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
SessionSemaphore.Release();
|
||||
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return null;
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (session != ESession.None) {
|
||||
@@ -1927,7 +1977,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
// Under special brain-damaged circumstances, Steam might just return our own profile as a response to the request, for absolutely no reason whatsoever - just try again in this case
|
||||
if (IsProfileUri(response.FinalUri)) {
|
||||
if (await IsProfileUri(response.FinalUri).ConfigureAwait(false)) {
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.WarningWorkaroundTriggered, nameof(IsProfileUri)));
|
||||
return await UrlPostToJsonObjectWithSession<T>(host, request, data, referer, session, --maxTries).ConfigureAwait(false);
|
||||
}
|
||||
@@ -1951,14 +2001,16 @@ namespace ArchiSteamFarm {
|
||||
await SessionSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
SessionSemaphore.Release();
|
||||
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return false;
|
||||
for (byte i = 0; (i < Program.GlobalConfig.ConnectionTimeout) && (SteamID == 0) && Bot.IsConnectedAndLoggedOn; i++) {
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (SteamID == 0) {
|
||||
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.ErrorFailingRequest, host + request));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (session != ESession.None) {
|
||||
@@ -2006,7 +2058,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
// Under special brain-damaged circumstances, Steam might just return our own profile as a response to the request, for absolutely no reason whatsoever - just try again in this case
|
||||
if (IsProfileUri(response.FinalUri)) {
|
||||
if (await IsProfileUri(response.FinalUri).ConfigureAwait(false)) {
|
||||
Bot.ArchiLogger.LogGenericDebug(string.Format(Strings.WarningWorkaroundTriggered, nameof(IsProfileUri)));
|
||||
return await UrlPostWithSession(host, request, data, referer, session, --maxTries).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user