Exemplo n.º 1
0
    void CheckManaInvitedFriend(int index, Action <string> callback)
    {
        if (index < _manaInvitedFriends.Count)
        {
            string uid = _manaInvitedFriends[index];

            FBHelper.GetAppUserName(uid, (name) => {
                if (string.IsNullOrEmpty(name))
                {
                    if (index < _manaInvitedFriends.Count - 1)
                    {
                        CheckManaInvitedFriend(index + 1, callback);
                    }
                    else
                    {
                        callback(null);
                    }
                }
                else
                {
                    RemoveManaInvitedFriend(uid);

                    callback(name);
                }
            });
        }
        else
        {
            callback(null);
        }
    }
Exemplo n.º 2
0
    void OnGUI()
    {
        if (_isLoggingIn)
        {
            return;
        }

        if (_isLogIn)
        {
            _isLogIn     = false;
            _isLoggingIn = true;

            FBHelper.LogIn((error) => {
                _isLoggingIn = false;

                if (_logInCallback != null)
                {
                    _logInCallback(error);
                }
            });

            return;
        }

        if (_isUpdateScore)
        {
            _isUpdateScore = false;

            UpdateScoreInternal(_updateScoreCallback);
        }
    }
Exemplo n.º 3
0
    void Awake()
    {
        Instance = this;

        Application.targetFrameRate = 60;

        FBHelper.Init();
    }
Exemplo n.º 4
0
        private IUser ValidateLogonFacebook(LoginFB login, out string Hash)
        {
            Hash = string.Empty;
            ApplicationRecord apprecord = _applicationsService.GetApplicationByKey(login.ApiKey);

            if (apprecord == null)
            {
                return(null);           // wrong cloudbast application id
            }
            DebugFB debuginfo = FBHelper.GetDebugInfo(login.Token, apprecord);

            if (!debuginfo.isValid)
            {
                return(null);           // access token is not valid
            }
            if (debuginfo.Application != apprecord.Name || debuginfo.AppId != apprecord.fbAppKey)
            {
                return(null);           // access token for another application
            }
            string email      = login.Username;
            var    lowerEmail = email == null ? "" : email.ToLowerInvariant();

            // load user with FBemail
            IUser           user    = _orchardServices.ContentManager.Query <UserPart, UserPartRecord>().Where(u => u.Email == lowerEmail).List().FirstOrDefault();
            UserProfilePart profile = null;

            if (user == null)
            {
                var     fb = new FacebookClient(login.Token);
                dynamic me = fb.Get("me");

                // since everything is correct, we have to create a new user
                var registrationSettings = _orchardServices.WorkContext.CurrentSite.As <RegistrationSettingsPart>();
                if (registrationSettings.UsersCanRegister)
                {
                    // create a user with random password
                    user = _membershipService.CreateUser(new CreateUserParams(lowerEmail, Guid.NewGuid().ToString(), lowerEmail, null, null, true)) as UserPart;

                    // add facebook fields
                    profile           = user.As <UserProfilePart>();
                    profile.FBemail   = lowerEmail;
                    profile.FBtoken   = login.Token;
                    profile.FirstName = me.first_name;
                    profile.LastName  = me.last_name;
                }
            }
            else
            {
                profile         = user.As <UserProfilePart>();
                profile.FBemail = lowerEmail;
                profile.FBtoken = login.Token;
            }
            Hash = _loginsService.CreateHash(profile, apprecord);
            _profileService.CreateUserForApplicationRecord(profile, apprecord);
            _orchardServices.WorkContext.HttpContext.Session["doticca_aid"] = apprecord.Id;
            return(user);
        }
Exemplo n.º 5
0
    public static void LogIn(Action <string> callback)
    {
#if UNITY_EDITOR
        _logInCallback = callback;
        _isLogIn       = true;
#else
        FBHelper.LogIn(callback);
#endif
    }
Exemplo n.º 6
0
    void LogoutFacebook()
    {
        FBHelper.LogOut();

        // Set sprite
        loginButton.SetSprite(logIn);

        // Show Facebook button
        SetShowFBButton(true, false);
    }
