Skip to content

Commit

Permalink
Take into account extended_onlyallowrunincountries when deciding upon…
Browse files Browse the repository at this point in the history
… region locks
  • Loading branch information
JustArchi committed Sep 1, 2024
1 parent 9898d47 commit 54a092a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 11 additions & 3 deletions ArchiSteamFarm/Steam/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,14 +1180,14 @@ internal static string FormatBotResponse(string response, string botName) {
return (0, DateTime.MaxValue, true);
}

if ((packageData.ProhibitRunInCountries == null) || packageData.ProhibitRunInCountries.IsEmpty) {
if (((packageData.ProhibitRunInCountries == null) || packageData.ProhibitRunInCountries.IsEmpty) && ((packageData.OnlyAllowRunInCountries == null) || packageData.OnlyAllowRunInCountries.IsEmpty)) {
// No restrictions, we're good to go
regionRestrictedUntil = null;

break;
}

if (packageData.ProhibitRunInCountries.Contains(IPCountryCode)) {
if ((packageData.ProhibitRunInCountries?.Contains(IPCountryCode) == true) || ((packageData.OnlyAllowRunInCountries?.Count > 0) && !packageData.OnlyAllowRunInCountries.Contains(IPCountryCode))) {
// We are restricted by this package, we can only be saved by another package that is not restricted
DateTime regionRestrictedUntilPackage = ownedPackageData.TimeCreated.AddMonths(RegionRestrictionPlayableBlockMonths);

Expand Down Expand Up @@ -1404,6 +1404,14 @@ internal static string FormatBotResponse(string response, string botName) {
}
}

string[]? onlyAllowRunInCountries = null;

string? onlyAllowRunInCountriesText = productInfo.KeyValues["extended"]["onlyallowrunincountries"].AsString();

if (!string.IsNullOrEmpty(onlyAllowRunInCountriesText)) {
onlyAllowRunInCountries = onlyAllowRunInCountriesText.Split(' ', StringSplitOptions.RemoveEmptyEntries);
}

string[]? prohibitRunInCountries = null;

string? prohibitRunInCountriesText = productInfo.KeyValues["extended"]["prohibitrunincountries"].AsString();
Expand All @@ -1412,7 +1420,7 @@ internal static string FormatBotResponse(string response, string botName) {
prohibitRunInCountries = prohibitRunInCountriesText.Split(' ', StringSplitOptions.RemoveEmptyEntries);
}

result[productInfo.ID] = new PackageData(changeNumber, validUntil, appIDs?.ToImmutableHashSet(), prohibitRunInCountries?.ToImmutableHashSet(StringComparer.Ordinal));
result[productInfo.ID] = new PackageData(changeNumber, validUntil, appIDs?.ToImmutableHashSet(), onlyAllowRunInCountries?.ToImmutableHashSet(StringComparer.Ordinal), prohibitRunInCountries?.ToImmutableHashSet(StringComparer.Ordinal));
}

return result;
Expand Down
9 changes: 8 additions & 1 deletion ArchiSteamFarm/Storage/PackageData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,24 @@ public sealed class PackageData {
[JsonRequired]
public uint ChangeNumber { get; private init; }

[JsonInclude]
public ImmutableHashSet<string>? OnlyAllowRunInCountries { get; private init; }

[JsonInclude]
public ImmutableHashSet<string>? ProhibitRunInCountries { get; private init; }

[JsonInclude]
[JsonRequired]
public DateTime ValidUntil { get; private init; }

internal PackageData(uint changeNumber, DateTime validUntil, ImmutableHashSet<uint>? appIDs = null, ImmutableHashSet<string>? prohibitRunInCountries = null) {
internal PackageData(uint changeNumber, DateTime validUntil, ImmutableHashSet<uint>? appIDs = null, ImmutableHashSet<string>? onlyAllowRunInCountries = null, ImmutableHashSet<string>? prohibitRunInCountries = null) {
ArgumentOutOfRangeException.ThrowIfZero(changeNumber);
ArgumentOutOfRangeException.ThrowIfEqual(validUntil, DateTime.MinValue);

ChangeNumber = changeNumber;
ValidUntil = validUntil;
AppIDs = appIDs;
OnlyAllowRunInCountries = onlyAllowRunInCountries;
ProhibitRunInCountries = prohibitRunInCountries;
}

Expand All @@ -59,6 +63,9 @@ private PackageData() { }
[UsedImplicitly]
public bool ShouldSerializeAppIDs() => AppIDs is { IsEmpty: false };

[UsedImplicitly]
public bool ShouldSerializeOnlyAllowRunInCountries() => OnlyAllowRunInCountries is { IsEmpty: false };

[UsedImplicitly]
public bool ShouldSerializeProhibitRunInCountries() => ProhibitRunInCountries is { IsEmpty: false };
}

0 comments on commit 54a092a

Please sign in to comment.