mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2025-12-16 14:30:31 +00:00
Initial code cleanup
This commit is contained in:
@@ -278,7 +278,7 @@
|
|||||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=WrongIndentSize/@EntryIndexedValue">WARNING</s:String>
|
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=WrongIndentSize/@EntryIndexedValue">WARNING</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=WrongMetadataUse/@EntryIndexedValue">WARNING</s:String>
|
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=WrongMetadataUse/@EntryIndexedValue">WARNING</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=Xaml_002EIgnoredPathHighlighting/@EntryIndexedValue">WARNING</s:String>
|
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=Xaml_002EIgnoredPathHighlighting/@EntryIndexedValue">WARNING</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/Highlighting/ValueAnalysisMode/@EntryValue">PESSIMISTIC</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Archi/@EntryIndexedValue"><?xml version="1.0" encoding="utf-16"?><Profile name="Archi"><CSReorderTypeMembers>True</CSReorderTypeMembers><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><HtmlReformatCode>True</HtmlReformatCode><JsInsertSemicolon>True</JsInsertSemicolon><FormatAttributeQuoteDescriptor>True</FormatAttributeQuoteDescriptor><CorrectVariableKindsDescriptor>True</CorrectVariableKindsDescriptor><VariablesToInnerScopesDescriptor>True</VariablesToInnerScopesDescriptor><StringToTemplatesDescriptor>True</StringToTemplatesDescriptor><JsReformatCode>True</JsReformatCode><JsFormatDocComments>True</JsFormatDocComments><RemoveRedundantQualifiersTs>True</RemoveRedundantQualifiersTs><OptimizeImportsTs>True</OptimizeImportsTs><OptimizeReferenceCommentsTs>True</OptimizeReferenceCommentsTs><PublicModifierStyleTs>True</PublicModifierStyleTs><ExplicitAnyTs>True</ExplicitAnyTs><TypeAnnotationStyleTs>True</TypeAnnotationStyleTs><RelativePathStyleTs>True</RelativePathStyleTs><AsInsteadOfCastTs>True</AsInsteadOfCastTs><XMLReformatCode>True</XMLReformatCode><CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="True" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="True" ArrangeArgumentsStyle="True" ArrangeCodeBodyStyle="True" ArrangeVarStyle="True" /><RemoveCodeRedundanciesVB>True</RemoveCodeRedundanciesVB><CssAlphabetizeProperties>True</CssAlphabetizeProperties><VBOptimizeImports>True</VBOptimizeImports><VBShortenReferences>True</VBShortenReferences><RemoveCodeRedundancies>True</RemoveCodeRedundancies><CSUseAutoProperty>True</CSUseAutoProperty><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSMakeAutoPropertyGetOnly>True</CSMakeAutoPropertyGetOnly><CSArrangeQualifiers>True</CSArrangeQualifiers><CSFixBuiltinTypeReferences>True</CSFixBuiltinTypeReferences><CssReformatCode>True</CssReformatCode><VBReformatCode>True</VBReformatCode><VBFormatDocComments>True</VBFormatDocComments><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><CSharpFormatDocComments>True</CSharpFormatDocComments><CSUpdateFileHeader>True</CSUpdateFileHeader></Profile></s:String>
|
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Archi/@EntryIndexedValue"><?xml version="1.0" encoding="utf-16"?><Profile name="Archi"><CSReorderTypeMembers>True</CSReorderTypeMembers><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><HtmlReformatCode>True</HtmlReformatCode><JsInsertSemicolon>True</JsInsertSemicolon><FormatAttributeQuoteDescriptor>True</FormatAttributeQuoteDescriptor><CorrectVariableKindsDescriptor>True</CorrectVariableKindsDescriptor><VariablesToInnerScopesDescriptor>True</VariablesToInnerScopesDescriptor><StringToTemplatesDescriptor>True</StringToTemplatesDescriptor><JsReformatCode>True</JsReformatCode><JsFormatDocComments>True</JsFormatDocComments><RemoveRedundantQualifiersTs>True</RemoveRedundantQualifiersTs><OptimizeImportsTs>True</OptimizeImportsTs><OptimizeReferenceCommentsTs>True</OptimizeReferenceCommentsTs><PublicModifierStyleTs>True</PublicModifierStyleTs><ExplicitAnyTs>True</ExplicitAnyTs><TypeAnnotationStyleTs>True</TypeAnnotationStyleTs><RelativePathStyleTs>True</RelativePathStyleTs><AsInsteadOfCastTs>True</AsInsteadOfCastTs><XMLReformatCode>True</XMLReformatCode><CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="True" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="True" ArrangeArgumentsStyle="True" ArrangeCodeBodyStyle="True" ArrangeVarStyle="True" /><RemoveCodeRedundanciesVB>True</RemoveCodeRedundanciesVB><CssAlphabetizeProperties>True</CssAlphabetizeProperties><VBOptimizeImports>True</VBOptimizeImports><VBShortenReferences>True</VBShortenReferences><RemoveCodeRedundancies>True</RemoveCodeRedundancies><CSUseAutoProperty>True</CSUseAutoProperty><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSMakeAutoPropertyGetOnly>True</CSMakeAutoPropertyGetOnly><CSArrangeQualifiers>True</CSArrangeQualifiers><CSFixBuiltinTypeReferences>True</CSFixBuiltinTypeReferences><CssReformatCode>True</CssReformatCode><VBReformatCode>True</VBReformatCode><VBFormatDocComments>True</VBFormatDocComments><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><CSharpFormatDocComments>True</CSharpFormatDocComments><CSUpdateFileHeader>True</CSUpdateFileHeader></Profile></s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue">Archi</s:String>
|
<s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue">Archi</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CommonFormatter/ALIGNMENT_TAB_FILL_STYLE/@EntryValue">USE_TABS_ONLY</s:String>
|
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CommonFormatter/ALIGNMENT_TAB_FILL_STYLE/@EntryValue">USE_TABS_ONLY</s:String>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
|
<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
|
<LangVersion>9</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -28,22 +28,22 @@ namespace ArchiSteamFarm.Collections {
|
|||||||
public T Current => Enumerator.Current;
|
public T Current => Enumerator.Current;
|
||||||
|
|
||||||
private readonly IEnumerator<T> Enumerator;
|
private readonly IEnumerator<T> Enumerator;
|
||||||
private readonly IDisposable Lock;
|
private readonly IDisposable LockObject;
|
||||||
|
|
||||||
object? IEnumerator.Current => Current;
|
object? IEnumerator.Current => Current;
|
||||||
|
|
||||||
internal ConcurrentEnumerator(IReadOnlyCollection<T> collection, IDisposable @lock) {
|
internal ConcurrentEnumerator(IReadOnlyCollection<T> collection, IDisposable lockObject) {
|
||||||
if ((collection == null) || (@lock == null)) {
|
if (collection == null) {
|
||||||
throw new ArgumentNullException(nameof(collection) + " || " + nameof(@lock));
|
throw new ArgumentNullException(nameof(collection));
|
||||||
}
|
}
|
||||||
|
|
||||||
Lock = @lock;
|
LockObject = lockObject ?? throw new ArgumentNullException(nameof(lockObject));
|
||||||
Enumerator = collection.GetEnumerator();
|
Enumerator = collection.GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
Enumerator.Dispose();
|
Enumerator.Dispose();
|
||||||
Lock.Dispose();
|
LockObject.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MoveNext() => Enumerator.MoveNext();
|
public bool MoveNext() => Enumerator.MoveNext();
|
||||||
|
|||||||
@@ -128,13 +128,27 @@ namespace ArchiSteamFarm.Collections {
|
|||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
|
|
||||||
// We use Count() and not Any() because we must ensure full loop pass
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public bool AddRange(IEnumerable<T> items) => items.Count(Add) > 0;
|
public bool AddRange(IEnumerable<T> items) {
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
foreach (T _ in items.Where(Add)) {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// We use Count() and not Any() because we must ensure full loop pass
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public bool RemoveRange(IEnumerable<T> items) => items.Count(Remove) > 0;
|
public bool RemoveRange(IEnumerable<T> items) {
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
foreach (T _ in items.Where(Remove)) {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public bool ReplaceIfNeededWith(IReadOnlyCollection<T> other) {
|
public bool ReplaceIfNeededWith(IReadOnlyCollection<T> other) {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ArchiSteamFarm.Localization;
|
using ArchiSteamFarm.Localization;
|
||||||
@@ -73,7 +74,7 @@ namespace ArchiSteamFarm.Helpers {
|
|||||||
case EFallback.SuccessPreviously:
|
case EFallback.SuccessPreviously:
|
||||||
return (false, InitializedValue);
|
return (false, InitializedValue);
|
||||||
default:
|
default:
|
||||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(fallback), fallback));
|
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(fallback), fallback));
|
||||||
|
|
||||||
goto case EFallback.DefaultForType;
|
goto case EFallback.DefaultForType;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace ArchiSteamFarm.Helpers {
|
|||||||
void ICrossProcessSemaphore.Release() {
|
void ICrossProcessSemaphore.Release() {
|
||||||
lock (LocalSemaphore) {
|
lock (LocalSemaphore) {
|
||||||
if (FileLock == null) {
|
if (FileLock == null) {
|
||||||
throw new ArgumentNullException(nameof(FileLock));
|
throw new InvalidOperationException(nameof(FileLock));
|
||||||
}
|
}
|
||||||
|
|
||||||
FileLock.Dispose();
|
FileLock.Dispose();
|
||||||
@@ -75,7 +75,7 @@ namespace ArchiSteamFarm.Helpers {
|
|||||||
try {
|
try {
|
||||||
lock (LocalSemaphore) {
|
lock (LocalSemaphore) {
|
||||||
if (FileLock != null) {
|
if (FileLock != null) {
|
||||||
throw new ArgumentNullException(nameof(FileLock));
|
throw new InvalidOperationException(nameof(FileLock));
|
||||||
}
|
}
|
||||||
|
|
||||||
EnsureFileExists();
|
EnsureFileExists();
|
||||||
@@ -120,7 +120,7 @@ namespace ArchiSteamFarm.Helpers {
|
|||||||
try {
|
try {
|
||||||
lock (LocalSemaphore) {
|
lock (LocalSemaphore) {
|
||||||
if (FileLock != null) {
|
if (FileLock != null) {
|
||||||
throw new ArgumentNullException(nameof(FileLock));
|
throw new InvalidOperationException(nameof(FileLock));
|
||||||
}
|
}
|
||||||
|
|
||||||
EnsureFileExists();
|
EnsureFileExists();
|
||||||
|
|||||||
@@ -34,7 +34,11 @@ namespace ArchiSteamFarm.Helpers {
|
|||||||
private bool ReadOnly;
|
private bool ReadOnly;
|
||||||
private bool SavingScheduled;
|
private bool SavingScheduled;
|
||||||
|
|
||||||
public virtual void Dispose() => FileSemaphore.Dispose();
|
public virtual void Dispose() {
|
||||||
|
FileSemaphore.Dispose();
|
||||||
|
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
protected async Task Save() {
|
protected async Task Save() {
|
||||||
if (string.IsNullOrEmpty(FilePath)) {
|
if (string.IsNullOrEmpty(FilePath)) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -46,7 +47,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(request.StringToEncrypt)) {
|
if (string.IsNullOrEmpty(request.StringToEncrypt)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request.StringToEncrypt))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.StringToEncrypt))));
|
||||||
}
|
}
|
||||||
|
|
||||||
string? encryptedString = Actions.Encrypt(request.CryptoMethod, request.StringToEncrypt!);
|
string? encryptedString = Actions.Encrypt(request.CryptoMethod, request.StringToEncrypt!);
|
||||||
@@ -84,7 +85,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(request.StringToHash)) {
|
if (string.IsNullOrEmpty(request.StringToHash)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request.StringToHash))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.StringToHash))));
|
||||||
}
|
}
|
||||||
|
|
||||||
string hash = Actions.Hash(request.HashingMethod, request.StringToHash!);
|
string hash = Actions.Hash(request.HashingMethod, request.StringToHash!);
|
||||||
@@ -100,12 +101,16 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)]
|
||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||||
public async Task<ActionResult<GenericResponse>> ASFPost([FromBody] ASFRequest request) {
|
public async Task<ActionResult<GenericResponse>> ASFPost([FromBody] ASFRequest request) {
|
||||||
if ((request == null) || (ASF.GlobalConfig == null)) {
|
if (request == null) {
|
||||||
throw new ArgumentNullException(nameof(request) + " || " + nameof(ASF.GlobalConfig));
|
throw new ArgumentNullException(nameof(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ASF.GlobalConfig == null) {
|
||||||
|
throw new InvalidOperationException(nameof(ASF.GlobalConfig));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.GlobalConfig == null) {
|
if (request.GlobalConfig == null) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request.GlobalConfig))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.GlobalConfig))));
|
||||||
}
|
}
|
||||||
|
|
||||||
(bool valid, string? errorMessage) = request.GlobalConfig.CheckValidation();
|
(bool valid, string? errorMessage) = request.GlobalConfig.CheckValidation();
|
||||||
@@ -137,7 +142,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
if (string.IsNullOrEmpty(filePath)) {
|
if (string.IsNullOrEmpty(filePath)) {
|
||||||
ASF.ArchiLogger.LogNullError(filePath);
|
ASF.ArchiLogger.LogNullError(filePath);
|
||||||
|
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(filePath))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(filePath))));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = await GlobalConfig.Write(filePath, request.GlobalConfig).ConfigureAwait(false);
|
bool result = await GlobalConfig.Write(filePath, request.GlobalConfig).ConfigureAwait(false);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -48,7 +49,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
||||||
|
|
||||||
if ((bots == null) || (bots.Count == 0)) {
|
if ((bots == null) || (bots.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botNames)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<bool> results = await Utilities.InParallel(bots.Select(bot => bot.DeleteAllRelatedFiles())).ConfigureAwait(false);
|
IList<bool> results = await Utilities.InParallel(bots.Select(bot => bot.DeleteAllRelatedFiles())).ConfigureAwait(false);
|
||||||
@@ -70,7 +71,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
||||||
|
|
||||||
if (bots == null) {
|
if (bots == null) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(bots))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(bots))));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(new GenericResponse<IReadOnlyDictionary<string, Bot>>(bots.Where(bot => !string.IsNullOrEmpty(bot.BotName)).ToDictionary(bot => bot.BotName, bot => bot, Bot.BotsComparer)!));
|
return Ok(new GenericResponse<IReadOnlyDictionary<string, Bot>>(bots.Where(bot => !string.IsNullOrEmpty(bot.BotName)).ToDictionary(bot => bot.BotName, bot => bot, Bot.BotsComparer)!));
|
||||||
@@ -84,12 +85,20 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
[ProducesResponseType(typeof(GenericResponse<IReadOnlyDictionary<string, bool>>), (int) HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(GenericResponse<IReadOnlyDictionary<string, bool>>), (int) HttpStatusCode.OK)]
|
||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||||
public async Task<ActionResult<GenericResponse>> BotPost(string botNames, [FromBody] BotRequest request) {
|
public async Task<ActionResult<GenericResponse>> BotPost(string botNames, [FromBody] BotRequest request) {
|
||||||
if (string.IsNullOrEmpty(botNames) || (request == null) || (Bot.Bots == null)) {
|
if (string.IsNullOrEmpty(botNames)) {
|
||||||
throw new ArgumentNullException(nameof(botNames) + " || " + nameof(request) + " || " + nameof(Bot.Bots));
|
throw new ArgumentNullException(nameof(botNames));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request == null) {
|
||||||
|
throw new ArgumentNullException(nameof(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Bot.Bots == null) {
|
||||||
|
throw new InvalidOperationException(nameof(Bot.Bots));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.BotConfig == null) {
|
if (request.BotConfig == null) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request.BotConfig))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.BotConfig))));
|
||||||
}
|
}
|
||||||
|
|
||||||
(bool valid, string? errorMessage) = request.BotConfig.CheckValidation();
|
(bool valid, string? errorMessage) = request.BotConfig.CheckValidation();
|
||||||
@@ -120,7 +129,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
request.BotConfig.SteamParentalCode = bot.BotConfig.SteamParentalCode;
|
request.BotConfig.SteamParentalCode = bot.BotConfig.SteamParentalCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((bot.BotConfig.AdditionalProperties != null) && (bot.BotConfig.AdditionalProperties.Count > 0)) {
|
if (bot.BotConfig.AdditionalProperties?.Count > 0) {
|
||||||
request.BotConfig.AdditionalProperties ??= new Dictionary<string, JToken>(bot.BotConfig.AdditionalProperties.Count, bot.BotConfig.AdditionalProperties.Comparer);
|
request.BotConfig.AdditionalProperties ??= new Dictionary<string, JToken>(bot.BotConfig.AdditionalProperties.Count, bot.BotConfig.AdditionalProperties.Comparer);
|
||||||
|
|
||||||
foreach ((string key, JToken value) in bot.BotConfig.AdditionalProperties.Where(property => !request.BotConfig.AdditionalProperties.ContainsKey(property.Key))) {
|
foreach ((string key, JToken value) in bot.BotConfig.AdditionalProperties.Where(property => !request.BotConfig.AdditionalProperties.ContainsKey(property.Key))) {
|
||||||
@@ -136,7 +145,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
if (string.IsNullOrEmpty(filePath)) {
|
if (string.IsNullOrEmpty(filePath)) {
|
||||||
ASF.ArchiLogger.LogNullError(filePath);
|
ASF.ArchiLogger.LogNullError(filePath);
|
||||||
|
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(filePath))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(filePath))));
|
||||||
}
|
}
|
||||||
|
|
||||||
result[botName] = await BotConfig.Write(filePath, request.BotConfig).ConfigureAwait(false);
|
result[botName] = await BotConfig.Write(filePath, request.BotConfig).ConfigureAwait(false);
|
||||||
@@ -159,7 +168,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
||||||
|
|
||||||
if ((bots == null) || (bots.Count == 0)) {
|
if ((bots == null) || (bots.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botNames)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<bool> results = await Utilities.InParallel(bots.Select(bot => Task.Run(bot.DeleteRedeemedKeysFiles))).ConfigureAwait(false);
|
IList<bool> results = await Utilities.InParallel(bots.Select(bot => Task.Run(bot.DeleteRedeemedKeysFiles))).ConfigureAwait(false);
|
||||||
@@ -181,7 +190,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
||||||
|
|
||||||
if ((bots == null) || (bots.Count == 0)) {
|
if ((bots == null) || (bots.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botNames)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<(Dictionary<string, string>? UnusedKeys, Dictionary<string, string>? UsedKeys)> results = await Utilities.InParallel(bots.Select(bot => bot.GetUsedAndUnusedKeys())).ConfigureAwait(false);
|
IList<(Dictionary<string, string>? UnusedKeys, Dictionary<string, string>? UsedKeys)> results = await Utilities.InParallel(bots.Select(bot => bot.GetUsedAndUnusedKeys())).ConfigureAwait(false);
|
||||||
@@ -204,24 +213,28 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
[ProducesResponseType(typeof(GenericResponse<IReadOnlyDictionary<string, IOrderedDictionary>>), (int) HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(GenericResponse<IReadOnlyDictionary<string, IOrderedDictionary>>), (int) HttpStatusCode.OK)]
|
||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||||
public async Task<ActionResult<GenericResponse>> GamesToRedeemInBackgroundPost(string botNames, [FromBody] BotGamesToRedeemInBackgroundRequest request) {
|
public async Task<ActionResult<GenericResponse>> GamesToRedeemInBackgroundPost(string botNames, [FromBody] BotGamesToRedeemInBackgroundRequest request) {
|
||||||
if (string.IsNullOrEmpty(botNames) || (request == null)) {
|
if (string.IsNullOrEmpty(botNames)) {
|
||||||
throw new ArgumentNullException(nameof(botNames) + " || " + nameof(request));
|
throw new ArgumentNullException(nameof(botNames));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request == null) {
|
||||||
|
throw new ArgumentNullException(nameof(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((request.GamesToRedeemInBackground == null) || (request.GamesToRedeemInBackground.Count == 0)) {
|
if ((request.GamesToRedeemInBackground == null) || (request.GamesToRedeemInBackground.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request.GamesToRedeemInBackground))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.GamesToRedeemInBackground))));
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
||||||
|
|
||||||
if ((bots == null) || (bots.Count == 0)) {
|
if ((bots == null) || (bots.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botNames)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IOrderedDictionary validGamesToRedeemInBackground = Bot.ValidateGamesToRedeemInBackground(request.GamesToRedeemInBackground);
|
IOrderedDictionary validGamesToRedeemInBackground = Bot.ValidateGamesToRedeemInBackground(request.GamesToRedeemInBackground);
|
||||||
|
|
||||||
if (validGamesToRedeemInBackground.Count == 0) {
|
if (validGamesToRedeemInBackground.Count == 0) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(validGamesToRedeemInBackground))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(validGamesToRedeemInBackground))));
|
||||||
}
|
}
|
||||||
|
|
||||||
await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.AddGamesToRedeemInBackground(validGamesToRedeemInBackground)))).ConfigureAwait(false);
|
await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.AddGamesToRedeemInBackground(validGamesToRedeemInBackground)))).ConfigureAwait(false);
|
||||||
@@ -243,18 +256,22 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)]
|
||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||||
public async Task<ActionResult<GenericResponse>> InputPost(string botNames, [FromBody] BotInputRequest request) {
|
public async Task<ActionResult<GenericResponse>> InputPost(string botNames, [FromBody] BotInputRequest request) {
|
||||||
if (string.IsNullOrEmpty(botNames) || (request == null)) {
|
if (string.IsNullOrEmpty(botNames)) {
|
||||||
throw new ArgumentNullException(nameof(botNames) + " || " + nameof(request));
|
throw new ArgumentNullException(nameof(botNames));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request == null) {
|
||||||
|
throw new ArgumentNullException(nameof(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((request.Type == ASF.EUserInputType.None) || !Enum.IsDefined(typeof(ASF.EUserInputType), request.Type) || string.IsNullOrEmpty(request.Value)) {
|
if ((request.Type == ASF.EUserInputType.None) || !Enum.IsDefined(typeof(ASF.EUserInputType), request.Type) || string.IsNullOrEmpty(request.Value)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(request.Type) + " || " + nameof(request.Value))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(request.Type) + " || " + nameof(request.Value))));
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
||||||
|
|
||||||
if ((bots == null) || (bots.Count == 0)) {
|
if ((bots == null) || (bots.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botNames)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<bool> results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.SetUserInput(request.Type, request.Value!)))).ConfigureAwait(false);
|
IList<bool> results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.SetUserInput(request.Type, request.Value!)))).ConfigureAwait(false);
|
||||||
@@ -270,14 +287,18 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)]
|
||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||||
public async Task<ActionResult<GenericResponse>> PausePost(string botNames, [FromBody] BotPauseRequest request) {
|
public async Task<ActionResult<GenericResponse>> PausePost(string botNames, [FromBody] BotPauseRequest request) {
|
||||||
if (string.IsNullOrEmpty(botNames) || (request == null)) {
|
if (string.IsNullOrEmpty(botNames)) {
|
||||||
throw new ArgumentNullException(nameof(botNames) + " || " + nameof(request));
|
throw new ArgumentNullException(nameof(botNames));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request == null) {
|
||||||
|
throw new ArgumentNullException(nameof(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
||||||
|
|
||||||
if ((bots == null) || (bots.Count == 0)) {
|
if ((bots == null) || (bots.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botNames)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<(bool Success, string Message)> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.Pause(request.Permanent, request.ResumeInSeconds))).ConfigureAwait(false);
|
IList<(bool Success, string Message)> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.Pause(request.Permanent, request.ResumeInSeconds))).ConfigureAwait(false);
|
||||||
@@ -297,18 +318,22 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
[ProducesResponseType(typeof(GenericResponse<IReadOnlyDictionary<string, IReadOnlyDictionary<string, ArchiHandler.PurchaseResponseCallback>>>), (int) HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(GenericResponse<IReadOnlyDictionary<string, IReadOnlyDictionary<string, ArchiHandler.PurchaseResponseCallback>>>), (int) HttpStatusCode.OK)]
|
||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||||
public async Task<ActionResult<GenericResponse>> RedeemPost(string botNames, [FromBody] BotRedeemRequest request) {
|
public async Task<ActionResult<GenericResponse>> RedeemPost(string botNames, [FromBody] BotRedeemRequest request) {
|
||||||
if (string.IsNullOrEmpty(botNames) || (request == null)) {
|
if (string.IsNullOrEmpty(botNames)) {
|
||||||
throw new ArgumentNullException(nameof(botNames) + " || " + nameof(request));
|
throw new ArgumentNullException(nameof(botNames));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request == null) {
|
||||||
|
throw new ArgumentNullException(nameof(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((request.KeysToRedeem == null) || (request.KeysToRedeem.Count == 0)) {
|
if ((request.KeysToRedeem == null) || (request.KeysToRedeem.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request.KeysToRedeem))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.KeysToRedeem))));
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
||||||
|
|
||||||
if ((bots == null) || (bots.Count == 0)) {
|
if ((bots == null) || (bots.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botNames)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<ArchiHandler.PurchaseResponseCallback?> results = await Utilities.InParallel(bots.Select(bot => request.KeysToRedeem.Select(key => bot.Actions.RedeemKey(key))).SelectMany(task => task)).ConfigureAwait(false);
|
IList<ArchiHandler.PurchaseResponseCallback?> results = await Utilities.InParallel(bots.Select(bot => request.KeysToRedeem.Select(key => bot.Actions.RedeemKey(key))).SelectMany(task => task)).ConfigureAwait(false);
|
||||||
@@ -337,16 +362,24 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)]
|
||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||||
public async Task<ActionResult<GenericResponse>> RenamePost(string botName, [FromBody] BotRenameRequest request) {
|
public async Task<ActionResult<GenericResponse>> RenamePost(string botName, [FromBody] BotRenameRequest request) {
|
||||||
if (string.IsNullOrEmpty(botName) || (request == null) || (Bot.Bots == null)) {
|
if (string.IsNullOrEmpty(botName)) {
|
||||||
throw new ArgumentNullException(nameof(botName) + " || " + nameof(request) + " || " + nameof(Bot.Bots));
|
throw new ArgumentNullException(nameof(botName));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(request.NewName) || request.NewName!.Equals(SharedInfo.ASF) || Bot.Bots.ContainsKey(request.NewName)) {
|
if (request == null) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(request.NewName))));
|
throw new ArgumentNullException(nameof(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Bot.Bots == null) {
|
||||||
|
throw new InvalidOperationException(nameof(Bot.Bots));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(request.NewName) || request.NewName!.Equals(SharedInfo.ASF, StringComparison.OrdinalIgnoreCase) || Bot.Bots.ContainsKey(request.NewName)) {
|
||||||
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(request.NewName))));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Bot.Bots.TryGetValue(botName, out Bot? bot)) {
|
if (!Bot.Bots.TryGetValue(botName, out Bot? bot)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botName)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = await bot.Rename(request.NewName).ConfigureAwait(false);
|
bool result = await bot.Rename(request.NewName).ConfigureAwait(false);
|
||||||
@@ -368,7 +401,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
||||||
|
|
||||||
if ((bots == null) || (bots.Count == 0)) {
|
if ((bots == null) || (bots.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botNames)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<(bool Success, string Message)> results = await Utilities.InParallel(bots.Select(bot => Task.Run(bot.Actions.Resume))).ConfigureAwait(false);
|
IList<(bool Success, string Message)> results = await Utilities.InParallel(bots.Select(bot => Task.Run(bot.Actions.Resume))).ConfigureAwait(false);
|
||||||
@@ -390,7 +423,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
||||||
|
|
||||||
if ((bots == null) || (bots.Count == 0)) {
|
if ((bots == null) || (bots.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botNames)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<(bool Success, string Message)> results = await Utilities.InParallel(bots.Select(bot => Task.Run(bot.Actions.Start))).ConfigureAwait(false);
|
IList<(bool Success, string Message)> results = await Utilities.InParallel(bots.Select(bot => Task.Run(bot.Actions.Start))).ConfigureAwait(false);
|
||||||
@@ -412,7 +445,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
||||||
|
|
||||||
if ((bots == null) || (bots.Count == 0)) {
|
if ((bots == null) || (bots.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botNames)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<(bool Success, string Message)> results = await Utilities.InParallel(bots.Select(bot => Task.Run(bot.Actions.Stop))).ConfigureAwait(false);
|
IList<(bool Success, string Message)> results = await Utilities.InParallel(bots.Select(bot => Task.Run(bot.Actions.Stop))).ConfigureAwait(false);
|
||||||
@@ -427,18 +460,22 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
[ProducesResponseType(typeof(GenericResponse<IReadOnlyDictionary<string, GenericResponse>>), (int) HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(GenericResponse<IReadOnlyDictionary<string, GenericResponse>>), (int) HttpStatusCode.OK)]
|
||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||||
public async Task<ActionResult<GenericResponse>> TwoFactorAuthenticationConfirmationsPost(string botNames, [FromBody] TwoFactorAuthenticationConfirmationsRequest request) {
|
public async Task<ActionResult<GenericResponse>> TwoFactorAuthenticationConfirmationsPost(string botNames, [FromBody] TwoFactorAuthenticationConfirmationsRequest request) {
|
||||||
if (string.IsNullOrEmpty(botNames) || (request == null)) {
|
if (string.IsNullOrEmpty(botNames)) {
|
||||||
throw new ArgumentNullException(nameof(botNames));
|
throw new ArgumentNullException(nameof(botNames));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request == null) {
|
||||||
|
throw new ArgumentNullException(nameof(request));
|
||||||
|
}
|
||||||
|
|
||||||
if (request.AcceptedType.HasValue && ((request.AcceptedType.Value == MobileAuthenticator.Confirmation.EType.Unknown) || !Enum.IsDefined(typeof(MobileAuthenticator.Confirmation.EType), request.AcceptedType.Value))) {
|
if (request.AcceptedType.HasValue && ((request.AcceptedType.Value == MobileAuthenticator.Confirmation.EType.Unknown) || !Enum.IsDefined(typeof(MobileAuthenticator.Confirmation.EType), request.AcceptedType.Value))) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(request.AcceptedType))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(request.AcceptedType))));
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
||||||
|
|
||||||
if ((bots == null) || (bots.Count == 0)) {
|
if ((bots == null) || (bots.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse<IReadOnlyDictionary<string, GenericResponse>>(false, string.Format(Strings.BotNotFound, botNames)));
|
return BadRequest(new GenericResponse<IReadOnlyDictionary<string, GenericResponse>>(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<(bool Success, string Message)> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.HandleTwoFactorAuthenticationConfirmations(request.Accept, request.AcceptedType, request.AcceptedCreatorIDs?.Count > 0 ? request.AcceptedCreatorIDs : null, request.WaitIfNeeded))).ConfigureAwait(false);
|
IList<(bool Success, string Message)> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.HandleTwoFactorAuthenticationConfirmations(request.Accept, request.AcceptedType, request.AcceptedCreatorIDs?.Count > 0 ? request.AcceptedCreatorIDs : null, request.WaitIfNeeded))).ConfigureAwait(false);
|
||||||
@@ -467,7 +504,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
HashSet<Bot>? bots = Bot.GetBots(botNames);
|
||||||
|
|
||||||
if ((bots == null) || (bots.Count == 0)) {
|
if ((bots == null) || (bots.Count == 0)) {
|
||||||
return BadRequest(new GenericResponse<IReadOnlyDictionary<string, GenericResponse<string>>>(false, string.Format(Strings.BotNotFound, botNames)));
|
return BadRequest(new GenericResponse<IReadOnlyDictionary<string, GenericResponse<string>>>(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<(bool Success, string? Token, string Message)> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.GenerateTwoFactorAuthenticationToken())).ConfigureAwait(false);
|
IList<(bool Success, string? Token, string Message)> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.GenerateTwoFactorAuthenticationToken())).ConfigureAwait(false);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -48,13 +49,13 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(request.Command)) {
|
if (string.IsNullOrEmpty(request.Command)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request.Command))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(request.Command))));
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong steamOwnerID = ASF.GlobalConfig?.SteamOwnerID ?? GlobalConfig.DefaultSteamOwnerID;
|
ulong steamOwnerID = ASF.GlobalConfig?.SteamOwnerID ?? GlobalConfig.DefaultSteamOwnerID;
|
||||||
|
|
||||||
if (steamOwnerID == 0) {
|
if (steamOwnerID == 0) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(ASF.GlobalConfig.SteamOwnerID))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(ASF.GlobalConfig.SteamOwnerID))));
|
||||||
}
|
}
|
||||||
|
|
||||||
Bot? targetBot = Bot.Bots?.OrderBy(bot => bot.Key, Bot.BotsComparer).Select(bot => bot.Value).FirstOrDefault();
|
Bot? targetBot = Bot.Bots?.OrderBy(bot => bot.Key, Bot.BotsComparer).Select(bot => bot.Value).FirstOrDefault();
|
||||||
@@ -69,7 +70,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
if (!string.IsNullOrEmpty(commandPrefix) && command.StartsWith(commandPrefix!, StringComparison.Ordinal)) {
|
if (!string.IsNullOrEmpty(commandPrefix) && command.StartsWith(commandPrefix!, StringComparison.Ordinal)) {
|
||||||
if (command.Length == commandPrefix!.Length) {
|
if (command.Length == commandPrefix!.Length) {
|
||||||
// If the message starts with command prefix and is of the same length as command prefix, then it's just empty command trigger, useless
|
// If the message starts with command prefix and is of the same length as command prefix, then it's just empty command trigger, useless
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(command))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(command))));
|
||||||
}
|
}
|
||||||
|
|
||||||
command = command.Substring(commandPrefix!.Length);
|
command = command.Substring(commandPrefix!.Length);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
@@ -49,8 +50,12 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
[ProducesResponseType(typeof(IEnumerable<GenericResponse<string>>), (int) HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<GenericResponse<string>>), (int) HttpStatusCode.OK)]
|
||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||||
public async Task<ActionResult> NLogGet() {
|
public async Task<ActionResult> NLogGet() {
|
||||||
|
if (HttpContext == null) {
|
||||||
|
throw new InvalidOperationException(nameof(HttpContext));
|
||||||
|
}
|
||||||
|
|
||||||
if (!HttpContext.WebSockets.IsWebSocketRequest) {
|
if (!HttpContext.WebSockets.IsWebSocketRequest) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.WarningFailedWithError, nameof(HttpContext.WebSockets.IsWebSocketRequest) + ": " + HttpContext.WebSockets.IsWebSocketRequest)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError!, nameof(HttpContext.WebSockets.IsWebSocketRequest) + ": " + HttpContext.WebSockets.IsWebSocketRequest)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// From now on we can return only EmptyResult as the response stream is already being used by existing websocket connection
|
// From now on we can return only EmptyResult as the response stream is already being used by existing websocket connection
|
||||||
@@ -74,7 +79,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (webSocket.State == WebSocketState.Open) {
|
while (webSocket.State == WebSocketState.Open) {
|
||||||
WebSocketReceiveResult result = await webSocket.ReceiveAsync(new byte[0], CancellationToken.None).ConfigureAwait(false);
|
WebSocketReceiveResult result = await webSocket.ReceiveAsync(Array.Empty<byte>(), CancellationToken.None).ConfigureAwait(false);
|
||||||
|
|
||||||
if (result.MessageType != WebSocketMessageType.Close) {
|
if (result.MessageType != WebSocketMessageType.Close) {
|
||||||
await webSocket.CloseAsync(WebSocketCloseStatus.InvalidMessageType, "You're not supposed to be sending any message but Close!", CancellationToken.None).ConfigureAwait(false);
|
await webSocket.CloseAsync(WebSocketCloseStatus.InvalidMessageType, "You're not supposed to be sending any message but Close!", CancellationToken.None).ConfigureAwait(false);
|
||||||
@@ -104,7 +109,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
throw new ArgumentNullException(nameof(newHistoryEntryArgs));
|
throw new ArgumentNullException(nameof(newHistoryEntryArgs));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ActiveLogWebSockets.Count == 0) {
|
if (ActiveLogWebSockets.IsEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,8 +119,16 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static async Task PostLoggedJsonUpdate(WebSocket webSocket, SemaphoreSlim sendSemaphore, string json) {
|
private static async Task PostLoggedJsonUpdate(WebSocket webSocket, SemaphoreSlim sendSemaphore, string json) {
|
||||||
if ((webSocket == null) || (sendSemaphore == null) || string.IsNullOrEmpty(json)) {
|
if (webSocket == null) {
|
||||||
throw new ArgumentNullException(nameof(webSocket) + " || " + nameof(sendSemaphore) + " || " + nameof(json));
|
throw new ArgumentNullException(nameof(webSocket));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sendSemaphore == null) {
|
||||||
|
throw new ArgumentNullException(nameof(sendSemaphore));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(json)) {
|
||||||
|
throw new ArgumentNullException(nameof(json));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (webSocket.State != WebSocketState.Open) {
|
if (webSocket.State != WebSocketState.Open) {
|
||||||
@@ -138,8 +151,16 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static async Task PostLoggedMessageUpdate(WebSocket webSocket, SemaphoreSlim sendSemaphore, string loggedMessage) {
|
private static async Task PostLoggedMessageUpdate(WebSocket webSocket, SemaphoreSlim sendSemaphore, string loggedMessage) {
|
||||||
if ((webSocket == null) || (sendSemaphore == null) || string.IsNullOrEmpty(loggedMessage)) {
|
if (webSocket == null) {
|
||||||
throw new ArgumentNullException(nameof(webSocket) + " || " + nameof(sendSemaphore) + " || " + nameof(loggedMessage));
|
throw new ArgumentNullException(nameof(webSocket));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sendSemaphore == null) {
|
||||||
|
throw new ArgumentNullException(nameof(sendSemaphore));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(loggedMessage)) {
|
||||||
|
throw new ArgumentNullException(nameof(loggedMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (webSocket.State != WebSocketState.Open) {
|
if (webSocket.State != WebSocketState.Open) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using ArchiSteamFarm.IPC.Responses;
|
using ArchiSteamFarm.IPC.Responses;
|
||||||
@@ -31,7 +32,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(typeof(GenericResponse<IReadOnlyCollection<IPlugin>>), (int) HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(GenericResponse<IReadOnlyCollection<IPlugin>>), (int) HttpStatusCode.OK)]
|
||||||
public ActionResult<GenericResponse<IReadOnlyCollection<IPlugin>>> PluginsGet() {
|
public ActionResult<GenericResponse<IReadOnlyCollection<IPlugin>>> PluginsGet() {
|
||||||
IReadOnlyCollection<IPlugin> activePlugins = PluginsCore.ActivePlugins ?? (IReadOnlyCollection<IPlugin>) new IPlugin[0];
|
IReadOnlyCollection<IPlugin> activePlugins = PluginsCore.ActivePlugins ?? (IReadOnlyCollection<IPlugin>) Array.Empty<IPlugin>();
|
||||||
|
|
||||||
return Ok(new GenericResponse<IReadOnlyCollection<IPlugin>>(activePlugins));
|
return Ok(new GenericResponse<IReadOnlyCollection<IPlugin>>(activePlugins));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using ArchiSteamFarm.IPC.Responses;
|
using ArchiSteamFarm.IPC.Responses;
|
||||||
using ArchiSteamFarm.Localization;
|
using ArchiSteamFarm.Localization;
|
||||||
@@ -45,7 +46,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
Type? targetType = WebUtilities.ParseType(structure);
|
Type? targetType = WebUtilities.ParseType(structure);
|
||||||
|
|
||||||
if (targetType == null) {
|
if (targetType == null) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, structure)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, structure)));
|
||||||
}
|
}
|
||||||
|
|
||||||
object? obj;
|
object? obj;
|
||||||
@@ -53,7 +54,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
try {
|
try {
|
||||||
obj = Activator.CreateInstance(targetType, true);
|
obj = Activator.CreateInstance(targetType, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorParsingObject, nameof(targetType)) + Environment.NewLine + e));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorParsingObject, nameof(targetType)) + Environment.NewLine + e));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(new GenericResponse<object>(obj));
|
return Ok(new GenericResponse<object>(obj));
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -49,7 +50,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
Type? targetType = WebUtilities.ParseType(type);
|
Type? targetType = WebUtilities.ParseType(type);
|
||||||
|
|
||||||
if (targetType == null) {
|
if (targetType == null) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, type)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, type)));
|
||||||
}
|
}
|
||||||
|
|
||||||
string? baseType = targetType.BaseType?.GetUnifiedName();
|
string? baseType = targetType.BaseType?.GetUnifiedName();
|
||||||
@@ -92,10 +93,10 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
if (string.IsNullOrEmpty(valueText)) {
|
if (string.IsNullOrEmpty(valueText)) {
|
||||||
ASF.ArchiLogger.LogNullError(nameof(valueText));
|
ASF.ArchiLogger.LogNullError(nameof(valueText));
|
||||||
|
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorObjectIsNull, nameof(valueText))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorObjectIsNull, nameof(valueText))));
|
||||||
}
|
}
|
||||||
|
|
||||||
string? valueObjText = Convert.ChangeType(value, enumType)?.ToString();
|
string? valueObjText = Convert.ChangeType(value, enumType, CultureInfo.InvariantCulture)?.ToString();
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(valueObjText)) {
|
if (string.IsNullOrEmpty(valueObjText)) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
@@ -51,7 +52,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
string directoryPath = Path.Combine(ArchiKestrel.WebsiteDirectory, directory);
|
string directoryPath = Path.Combine(ArchiKestrel.WebsiteDirectory, directory);
|
||||||
|
|
||||||
if (!Directory.Exists(directoryPath)) {
|
if (!Directory.Exists(directoryPath)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, directory)));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, directory)));
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] files;
|
string[] files;
|
||||||
@@ -59,7 +60,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
try {
|
try {
|
||||||
files = Directory.GetFiles(directoryPath);
|
files = Directory.GetFiles(directoryPath);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return StatusCode((int) HttpStatusCode.InternalServerError, new GenericResponse(false, string.Format(Strings.ErrorParsingObject, nameof(files)) + Environment.NewLine + e));
|
return StatusCode((int) HttpStatusCode.InternalServerError, new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorParsingObject, nameof(files)) + Environment.NewLine + e));
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<string> result = files.Select(Path.GetFileName).Where(fileName => !string.IsNullOrEmpty(fileName)).ToHashSet()!;
|
HashSet<string> result = files.Select(Path.GetFileName).Where(fileName => !string.IsNullOrEmpty(fileName)).ToHashSet()!;
|
||||||
@@ -79,7 +80,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
public async Task<ActionResult<GenericResponse>> GitHubReleaseGet() {
|
public async Task<ActionResult<GenericResponse>> GitHubReleaseGet() {
|
||||||
GitHub.ReleaseResponse? releaseResponse = await GitHub.GetLatestRelease(false).ConfigureAwait(false);
|
GitHub.ReleaseResponse? releaseResponse = await GitHub.GetLatestRelease(false).ConfigureAwait(false);
|
||||||
|
|
||||||
return releaseResponse != null ? Ok(new GenericResponse<GitHubReleaseResponse>(new GitHubReleaseResponse(releaseResponse))) : StatusCode((int) HttpStatusCode.ServiceUnavailable, new GenericResponse(false, string.Format(Strings.ErrorRequestFailedTooManyTimes, WebBrowser.MaxTries)));
|
return releaseResponse != null ? Ok(new GenericResponse<GitHubReleaseResponse>(new GitHubReleaseResponse(releaseResponse))) : StatusCode((int) HttpStatusCode.ServiceUnavailable, new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorRequestFailedTooManyTimes, WebBrowser.MaxTries)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -106,7 +107,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!Version.TryParse(version, out Version? parsedVersion)) {
|
if (!Version.TryParse(version, out Version? parsedVersion)) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(version))));
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(version))));
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseResponse = await GitHub.GetRelease(parsedVersion.ToString(4)).ConfigureAwait(false);
|
releaseResponse = await GitHub.GetRelease(parsedVersion.ToString(4)).ConfigureAwait(false);
|
||||||
@@ -114,7 +115,7 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return releaseResponse != null ? Ok(new GenericResponse<GitHubReleaseResponse>(new GitHubReleaseResponse(releaseResponse))) : StatusCode((int) HttpStatusCode.ServiceUnavailable, new GenericResponse(false, string.Format(Strings.ErrorRequestFailedTooManyTimes, WebBrowser.MaxTries)));
|
return releaseResponse != null ? Ok(new GenericResponse<GitHubReleaseResponse>(new GitHubReleaseResponse(releaseResponse))) : StatusCode((int) HttpStatusCode.ServiceUnavailable, new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorRequestFailedTooManyTimes, WebBrowser.MaxTries)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -129,17 +130,21 @@ namespace ArchiSteamFarm.IPC.Controllers.Api {
|
|||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
|
||||||
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.ServiceUnavailable)]
|
[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.ServiceUnavailable)]
|
||||||
public async Task<ActionResult<GenericResponse>> SendPost([FromBody] WWWSendRequest request) {
|
public async Task<ActionResult<GenericResponse>> SendPost([FromBody] WWWSendRequest request) {
|
||||||
if ((request == null) || (ASF.WebBrowser == null)) {
|
if ((request == null)) {
|
||||||
throw new ArgumentNullException(nameof(request) + " || " + nameof(ASF.WebBrowser));
|
throw new ArgumentNullException(nameof(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(request.URL) || !Uri.TryCreate(request.URL, UriKind.Absolute, out Uri? uri) || !uri.Scheme.Equals(Uri.UriSchemeHttps)) {
|
if (ASF.WebBrowser == null) {
|
||||||
return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(request.URL))));
|
throw new InvalidOperationException(nameof(ASF.WebBrowser));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(request.URL) || !Uri.TryCreate(request.URL, UriKind.Absolute, out Uri? uri) || !uri.Scheme.Equals(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase)) {
|
||||||
|
return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(request.URL))));
|
||||||
}
|
}
|
||||||
|
|
||||||
WebBrowser.StringResponse? urlResponse = await ASF.WebBrowser.UrlGetToString(request.URL!).ConfigureAwait(false);
|
WebBrowser.StringResponse? urlResponse = await ASF.WebBrowser.UrlGetToString(request.URL!).ConfigureAwait(false);
|
||||||
|
|
||||||
return urlResponse?.Content != null ? Ok(new GenericResponse<string>(urlResponse.Content)) : StatusCode((int) HttpStatusCode.ServiceUnavailable, new GenericResponse(false, string.Format(Strings.ErrorRequestFailedTooManyTimes, WebBrowser.MaxTries)));
|
return urlResponse?.Content != null ? Ok(new GenericResponse<string>(urlResponse.Content)) : StatusCode((int) HttpStatusCode.ServiceUnavailable, new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorRequestFailedTooManyTimes, WebBrowser.MaxTries)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,8 +76,12 @@ namespace ArchiSteamFarm.IPC.Integration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<HttpStatusCode> GetAuthenticationStatus(HttpContext context) {
|
private static async Task<HttpStatusCode> GetAuthenticationStatus(HttpContext context) {
|
||||||
if ((context == null) || (ClearFailedAuthorizationsTimer == null)) {
|
if ((context == null)) {
|
||||||
throw new ArgumentNullException(nameof(context) + " || " + nameof(ClearFailedAuthorizationsTimer));
|
throw new ArgumentNullException(nameof(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ClearFailedAuthorizationsTimer == null) {
|
||||||
|
throw new InvalidOperationException(nameof(ClearFailedAuthorizationsTimer));
|
||||||
}
|
}
|
||||||
|
|
||||||
string? ipcPassword = ASF.GlobalConfig != null ? ASF.GlobalConfig.IPCPassword : GlobalConfig.DefaultIPCPassword;
|
string? ipcPassword = ASF.GlobalConfig != null ? ASF.GlobalConfig.IPCPassword : GlobalConfig.DefaultIPCPassword;
|
||||||
@@ -89,7 +93,7 @@ namespace ArchiSteamFarm.IPC.Integration {
|
|||||||
IPAddress? clientIP = context.Connection.RemoteIpAddress;
|
IPAddress? clientIP = context.Connection.RemoteIpAddress;
|
||||||
|
|
||||||
if (clientIP == null) {
|
if (clientIP == null) {
|
||||||
throw new ArgumentNullException(nameof(context.Connection.RemoteIpAddress));
|
throw new InvalidOperationException(nameof(clientIP));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FailedAuthorizations.TryGetValue(clientIP, out byte attempts)) {
|
if (FailedAuthorizations.TryGetValue(clientIP, out byte attempts)) {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Microsoft.OpenApi.Any;
|
using Microsoft.OpenApi.Any;
|
||||||
using Microsoft.OpenApi.Extensions;
|
using Microsoft.OpenApi.Extensions;
|
||||||
@@ -30,11 +31,15 @@ namespace ArchiSteamFarm.IPC.Integration {
|
|||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
internal sealed class EnumSchemaFilter : ISchemaFilter {
|
internal sealed class EnumSchemaFilter : ISchemaFilter {
|
||||||
public void Apply(OpenApiSchema schema, SchemaFilterContext context) {
|
public void Apply(OpenApiSchema schema, SchemaFilterContext context) {
|
||||||
if ((schema == null) || (context == null)) {
|
if (schema == null) {
|
||||||
throw new ArgumentNullException(nameof(schema) + " || " + nameof(context));
|
throw new ArgumentNullException(nameof(schema));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context.Type.IsEnum) {
|
if (context == null) {
|
||||||
|
throw new ArgumentNullException(nameof(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((context.Type == null) || !context.Type.IsEnum) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,9 +72,9 @@ namespace ArchiSteamFarm.IPC.Integration {
|
|||||||
enumObject = new OpenApiLong(longValue);
|
enumObject = new OpenApiLong(longValue);
|
||||||
} else if (TryCast(enumValue, out ulong ulongValue)) {
|
} else if (TryCast(enumValue, out ulong ulongValue)) {
|
||||||
// OpenApi spec doesn't support ulongs as of now
|
// OpenApi spec doesn't support ulongs as of now
|
||||||
enumObject = new OpenApiString(ulongValue.ToString());
|
enumObject = new OpenApiString(ulongValue.ToString(CultureInfo.InvariantCulture));
|
||||||
} else {
|
} else {
|
||||||
throw new ArgumentOutOfRangeException(nameof(enumValue));
|
throw new InvalidOperationException(nameof(enumValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
definition.Add(enumName!, enumObject);
|
definition.Add(enumName!, enumObject);
|
||||||
@@ -84,7 +89,7 @@ namespace ArchiSteamFarm.IPC.Integration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
typedValue = (T) Convert.ChangeType(value, typeof(T));
|
typedValue = (T) Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (InvalidCastException) {
|
} catch (InvalidCastException) {
|
||||||
|
|||||||
@@ -31,14 +31,14 @@ namespace ArchiSteamFarm.IPC.Requests {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly ArchiCryptoHelper.ECryptoMethod CryptoMethod;
|
public ArchiCryptoHelper.ECryptoMethod CryptoMethod { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// String to encrypt with provided <see cref="CryptoMethod" />.
|
/// String to encrypt with provided <see cref="CryptoMethod" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly string? StringToEncrypt;
|
public string? StringToEncrypt { get; private set; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
private ASFEncryptRequest() { }
|
private ASFEncryptRequest() { }
|
||||||
|
|||||||
@@ -31,14 +31,14 @@ namespace ArchiSteamFarm.IPC.Requests {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly ArchiCryptoHelper.EHashingMethod HashingMethod;
|
public ArchiCryptoHelper.EHashingMethod HashingMethod { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// String to hash with provided <see cref="HashingMethod" />.
|
/// String to hash with provided <see cref="HashingMethod" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly string? StringToHash;
|
public string? StringToHash { get; private set; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
private ASFHashRequest() { }
|
private ASFHashRequest() { }
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace ArchiSteamFarm.IPC.Requests {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly GlobalConfig? GlobalConfig;
|
public GlobalConfig? GlobalConfig { get; private set; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
private ASFRequest() { }
|
private ASFRequest() { }
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace ArchiSteamFarm.IPC.Requests {
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly OrderedDictionary? GamesToRedeemInBackground;
|
public OrderedDictionary? GamesToRedeemInBackground { get; private set; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
private BotGamesToRedeemInBackgroundRequest() { }
|
private BotGamesToRedeemInBackgroundRequest() { }
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ namespace ArchiSteamFarm.IPC.Requests {
|
|||||||
/// Specifies the type of the input.
|
/// Specifies the type of the input.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
public readonly ASF.EUserInputType Type;
|
public ASF.EUserInputType Type { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies the value for given input type (declared in <see cref="Type" />)
|
/// Specifies the value for given input type (declared in <see cref="Type" />)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
public readonly string? Value;
|
public string? Value { get; private set; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
private BotInputRequest() { }
|
private BotInputRequest() { }
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ namespace ArchiSteamFarm.IPC.Requests {
|
|||||||
/// Specifies if pause is permanent or temporary (default).
|
/// Specifies if pause is permanent or temporary (default).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public readonly bool Permanent;
|
public bool Permanent { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies automatic resume action in given seconds. Default value of 0 disables automatic resume.
|
/// Specifies automatic resume action in given seconds. Default value of 0 disables automatic resume.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public readonly ushort ResumeInSeconds;
|
public ushort ResumeInSeconds { get; private set; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
private BotPauseRequest() { }
|
private BotPauseRequest() { }
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace ArchiSteamFarm.IPC.Requests {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly ImmutableHashSet<string>? KeysToRedeem;
|
public ImmutableHashSet<string>? KeysToRedeem { get; private set; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
private BotRedeemRequest() { }
|
private BotRedeemRequest() { }
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace ArchiSteamFarm.IPC.Requests {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly string? NewName;
|
public string? NewName { get; private set; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
private BotRenameRequest() { }
|
private BotRenameRequest() { }
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace ArchiSteamFarm.IPC.Requests {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly BotConfig? BotConfig;
|
public BotConfig? BotConfig { get; private set; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
private BotRequest() { }
|
private BotRequest() { }
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace ArchiSteamFarm.IPC.Requests {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly string? Command;
|
public string? Command { get; private set; }
|
||||||
|
|
||||||
internal CommandRequest(string command) {
|
internal CommandRequest(string command) {
|
||||||
if (string.IsNullOrEmpty(command)) {
|
if (string.IsNullOrEmpty(command)) {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Globalization;
|
||||||
using ArchiSteamFarm.Localization;
|
using ArchiSteamFarm.Localization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
@@ -33,19 +34,19 @@ namespace ArchiSteamFarm.IPC.Requests {
|
|||||||
/// Specifies the target action, whether we should accept the confirmations (true), or decline them (false).
|
/// Specifies the target action, whether we should accept the confirmations (true), or decline them (false).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
public readonly bool Accept;
|
public bool Accept { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies the type of confirmations to handle. If not provided, all confirmation types are considered for an action.
|
/// Specifies the type of confirmations to handle. If not provided, all confirmation types are considered for an action.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public readonly MobileAuthenticator.Confirmation.EType? AcceptedType;
|
public MobileAuthenticator.Confirmation.EType? AcceptedType { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies whether we should wait for the confirmations to arrive, in case they're not available immediately. This option makes sense only if <see cref="AcceptedCreatorIDs" /> is specified as well, and in this case ASF will add a few more tries if needed to ensure that all specified IDs are handled. Useful if confirmations are generated with a delay on Steam network side, which happens fairly often.
|
/// Specifies whether we should wait for the confirmations to arrive, in case they're not available immediately. This option makes sense only if <see cref="AcceptedCreatorIDs" /> is specified as well, and in this case ASF will add a few more tries if needed to ensure that all specified IDs are handled. Useful if confirmations are generated with a delay on Steam network side, which happens fairly often.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.DisallowNull)]
|
[JsonProperty(Required = Required.DisallowNull)]
|
||||||
public readonly bool WaitIfNeeded;
|
public bool WaitIfNeeded { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies IDs of the confirmations that we're supposed to handle. CreatorID of the confirmation is equal to ID of the object that triggered it - e.g. ID of the trade offer, or ID of the market listing. If not provided, or empty array, all confirmation IDs are considered for an action.
|
/// Specifies IDs of the confirmations that we're supposed to handle. CreatorID of the confirmation is equal to ID of the object that triggered it - e.g. ID of the trade offer, or ID of the market listing. If not provided, or empty array, all confirmation IDs are considered for an action.
|
||||||
@@ -67,7 +68,7 @@ namespace ArchiSteamFarm.IPC.Requests {
|
|||||||
|
|
||||||
foreach (string creatorIDText in value) {
|
foreach (string creatorIDText in value) {
|
||||||
if (!ulong.TryParse(creatorIDText, out ulong creatorID) || (creatorID == 0)) {
|
if (!ulong.TryParse(creatorIDText, out ulong creatorID) || (creatorID == 0)) {
|
||||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(SAcceptedCreatorIDs)));
|
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(SAcceptedCreatorIDs)));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace ArchiSteamFarm.IPC.Requests {
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
[Required]
|
[Required]
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
public readonly string? URL;
|
public string? URL { get; private set; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
private WWWSendRequest() { }
|
private WWWSendRequest() { }
|
||||||
|
|||||||
@@ -30,54 +30,50 @@ namespace ArchiSteamFarm.IPC.Responses {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly string BuildVariant;
|
public string BuildVariant { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A value specifying whether this variant of ASF is capable of auto-update.
|
/// A value specifying whether this variant of ASF is capable of auto-update.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly bool CanUpdate;
|
public bool CanUpdate { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Currently loaded ASF's global config.
|
/// Currently loaded ASF's global config.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly GlobalConfig GlobalConfig;
|
public GlobalConfig GlobalConfig { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current amount of managed memory being used by the process, in kilobytes.
|
/// Current amount of managed memory being used by the process, in kilobytes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly uint MemoryUsage;
|
public uint MemoryUsage { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Start date of the process.
|
/// Start date of the process.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly DateTime ProcessStartTime;
|
public DateTime ProcessStartTime { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ASF version of currently running binary.
|
/// ASF version of currently running binary.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly Version Version;
|
public Version Version { get; private set; }
|
||||||
|
|
||||||
internal ASFResponse(string buildVariant, bool canUpdate, GlobalConfig globalConfig, uint memoryUsage, DateTime processStartTime, Version version) {
|
internal ASFResponse(string buildVariant, bool canUpdate, GlobalConfig globalConfig, uint memoryUsage, DateTime processStartTime, Version version) {
|
||||||
if (string.IsNullOrEmpty(buildVariant) || (globalConfig == null) || (memoryUsage == 0) || (processStartTime == DateTime.MinValue) || (version == null)) {
|
BuildVariant = !string.IsNullOrEmpty(buildVariant) ? buildVariant : throw new ArgumentNullException(nameof(buildVariant));
|
||||||
throw new ArgumentNullException(nameof(buildVariant) + " || " + nameof(globalConfig) + " || " + nameof(memoryUsage) + " || " + nameof(processStartTime) + " || " + nameof(version));
|
|
||||||
}
|
|
||||||
|
|
||||||
BuildVariant = buildVariant;
|
|
||||||
CanUpdate = canUpdate;
|
CanUpdate = canUpdate;
|
||||||
GlobalConfig = globalConfig;
|
GlobalConfig = globalConfig ?? throw new ArgumentNullException(nameof(globalConfig));
|
||||||
MemoryUsage = memoryUsage;
|
MemoryUsage = memoryUsage > 0 ? memoryUsage : throw new ArgumentOutOfRangeException(nameof(memoryUsage));
|
||||||
ProcessStartTime = processStartTime;
|
ProcessStartTime = processStartTime > DateTime.MinValue ? processStartTime : throw new ArgumentOutOfRangeException(nameof(processStartTime));
|
||||||
Version = version;
|
Version = version ?? throw new ArgumentNullException(nameof(version));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ namespace ArchiSteamFarm.IPC.Responses {
|
|||||||
/// Keys that were redeemed and not used during the process, if available.
|
/// Keys that were redeemed and not used during the process, if available.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public readonly Dictionary<string, string>? UnusedKeys;
|
public Dictionary<string, string>? UnusedKeys { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Keys that were redeemed and used during the process, if available.
|
/// Keys that were redeemed and used during the process, if available.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public readonly Dictionary<string, string>? UsedKeys;
|
public Dictionary<string, string>? UsedKeys { get; private set; }
|
||||||
|
|
||||||
internal GamesToRedeemInBackgroundResponse(Dictionary<string, string>? unusedKeys = null, Dictionary<string, string>? usedKeys = null) {
|
internal GamesToRedeemInBackgroundResponse(Dictionary<string, string>? unusedKeys = null, Dictionary<string, string>? usedKeys = null) {
|
||||||
UnusedKeys = unusedKeys;
|
UnusedKeys = unusedKeys;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace ArchiSteamFarm.IPC.Responses {
|
|||||||
/// The type of the result depends on the API endpoint that you've called.
|
/// The type of the result depends on the API endpoint that you've called.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public readonly T? Result;
|
public T? Result { get; private set; }
|
||||||
|
|
||||||
public GenericResponse(T? result) : base(result != null) => Result = result;
|
public GenericResponse(T? result) : base(result != null) => Result = result;
|
||||||
public GenericResponse(bool success, string message) : base(success, message) { }
|
public GenericResponse(bool success, string message) : base(success, message) { }
|
||||||
@@ -48,14 +48,14 @@ namespace ArchiSteamFarm.IPC.Responses {
|
|||||||
/// This property will provide exact reason for majority of expected failures.
|
/// This property will provide exact reason for majority of expected failures.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public readonly string Message;
|
public string Message { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Boolean type that specifies if the request has succeeded.
|
/// Boolean type that specifies if the request has succeeded.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly bool Success;
|
public bool Success { get; private set; }
|
||||||
|
|
||||||
public GenericResponse(bool success, string? message = null) {
|
public GenericResponse(bool success, string? message = null) {
|
||||||
Success = success;
|
Success = success;
|
||||||
|
|||||||
@@ -30,28 +30,28 @@ namespace ArchiSteamFarm.IPC.Responses {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly string? ChangelogHTML;
|
public string? ChangelogHTML { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Date of the release.
|
/// Date of the release.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly DateTime ReleasedAt;
|
public DateTime ReleasedAt { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Boolean value that specifies whether the build is stable or not (pre-release).
|
/// Boolean value that specifies whether the build is stable or not (pre-release).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly bool Stable;
|
public bool Stable { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Version of the release.
|
/// Version of the release.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly string? Version;
|
public string? Version { get; private set; }
|
||||||
|
|
||||||
internal GitHubReleaseResponse(GitHub.ReleaseResponse releaseResponse) {
|
internal GitHubReleaseResponse(GitHub.ReleaseResponse releaseResponse) {
|
||||||
if (releaseResponse == null) {
|
if (releaseResponse == null) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace ArchiSteamFarm.IPC.Responses {
|
namespace ArchiSteamFarm.IPC.Responses {
|
||||||
@@ -36,22 +37,18 @@ namespace ArchiSteamFarm.IPC.Responses {
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly Dictionary<string, string> Body;
|
public Dictionary<string, string> Body { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Metadata of given type.
|
/// Metadata of given type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(Required = Required.Always)]
|
[JsonProperty(Required = Required.Always)]
|
||||||
[Required]
|
[Required]
|
||||||
public readonly TypeProperties Properties;
|
public TypeProperties Properties { get; private set; }
|
||||||
|
|
||||||
internal TypeResponse(Dictionary<string, string> body, TypeProperties properties) {
|
internal TypeResponse([NotNull] Dictionary<string, string> body, [NotNull] TypeProperties properties) {
|
||||||
if ((body == null) || (properties == null)) {
|
Body = body ?? throw new ArgumentNullException(nameof(body));
|
||||||
throw new ArgumentNullException(nameof(body) + " || " + nameof(properties));
|
Properties = properties ?? throw new ArgumentNullException(nameof(properties));
|
||||||
}
|
|
||||||
|
|
||||||
Body = body;
|
|
||||||
Properties = properties;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class TypeProperties {
|
public sealed class TypeProperties {
|
||||||
@@ -62,7 +59,7 @@ namespace ArchiSteamFarm.IPC.Responses {
|
|||||||
/// This can be used for determining how <see cref="Body" /> should be interpreted.
|
/// This can be used for determining how <see cref="Body" /> should be interpreted.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public readonly string? BaseType;
|
public string? BaseType { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Custom attributes of given type, if available.
|
/// Custom attributes of given type, if available.
|
||||||
@@ -71,7 +68,7 @@ namespace ArchiSteamFarm.IPC.Responses {
|
|||||||
/// This can be used for determining main enum type if <see cref="BaseType" /> is <see cref="Enum" />.
|
/// This can be used for determining main enum type if <see cref="BaseType" /> is <see cref="Enum" />.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public readonly HashSet<string>? CustomAttributes;
|
public HashSet<string>? CustomAttributes { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Underlying type of given type, if available.
|
/// Underlying type of given type, if available.
|
||||||
@@ -80,7 +77,7 @@ namespace ArchiSteamFarm.IPC.Responses {
|
|||||||
/// This can be used for determining underlying enum type if <see cref="BaseType" /> is <see cref="Enum" />.
|
/// This can be used for determining underlying enum type if <see cref="BaseType" /> is <see cref="Enum" />.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[JsonProperty]
|
[JsonProperty]
|
||||||
public readonly string? UnderlyingType;
|
public string? UnderlyingType { get; private set; }
|
||||||
|
|
||||||
internal TypeProperties(string? baseType = null, HashSet<string>? customAttributes = null, string? underlyingType = null) {
|
internal TypeProperties(string? baseType = null, HashSet<string>? customAttributes = null, string? underlyingType = null) {
|
||||||
BaseType = baseType;
|
BaseType = baseType;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -56,8 +57,12 @@ namespace ArchiSteamFarm.IPC {
|
|||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
|
||||||
#endif
|
#endif
|
||||||
if ((app == null) || (env == null)) {
|
if (app == null) {
|
||||||
throw new ArgumentNullException(nameof(app) + " || " + nameof(env));
|
throw new ArgumentNullException(nameof(app));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (env == null) {
|
||||||
|
throw new ArgumentNullException(nameof(env));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Debugging.IsUserDebugging) {
|
if (Debugging.IsUserDebugging) {
|
||||||
@@ -137,14 +142,14 @@ namespace ArchiSteamFarm.IPC {
|
|||||||
|
|
||||||
HashSet<IPNetwork>? knownNetworks = null;
|
HashSet<IPNetwork>? knownNetworks = null;
|
||||||
|
|
||||||
if ((knownNetworksTexts != null) && (knownNetworksTexts.Count > 0)) {
|
if (knownNetworksTexts?.Count > 0) {
|
||||||
knownNetworks = new HashSet<IPNetwork>(knownNetworksTexts.Count);
|
knownNetworks = new HashSet<IPNetwork>(knownNetworksTexts.Count);
|
||||||
|
|
||||||
foreach (string knownNetworkText in knownNetworksTexts) {
|
foreach (string knownNetworkText in knownNetworksTexts) {
|
||||||
string[] addressParts = knownNetworkText.Split('/', StringSplitOptions.RemoveEmptyEntries);
|
string[] addressParts = knownNetworkText.Split('/', StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
if ((addressParts.Length != 2) || !IPAddress.TryParse(addressParts[0], out IPAddress? ipAddress) || !byte.TryParse(addressParts[1], out byte prefixLength)) {
|
if ((addressParts.Length != 2) || !IPAddress.TryParse(addressParts[0], out IPAddress? ipAddress) || !byte.TryParse(addressParts[1], out byte prefixLength)) {
|
||||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(knownNetworkText)));
|
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(knownNetworkText)));
|
||||||
ASF.ArchiLogger.LogGenericDebug(nameof(knownNetworkText) + ": " + knownNetworkText);
|
ASF.ArchiLogger.LogGenericDebug(nameof(knownNetworkText) + ": " + knownNetworkText);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -199,7 +204,7 @@ namespace ArchiSteamFarm.IPC {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
new string[0]
|
Array.Empty<string>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user