Exemplo n.º 7
0
    public static void GetAvatar(string id, Action <Sprite> callback)
    {
#if UNITY_EDITOR
        FBHelper.GetAvatar(id, (texture, error) => {
            if (string.IsNullOrEmpty(error))
            {
                callback(texture.ToSprite());
            }
            else
            {
                callback(null);
            }
        });
#else
        string path = Helper.GetFilePath("avatars");

        try
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }
        catch (IOException ex)
        {
            //Debug.Log(ex.Message);
        }

        path = string.Format("{0}/{1}.png", path, id);

        Texture2D texture = TextureHelper.Load(path);

        if (texture != null)
        {
            callback(texture.ToSprite());
        }
        else
        {
            FBHelper.GetAvatar(id, (texture2, error) => {
                if (string.IsNullOrEmpty(error))
                {
                    texture2.Save(path);

                    callback(texture2.ToSprite());
                }
                else
                {
                    callback(null);
                }
            });
        }
#endif
    }
Exemplo n.º 8
0
    void UpdateRequests()
    {
        if (!FB.IsLoggedIn)
        {
            return;
        }

        _requestUpdater.Stop();

        FBHelper.GetAskRequests((result, error) => {
            _requestUpdater.Play();

            if (!string.IsNullOrEmpty(error))
            {
                return;
            }
            if (result == null)
            {
                return;
            }

            RequestData[] requests = result.ToArray();
            int requestCount       = requests.Length;
            if (requestCount == 0)
            {
                return;
            }

            _requestUpdater.Stop();

            // Ask mana
            List <string> askManaIds = new List <string>(requestCount);

            for (int i = 0; i < requestCount; i++)
            {
                RequestData request = requests[i];

                if (request.ObjectType == FBObjectType.Mana)
                {
                    askManaIds.Add(request.FromId);

                    FBHelper.DeleteRequest(request.Id);
                }
            }

            if (askManaIds.Count > 0)
            {
                FBHelper.SendObject(null, "mana", Settings.SendManaTitle, Settings.SendManaMessage, (err) => {
                    _requestUpdater.Play();
                }, askManaIds.ToArray());
            }
        });
    }
Exemplo n.º 9
0
    void UpdateScoreInternal(Action callback)
    {
        // Get score
        FBHelper.GetScore(null, (score, error) => {
            // Get current level (zero-based)
            int level = UserData.Instance.Level - 1;

            if (score < level)
            {
                // Update score
                FBHelper.PostScore(null, level, (success, err) => {
                    if (callback != null)
                    {
                        callback();
                    }
                });
            }
            else
            {
                if (score > level)
                {
                    // Anti-hack
                    if (score > Settings.MapCount)
                    {
                        score = Settings.MapCount;

                        // Update score
                        FBHelper.PostScore(null, score);
                    }

                    // Set winned
                    UserData.Instance.SetWinned(level + 1, score);

                    // Update level
                    UserData.Instance.Level = score + 1;
                }

                if (callback != null)
                {
                    callback();
                }
            }
        });
    }
Exemplo n.º 10
0
        static void HandleReceiveMessage(MSG_HEAD msgHead, MemoryStream kMsgBodyStream, int iMsgBodySize)
        {
            switch (msgHead.m_usMsgType)
            {
            case (ushort)MessageType.MT_E2D_START:
                SyncManager.SyncFrameRate = System.BitConverter.ToInt16(kMsgBodyStream.ToArray(), 0);
                SendSceneID();
                break;

            case (ushort)MessageType.MT_E2D_SYNC_REQUEST:
                SyncManager.FindD2ESyncObjects(FBHelper.DeserializeSyncIDList(kMsgBodyStream.ToArray()));
                MessageHelper.SendShortMessage(m_kConnector, MessageType.MT_D2E_SYNC_RESPOND, (ushort)SyncManager.D2ESyncObjectsCount);
                break;

            case (ushort)MessageType.MT_E2D_START_SYNC:
                SyncManager.IsD2ESyncStart = true;
                break;

            case (ushort)MessageType.MT_E2D_STOP_SYNC:
                SyncManager.IsD2ESyncStart = false;
                break;

            case (ushort)MessageType.MT_E2D_CONTROL_REQUEST:
                SyncManager.FindE2DControlObjects(FBHelper.DeserializeSyncIDList(kMsgBodyStream.ToArray()));
                MessageHelper.SendShortMessage(m_kConnector, MessageType.MT_D2E_CONTROL_RESPOND, (ushort)SyncManager.E2DControlObjectsCount);
                break;

            case (ushort)MessageType.MT_E2D_CONTROL_UPDATE:
                SyncManager.E2DControlUpdate(kMsgBodyStream.ToArray());
                break;

            case (ushort)MessageType.MT_E2D_STOP_CONTROL:
                break;

            case (ushort)MessageType.MT_E2D_UPDATE_SYNC_RATE:
                SyncManager.SyncFrameRate = System.BitConverter.ToInt16(kMsgBodyStream.ToArray(), 0);
                break;

            default:
                Debug.LogError("Wrong Message Type : " + msgHead.m_usMsgType);
                break;
            }
        }
