示例#1
0
 private void SendRequestLoginByUsername(string _username)
 {
     OverloadSFS.Instance.Request <LoginViaUsernameResponse> (new LoginViaUsernameRequest(_username), (res, state, unit) => {
         if (state == SUGA.SFS2X.Network.SGSFRequestUnit.State.Completed)
         {
             if (res.ErrorCode == SUGA.SFS2X.Network.SGSFErrorCode.OK)
             {
                 string currentUID = SGLocalDataManager.LoadData <string>(LocalDataType.uid);
                 string _uid       = res.uid;
                 if (currentUID != _uid)                    //relogin with new UID
                 {
                     currentUID = _uid;
                     SGLocalDataManager.SaveData <string>(LocalDataType.uid, _uid);
                     StartCoroutine(Relogin_Coroutine(_uid));
                 }
             }
             else
             {
                 UIManager.HideLoading();
                 if (res.ErrorCode == SUGA.SFS2X.Network.SGSFErrorCode.REQUIRE_REGISTER)
                 {
                     registerUI.SetActive(true);
                 }
                 else if (res.ErrorCode == SUGA.SFS2X.Network.SGSFErrorCode.NOT_EXISTS_USER)
                 {
                     UIManager.ShowMessage("Not Exists User\t");
                 }
                 else
                 {
                     UIManager.ShowMessage(string.Format("Something went wrong (ErrorCode = {0})", (int)res.ErrorCode));
                 }
             }
         }
     }, null, 15);
 }
示例#2
0
    private void DoLoginUsingFB()
    {
        string uid = SGLocalDataManager.LoadData <string> (LocalDataType.uid);

        if (uid == "")
        {
            uid = System.Guid.NewGuid().ToString();
            SGLocalDataManager.SaveData <string> (LocalDataType.uid, uid);
        }
        ISFSObject data = new SFSObject();

        data.PutUtfString("fbid", fbid);
        data.PutUtfString("version", OverloadSFS.Instance.version);
        sfs.Send(new LoginRequest(uid, "", OverloadSFS.Instance.zone, data));
    }
示例#3
0
    private void DoLoginUsingUsername(string _username)
    {
        if (sfs.MySelf == null)
        {
            string uid = System.Guid.NewGuid().ToString();
            SGLocalDataManager.SaveData(LocalDataType.uid, uid);

            ISFSObject data = new SFSObject();
            data.PutUtfString("testUserName", _username);
            data.PutUtfString("version", OverloadSFS.Instance.version);
            sfs.Send(new LoginRequest(uid, "", OverloadSFS.Instance.zone, data));
        }
        else
        {
            SendRequestLoginByUsername(_username);
        }
    }
示例#4
0
    private void InitCallback()
    {
        if (FB.IsInitialized)
        {
            // Signal an app activation App Event
            FB.ActivateApp();
            // Continue with Facebook SDK
            // ...

            Debug.Log("Init FB success, Logged in =" + FB.IsLoggedIn);

            if (FB.IsLoggedIn)
            {
                Debug.Log("Logged in FB");
                OnLoginFB();
            }
            else
            {
#if !UNITY_EDITOR
                //check if exists fbid in PlayerPrefs -> auto login using fb
                string fbid = SGLocalDataManager.LoadData <string>(LocalDataType.fbid);
                Debug.Log("fbid = " + fbid);
                if (fbid != "")
                {
                    OnLoginFB();
                }
                else
                {
                    loginObj.SetActive(true);
                    UIManager.HideLoading();
                }
#else
                loginObj.SetActive(true);
                UIManager.HideLoading();
#endif
            }
        }
        else
        {
            Debug.Log("Failed to Initialize the Facebook SDK");
            loginObj.SetActive(true);
            UIManager.HideLoading();
        }
    }
