Avoid excessive parental request

We can make use of the one in logged-in, which is superior
This commit is contained in:
JustArchi
2019-07-22 13:55:26 +02:00
parent a79720f0b5
commit 176efac2dc
6 changed files with 8587 additions and 94 deletions

View File

@@ -43,7 +43,6 @@ namespace ArchiSteamFarm {
private readonly SteamUnifiedMessages.UnifiedService<IClanChatRooms> UnifiedClanChatRoomsService;
private readonly SteamUnifiedMessages.UnifiedService<IEcon> UnifiedEconService;
private readonly SteamUnifiedMessages.UnifiedService<IFriendMessages> UnifiedFriendMessagesService;
private readonly SteamUnifiedMessages.UnifiedService<IParental> UnifiedParentalService;
private readonly SteamUnifiedMessages.UnifiedService<IPlayer> UnifiedPlayerService;
internal DateTime LastPacketReceived { get; private set; }
@@ -58,7 +57,6 @@ namespace ArchiSteamFarm {
UnifiedClanChatRoomsService = steamUnifiedMessages.CreateService<IClanChatRooms>();
UnifiedEconService = steamUnifiedMessages.CreateService<IEcon>();
UnifiedFriendMessagesService = steamUnifiedMessages.CreateService<IFriendMessages>();
UnifiedParentalService = steamUnifiedMessages.CreateService<IParental>();
UnifiedPlayerService = steamUnifiedMessages.CreateService<IPlayer>();
}
@@ -631,90 +629,6 @@ namespace ArchiSteamFarm {
Client.Send(request);
}
internal async Task<(bool IsSteamParentalEnabled, string SteamParentalCode)?> ValidateSteamParental(string steamParentalCode = null) {
if (!Client.IsConnected) {
return null;
}
CParental_GetParentalSettings_Request request = new CParental_GetParentalSettings_Request { steamid = Client.SteamID };
SteamUnifiedMessages.ServiceMethodResponse response;
try {
response = await UnifiedParentalService.SendMessage(x => x.GetParentalSettings(request));
} catch (Exception e) {
ArchiLogger.LogGenericWarningException(e);
return null;
}
if (response == null) {
ArchiLogger.LogNullError(nameof(response));
return null;
}
if (response.Result != EResult.OK) {
return null;
}
CParental_GetParentalSettings_Response body = response.GetDeserializedResponse<CParental_GetParentalSettings_Response>();
if (body.settings == null) {
return null;
}
if (!body.settings.is_enabled) {
return (false, null);
}
ArchiCryptoHelper.ESteamParentalAlgorithm steamParentalAlgorithm;
switch (body.settings.passwordhashtype) {
case 4:
steamParentalAlgorithm = ArchiCryptoHelper.ESteamParentalAlgorithm.Pbkdf2;
break;
case 6:
steamParentalAlgorithm = ArchiCryptoHelper.ESteamParentalAlgorithm.SCrypt;
break;
default:
ASF.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(body.settings.passwordhashtype), body.settings.passwordhashtype));
return (false, null);
}
if ((steamParentalCode != null) && (steamParentalCode.Length == BotConfig.SteamParentalCodeLength)) {
byte i = 0;
byte[] password = new byte[steamParentalCode.Length];
foreach (char character in steamParentalCode) {
if ((character < '0') || (character > '9')) {
break;
}
password[i++] = (byte) character;
}
if (i >= steamParentalCode.Length) {
byte[] passwordHash = ArchiCryptoHelper.GenerateSteamParentalHash(password, body.settings.salt, (byte) body.settings.passwordhash.Length, steamParentalAlgorithm);
if (passwordHash.SequenceEqual(body.settings.passwordhash)) {
return (true, steamParentalCode);
}
}
}
ArchiLogger.LogGenericInfo(Strings.BotGeneratingSteamParentalCode);
steamParentalCode = ArchiCryptoHelper.RecoverSteamParentalCode(body.settings.passwordhash, body.settings.salt, steamParentalAlgorithm);
ArchiLogger.LogGenericInfo(Strings.Done);
return (true, steamParentalCode);
}
private void HandleItemAnnouncements(IPacketMsg packetMsg) {
if (packetMsg == null) {
ArchiLogger.LogNullError(nameof(packetMsg));