public static async void AuthenticateAccount(Account account, string html, string code) { //* get csrf token LoginData data = GetLoginData(html, true); //* build our values NameValueCollection collection = CreateAuthenticationCollection(account, data, code); string response = string.Empty; try { response = await account.Client.PostData(GetRegionAuthentication(account.Region), collection); } catch (Exception ex) { CreateException(ex, account); return; } collection.Clear(); collection = null; LoginResult result = GetLoginResult(response); if (result == LoginResult.Success) { await GetAccountGames(account, response); account.LastUpdated = DateTime.Now; account.IsUpdating = false; return; } CreateWebError(result, account); }
/// <summary> /// Adds the specified account to the list and immediately updates it /// </summary> /// <param name="account"></param> public static async void AddAccount(Account account) { if (Accounts == null) Accounts = new ObservableCollection<Account>(); Accounts.Add(account); bool result = await UpdateAccount(account); //* schedule next update if (p_NextUpdate.Enabled) return; p_NextUpdate.Interval = 5 * 60 * 1000; p_NextUpdate.Start(); }
private void bAddAccount_Click(object sender, RoutedEventArgs e) { AddAccount dialog = new AddAccount(); dialog.Owner = this; bool? result = dialog.ShowDialog(); if (!result.HasValue) return; if (!result.Value) return; Account account = new Account(dialog.Username, dialog.Password, dialog.Region, dialog.Key, dialog.IV); dialog = null; Status.AddAccount(account); Files.SaveAccounts(Status.Accounts.ToList()); }
private static NameValueCollection CreateAuthenticationCollection(Account account, LoginData data, string code) { NameValueCollection collection = new NameValueCollection(); collection.Add("authValue", code); collection.Add("persistAuthenticator", "true"); collection.Add("csrftoken", data.CSRFToken); return collection; }
private static bool AccountOK(Account account) { if (account == null) return false; if (account.Username == null || account.Password == null || account.Username == string.Empty || account.Password == string.Empty) return false; if (account.Client == null) account.Client = new Client(); if (account.Region == Regions.None) account.Region = Regions.US; return true; }
private static NameValueCollection CreateLoginCollection(Account account, LoginData data) { NameValueCollection collection = new NameValueCollection(); collection.Add("accountName", account.Username); collection.Add("password", account.Password); collection.Add("useSrp", "false"); collection.Add("publicA", string.Empty); collection.Add("clientEvidenceM1", string.Empty); collection.Add("persistLogin", "false"); collection.Add("submit", "submit"); collection.Add("csrftoken", data.CSRFToken); collection.Add("sessionTimeout", data.SessionTimeout.ToString()); return collection; }
private static async Task<bool> GetAccountGames(Account account, string html) { if (!html.Contains("<title>Battle.net Account</title>")) html = await account.Client.GetHTML(GetRegionURL(account.Region, false)); html = html.Remove(0, html.IndexOf("Your Game Accounts")); html = html.Remove(html.IndexOf("Add a Game Key")); if (html.Contains("Overwatch® Beta")) { account.HasOverwatchBeta = true; BetaFoundEventArgs e = new BetaFoundEventArgs(); e.Account = account; NotifyBetaFound(e); } return true; }
private static void CreateWebError(LoginResult result, Account account) { WebErrorEventArgs e = new WebErrorEventArgs(); e.Reason = result; e.Account = account; NotifyWebErrorOccurred(e); }
private static void CreateException(Exception ex, Account account) { ExceptionEventArgs e = new ExceptionEventArgs(); e.Exception = ex; e.Account = account; NotifyExceptionOccurred(e); }
private static async Task<bool> UpdateAccount(Account account) { if (!AccountOK(account)) return false; string html = string.Empty, url, response = string.Empty; NameValueCollection post; Pages page; LoginResult result; //* flag we are updating account.IsUpdating = true; //* lets try to log in url = GetRegionURL(account.Region, true); if (url == null) { account.IsUpdating = false; CreateWebError(LoginResult.InvalidRegion, account); return false; } try { html = await account.Client.GetHTML(url); } catch (Exception ex) { CreateException(ex, account); return false; } //* we wanted to go to the login page, if it redirected us, we are probably already logged in page = GetPage(html); if (page == Pages.AccountManagement || page == Pages.Root) { //* navigate to account management and read available games try { await GetAccountGames(account, html); } catch (Exception ex) { CreateException(ex, account); return false; } account.LastUpdated = DateTime.Now; account.IsUpdating = false; return true; } //* we got a page we didn't expect; for now just return false if (page != Pages.Login) return false; post = CreateLoginCollection(account, GetLoginData(html, false)); //* now log in try { response = await account.Client.PostData(url, post); } catch (Exception ex) { CreateException(ex, account); return false; } post.Clear(); post = null; result = GetLoginResult(response); if (result == LoginResult.Success) { //* navigate to account management and read available games try { await GetAccountGames(account, response); } catch (Exception ex) { CreateException(ex, account); return false; } account.LastUpdated = DateTime.Now; account.IsUpdating = false; return true; } else if (result == LoginResult.AuthenticationRequired) { //* everything went fine BUT we need to authenticate (either authenticator or sms) InputRequiredEventArgs e = new InputRequiredEventArgs(); e.Account = account; e.HTML = response; e.Type = GetAuthenticationType(response); NotifyInputRequired(e); return true; } else { CreateWebError(result, account); return false; } }