Skip to content

Commit

Permalink
Skip spamming ASFB with requests from unlicensed users
Browse files Browse the repository at this point in the history
Check license prior to fetching inventory and sending data to ASFB, will also limit traffic on Steam side.
  • Loading branch information
JustArchi committed Feb 4, 2024
1 parent a23b7e1 commit 348c43b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Backend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ internal static string GenerateChecksumFor(IList<AssetForListing> assetsForListi
return Utilities.GenerateChecksumFor(bytes);
}

internal static async Task<HttpStatusCode?> GetLicenseStatus(Guid licenseID, WebBrowser webBrowser) {
ArgumentOutOfRangeException.ThrowIfEqual(licenseID, Guid.Empty);
ArgumentNullException.ThrowIfNull(webBrowser);

Uri request = new(ArchiNet.URL, "/Api/Licenses/Status");

Dictionary<string, string> headers = new(1, StringComparer.Ordinal) {
{ "X-License-Key", licenseID.ToString("N") }
};

ObjectResponse<GenericResponse>? response = await webBrowser.UrlGetToJsonObject<GenericResponse>(request, headers, requestOptions: WebBrowser.ERequestOptions.ReturnClientErrors | WebBrowser.ERequestOptions.AllowInvalidBodyOnErrors).ConfigureAwait(false);

return response?.StatusCode;
}

internal static async Task<(HttpStatusCode StatusCode, ImmutableHashSet<ListedUser> Users)?> GetListedUsersForMatching(Guid licenseID, Bot bot, WebBrowser webBrowser, IReadOnlyCollection<Asset> inventory, IReadOnlyCollection<Asset.EType> acceptedMatchableTypes) {
ArgumentOutOfRangeException.ThrowIfEqual(licenseID, Guid.Empty);
ArgumentNullException.ThrowIfNull(bot);
Expand Down
14 changes: 14 additions & 0 deletions ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,20 @@ private async void MatchActively(object? state = null) {
try {
Bot.ArchiLogger.LogGenericInfo(Strings.Starting);

HttpStatusCode? licenseStatus = await Backend.GetLicenseStatus(ASF.GlobalConfig.LicenseID.Value, WebBrowser).ConfigureAwait(false);

if (licenseStatus == null) {
Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(licenseStatus)));

return;
}

if (!licenseStatus.Value.IsSuccessCode()) {
Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, licenseStatus.Value));

return;
}

HashSet<Asset> assetsForMatching;

try {
Expand Down

0 comments on commit 348c43b

Please sign in to comment.