Exemplo n.º 11
0
        void SelectObjects(ref Dictionary <int, GameObject> selectedList, System.Action <int, GameObject> callback, System.Action <byte[]> send)
        {
            List <string> selectObjects = new List <string>();

            selectedList.Clear();
            int index = 0;

            foreach (var id in Selection.instanceIDs)
            {
                if (m_kSceneObjectDic.ContainsKey(id))
                {
                    GameObject selectedObject = GameObject.Find(m_kSceneObjectDic[id]);
                    callback(index, selectedObject);
                    index++;
                    selectObjects.Add(m_kSceneObjectDic[id]);
                    selectedList.Add(id, selectedObject);
                }
            }

            send(FBHelper.SerializeSyncIDList(selectObjects));
        }
Exemplo n.º 12
0
    public void Invite()
    {
        // Play sound
        SoundManager.PlayButtonClick();

        if (!Helper.IsOnline())
        {
            Manager.Instance.ShowMessage(Settings.NoInternetConnection);
            return;
        }

        FBHelper.Invite(Settings.InviteTitle, Settings.InviteMessage, FriendType.Invitable, FBObjectType.Coin, (error) => {
            if (!string.IsNullOrEmpty(error))
            {
                //Log.Debug("Invite error: " + error);
                Manager.Instance.ShowMessage(Settings.InviteFailed);
            }
            else
            {
                // Close popup
                Close();
            }
        });
    }
Exemplo n.º 13
0
    public void AskMana()
    {
        // Play sound
        SoundManager.PlayButtonClick();

        if (!Helper.IsOnline())
        {
            Manager.Instance.ShowMessage(Settings.NoInternetConnection);
            return;
        }

        FBHelper.AskForObject(null, "mana", Settings.AskManaTitle, Settings.AskManaMessage, (error) => {
            if (!string.IsNullOrEmpty(error))
            {
                ///Log.Debug("Ask mana error: " + error);
                Manager.Instance.ShowMessage(Settings.AskManaFailed);
            }
            else
            {
                // Close popup
                Close();
            }
        });
    }
Exemplo n.º 14
0
    void UpdateSendRequests()
    {
        FBHelper.GetSendRequests((result, error) => {
            if (!string.IsNullOrEmpty(error))
            {
                return;
            }
            if (result == null)
            {
                return;
            }

            RequestData[] requests = result.ToArray();
            int requestCount       = requests.Length;
            if (requestCount == 0)
            {
                return;
            }

            // Send coin
            int totalCoin = 0;
            List <string> sendCoinNames = new List <string>(requestCount);

            for (int i = 0; i < requestCount; i++)
            {
                RequestData request = requests[i];

                if (request.ObjectType == FBObjectType.Coin)
                {
                    totalCoin++;

                    sendCoinNames.Add(request.FromName);

                    FBHelper.DeleteRequest(request.Id);
                }
//				else if (request.ObjectType == FBObjectType.InviteCoin)
//				{
//					totalCoin += Settings.CoinByInvite;
//
//					sendCoinNames.Add(request.FromName);
//
//					FBHelper.DeleteRequest(request.Id);
//				}
            }

            if (totalCoin > 0)
            {
                // Add coins
                UserData.Instance.Coin += totalCoin;

                ShowNotification(string.Format("You get {0} {1} from {2}.", totalCoin, totalCoin > 1 ? "coins" : "coin", sendCoinNames.ToUniqueNames()));
            }

            // Send mana
            int totalMana = 0;
            List <string> sendManaNames = new List <string>(requestCount);

            for (int i = 0; i < requestCount; i++)
            {
                RequestData request = requests[i];

                if (request.ObjectType == FBObjectType.Mana)
                {
                    totalMana++;

                    sendManaNames.Add(request.FromName);

                    FBHelper.DeleteRequest(request.Id);
                }
//				else if (request.ObjectType == FBObjectType.InviteMana)
//				{
//					totalMana += Settings.ManaByInvite;
//
//					sendManaNames.Add(request.FromName);
//
//					FBHelper.DeleteRequest(request.Id);
//				}
            }

            if (totalMana > 0)
            {
                // Add mana
                UserData.Instance.Mana += totalMana;

                ShowNotification(string.Format("You get {0} {1} from {2}.", totalMana, totalMana > 1 ? "manas" : "mana", sendManaNames.ToUniqueNames()));
            }
        });
    }
Exemplo n.º 15
0
 public void PressShareButton()
 {
     FBHelper.Feed();
 }
