Exemple #1
0
    IEnumerator FetchProductMessages_Corutine(string inMailboxName = null)
    {
        // construct special user needed for accessing global per product inbox...
        UnigueUserID product_user = new UnigueUserID("", "", PPIManager.ProductID);

        // Create action for fetching messages from global product inbox...
        BaseCloudAction action = new GetProductGlobalMessages(product_user, m_LastMessageIndexFromProductInbox, inMailboxName);

        GameCloudManager.AddAction(action);

        // wait for action finish...
        while (action.isDone == false)
        {
            yield return(new WaitForSeconds(0.2f));
        }

        // end with error if action was not succesfully...
        if (action.isFailed == true)
        {
            Debug.LogError("Can't obtain messages " + action.result);
            yield break;
        }

        // try to process returned result and save Inbox if there are new messages...
        int lastMessageIndex = ProcessMessages(action.result, true);

        if (m_LastMessageIndexFromProductInbox < lastMessageIndex)
        {
            m_LastMessageIndexFromProductInbox = lastMessageIndex;
            Save();

            OnInboxChanged();
        }
    }
Exemple #2
0
    public void LoadAuthenticationData()
    {
        m_NickName       = PlayerPrefs.GetString(NICKNAME_KEY, null);
        m_UserName       = PlayerPrefs.GetString(USERNAME_KEY, null);
        m_PrimaryKey     = PlayerPrefs.GetString(PRIMARY_KEY_KEY, null);
        m_PasswordHash   = PlayerPrefs.GetString(PASSWORD_HASH_KEY, null);
        m_PasswordLength = PlayerPrefs.GetInt(PASSWORD_LENGTH_KEY, 0);
        m_AutoLogin      = (PlayerPrefs.GetInt(AUTO_LOGIN_KEY, 0) != 0 ? true : false);

        if (string.IsNullOrEmpty(m_UserName) == false)
        {
            m_UserName = m_UserName.ToLower();
        }

        if (string.IsNullOrEmpty(m_PrimaryKey) == true)
        {
            m_PrimaryKey = m_UserName;
        }

        m_AuthenticationDataLoaded = authenticationDataPresent;

        if (m_AuthenticationDataLoaded == false)
        {
            // try to load old auth data...
            LoadAuthenticationData_OLD();
        }

        if (m_AuthenticationDataLoaded == true)
        {
            m_AuthenticatedUserID = new UnigueUserID(primaryKey, passwordHash, productID);
        }
    }
Exemple #3
0
 public QueryLeaderBoardScore(UnigueUserID inUserID,
                              string inLeaderBoardName,
                              int inStartIndex,
                              int inCount     = 1,
                              float inTimeOut = NoTimeOut)
     : base(inUserID, inTimeOut)
 {
     startRankIndex  = inStartIndex;
     leaderBoardName = inLeaderBoardName;
 }
    // HANDLERS

    void OnUserAuthenticationChanged(bool state)
    {
        if (state == true)
        {
            m_UserId = CloudUser.instance.authenticatedUserID;
            UserGuide.RegisterAction(m_UserGuideAction);
            StartCoroutine(CheckDailyRewards_Coroutine());
        }
        else
        {
            StopAllCoroutines();
            UserGuide.UnregisterAction(m_UserGuideAction);
            m_UserId = null;
        }
    }
Exemple #5
0
    public void SetLoginData(string inPrimaryKey,
                             string inNickName,
                             string inUserName,
                             string inPaswordHash,
                             int inPasswordLength,
                             bool inRemeberThem,
                             bool inAutoLogin)
    {
        m_PrimaryKey     = inPrimaryKey;
        m_NickName       = string.IsNullOrEmpty(inNickName) ? null : inNickName;
        m_UserName       = string.IsNullOrEmpty(inUserName) ? null : inUserName.ToLower();
        m_PasswordHash   = string.IsNullOrEmpty(inPaswordHash) ? null : inPaswordHash;
        m_PasswordLength = inPasswordLength;
        m_AutoLogin      = inAutoLogin;

        m_AuthenticatedUserID = new UnigueUserID(primaryKey, passwordHash, productID);

        m_AuthenticationDataLoaded = inRemeberThem;
        if (inRemeberThem == true)
        {
            PlayerPrefs.SetString(NICKNAME_KEY, m_NickName);
            PlayerPrefs.SetString(USERNAME_KEY, m_UserName);
            PlayerPrefs.SetString(PRIMARY_KEY_KEY, m_PrimaryKey);
            PlayerPrefs.SetString(PASSWORD_HASH_KEY, m_PasswordHash);
            PlayerPrefs.SetInt(PASSWORD_LENGTH_KEY, m_PasswordLength);
            PlayerPrefs.SetInt(AUTO_LOGIN_KEY, m_AutoLogin ? 1 : 0);
            PlayerPrefs.Save();
        }
        else
        {
            // delete, if user don't want to store this values...
            PlayerPrefs.DeleteKey(NICKNAME_KEY);
            PlayerPrefs.DeleteKey(USERNAME_KEY);
            PlayerPrefs.DeleteKey(PRIMARY_KEY_KEY);
            PlayerPrefs.DeleteKey(PASSWORD_HASH_KEY);
            PlayerPrefs.DeleteKey(PASSWORD_LENGTH_KEY);
            PlayerPrefs.DeleteKey(AUTO_LOGIN_KEY);
            PlayerPrefs.Save();
        }
    }
