Exemplo n.º 1
0
    // =========================================================================================================================

    #region --- Create new user...

    public UsernameAlreadyExists CheckIfUserNameExist(string inUserName)     //TODO: PRIMARY KEY - nemelo by se tu pouzvat primaryKey?
    {
        UsernameAlreadyExists action = new UsernameAlreadyExists(inUserName);

        GameCloudManager.AddAction(action);
        return(action);
    }
Exemplo n.º 2
0
    IEnumerator Login_Coroutine(E_UserAcctKind kind,
                                string userid,
                                string vendorID,
                                string legacyUsername,
                                string[] usernames,
                                string nickname,
                                string password,
                                string email)
    {
        if (string.IsNullOrEmpty(userid) == true && string.IsNullOrEmpty(vendorID) == true)
        {
            ShowMessage(MESSAGE_FAILED, true);
            yield break;
        }

        string pwdhash    = CloudServices.CalcPasswordHash(password);
        string username   = null;
        string primaryKey = null;

        ShowMessage(MESSAGE_WAIT, false);
        yield return(new WaitForSeconds(0.1f));

#if UNITY_IPHONE
        // fail when there is invalid guest account based on invalid MAC address generated
        if (legacyUsername == "guest6024a02ea5577bcb6442a70d0bfa791935839db3i")
        {
            Debug.LogWarning("It's not possible to deduce valid guest account. Login failed!");
            ShowMessage(MESSAGE_FAILED, true);
            yield break;
        }
#endif

        // check if username exists
        bool legacyUsernameExists = false;
        if (string.IsNullOrEmpty(legacyUsername) == false)
        {
            // NOTE: this check is obsolete but we need to do it
            //       to support legacy accounts
            UsernameAlreadyExists usernameExists = CloudUser.instance.CheckIfUserNameExist(legacyUsername);
            while (usernameExists.isDone == false)
            {
                yield return(new WaitForEndOfFrame());
            }

            if (usernameExists.isFailed == true)
            {
                ShowMessage(MESSAGE_FAILED, true);
                yield break;
            }

            legacyUsernameExists = usernameExists.userExist;
        }

        if (legacyUsernameExists == true)
        {
            username = legacyUsername;

            // obtain primaryKey using legacyUsername
            UserGetPrimaryKey action = new UserGetPrimaryKey(legacyUsername);
            GameCloudManager.AddAction(action);

            while (action.isDone == false)
            {
                yield return(new WaitForEndOfFrame());
            }

            if (action.isSucceeded == true)
            {
                primaryKey = action.primaryKey;
            }
        }
        else
        {
            // obtain primaryKey using userid
            string idType = kind == E_UserAcctKind.Guest ? CloudServices.LINK_ID_TYPE_DEVICE : CloudServices.LINK_ID_TYPE_FACEBOOK;

            GetPrimaryKeyLinkedWithID action = new GetPrimaryKeyLinkedWithID(kind, userid, idType);
            GameCloudManager.AddAction(action);

            while (action.isDone == false)
            {
                yield return(new WaitForEndOfFrame());
            }

            if (action.isSucceeded == true && action.isPrimaryKeyForSHDZ == true)
            {
                primaryKey = action.primaryKey;
            }
        }

#if UNITY_IPHONE || TEST_IOS_VENDOR_ID
        if (kind == E_UserAcctKind.Guest && string.IsNullOrEmpty(primaryKey) == true)
        {
            // obtain username using userid
            GetPrimaryKeyLinkedWithID action = new GetPrimaryKeyLinkedWithID(kind, vendorID, CloudServices.LINK_ID_TYPE_IOSVENDOR);
            GameCloudManager.AddAction(action);

            while (action.isDone == false)
            {
                yield return(new WaitForEndOfFrame());
            }

            //Debug.Log(">>>> action.isSucceeded="+action.isSucceeded+", action.primaryKey="+action.primaryKey);

            if (action.isSucceeded == true && action.isPrimaryKeyForSHDZ == true)
            {
                primaryKey = action.primaryKey;
            }
        }
#endif

        // create new account if needed
        if (string.IsNullOrEmpty(primaryKey) == true)
        {
            ShowMessage(MESSAGE_NEW_ACCT, false);

            // check available names
            UsernamesAlreadyExist checkAvailableNames = new UsernamesAlreadyExist(usernames);
            GameCloudManager.AddAction(checkAvailableNames);
            while (checkAvailableNames.isDone == false)
            {
                yield return(new WaitForEndOfFrame());
            }

            List <string> availableNames = new List <string>();
            foreach (var pair in checkAvailableNames.usernames)
            {
                if (pair.Exists == false)
                {
                    availableNames.Add(pair.Username);
                }
            }

            if (availableNames.Count == 0)
            {
                ShowMessage(MESSAGE_FAILED, true);
                yield break;
            }

            username = availableNames[0];
            nickname = string.IsNullOrEmpty(nickname) == true ? username : nickname.RemoveDiacritics();

            //Debug.Log(string.Join(System.Environment.NewLine, availableNames.ToArray()));
            //Debug.Log(">>>> "+kind+" :: username="******", nickname="+nickname+", email="+email+", password="******">>>> LOGIN :: primaryKey="+primaryKey+", username="******", nickname="+nickname+", email="+email+", password="******"Authentication",
                            TextDatabase.instance[02040016],
                            "",
                            (inPopup, inResult) =>
            {
                if (inResult == E_PopupResultCode.Success)
                {
                    Owner.Exit();
                }
            });
        }
    }