Exemplo n.º 16
0
    public void Show(Action callback = null)
    {
        // Set callback
        _callback = callback;

        // Disable interaction
        SetInteractable(false);

        // Show loading
        if (loading != null)
        {
            loading.Show();
        }

        // Clear content
        contentTransform.DestroyChildren();

        // Get highscores
        FBHelper.GetHighscores((ids, names, scores, error) => {
            // Hide loading
            if (loading != null)
            {
                loading.Hide();
            }

            if (string.IsNullOrEmpty(error))
            {
                // Show popup
                UIHelper.ShowPopup(gameObject, () => {
                    Vector2 position = new Vector2(0, -space * 0.5f);
                    float step       = rowPrefab.GetComponent <RectTransform>().sizeDelta.y + space;
                    int count        = ids.Length;

                    // Add rows
                    for (int i = 0; i < count; i++)
                    {
                        GameObject row = rowPrefab.CreateUI(contentTransform, position, false);
                        LeaderboardRowScript script = row.GetComponent <LeaderboardRowScript>();

                        if (script != null)
                        {
                            script.Construct(ids[i], names[i], scores[i]);
                        }

                        position.y -= step;
                    }

                    // Set content size
                    Vector2 size = contentTransform.sizeDelta;
                    size.y       = count * step;
                    contentTransform.sizeDelta = size;

                    // Enable interaction
                    SetInteractable(true);
                });
            }
            else
            {
                // Enable interaction
                SetInteractable(true);

                Manager.Instance.ShowMessage(Settings.LeaderboardFailed);
            }
        });
    }
Exemplo n.º 17
0
 public static void E2DControlUpdate(byte[] data)
 {
     FBHelper.DeserializeSyncObject(data, m_dE2DControlObjectDic);
 }
Exemplo n.º 18
0
 public static void D2ESyncUpdate(byte[] data)
 {
     FBHelper.DeserializeSyncObject(data, m_dD2ESyncObjectDic);
 }
Exemplo n.º 19
0
 public static byte[] GetE2DControlData()
 {
     return(FBHelper.SerializeSyncObject(m_dE2DControlObjectDic));
 }
Exemplo n.º 20
0
 public static byte[] GetD2ESyncData()
 {
     return(FBHelper.SerializeSyncObject(m_dD2ESyncObjectDic));
 }
Exemplo n.º 21
0
    void OnGUI()
    {
        if (!_showDebug)
        {
            if (GUI.Button(new Rect(0, 0, 100, 100), "", GUIStyle.none))
            {
                double time = System.DateTime.Now.TimeOfDay.TotalSeconds;

                if (time - _lastTime < 0.35)
                {
                    _lastTime = 0;

                    _showDebug = !_showDebug;
                }
                else
                {
                    _lastTime = time;
                }
            }
        }

        if (_showDebug)
        {
            GUILayout.BeginArea(new Rect(10, 10, Screen.width, Screen.height));
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();

//			if (!FB.IsLoggedIn)
//			{
//				if (settingsPopup.activeSelf)
//				{
//					if (GUILayout.Button("Log in Facebook"))
//					{
//						LoginFacebook();
//					}
//				}
//				else
//				{
//					if (GUILayout.Button("Connect Facebook"))
//					{
//						ConnectFacebook();
//					}
//				}
//			}

            if (FB.IsLoggedIn)
            {
                if (GUILayout.Button("Get score"))
                {
                    FBHelper.GetScore(null, (score, error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Get score error: " + error);
                        }
                        else
                        {
                            //Log.Debug("Score: " + score);
                        }
                    });
                }

                if (GUILayout.Button("Post score"))
                {
                    int score = Random.Range(1, 10);

                    FBHelper.PostScore(null, score, (result, error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Post score error: " + error);
                        }
                        else
                        {
                            //Log.Debug(string.Format("Post score {0}: {1}", score, result));
                        }
                    });
                }

                if (GUILayout.Button("Delete score"))
                {
                    FBHelper.DeleteScore(null, (result, error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Delete score error: " + error);
                        }
                        else
                        {
                            //Log.Debug("Delete score: " + result);
                        }
                    });
                }

                if (GUILayout.Button("Get highscores"))
                {
                    FBHelper.GetHighscores((ids, names, scores, error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Get highscores error: " + error);
                        }
                        else
                        {
                            int count = ids.Length;

                            for (int i = 0; i < count; i++)
                            {
                                //Debug.Log(string.Format("{0}. {1}\t{2}\t{3}", i + 1, ids[i], names[i], scores[i]));
                            }
                        }
                    });
                }

                if (GUILayout.Button("Delete highscores"))
                {
                    FBHelper.DeleteHighscores((result, error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Delete highscores error: " + error);
                        }
                        else
                        {
                            //Log.Debug("Delete highscores: " + result);
                        }
                    });
                }

                if (GUILayout.Button("Invite friends"))
                {
                    FBHelper.Invite(Settings.InviteTitle, Settings.InviteMessage, FriendType.Invitable, FBObjectType.Coin, (error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Invite friends error: " + error);
                        }
                    });
                }

                if (GUILayout.Button("Invite users"))
                {
                    FBHelper.Invite(Settings.InviteTitle, Settings.InviteMessage, FriendType.Game, FBObjectType.Coin, (error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Invite users error: " + error);
                        }
                    });
                }

                if (GUILayout.Button("Send Coin"))
                {
                    FBHelper.SendObject(null, "coin", "Send a coin to your friend", "Take this coin", (error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Send coin error: " + error);
                        }
                    });
                }

                if (GUILayout.Button("Ask Coin"))
                {
                    FBHelper.AskForObject(null, "coin", "Request a coin from your friend", "Give me a coin", (error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Ask coin error: " + error);
                        }
                    });
                }

                if (GUILayout.Button("Send Mana"))
                {
                    FBHelper.SendObject(null, "mana", Settings.SendManaTitle, Settings.SendManaMessage, (error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Send mana error: " + error);
                        }
                    });
                }

                if (GUILayout.Button("Ask Mana"))
                {
                    FBHelper.AskForObject(null, "mana", Settings.AskManaTitle, Settings.AskManaMessage, (error) => {
                        if (!string.IsNullOrEmpty(error))
                        {
                            //Log.Debug("Ask mana error: " + error);
                        }
                    });
                }
            }

            if (GUILayout.Button("Reset Data"))
            {
                UserData.Instance.Reset();

                NotificationManager.ManaChanged(UserData.Instance.Mana);
                NotificationManager.CoinChanged(UserData.Instance.Coin);

                if (FB.IsLoggedIn)
                {
                    // Delete Facebook score
                    FBHelper.DeleteScore(null);
                }
            }

            if (GUILayout.Button("Close"))
            {
                _showDebug = false;
            }

            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
        }
    }