Exemple #6
0
    IEnumerator PairGuestAccountWithVendorID_Coroutine(UnigueUserID userID)
    {
        List <BaseCloudAction> actions = new List <BaseCloudAction>();

        // it can happen that iOSVendorID is null
        // so we need to try it again
        int    guard    = 100;
        string vendorID = string.Empty;

        while (guard > 0)
        {
            vendorID = MFNativeUtils.IOS.VendorId;
            if (string.IsNullOrEmpty(vendorID) == false)
            {
                break;
            }

            yield return(new WaitForEndOfFrame());

            guard -= 1;
        }
        if (string.IsNullOrEmpty(vendorID) == false)
        {
            actions.Add(new SetiOSVendorId(userID, vendorID));
        }

        // it can happen that iOSAdvertisingID is null
        // so we need to try it again
        guard = 100;
        string advertID = string.Empty;

        while (guard > 0)
        {
            advertID = MFNativeUtils.IOS.AdvertisingId;
            if (string.IsNullOrEmpty(advertID) == false)
            {
                break;
            }

            yield return(new WaitForEndOfFrame());

            guard -= 1;
        }
        if (string.IsNullOrEmpty(advertID) == false)
        {
            actions.Add(new SetiOSAdvertisingId(userID, advertID));
        }

        //Debug.Log(">>>> AUTHENTICATE :: vendorID="+vendorID+", advertID="+advertID);

        if (actions.Count > 0)
        {
            CloudActionSerial action = new CloudActionSerial(null, BaseCloudAction.NoTimeOut, actions.ToArray());
            GameCloudManager.AddAction(action);

            while (action.isDone == false)
            {
                yield return(new WaitForEndOfFrame());
            }
        }
    }
Exemple #7
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);
    }
Exemple #8
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);
    }
