Esempio n. 1
0
    public Coroutine CreateNewUser(string inUserName,
                                   string inPasswordHash,
                                   string inNickName,
                                   string inEmail,
                                   bool inIWantNews,
                                   E_UserAcctKind inKind,
                                   System.Action <bool> callback)
    {
        E_AppProvider appProvider = E_AppProvider.Madfinger;

        // reset authentication status. New player is creating...
        SetAuthenticationStatus(E_AuthenticationStatus.None);

        return(StartCoroutine(CreateNewUser_Coroutine(inUserName, inPasswordHash, inNickName, inEmail, inIWantNews, inKind, appProvider, callback)));
    }
Esempio n. 2
0
    bool ProcessAuthenticationData(BaseCloudAction[] actions, out string err)
    {
        err = string.Empty;

        foreach (BaseCloudAction action in actions)
        {
            // -------------------------------------------------------------------------
            // Get actual region info...
            if (action is GetUserRegionInfo)
            {
                GetUserRegionInfo data = (GetUserRegionInfo)action;
                m_RealRegion  = data.region;
                m_CountryCode = data.countryCode;
            }
            // -------------------------------------------------------------------------
            // Get custom region info...
            else if (action is GetCustomRegionInfo)
            {
                if (action.isSucceeded == true)
                {
                    GetCustomRegionInfo data = (GetCustomRegionInfo)action;
                    m_CustomRegion = data.region;
                }
                else if (action.isFailed == true)
                {
                    SetUserProductData setAction = new SetUserProductData(m_AuthenticatedUserID, CloudServices.PROP_ID_CUSTOM_REGION, "none");
                    GameCloudManager.AddAction(setAction);
                }
            }
            // -------------------------------------------------------------------------
            // Get available premium accounts...
            else if (action is GetAvailablePremiumAccounts)
            {
                GetAvailablePremiumAccounts data = (GetAvailablePremiumAccounts)action;
                m_AvailableAccts = data.accounts;
                if (m_AvailableAccts == null)
                {
                    // do not break, this isn't critical...
                    Debug.LogWarning("Can't retrive list of all available premium accounts!");
                }
            }
            else if (action is GetUserData)
            {
                if (action.isSucceeded == true)
                {
                    GetUserData data = (GetUserData)action;
                    // -------------------------------------------------------------------------
                    // Get nick name from cloud...
                    if (data.dataID == CloudServices.PROP_ID_NICK_NAME)
                    {
                        string nickName = data.result;
                        if (string.IsNullOrEmpty(nickName) == false)
                        {
                            m_NickName = GuiBaseUtils.FixNickname(nickName, m_UserName);
                        }
                    }
                    // -------------------------------------------------------------------------
                    // Get 'i want news' from cloud...
                    else if (data.dataID == CloudServices.PROP_ID_I_WANT_NEWS)
                    {
                        bool receiveNews;
                        if (bool.TryParse(action.result, out receiveNews) == true)
                        {
                            m_ReceiveNews = receiveNews;
                        }
                    }
                    // -------------------------------------------------------------------------
                    // Get account kind from cloud...
                    else if (data.dataID == CloudServices.PROP_ID_ACCT_KIND)
                    {
                        try
                        {
                            m_UserAcctKind = (E_UserAcctKind)System.Enum.Parse(typeof(E_UserAcctKind), data.result, false);
                        }
                        catch
                        {
                        }
                    }
                }
            }
        }

        return(true);
    }
Esempio n. 3
0
    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);
    }
Esempio n. 4
0
    IEnumerator CreateNewUser_Coroutine(string inUserName,
                                        string inPasswordHash,
                                        string inNickName,
                                        string inEmail,
                                        bool inIWantNews,
                                        E_UserAcctKind inKind,
                                        E_AppProvider inAppProvider,
                                        System.Action <bool> callback)
    {
        // create user
        {
            _CreateNewUser action = new _CreateNewUser(inUserName, inPasswordHash, productID);
            GameCloudManager.AddAction(action);

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

            if (action.isFailed == true)
            {
                callback(false);
                yield break;
            }
        }

        // get primary key
        UnigueUserID userID;

        {
            UserGetPrimaryKey action = new UserGetPrimaryKey(inUserName);
            GameCloudManager.AddAction(action);

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

            userID = new UnigueUserID(action.primaryKey, inPasswordHash, productID);
        }

        // set user data
        {
            Dictionary <string, string> userData = new Dictionary <string, string>();

            userData.Add(CloudServices.PROP_ID_NICK_NAME, inNickName);
            userData.Add(CloudServices.PROP_ID_EMAIL, inEmail);
            userData.Add(CloudServices.PROP_ID_I_WANT_NEWS, inIWantNews.ToString());
            userData.Add(CloudServices.PROP_ID_ACCT_KIND, inKind.ToString());

            List <BaseCloudAction> actions = new List <BaseCloudAction>();

            actions.Add(new SetUserDataList(userID, userData));

            if (inAppProvider != E_AppProvider.Madfinger)
            {
                actions.Add(new SetUserProductData(userID, CloudServices.PROP_ID_APP_PROVIDER, inAppProvider.ToString()));
            }

            CloudActionSerial action = new CloudActionSerial(null, BaseCloudAction.NoTimeOut, actions.ToArray());
            GameCloudManager.AddAction(action);

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

        callback(true);
    }
Esempio n. 5
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();
                }
            });
        }
    }