Disable server-side functionality in custom ASF builds

This commit is contained in:
Archi
2023-12-02 18:37:40 +01:00
parent eef66cebf3
commit 42ceb6d413
5 changed files with 56 additions and 1 deletions

View File

@@ -65,6 +65,10 @@ internal static class Backend {
ArgumentNullException.ThrowIfNull(inventoryRemoved);
ArgumentException.ThrowIfNullOrEmpty(previousInventoryChecksum);
if (SharedInfo.BuildInfo.IsCustomBuild) {
return null;
}
Uri request = new(ArchiNet.URL, "/Api/Listing/AnnounceDiff");
AnnouncementDiffRequest data = new(ASF.GlobalDatabase?.Identifier ?? Guid.NewGuid(), steamID, inventory, inventoryChecksum, acceptedMatchableTypes, totalInventoryCount, matchEverything, ASF.GlobalConfig?.MaxTradeHoldDuration ?? GlobalConfig.DefaultMaxTradeHoldDuration, tradeToken, inventoryRemoved, previousInventoryChecksum, nickname, avatarHash);
@@ -96,6 +100,10 @@ internal static class Backend {
throw new ArgumentOutOfRangeException(nameof(tradeToken));
}
if (SharedInfo.BuildInfo.IsCustomBuild) {
return null;
}
Uri request = new(ArchiNet.URL, "/Api/Listing/Announce/v4");
AnnouncementRequest data = new(ASF.GlobalDatabase?.Identifier ?? Guid.NewGuid(), steamID, inventory, inventoryChecksum, acceptedMatchableTypes, totalInventoryCount, matchEverything, ASF.GlobalConfig?.MaxTradeHoldDuration ?? GlobalConfig.DefaultMaxTradeHoldDuration, tradeToken, nickname, avatarHash);
@@ -127,6 +135,10 @@ internal static class Backend {
throw new ArgumentNullException(nameof(acceptedMatchableTypes));
}
if (SharedInfo.BuildInfo.IsCustomBuild) {
return null;
}
Uri request = new(ArchiNet.URL, "/Api/Listing/Inventories/v2");
Dictionary<string, string> headers = new(1, StringComparer.Ordinal) {
@@ -159,6 +171,10 @@ internal static class Backend {
throw new ArgumentNullException(nameof(realAppIDs));
}
if (SharedInfo.BuildInfo.IsCustomBuild) {
return null;
}
Uri request = new(ArchiNet.URL, "/Api/SetParts/Request");
SetPartsRequest data = new(ASF.GlobalDatabase?.Identifier ?? Guid.NewGuid(), steamID, matchableTypes, realAppIDs);
@@ -170,6 +186,10 @@ internal static class Backend {
ArgumentNullException.ThrowIfNull(bot);
ArgumentNullException.ThrowIfNull(webBrowser);
if (SharedInfo.BuildInfo.IsCustomBuild) {
return null;
}
Uri request = new(ArchiNet.URL, "/Api/Listing/HeartBeat");
HeartBeatRequest data = new(ASF.GlobalDatabase?.Identifier ?? Guid.NewGuid(), bot.SteamID);

View File

@@ -66,6 +66,10 @@ internal sealed class ItemsMatcherPlugin : OfficialPlugin, IBot, IBotCommand2, I
throw new ArgumentOutOfRangeException(nameof(steamID));
}
if (SharedInfo.BuildInfo.IsCustomBuild) {
return null;
}
return await Commands.OnBotCommand(bot, access, args, steamID).ConfigureAwait(false);
}
@@ -90,6 +94,10 @@ internal sealed class ItemsMatcherPlugin : OfficialPlugin, IBot, IBotCommand2, I
await remoteCommunication.DisposeAsync().ConfigureAwait(false);
}
if (SharedInfo.BuildInfo.IsCustomBuild) {
return;
}
remoteCommunication = new RemoteCommunication(bot);
if (!RemoteCommunications.TryAdd(bot, remoteCommunication)) {
@@ -132,6 +140,12 @@ internal sealed class ItemsMatcherPlugin : OfficialPlugin, IBot, IBotCommand2, I
}
public override Task OnLoaded() {
if (SharedInfo.BuildInfo.IsCustomBuild) {
ASF.ArchiLogger.LogGenericWarning(Strings.PluginDisabledCustomBuild);
return Task.CompletedTask;
}
Utilities.WarnAboutIncompleteTranslation(Strings.ResourceManager);
return Task.CompletedTask;

View File

@@ -74,5 +74,11 @@ namespace ArchiSteamFarm.OfficialPlugins.ItemsMatcher.Localization {
return ResourceManager.GetString("ActivelyMatchingSomeConfirmationsFailed", resourceCulture);
}
}
internal static string PluginDisabledCustomBuild {
get {
return ResourceManager.GetString("PluginDisabledCustomBuild", resourceCulture);
}
}
}
}

View File

@@ -82,4 +82,7 @@
<value>Some confirmations have failed, approximately {0} out of {1} trades were sent successfully.</value>
<comment>{0} will be replaced by amount of the trade offers that succeeded (number), {1} will be replaced by amount of the trade offers that were supposed to be sent in total (number)</comment>
</data>
<data name="PluginDisabledCustomBuild" xml:space="preserve">
<value>ItemsMatcherPlugin is not supported in custom ASF builds, the functionality is disabled.</value>
</data>
</root>

View File

@@ -51,6 +51,10 @@ internal static class ArchiNet {
throw new InvalidOperationException(nameof(ASF.WebBrowser));
}
if (SharedInfo.BuildInfo.IsCustomBuild) {
return null;
}
Uri request = new(URL, $"/Api/Checksum/{version}/{variant}");
ObjectResponse<GenericResponse<string>>? response = await ASF.WebBrowser.UrlGetToJsonObject<GenericResponse<string>>(request, cancellationToken: cancellationToken).ConfigureAwait(false);
@@ -67,6 +71,10 @@ internal static class ArchiNet {
throw new ArgumentOutOfRangeException(nameof(steamID));
}
if (SharedInfo.BuildInfo.IsCustomBuild) {
return null;
}
(_, IReadOnlyCollection<ulong>? badBots) = await CachedBadBots.GetValue(ECacheFallback.FailedNow, cancellationToken).ConfigureAwait(false);
return badBots?.Contains(steamID);
@@ -76,7 +84,7 @@ internal static class ArchiNet {
ArgumentNullException.ThrowIfNull(bot);
ArgumentNullException.ThrowIfNull(webBrowser);
if (!bot.IsConnectedAndLoggedOn) {
if (!bot.IsConnectedAndLoggedOn || SharedInfo.BuildInfo.IsCustomBuild) {
return null;
}
@@ -180,6 +188,10 @@ internal static class ArchiNet {
throw new InvalidOperationException(nameof(ASF.WebBrowser));
}
if (SharedInfo.BuildInfo.IsCustomBuild) {
return (false, null);
}
Uri request = new(URL, "/Api/BadBots");
ObjectResponse<GenericResponse<ImmutableHashSet<ulong>>>? response = await ASF.WebBrowser.UrlGetToJsonObject<GenericResponse<ImmutableHashSet<ulong>>>(request, cancellationToken: cancellationToken).ConfigureAwait(false);