Improve valid cd-key checks, closes #69

This commit is contained in:
JustArchi
2016-01-10 22:25:15 +01:00
parent 8d06dd90d8
commit 35fb7c4e7f
2 changed files with 19 additions and 11 deletions

View File

@@ -87,17 +87,10 @@ namespace ArchiSteamFarm {
return false;
}
if (key.Length != 17 && key.Length != 29) {
return false;
}
for (byte i = 5; i < key.Length; i += 6) {
if (key[i] != '-') {
return false;
}
}
return true;
// Steam keys are offered in many formats: https://support.steampowered.com/kb_article.php?ref=7480-WUSF-3601
// It's pointless to implement them all, so we'll just do a simple check if key is supposed to be valid
// Every valid key, apart from Prey one has at least two dashes
return Utilities.GetCharCountInString(key, '-') >= 2;
}
internal static string GetAnyBotName() {

View File

@@ -57,5 +57,20 @@ namespace ArchiSteamFarm {
return Regex.Replace(text, @"[^\d]", "");
}
internal static uint GetCharCountInString(string s, char c) {
if (string.IsNullOrEmpty(s)) {
return 0;
}
uint count = 0;
foreach (char singleChar in s) {
if (singleChar == c) {
count++;
}
}
return count;
}
}
}