Esempio n. 1
0
        public void ExecuteAuthMethod(string Id)
        {
            if (AuthRunning)
            {
                return;
            }

            if (!Methodsdb.TryGetValue(Id, out SelectedMethod))
            {
                Logger.LogError("Auth Method not found for id: " + Id, this);
                return;
            }
        }
Esempio n. 2
0
        private void Checkdb()
        {
            string uid = AuthManager.Instance.auth.CurrentUser.UserId;

            Logger.Log("Check user in Database", this);
            result = ProcessResult.Running;
            QDataManager.Instance.UserExists(uid, (bool exists) =>
            {
                if (!exists)
                {
                    Logger.Log("User not found in database, Uploading...", this, true);
                    QDataManager.Instance.RegisterPlayerToDatabase(new UserPlayer(uid), () =>
                    {
                        Logger.Log("Upload user to database completed!", this, true);
                        AuthManager.FinishProcess();
                        result = ProcessResult.Completed;
                    }, (System.Exception ex) =>
                    {
                        _ex = ex;
                        AuthManager.FinishProcess();
                        result = ProcessResult.Failure;
                    });
                }
                else
                {
                    Logger.Log("User already exists in database, continue without changes", this, true);
                    AuthManager.FinishProcess();
                    result = ProcessResult.Completed;
                }
            }, (System.Exception ex) =>
            {
                AuthManager.FinishProcess();
                _ex    = ex;
                result = ProcessResult.Failure;
            });
        }
Esempio n. 3
0
        // RUN AUTH METHOD ----
        private IEnumerator I_ExecuteMethod()
        {
            if (SelectedMethod != null)
            {
                bool Method_Retry = false;
                AuthRunning = true;
                DisplayLayout(true);
                IAuthCustomUI customUI = SelectedMethod as IAuthCustomUI;

                if (customUI != null)
                {
                    customUI.DisplayUI(auth.CurrentUser != null && auth.CurrentUser.IsAnonymous);
                }

                IAuthCustomNavigation customNavigation = SelectedMethod as IAuthCustomNavigation;

                SelectedMethod.OnEnter();

                ProcessResult tres = ProcessResult.None;
                do
                {
                    if (Method_Retry)
                    {
                        SelectedMethod.OnEnter();
                        Method_Retry = false;
                    }

                    tres = SelectedMethod.GetResult();
                    bool goback = (customNavigation != null) ? customNavigation.GoBack() : Input.GetKey(KeyCode.Escape);

                    if (customUI != null && tres == ProcessResult.None && goback)
                    {
                        customUI.HideUI();

                        if (OnAuthCancelled != null)
                        {
                            OnAuthCancelled.Invoke();
                        }

                        fsm.MoveNext(AuthCheckCommand.GoBack);

                        break;
                    }

                    if (tres == ProcessResult.Failure)
                    {
                        Logger.LogWarning("Got Error during process of Method " + SelectedMethod.GetException(), this);
                        yield return(new WaitForSeconds(0.5f));

                        Logger.LogWarning("Retrying...", this);
                        Method_Retry = true;
                    }

                    yield return(new WaitForEndOfFrame());
                } while (tres != ProcessResult.Completed);

                if (tres == ProcessResult.Completed)
                {
                    if (customUI != null)
                    {
                        customUI.HideUI();
                    }

                    SelectedMethod.OnFinish();

                    if (OnAuthCompleted != null)
                    {
                        OnAuthCompleted.Invoke();
                    }

                    AuthCheckCommand cmd = auth.CurrentUser != null ? AuthCheckCommand.Next : AuthCheckCommand.Exit;

                    fsm.MoveNext(cmd);
                }
            }

            AuthRunning    = false;
            SelectedMethod = null;
            Logger.Log("Auth Execution Finished", this, true);
            yield return(0);
        }
