IEnumerator Login_Coroutine() { GuiPopupMessageBox msgBox = Owner.ShowPopup("MessageBox", TextDatabase.instance[02040016], TextDatabase.instance[02040017]) as GuiPopupMessageBox; // get primary key string primaryKey; { UserGetPrimaryKey action = new UserGetPrimaryKey(m_UserName); GameCloudManager.AddAction(action); while (action.isDone == false) { yield return(new WaitForEndOfFrame()); } primaryKey = action.primaryKey; } #if UNITY_IPHONE || TEST_IOS_VENDOR_ID if (string.IsNullOrEmpty(m_UserName) == false && m_UserName.StartsWith("guest") == true) { string userid = SysUtils.GetUniqueDeviceID(); string vendorID = null; while (string.IsNullOrEmpty(vendorID) == true) { vendorID = MFNativeUtils.IOS.VendorId; yield return(new WaitForEndOfFrame()); } string id = string.IsNullOrEmpty(userid) ? vendorID : userid; string idtype = string.IsNullOrEmpty(userid) ? CloudServices.LINK_ID_TYPE_IOSVENDOR : CloudServices.LINK_ID_TYPE_DEVICE; //Debug.Log(">>>> ID="+id+", IDType="+idtype); GetPrimaryKeyLinkedWithID action = new GetPrimaryKeyLinkedWithID(E_UserAcctKind.Guest, id, idtype); GameCloudManager.AddAction(action); while (action.isDone == false) { yield return(new WaitForEndOfFrame()); } msgBox.ForceClose(); //Debug.Log(">>>> action.isSucceeded="+action.isSucceeded+", action.primaryKey="+action.primaryKey+", primaryKey="+primaryKey); bool force = action.isFailed == true || action.isPrimaryKeyForSHDZ == false || action.primaryKey != primaryKey; bool migrate = false; GuiPopupMigrateGuest migratePopup = (GuiPopupMigrateGuest)Owner.ShowPopup("MigrateGuest", null, null, (inPopup, inResult) => { migrate = inResult == E_PopupResultCode.Ok; }); migratePopup.Usage = force ? GuiPopupMigrateGuest.E_Usage.QuickPlay : GuiPopupMigrateGuest.E_Usage.LoginScreen; migratePopup.PrimaryKey = primaryKey; migratePopup.Password = m_PasswordHash; while (migratePopup.IsVisible == true) { yield return(new WaitForEndOfFrame()); } if (migrate == true) { yield break; } } #endif if (msgBox.IsVisible == true) { msgBox.ForceClose(); } CloudUser cloudUser = CloudUser.instance; cloudUser.SetLoginData(primaryKey, m_UserName, m_UserName, m_PasswordHash, m_PasswordLength, m_RememberMe, m_AutoLogin); CloudUser.instance.AuthenticateLocalUser(); Owner.ShowPopup("Authentication", TextDatabase.instance[02040016], "", AuthenticationResultHandler); // Invoke("AuthenticationDeadLoopFixer", 20); // TODO disable Login screen. }
IEnumerator AuthenticateUser_Corutine() { UnigueUserID userID = new UnigueUserID(primaryKey, passwordHash, productID); string deviceID = SysUtils.GetUniqueDeviceID(); string facebookID = string.Empty; SetAuthenticationStatus(E_AuthenticationStatus.InProgress); // capa // ------------------------------------------------------------------------- // retrieve facebook id... if (FacebookPlugin.Instance.CurrentUser != null) { facebookID = FacebookPlugin.Instance.CurrentUser.ID; } // ------------------------------------------------------------------------- // authenticate user... // capa // SetAuthenticationStatus(E_AuthenticationStatus.InProgress); { AuthenticateUser action = new AuthenticateUser(userID, deviceID, facebookID); GameCloudManager.AddAction(action); // wait for async action... while (action.isDone == false) { yield return(new WaitForEndOfFrame()); } // process action result... if (action.isFailed == true) { SetAuthenticationStatus(E_AuthenticationStatus.Failed, action.failInfo); yield break; } authenticatedUserID = userID; // this will be overwritten later ProcessAuthenticationData() m_UserAcctKind = E_UserAcctKind.Normal; // rip data from sub-actions string err; if (ProcessAuthenticationData(action.actions, out err) == false) { SetAuthenticationStatus(E_AuthenticationStatus.Failed, err); yield break; } } #if UNITY_IPHONE || TEST_IOS_VENDOR_ID // pair guest account with vendorID if (m_UserAcctKind == E_UserAcctKind.Guest) { yield return(StartCoroutine(PairGuestAccountWithVendorID_Coroutine(userID))); } #endif // ------------------------------------------------------------------------- // Retrive player persistent info... SetAuthenticationStatus(E_AuthenticationStatus.RetrievingPPI); { BaseCloudAction action = new FetchPlayerPersistantInfo(userID); GameCloudManager.AddAction(action); // wait for async action... while (action.isDone == false) { yield return(new WaitForEndOfFrame()); } // process action result... if (action.isFailed == true) { SetAuthenticationStatus(E_AuthenticationStatus.Failed, "Can't retrive Player Data"); yield break; } //Debug.Log("Authentication process succeful"); } // ------------------------------------------------------------------------- SetAuthenticationStatus(E_AuthenticationStatus.Ok); // ------------------------------------------------------------------------- // raise authentication changed event OnAuthenticationChanged(true); // ------------------------------------------------------------------------- // raise premium acct changed event CheckPremiumAcct(true); }
// PRIVATE METHODS IEnumerator LoginAsGuest_Coroutine() { ShowMessage(MESSAGE_WAIT, false); yield return(new WaitForSeconds(0.1f)); #if TEST_IOS_VENDOR_ID string userid = string.Empty; #else string userid = SysUtils.GetUniqueDeviceID(); #endif string vendorID = string.Empty; #if UNITY_IPHONE || TEST_IOS_VENDOR_ID char deviceType = 'i'; // it can happen that vendotID is null // so we need to try it again while (string.IsNullOrEmpty(vendorID) == true) { vendorID = MFNativeUtils.IOS.VendorId; yield return(new WaitForEndOfFrame()); } // should we ask the user to migrate his account? if (string.IsNullOrEmpty(userid) == true) { string storedUsername = PlayerPrefs.GetString(CloudUser.USERNAME_KEY, string.Empty); string storedPrimaryKey = PlayerPrefs.GetString(CloudUser.PRIMARY_KEY_KEY, string.Empty); string storedPassword = PlayerPrefs.GetString(CloudUser.PASSWORD_HASH_KEY, string.Empty); if (string.IsNullOrEmpty(storedPrimaryKey) == true) { storedPrimaryKey = storedUsername; } if (string.IsNullOrEmpty(storedUsername) == false && storedUsername.StartsWith("guest") == true) { string id = string.IsNullOrEmpty(userid) ? vendorID : userid; string idtype = string.IsNullOrEmpty(userid) ? CloudServices.LINK_ID_TYPE_IOSVENDOR : CloudServices.LINK_ID_TYPE_DEVICE; //Debug.Log(">>>> ID="+id+", IDType="+idtype); GetPrimaryKeyLinkedWithID action = new GetPrimaryKeyLinkedWithID(E_UserAcctKind.Guest, id, idtype); GameCloudManager.AddAction(action); while (action.isDone == false) { yield return(new WaitForEndOfFrame()); } //Debug.Log(">>>> action.isSucceeded="+action.isSucceeded+", action.primaryKey="+action.primaryKey+", storedPrimaryKey="+storedPrimaryKey); if (action.isSucceeded == true && action.isPrimaryKeyForSHDZ == true && action.primaryKey != storedPrimaryKey) { HideMessage(); bool migrate = false; GuiPopupMigrateGuest migratePopup = (GuiPopupMigrateGuest)Owner.ShowPopup("MigrateGuest", null, null, (inPopup, inResult) => { migrate = inResult == E_PopupResultCode.Ok; }); migratePopup.Usage = GuiPopupMigrateGuest.E_Usage.QuickPlay; migratePopup.PrimaryKey = storedPrimaryKey; migratePopup.Password = storedPassword; while (migratePopup.IsVisible == true) { yield return(new WaitForEndOfFrame()); } if (migrate == true) { yield break; } } } } #else char deviceType = 'a'; #endif string username = null; string nickname = null; string email = ""; string password = null; if (string.IsNullOrEmpty(userid) == false) { username = string.Format("guest{0}{1}", userid.ToLower(), deviceType); password = string.Format("pwd{0}!", userid); } else { password = string.Format("pwd{0}!", string.Format("VID{0}", utils.CryptoUtils.CalcSHA1Hash(vendorID))); } List <string> usernames = new List <string>(); usernames.AddRange(GuiBaseUtils.GenerateUsernames("guest", false)); if (string.IsNullOrEmpty(username) == false) { usernames.Add(username); } //Debug.Log(">>>> GUEST :: username="******", nickname="+nickname+", email="+email+", password="+password); yield return (StartCoroutine(Login_Coroutine(E_UserAcctKind.Guest, userid, vendorID, username, usernames.ToArray(), nickname, password, email))); }