示例#5
0
    private void DoLoginAsGuest()
    {
        string uid = SGLocalDataManager.LoadData <string> (LocalDataType.uid);

        if (uid == "")
        {
            uid = System.Guid.NewGuid().ToString();
            SGLocalDataManager.SaveData <string> (LocalDataType.uid, uid);
        }
//		Debug.Log ("Login as Guess: " + uid);
        if (!isLoggedIn)
        {
            ISFSObject data = new SFSObject();
            data.PutUtfString("version", OverloadSFS.Instance.version);
            sfs.Send(new LoginRequest(uid, "", OverloadSFS.Instance.zone, data));
        }
        else
        {
            RandomName();
            registerUI.gameObject.SetActive(true);
        }
    }
示例#6
0
    public void OnLoginFB()
    {
#if !UNITY_STANDALONE
        if (FB.IsInitialized)
        {
            UIManager.HideLoading();
            if (FB.IsLoggedIn == false)
            {
                FB.LogInWithReadPermissions(new List <string>()
                {
                    "public_profile", "email", "user_friends"
                }, result => {
                    if (!string.IsNullOrEmpty(result.Error))
                    {
                        Debug.LogError("Error - Check log for details");
                        Debug.LogError(result.Error);
                    }
                    else if (result.Cancelled)
                    {
                        Debug.LogWarning("Cancelled - Check log for details");
                    }
                    else if (!string.IsNullOrEmpty(result.RawResult))
                    {
                        Debug.Log("Success");
//						Debug.Log(AccessToken.CurrentAccessToken.UserId);
                        fbid = AccessToken.CurrentAccessToken.UserId;
                        SGLocalDataManager.SaveData <string>(LocalDataType.fbid, fbid);

                        if (!OverloadSFS.Instance.SFS.IsConnected)
                        {
                            OverloadSFS.Instance.Connect();
                        }

                        sfs = OverloadSFS.Instance.SFS;

                        if (sfs != null)
                        {
                            if (sfs.IsConnected)
                            {
                                DoLoginUsingFB();
                            }
                            else                             //connect sfs and login using fb
                            {
                                StartCoroutine(DoConnect(TypeLogin.FACEBOOK));
                            }
                        }
                        else
                        {
                            Debug.LogError("WTF???");
                        }
                    }
                });
            }
            else
            {
                fbid = AccessToken.CurrentAccessToken.UserId;
                SGLocalDataManager.SaveData <string>(LocalDataType.fbid, fbid);

                if (!OverloadSFS.Instance.SFS.IsConnected)
                {
                    OverloadSFS.Instance.Connect();
                }

                sfs = OverloadSFS.Instance.SFS;

                if (sfs != null)
                {
                    if (sfs.IsConnected)
                    {
                        DoLoginUsingFB();
                    }
                    else
                    {
                        StartCoroutine(DoConnect(TypeLogin.FACEBOOK));
                    }
                }
                else
                {
                    Debug.LogError("WTF???");
                }
            }
        }
#endif
    }