Exemplo n.º 22
0
    public void ShowTopFriends(int level)
    {
        // Show
        gameObject.Show();

        _isStopped = false;

        // Show loading
        if (loading != null)
        {
            loading.Show();
        }

        // Clear content
        contentTransform.DestroyChildren();

        // Hide background
        Image background = GetComponent <Image>();

        if (background != null)
        {
            background.enabled = false;
        }

        if (deco != null)
        {
            deco.SetActive(false);
        }

        // Get highscores
        FBHelper.GetHighscores((ids, names, scores, error) => {
            if (_isStopped)
            {
                return;
            }

            // Hide loading
            if (loading != null)
            {
                loading.Hide();
            }

            if (string.IsNullOrEmpty(error))
            {
                Vector2 position = new Vector2(space * 0.5f, 0);
                float step       = rowPrefab.GetComponent <RectTransform>().sizeDelta.x + space;
                int length       = ids.Length;
                int count        = 0;

                // Add rows
                for (int i = 0; i < length; i++)
                {
                    if (scores[i] >= level)
                    {
                        if (ids[i] == FBHelper.UserID)
                        {
                            continue;
                        }

                        GameObject row             = rowPrefab.CreateUI(contentTransform, position, false);
                        TopFriendsRowScript script = row.GetComponent <TopFriendsRowScript>();

                        if (script != null)
                        {
                            script.Construct(ids[i], names[i]);
                        }

                        position.x += step;

                        count++;
                    }
                    else
                    {
                        break;
                    }
                }

                if (count > 0)
                {
                    // Set content size
                    Vector2 size = contentTransform.sizeDelta;
                    size.x       = count * step;
                    contentTransform.sizeDelta = size;

                    // Show background
                    if (background != null)
                    {
                        background.enabled = true;
                    }

                    if (deco != null)
                    {
                        deco.SetActive(true);
                    }
                }
                else
                {
                    gameObject.Hide();
                }
            }
            else
            {
                //Log.Debug("Load top friends error: " + error);
            }
        });
    }
Exemplo n.º 23
0
 private async void RetrieveUsersFromDB()
 {
     UserRecords = await FBHelper.GetAllUsers();
 }
Exemplo n.º 24
0
 private async void RetrievePostsFromDB()
 {
     PostRecords = await FBHelper.GetAllPosts();
 }