public void OnError_DetachIdentity(int statusCode, int reasonCode, string statusMessage, object cbObject) { m_state = ResponseState.Error; m_response = reasonCode + ":" + statusMessage; Debug.LogError("OnError_DetachIdentity: " + statusMessage); if (ErrorHandling.SharedErrorHandling(statusCode, reasonCode, statusMessage, cbObject, gameObject)) { return; } switch (reasonCode) { case ReasonCodes.DOWNGRADING_TO_ANONYMOUS_ERROR: { // Display to the user that removing this identity would make there account // anonymous. Ask them if they are sure they want to perform this action Destroy(gameObject); AnonymousDowngradeDialog.CreateDialog(m_exampleAccountType); break; } case ReasonCodes.MISSING_IDENTITY_ERROR: { Destroy(gameObject); ErrorDialog.DisplayErrorDialog( string.Format("You can't detach an {0} identity when you don't have one.", UtilExampleAccountType.getTypeName(m_exampleAccountType)), reasonCode + ":" + statusMessage); break; } case ReasonCodes.SECURITY_ERROR: { Destroy(gameObject); ErrorDialog.DisplayErrorDialog( string.Format("You can't detach an {0} identity that doesn't belong to you.", UtilExampleAccountType.getTypeName(m_exampleAccountType)), reasonCode + ":" + statusMessage); break; } default: { // log the reasonCode to your own internal error checking ErrorHandling.UncaughtError(statusCode, reasonCode, statusMessage, cbObject, gameObject); break; } } }
/// <summary> /// /// </summary> /// <param name="statusCode"></param> /// <param name="reasonCode"></param> /// <param name="statusMessage"></param> /// <param name="cbObject"></param> /// <param name="parentDialog"></param> public static void UncaughtError(int statusCode, int reasonCode, string statusMessage, object cbObject, GameObject parentDialog) { string response = reasonCode + ":" + statusMessage; if (parentDialog) { Object.Destroy(parentDialog); } // log the reasonCode to your own internal error checking ErrorDialog.DisplayErrorDialog("Untracked error", response); }
public void OnError_AttachIdentity(int statusCode, int reasonCode, string statusMessage, object cbObject) { m_state = ResponseState.Error; m_response = reasonCode + ":" + statusMessage; Debug.LogError("OnError_AttachIdentity: " + statusMessage); if (ErrorHandling.SharedErrorHandling(statusCode, reasonCode, statusMessage, cbObject, gameObject)) { return; } switch (reasonCode) { case ReasonCodes.DUPLICATE_IDENTITY_TYPE: { //Users cannot attach an identity of a type that is already on there account // decide how this will be handled, such as prompting the user remove the current // identity before attaching one of the same type Destroy(gameObject); ErrorDialog.DisplayErrorDialog( string.Format("Account already has an identity of this {0} type, please detach first.", UtilExampleAccountType.getTypeName(m_exampleAccountType)), m_response); break; } case ReasonCodes.MERGE_PROFILES: case ReasonCodes.SWITCHING_PROFILES: { //User cannot attach an identity that is already in use by another user // decide how this will be handled, such as prompting the user to merge the // two user accounts Destroy(gameObject); MergeIdentityDialog.MergIdentityRequestDialog(m_exampleAccountType); break; } default: { // log the reasonCode to your own internal error checking ErrorHandling.UncaughtError(statusCode, reasonCode, statusMessage, cbObject, gameObject); break; } } }
public static void AttachIdentityGooglePlay() { #if UNITY_ANDROID GameObject dialogObject = new GameObject("Dialog"); AttachIdentityDialog dialog = dialogObject.AddComponent <AttachIdentityDialog>(); dialog.m_exampleAccountType = ExampleAccountType.GooglePlay; GoogleIdentity.RefreshGoogleIdentity(identity => { BrainCloudWrapper.Client.IdentityService.AttachGoogleIdentity(identity.GoogleId, identity.GoogleToken, dialog.OnSuccess_AttachIndentity, dialog.OnError_AttachIdentity); }); #else ErrorDialog.DisplayErrorDialog("AuthenticateAsGooglePlay", "You can only use GooglePlay auth on Android Devices"); #endif }
public static void AuthenticateAsGooglePlay(bool forceCreate = false) { #if UNITY_ANDROID GameObject dialogObject = new GameObject("Dialog"); AuthenticateDialog dialog = dialogObject.AddComponent <AuthenticateDialog>(); dialog.m_exampleAccountType = ExampleAccountType.GooglePlay; GoogleIdentity.RefreshGoogleIdentity(identity => { App.Bc.AuthenticateGoogle(identity.GoogleId, identity.GoogleToken, forceCreate, dialog.OnSuccess_Authenticate, dialog.OnError_Authenticate); }); #else ErrorDialog.DisplayErrorDialog("AuthenticateAsGooglePlay", "You can only use GooglePlay auth on Android Devices"); #endif }
public static void DetachIdentityGooglePlay(bool contiuneAsAnonymous = false) { #if UNITY_ANDROID GameObject dialogObject = new GameObject("Dialog"); DetachIdentityDialog dialog = dialogObject.AddComponent <DetachIdentityDialog>(); dialog.m_exampleAccountType = ExampleAccountType.GooglePlay; GoogleIdentity.RefreshGoogleIdentity(identity => { App.Bc.Client.IdentityService.DetachGoogleIdentity(identity.GoogleId, contiuneAsAnonymous, dialog.OnSuccess_DetachIdentity, dialog.OnError_DetachIdentity); }); #else ErrorDialog.DisplayErrorDialog("AuthenticateAsGooglePlay", "You can only use GooglePlay auth on Android Devices"); #endif }
public void OnError_MergeIdentity(int statusCode, int reasonCode, string statusMessage, object cbObject) { m_state = ResponseState.Error; m_response = reasonCode + ":" + statusMessage; Debug.LogError("OnError_MergeIdentity: " + statusMessage); if (ErrorHandling.SharedErrorHandling(statusCode, reasonCode, statusMessage, cbObject, gameObject)) { return; } switch (reasonCode) { case ReasonCodes.DUPLICATE_IDENTITY_TYPE: { // Users cannot attach an identity of a type that is already on there account // Inform user to detach identities that are of the same type, before the merge Destroy(gameObject); ErrorDialog.DisplayErrorDialog( string.Format( "Accounts has conflicting identities, and cannot be merged. Remove identity types {0} matching the merging account, then merge.", User.getIdentities()), m_response); break; } default: { // log the reasonCode to your own internal error checking ErrorHandling.UncaughtError(statusCode, reasonCode, statusMessage, cbObject, gameObject); break; } } }
public void OnError_Authenticate(int statusCode, int reasonCode, string statusMessage, object cbObject) { m_state = ResponseState.Error; m_response = reasonCode + ":" + statusMessage; Debug.LogError("OnError_Authenticate: " + statusMessage); if (ErrorHandling.SharedErrorHandling(statusCode, reasonCode, statusMessage, cbObject, gameObject)) { return; } switch (reasonCode) { case ReasonCodes.MISSING_IDENTITY_ERROR: { // User's identity doesn't match one existing on brainCloud // Reset profile id and re-authenticate App.Bc.Client.AuthenticationService.ClearSavedProfileID(); ReAuthenticate(true); // @see WrapperAuthenticateDialog for an example that uses // permission dialog before creating the new profile break; } case ReasonCodes.SWITCHING_PROFILES: { // User profile id doesn't match the identity they are attempting to authenticate // Reset profile id and re-authenticate App.Bc.Client.AuthenticationService.ClearSavedProfileID(); ReAuthenticate(); // @see WrapperAuthenticateDialog for an example that uses // permission dialog before swapping break; } case ReasonCodes.TOKEN_DOES_NOT_MATCH_USER: { // User is receiving an error that they're username or password is wrong. // decide how this will be handled, such as prompting the user to re-enter // there login details Destroy(gameObject); ErrorDialog.DisplayErrorDialog( "Incorrect username or password. Please check your information and try again.", m_response); break; } case ReasonCodes.MISSING_PROFILE_ERROR: { // User is receiving an error that they're trying to authenticate an account that doesn't exist. // decide how this will be handled, such as creating the account by setting the forceCreate flag to true ReAuthenticate(true); break; } default: { // log the reasonCode to your own internal error checking ErrorHandling.UncaughtError(statusCode, reasonCode, statusMessage, cbObject, gameObject); break; } } }
/// <summary> /// Error handling that can occur on any call /// /// Return true if the reasonCode is handled /// /// </summary> /// <param name="statusCode"></param> /// <param name="reasonCode"></param> /// <param name="statusMessage"></param> /// <param name="cbObject"></param> /// <param name="parentDialog"></param> /// <returns></returns> public static bool SharedErrorHandling(int statusCode, int reasonCode, string statusMessage, object cbObject, GameObject parentDialog) { string response = reasonCode + ":" + statusMessage; switch (reasonCode) { case ReasonCodes.NO_SESSION: { // User session has expired, or they have no session // They will need to authenticate if (parentDialog != null) { Object.Destroy(parentDialog); } ErrorDialog.DisplayErrorDialog("Your session has expired, or your not logged in. Please log in again", response); return(true); } case ReasonCodes.PLATFORM_NOT_SUPPORTED: { // User is using an unsupported platform // If the platform is meant to be supported, it needs to be enabled via 'Core App Info - Platforms' on the brainCloud dashboard if (parentDialog != null) { Object.Destroy(parentDialog); } ErrorDialog.DisplayErrorDialog("The current platform is not supported.", response); return(true); } case ReasonCodes.GAME_VERSION_NOT_SUPPORTED: { // User game version is out of date, // Display a dialog to update their app to the latest version you have supplied // This version number is set in the 'Core App Info - Platforms' on the brainCloud dashboard // And is compared locally against GameVersion set in the BrainCloudSettings config if (parentDialog != null) { Object.Destroy(parentDialog); } ErrorDialog.DisplayErrorDialog( "Your app version is out of date. Please update to the latest Error Handling demo app", response); return(true); } case ReasonCodes.CLIENT_NETWORK_ERROR_TIMEOUT: { // User cannot connect to brainCloud. // Display a connection error, and ask them if they wish to try again now or later if (parentDialog != null) { Object.Destroy(parentDialog); } ErrorDialog.DisplayErrorDialog("Can't connect to server. Try again later.", response); return(true); } default: { return(false); } } }
public void OnError_Authenticate(int statusCode, int reasonCode, string statusMessage, object cbObject) { m_state = ResponseState.Error; m_response = reasonCode + ":" + statusMessage; Debug.LogError("OnError_Authenticate: " + statusMessage); if (ErrorHandling.SharedErrorHandling(statusCode, reasonCode, statusMessage, cbObject, gameObject)) { return; } switch (reasonCode) { case ReasonCodes.MISSING_IDENTITY_ERROR: { // User's identity doesn't match one existing on brainCloud // Clear the invalid Profile and Anon Id values, and reauthenticate App.Bc.ResetStoredProfileId(); App.Bc.ResetStoredAnonymousId(); ReAuthenticate(); break; } case ReasonCodes.SWITCHING_PROFILES: { // User profile id doesn't match the identity they are attempting to authenticate // decide how this will be handled, such as with a switch account prompt, informing // them that they'll be switching profiles Destroy(gameObject); WrapperSwitchAccountDialog.CreateDialog(m_exampleAccountType); break; } case ReasonCodes.TOKEN_DOES_NOT_MATCH_USER: { // User is receiving an error that they're username or password is wrong. // decide how this will be handled, such as prompting the user to re-enter // there login details Destroy(gameObject); ErrorDialog.DisplayErrorDialog( "Incorrect username or password. Please check your information and try again.", m_response); break; } case ReasonCodes.MISSING_PROFILE_ERROR: { // User is receiving an error that they're trying to authenticate an account that doesn't exist. // decide how this will be handled, such as creating the account by setting the forceCreate flag to true Destroy(gameObject); WrapperCreateAccountDialog.CreateDialog(m_exampleAccountType); break; } default: { // log the reasonCode to your own internal error checking ErrorHandling.UncaughtError(statusCode, reasonCode, statusMessage, cbObject, gameObject); break; } } }