Esempio n. 4
0
        // Coroutines /-/-/-/-/-/-/-/-/-/-/-/-/

        // RUN AUTH MODULE
        private IEnumerator I_RunModule(AuthModule module)
        {
            ModuleRunning = true;
            int  retrys          = 0;
            bool module_retrying = false;

            module.OnEnter();

            IAsyncModule asyncModule = module as IAsyncModule;

            if (asyncModule != null)
            {
                ProcessResult ares = ProcessResult.None;
                do
                {
                    if (module_retrying)
                    {
                        module.OnEnter();
                        module_retrying = false;
                    }

                    ares = asyncModule.AsyncResult();

                    if (ares == ProcessResult.Failure)
                    {
                        Logger.LogWarning("Got Error during process of AsyncModule " + module.GetException(), this);

                        if (retrys < MaximunErrorRetrys)
                        {
                            yield return(new WaitForSeconds(0.5f));

                            Logger.LogWarning("Retrying... " + retrys, this);
                            retrys++;
                            module_retrying = true;
                        }
                    }

                    yield return(new WaitForEndOfFrame());
                } while (ares != ProcessResult.Completed);

                yield return(new WaitUntil(() => ares == ProcessResult.Completed || retrys >= MaximunErrorRetrys));
            }

            retrys = 0;

            if (module.IsValid(WasRequestedByGuest, auth.CurrentUser))
            {
                module.Execute(this);

                ProcessResult tres       = ProcessResult.None;
                float         time_enter = Time.time;

                do
                {
                    if (module_retrying)
                    {
                        module.OnEnter();
                        module.Execute(this);
                        time_enter = Time.time;

                        module_retrying = false;
                    }

                    tres = module.GetResult();

                    //Debug.Log("MODULE " + module.GetType().Name + " RESULT: " + tres);

                    if (Input.GetKey(KeyCode.Escape) && Time.time - time_enter >= 0.15f)
                    {
                        RequestExit();
                    }

                    //Interrumpt the module when you're about to upgrade the acocount
                    float diff = Time.time - ExitTime;
                    if (IsAuthenticated && (module.IsInterruptible() && ExitRequest && diff > 0.2f && diff < 0.5f))
                    {
                        fsm.MoveNext(AuthCheckCommand.GoBack);
                        yield break;
                    }

                    if (diff >= 0.55f)
                    {
                        ExitTime = 0;
                    }

                    if (tres == ProcessResult.Failure)
                    {
                        Logger.LogWarning("Got Error during process of module " + module.GetException(), this);

                        if (retrys < MaximunErrorRetrys)
                        {
                            yield return(new WaitForSeconds(0.5f));

                            Logger.LogWarning("Retrying... " + retrys, this);
                            retrys++;
                            module_retrying = true;
                        }
                    }

                    yield return(new WaitForEndOfFrame());
                } while (tres != ProcessResult.Completed);

                if (tres == ProcessResult.Completed)
                {
                    Logger.Log("Module completed: " + module.GetType().Name, this, true);
                    module.OnFinish(this, ExitRequest);

                    ICustomCommand cmd = module as ICustomCommand;

                    fsm.MoveNext(cmd != null ? cmd.GetNextCommand() : AuthCheckCommand.Next);
                    ExitRequest = false;
                }
            }
            else
            {
                fsm.MoveNext(AuthCheckCommand.Next);
                yield break;
            }

            ModuleRunning = false;
            yield return(0);
        }
Esempio n. 5
0
        // PRIVATE API /-/-/-/-/-/-/-/-/-/-/-/

        private void InitFSM()
        {
            fsm.AddTransition(AuthCheckState.None, AuthCheckCommand.Next, () =>
            {
                return(AuthCheckState.InternetCheck);
            });

            fsm.AddTransition(AuthCheckState.InternetCheck, AuthCheckCommand.Next, () => AuthCheckState.MainMenu);

            fsm.AddTransition(AuthCheckState.InternetCheck, AuthCheckCommand.Exit, () => AuthCheckState.None);

            fsm.AddTransition(AuthCheckState.MainMenu, AuthCheckCommand.Next, () =>
            {
                return(AuthCheckState.AuthMethod);
            });

            fsm.AddTransition(AuthCheckState.AuthMethod, AuthCheckCommand.Exit, () =>
            {
                if (!AlwaysAskForAccount)
                {
                    PlayerPrefs.SetInt(AccountSateKey, 1);
                }
                else
                {
                    PlayerPrefs.SetInt(AccountSateKey, 0);
                }

                return(AuthCheckState.None);
            });

            fsm.AddTransition(AuthCheckState.AuthMethod, AuthCheckCommand.Next, () => AuthCheckState.DatabaseCheck);

            fsm.AddTransition(AuthCheckState.DatabaseCheck, AuthCheckCommand.Next, () => AuthCheckState.SetupProfile);

            fsm.AddTransition(AuthCheckState.AuthMethod, AuthCheckCommand.GoBack, () => AuthCheckState.MainMenu);

            fsm.AddTransition(AuthCheckState.MainMenu, AuthCheckCommand.GoBack, () => AuthCheckState.None);

            fsm.AddTransition(AuthCheckState.SetupProfile, AuthCheckCommand.Next, () => AuthCheckState.None);

            fsm.AddTransition(AuthCheckState.DatabaseCheck, AuthCheckCommand.Exit, () => AuthCheckState.None);

            fsm.OnStateChanged = (AuthCheckState state) =>
            {
                AuthModule module = null;

                Logger.Log($"<color=blue>State changed:: { state } </color>", this, true);

                DisplayLayout(true);

                switch (state)
                {
                case AuthCheckState.InternetCheck:

                    module = internetcheck;

                    break;

                case AuthCheckState.MainMenu:

                    module = menuModule;

                    break;

                case AuthCheckState.AuthMethod:

                    if (SelectedMethod == null)
                    {
                        fsm.MoveNext(AuthCheckCommand.Next);
                    }
                    else if (!AuthRunning)
                    {
                        StartCoroutine(I_ExecuteMethod());
                    }

                    break;

                case AuthCheckState.DatabaseCheck:

                    if (auth.CurrentUser != null)
                    {
                        module = databaseCheck;
                    }
                    else
                    {
                        fsm.MoveNext(AuthCheckCommand.Exit);
                    }

                    break;

                case AuthCheckState.SetupProfile:

                    module = profileModule;

                    PlayerPrefs.SetInt(AccountSateKey, 0);

                    break;

                case AuthCheckState.None:

                    if (BaseLayout.activeInHierarchy)
                    {
                        DisplayLayout(false);

                        if (OnVerifyCompleted != null)
                        {
                            OnVerifyCompleted.Invoke();
                        }
                    }

                    ModuleRunning = false;

                    break;
                }

                if (state != AuthCheckState.None && module != null)
                {
                    StartCoroutine(I_RunModule(module));
                }
            };
        }