private static async Task <int> OnReset(ResetOptions options) { if (options == null) { Console.WriteLine("Unknown parameter error"); return(-1); } DevAccount account = ToolAuthentication.LoadLastSignedInUser(); if (account == null) { Console.Error.WriteLine("Didn't found dev sign in info, please use \"XblDevAccount.exe signin\" to initiate."); return(-1); } Console.WriteLine($"Using Dev account {account.Name} from {account.AccountSource}"); Console.WriteLine($"Resetting player {options.XboxUserId} data for scid {options.ServiceConfigurationId}, sandbox {options.Sandbox}"); try { UserResetResult result = await PlayerReset.ResetPlayerDataAsync( options.ServiceConfigurationId, options.Sandbox, options.XboxUserId); switch (result.OverallResult) { case ResetOverallResult.Succeeded: Console.WriteLine("Resetting has completed successfully."); return(0); case ResetOverallResult.CompletedError: Console.WriteLine("Resetting has completed with some error:"); if (!string.IsNullOrEmpty(result.HttpErrorMessage)) { Console.WriteLine($"\t{result.HttpErrorMessage}"); } PrintProviderDetails(result.ProviderStatus); return(-1); case ResetOverallResult.Timeout: Console.WriteLine("Resetting has timed out:"); PrintProviderDetails(result.ProviderStatus); return(-1); default: Console.WriteLine("has completed with unknown error"); return(-1); } } catch (HttpRequestException ex) { Console.WriteLine("Error: player data reset failed"); if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Unauthorized))) { Console.WriteLine( $"Unable to authorize the account with XboxLive service with scid : {options.ServiceConfigurationId} and sandbox : {options.Sandbox}, please contact your administrator."); } else if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Forbidden))) { Console.WriteLine( "Your account doesn't have access to perform the operation, please contact your administrator."); } else { Console.WriteLine(ex.Message); } return(-1); } }
private static async Task <int> OnReset(ResetOptions options) { string xuid = string.Empty; if (options == null) { Console.WriteLine("Unknown parameter error"); return(-1); } if (!string.IsNullOrEmpty(options.TestAccount)) { TestAccount testAccount = await ToolAuthentication.SignInTestAccountAsync(options.TestAccount, options.Sandbox); if (testAccount == null) { Console.Error.WriteLine($"Failed to log in to test account {options.TestAccount}."); return(-1); } xuid = testAccount.Xuid; Console.WriteLine($"Using Test account {options.TestAccount} ({testAccount.Gamertag}) with xuid {xuid}"); } else if (!string.IsNullOrEmpty(options.XboxUserId)) { DevAccount account = ToolAuthentication.LoadLastSignedInUser(); if (account == null) { Console.Error.WriteLine("Resetting by XUID requires a signed in Partner Center account. Please use \"XblDevAccount.exe signin\" to log in."); return(-1); } xuid = options.XboxUserId; Console.WriteLine($"Using Dev account {account.Name} from {account.AccountSource}"); } Console.WriteLine($"Resetting data for player with XUID {xuid} for SCID {options.ServiceConfigurationId} in sandbox {options.Sandbox}"); try { UserResetResult result = await PlayerReset.ResetPlayerDataAsync( options.ServiceConfigurationId, options.Sandbox, xuid); switch (result.OverallResult) { case ResetOverallResult.Succeeded: Console.WriteLine("Player data has been reset successfully."); return(0); case ResetOverallResult.CompletedError: Console.WriteLine("An error occurred while resetting player data:"); if (!string.IsNullOrEmpty(result.HttpErrorMessage)) { Console.WriteLine($"\t{result.HttpErrorMessage}"); } PrintProviderDetails(result.ProviderStatus); return(-1); case ResetOverallResult.Timeout: Console.WriteLine("Player data reset has timed out:"); PrintProviderDetails(result.ProviderStatus); return(-1); default: Console.WriteLine("An unknown error occurred while resetting player data."); return(-1); } } catch (HttpRequestException ex) { Console.WriteLine("Error: player data reset failed"); if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Unauthorized))) { Console.WriteLine( $"Unable to authorize the account with Xbox Live and scid : {options.ServiceConfigurationId} and sandbox : {options.Sandbox}, please contact your administrator."); } else if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Forbidden))) { Console.WriteLine( "Your account doesn't have access to perform the operation, please contact your administrator."); } else { Console.WriteLine(ex.Message); } return(-1); } }