示例#7
0
    private void OnLogin(string zone, User user, ISFSObject data)
    {
        // Initialize UDP communication
//		Debug.Log ("User " + user.Name + " login SFS Success!");

//		loginStatus.gameObject.SetActive (true);
//		loginObj.SetActive (false);
        isLoggedIn = true;
        string username = (nickname != "") ? nickname : user.Name;

        SGPlayersManager.Instance.CreatePlayerMe(user, username, username, fbid, 0);

        if (data != null && data.ContainsKey("relogin"))
        {
            LoadToGarage(isRelogin: true);
        }
        else
        {
            if (fbid != "")
            {
                #region LOGIN USING FBID (CACHED FROM PLAYER_PREF)
                OverloadSFS.Instance.Request <LoginViaFBResponse> (new LoginViaFBRequest(fbid, Application.systemLanguage.ToString()), (res, state, unit) => {
                    if (state == SUGA.SFS2X.Network.SGSFRequestUnit.State.Completed)
                    {
                        if (res.ErrorCode == SUGA.SFS2X.Network.SGSFErrorCode.OK)
                        {
                            SGPlayersManager.Instance.PlayerMe.Nickname = res.nickname;
                            if (SGPlayersManager.Instance.PlayerMe.SetUserDataFromLogin(res.userdata, this))
                            {
                                LoadToGarage();
                            }
                        }
                        else if (res.ErrorCode == SUGA.SFS2X.Network.SGSFErrorCode.CHANGE_UID)
                        {
                            string _newUID = res.uid;
                            SGLocalDataManager.SaveData <string>(LocalDataType.uid, _newUID);
                            Relogin(_newUID);
                        }
                        else
                        {
                            UIManager.HideLoading();
                            if (res.ErrorCode == SUGA.SFS2X.Network.SGSFErrorCode.REQUIRE_REGISTER)
                            {
                                registerUI.SetActive(true);
                            }
                            else
                            {
                                UIManager.ShowMessage(string.Format("Something went wrong (ErrorCode = {0})", (int)res.ErrorCode));
                            }
                        }
                    }
                }, null, 15);
                #endregion
            }
            else
            {
                #region LOGIN USING FBID
                if (data != null && data.ContainsKey("fbid"))
                {
                    fbid = data.GetUtfString("fbid");
                    OverloadSFS.Instance.Request <LoginViaFBResponse> (new LoginViaFBRequest(fbid, Application.systemLanguage.ToString()), (res, state, unit) => {
                        if (state == SUGA.SFS2X.Network.SGSFRequestUnit.State.Completed)
                        {
                            if (res.ErrorCode == SUGA.SFS2X.Network.SGSFErrorCode.OK)
                            {
                                SGPlayersManager.Instance.PlayerMe.Nickname = res.nickname;
                                if (SGPlayersManager.Instance.PlayerMe.SetUserDataFromLogin(res.userdata, this))
                                {
                                    LoadToGarage();
                                }
                            }
                            else if (res.ErrorCode == SUGA.SFS2X.Network.SGSFErrorCode.CHANGE_UID)
                            {
                                string _newUID = res.uid;
                                SGLocalDataManager.SaveData <string>(LocalDataType.uid, _newUID);
                                Relogin(_newUID);
                            }
                            else
                            {
                                UIManager.HideLoading();
                                if (res.ErrorCode == SUGA.SFS2X.Network.SGSFErrorCode.REQUIRE_REGISTER)
                                {
                                    registerUI.SetActive(true);
                                }
                                else
                                {
                                    UIManager.ShowMessage(string.Format("Something went wrong (ErrorCode = {0})", (int)res.ErrorCode));
                                }
                            }
                        }
                    }, null, 15);
                }
                #endregion
                else
                {
                    #region LOGIN USING USER_NAME (ONLY TEST)
                    if (data != null && data.ContainsKey("testUserName"))
                    {
                        string _testUsername = data.GetUtfString("testUserName");
                        SendRequestLoginByUsername(_testUsername);
                    }
                    #endregion

                    #region LOGIN VIA GUESS
                    else
                    {
                        OverloadSFS.Instance.Request <LoginViaGuessResponse> (new LoginViaGuessRequest(Application.systemLanguage.ToString()), (res, state, unit) => {
                            if (state == SUGA.SFS2X.Network.SGSFRequestUnit.State.Completed)
                            {
                                if (res.ErrorCode == SUGA.SFS2X.Network.SGSFErrorCode.OK)
                                {
                                    SGPlayersManager.Instance.PlayerMe.Nickname = res.nickname;
                                    if (SGPlayersManager.Instance.PlayerMe.SetUserDataFromLogin(res.userdata, this))
                                    {
                                        LoadToGarage();
                                    }
                                }
                                else
                                {
                                    UIManager.HideLoading();
                                    if (res.ErrorCode == SUGA.SFS2X.Network.SGSFErrorCode.REQUIRE_REGISTER)
                                    {
                                        RandomName();
                                        registerUI.SetActive(true);
                                    }
                                    else
                                    {
                                        UIManager.ShowMessage(string.Format("Something went wrong (ErrorCode = {0})", (int)res.ErrorCode));
                                    }
                                }
                            }
                        }, null, 15);
                    }
                    #endregion
                }
            }
        }
    }