Exemple #9
0
    //Funkce pro fixnuti equipu na ppi
    //Projdeme casti equipu ktere by nemuseli byt validni a vytvorime seznam akci ktere je treba vykonat aby byl zase v poradku.
    //Pokud je vse v poradku, vraci null, jinak serial cloud action ktera se ma provest
    public static BaseCloudAction ValidateEquip()
    {
        List <BaseCloudAction> outActions = new List <BaseCloudAction>();
        PlayerPersistantInfo   ppi        = ShopDataBridge.Instance.PPI;
        UnigueUserID           userID     = CloudUser.instance.authenticatedUserID;

        //weapons:
        //bool anyWeaponEquipped = false;
        foreach (PPIWeaponData w in ppi.EquipList.Weapons)
        {
            //ignoruj prazdna id
            if (w.ID == E_WeaponID.None)
            {
                continue;
            }

            //pokud je item zakazany, nebo ma locknuty slot, odstran ho z equipu.
            WeaponSettings s = WeaponSettingsManager.Instance.Get(w.ID);
            if (s.DISABLED || ShopDataBridge.Instance.IsWeaponSlotLocked(w.EquipSlotIdx))
            {
                //unequip it
                outActions.Add(new SlotEquipAction(userID, s.GUID, w.EquipSlotIdx, false));
                continue;
            }

            //	anyWeaponEquipped = true;
        }

        /* we don't need this functionality right now,
         * because we don't allow player to spawn without any weapon now
         * //pokud nemame equpnutou zadnou zbran, pridej nejakou do prvniho slotu
         * if(!anyWeaponEquipped)
         * {
         *      List<ShopItemId> ownedWeapons = ShopDataBridge.Instance.GetOwnedWeapons();
         *      if(ownedWeapons.Count > 0)
         *      {
         *              int guid = ShopDataBridge.Instance.GetShopItemGUID(ownedWeapons[0]);
         *              outActions.Add(new SlotEquipAction(userID, guid, 0, true ));
         *      }
         * }*/

        //items:
        foreach (PPIItemData w in ppi.EquipList.Items)
        {
            //ignoruj prazdna id
            if (w.ID == E_ItemID.None)
            {
                continue;
            }

            //pokud je item zakazany, nebo ma locknuty slot, odstran ho z equipu.
            ItemSettings s = ItemSettingsManager.Instance.Get(w.ID);
            if (s.DISABLED || ShopDataBridge.Instance.IsItemSlotLocked(w.EquipSlotIdx))
            {
                //unequip it
                outActions.Add(new SlotEquipAction(userID, s.GUID, w.EquipSlotIdx, false));
                continue;
            }

            //pokud mame od itemu v inventari lepsi nebo naopak horsi verzi, updatni jej ve slotu.
            E_ItemID bestVersion = ShopDataBridge.Instance.FindBestItemUpgrade(w.ID);
            if (w.ID != bestVersion)
            {
                //replace it with actual version from inventory
                int bestVersionGUID = ItemSettingsManager.Instance.Get(bestVersion).GUID;
                outActions.Add(new SlotEquipAction(userID, bestVersionGUID, w.EquipSlotIdx, true));
                continue;
            }
        }

        //perk:
        if (ppi.EquipList.Perk != E_PerkID.None)
        {
            E_PerkID perk        = ppi.EquipList.Perk;
            E_PerkID bestVersion = ShopDataBridge.Instance.FindBestPerkUpgrade(ppi.EquipList.Perk);

            //pokud je zakazany, odstran jej ze slotu
            PerkSettings s = PerkSettingsManager.Instance.Get(perk);
            if (s.DISABLED)
            {
                //unequip it
                outActions.Add(new SlotEquipAction(userID, s.GUID, 0, false));
            }
            else if (perk != bestVersion)
            {
                //replace it with actual version from inventory
                int bestVersionGUID = PerkSettingsManager.Instance.Get(bestVersion).GUID;
                outActions.Add(new SlotEquipAction(userID, bestVersionGUID, 0, true));
            }
        }

        //skins:
        {
            ShopItemId        currSkin   = new ShopItemId((int)ppi.EquipList.Outfits.Skin, GuiShop.E_ItemType.Skin);
            List <ShopItemId> ownedSkins = ShopDataBridge.Instance.GetOwnedSkins();
            if (!ownedSkins.Contains(currSkin))
            {
                //Debug.Log("Equiped skin " + currSkin + " is not in inventory, switching to: " + ( (ownedSkins.Count > 0) ? ownedSkins[0].ToString() : "-none-") );

                if (ownedSkins.Count > 0)
                {
                    //equipnuty skin neni v inventari, vyber misto neho nejaky jiny
                    ownedSkins.Sort();
                    int guid = ShopDataBridge.Instance.GetShopItemGUID(ownedSkins[0]);
                    outActions.Add(new SlotEquipAction(userID, guid, 0, true));
                }
                else
                {
                    Debug.LogError("No skins in inventory!");
                }
            }
        }

        //upgrades:
        {
            List <PPIUpgradeList.UpgradeData> upgs = ppi.Upgrades.Upgrades;
            if (upgs.Find(u => u.ID == E_UpgradeID.ItemSlot2).ID != E_UpgradeID.ItemSlot2)
            {
                int guid = ShopDataBridge.Instance.GetShopItemGUID(new ShopItemId((int)E_UpgradeID.ItemSlot2, GuiShop.E_ItemType.Upgrade));
                outActions.Add(new ShopBuyAction(userID, guid));
            }

            if (upgs.Find(u => u.ID == E_UpgradeID.WeaponSlot2).ID != E_UpgradeID.WeaponSlot2)
            {
                int guid = ShopDataBridge.Instance.GetShopItemGUID(new ShopItemId((int)E_UpgradeID.WeaponSlot2, GuiShop.E_ItemType.Upgrade));
                outActions.Add(new ShopBuyAction(userID, guid));
            }
        }

        //pokud jsme neco zmenili, updatuj na zaver PPI
        if (outActions.Count > 0)
        {
            outActions.Add(new FetchPlayerPersistantInfo(userID));
            BaseCloudAction resultAction = new CloudActionSerial(userID, BaseCloudAction.NoTimeOut, outActions.ToArray());
            return(resultAction);
        }
        else
        {
            return(null);
        }
    }
Exemple #10
0
 public QueryLeaderBoardRankAndScores(UnigueUserID inUserID, string inLeaderBoardName, string[] inPrimaryKeys, float inTimeOut = NoTimeOut)
     : base(inUserID, inTimeOut)
 {
     users           = inPrimaryKeys;
     leaderBoardName = inLeaderBoardName;
 }
Exemple #11
0
 public QueryLeaderBoardRank(UnigueUserID inUserID, string inLeaderBoardName, string inPrimaryKey, float inTimeOut = NoTimeOut)
     : base(inUserID, inTimeOut)
 {
     users           = new string[] { inPrimaryKey };
     leaderBoardName = inLeaderBoardName;
 }