public static void ClaimRestoreToken(string token, Action <bool> callback)
        {
            if (mInstance == null)
            {
                return;
            }

            SingleRequestClient.Request(SnipeConfig.Instance.auth,
                                        new ExpandoObject()
            {
                ["messageType"] = REQUEST_CLAIM_RESTORE_TOKEN,
                ["token"]       = token,
            },
                                        (response) =>
            {
                string error_code = response?.SafeGetString("errorCode");
                if (error_code == "ok")
                {
                    ClearAllBindings();
                    UserID = 0;
                    SnipeAuthCommunicator.LoginToken = "";
                    PlayerPrefs.SetString(SnipePrefs.AUTH_UID, response.SafeGetString("uid"));
                    PlayerPrefs.SetString(SnipePrefs.AUTH_KEY, response.SafeGetString("password"));
                    PlayerPrefs.Save();
                    callback?.Invoke(true);
                }
                else
                {
                    callback?.Invoke(false);
                }
            });
        }
        public static void Request(SnipeServerConfig config, ExpandoObject request, Action <ExpandoObject> callback)
        {
            // ????
            //if (mClient != null)
            //	DisposeClient();

            SnipeClient client = SnipeClient.CreateInstance(SnipeConfig.Instance.snipe_client_key, "SnipeSingleRequestClient", false);

            client.AppInfo = SnipeConfig.Instance.snipe_app_info;
            SingleRequestClient instance = client.gameObject.AddComponent <SingleRequestClient>();

            instance.InitClient(client, config, request, callback);
        }
Beispiel #3
0
        protected void RequestLogin(string provider, string login, string token, bool reset_auth = false)
        {
            ExpandoObject data = new ExpandoObject()
            {
                ["messageType"] = REQUEST_USER_LOGIN,
                ["provider"]    = provider,
                ["login"]       = login,
                ["auth"]        = token,
            };

            if (reset_auth)
            {
                data["resetInternalAuth"] = reset_auth;
            }

            //LoggedIn = false;

            SingleRequestClient.Request(SnipeConfig.Instance.auth, data, OnAuthLoginResponse);
        }
        protected virtual void CheckAuthExists(string user_id, CheckAuthExistsCallback callback)
        {
            mCheckAuthExistsCallback = callback;

            Debug.Log($"[BindProvider] ({ProviderId}) CheckAuthExists {user_id}");

            ExpandoObject data = new ExpandoObject();

            data["messageType"] = REQUEST_USER_EXISTS;
            data["provider"]    = ProviderId;
            data["login"]       = user_id;

            string login_id = PlayerPrefs.GetString(SnipePrefs.LOGIN_USER_ID);

            if (!string.IsNullOrEmpty(login_id))
            {
                data["id"] = Convert.ToInt32(login_id);
            }

            SingleRequestClient.Request(SnipeConfig.Instance.auth, data, OnCheckAuthExistsResponse);
        }
        private void RequestRegister()
        {
            ExpandoObject data = new ExpandoObject();

            data["messageType"] = REQUEST_USER_REGISTER;

            if (SystemInfo.unsupportedIdentifier != SystemInfo.deviceUniqueIdentifier)
            {
                data["name"] = SystemInfo.deviceUniqueIdentifier;                 // optional
            }
            SingleRequestClient.Request(SnipeConfig.Instance.auth, data, (response) =>
            {
                string error_code = response?.SafeGetString("errorCode");
                if (error_code == "ok")
                {
                    JustRegistered = true;

                    string auth_login = response.SafeGetString("uid");
                    string auth_token = response.SafeGetString("password");

                    PlayerPrefs.SetString(SnipePrefs.AUTH_UID, auth_login);
                    PlayerPrefs.SetString(SnipePrefs.AUTH_KEY, auth_token);

                    SwitchToDefaultAuthProvider();
                    mCurrentProvider.RequestAuth(OnCurrentProviderAuthSuccess, OnCurrentProviderAuthFail);

                    BindAllProviders(false);
                }
                else
                {
                    InvokeAuthFailCallback();
                }

                AccountRegisterResponded?.Invoke(error_code);
            });
        }