From 348c43b2599d9378455e5ceb312d7fad36e6c003 Mon Sep 17 00:00:00 2001 From: Archi Date: Sun, 4 Feb 2024 22:28:59 +0100 Subject: [PATCH] Skip spamming ASFB with requests from unlicensed users Check license prior to fetching inventory and sending data to ASFB, will also limit traffic on Steam side. --- .../Backend.cs | 15 +++++++++++++++ .../RemoteCommunication.cs | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Backend.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Backend.cs index 5a1016e8c83c6..047b6befa9889 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Backend.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Backend.cs @@ -114,6 +114,21 @@ internal static string GenerateChecksumFor(IList assetsForListi return Utilities.GenerateChecksumFor(bytes); } + internal static async Task GetLicenseStatus(Guid licenseID, WebBrowser webBrowser) { + ArgumentOutOfRangeException.ThrowIfEqual(licenseID, Guid.Empty); + ArgumentNullException.ThrowIfNull(webBrowser); + + Uri request = new(ArchiNet.URL, "/Api/Licenses/Status"); + + Dictionary headers = new(1, StringComparer.Ordinal) { + { "X-License-Key", licenseID.ToString("N") } + }; + + ObjectResponse? response = await webBrowser.UrlGetToJsonObject(request, headers, requestOptions: WebBrowser.ERequestOptions.ReturnClientErrors | WebBrowser.ERequestOptions.AllowInvalidBodyOnErrors).ConfigureAwait(false); + + return response?.StatusCode; + } + internal static async Task<(HttpStatusCode StatusCode, ImmutableHashSet Users)?> GetListedUsersForMatching(Guid licenseID, Bot bot, WebBrowser webBrowser, IReadOnlyCollection inventory, IReadOnlyCollection acceptedMatchableTypes) { ArgumentOutOfRangeException.ThrowIfEqual(licenseID, Guid.Empty); ArgumentNullException.ThrowIfNull(bot); diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index cb496feff6759..6d07da6c9104f 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -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 assetsForMatching; try {