コード例 #1
0
        private IEnumerator OnCreateAccountResponse(string url, Dictionary <string, string> formData, CreateAccountCallback cb, string gameVersion)
        {
            using (UnityWebRequest request = WebConfig.Post(url, formData))
            {
                yield return(request.SendWebRequest());

                m_WebCoroutine = null;

                ErrorResponse error = WebConfig.ProcessGenericErrors(request);

                if (error != null)
                {
                    cb?.Invoke(new CreateAccountResponse(), error);
                    yield break;
                }

                CreateAccountResponse response = CreateAccountResponse.FromJson(request.downloadHandler.text);

                // -2 | Bad Data
                // -1 | Internal Error
                // 1 | Valid
                // 2 | Email Bad Format
                // 3 | Email Already Taken
                // 4 | UserName Bad Format
                // 5 | UserName Already Taken
                // 6 | DisplayName Bad Format
                // 7 | DisplayName Already Taken
                // 8 | Password needs different characters
                // 9 | Password needs Upper Number Symbol And Lower
                // 10 | Password too similar to name
                // 11 | Bad Version | $foundVersion
                // 12 | Down for maintenance
                switch (response.code)
                {
                case 1:         cb?.Invoke(response, null);                                                                                                                                                                                                                                             break;

                case 2:         cb?.Invoke(response, new ErrorResponse("Email format is invalid.", response.message, null, response.code));                                                                             break;

                case 3:         cb?.Invoke(response, new ErrorResponse("Email already in use.", response.message, null, response.code));                                                                                break;

                case 4:         cb?.Invoke(response, new ErrorResponse("User name must contain only letters and numbers.", response.message, null, response.code));                             break;

                case 5:         cb?.Invoke(response, new ErrorResponse("User name already exists.", response.message, null, response.code));                                                                    break;

                case 6:         cb?.Invoke(response, new ErrorResponse("Display name must contain only letters and numbers.", response.message, null, response.code));                  break;

                case 7:         cb?.Invoke(response, new ErrorResponse("Display name already exists.", response.message, null, response.code));                                                                 break;

                case 8:         cb?.Invoke(response, new ErrorResponse("Password must contain at least 8 different characters.", response.message, null, response.code));               break;

                case 9:         cb?.Invoke(response, new ErrorResponse("Password must contain at least 1 upper case letter, number or symbol and 1 lower case letter.", response.message, null, response.code));        break;

                case 10:        cb?.Invoke(response, new ErrorResponse("Password too similar to name.", response.message, null, response.code));                                                                break;

                case 11:
                    cb?.Invoke(response, new ErrorResponse("Your app version is out of date.\n\nCurrent Version: " + response.serverVersion + "\nYour Version: " + gameVersion,
                                                           response.message, null, response.code));
                    break;

                case 12:
                    // Down for maintenance
                    cb?.Invoke(response, new ErrorResponse(response.message, response.displayMessage, null, response.code));
                    break;

                default:
                    // Unknown code error
                    cb?.Invoke(response, WebConfig.GetUnknownError(request));
                    break;
                }
            }
        }
コード例 #2
0
        private IEnumerator OnLoginResponse(string url, Dictionary <string, string> formData, LoginCallback cb, string userName, string gameVersion)
        {
            using (UnityWebRequest request = WebConfig.Post(url, formData))
            {
                yield return(request.SendWebRequest());

                m_WebCoroutine = null;

                ErrorResponse error = WebConfig.ProcessGenericErrors(request);

                if (error != null)
                {
                    cb?.Invoke(new LoginResponse(), error);
                    yield break;
                }

                LoginResponse response = LoginResponse.FromJson(request.downloadHandler.text);

                switch (response.code)
                {
                case 1:
                    // Save remember me credentials
                    PlayerPrefs.SetInt("FlexAS_Login_RememberMe", !string.IsNullOrEmpty(response.rememberMeToken) ? 1 : 0);
                    if (!string.IsNullOrEmpty(response.rememberMeToken))
                    {
                        PlayerPrefs.SetString("FlexAS_Login_UserName", userName);
                        PlayerPrefs.SetString("FlexAS_Login_RememberMeToken", response.rememberMeToken);
                    }
                    PlayerPrefs.Save();

                    cb?.Invoke(response, null);

                    break;

                case 2:
                    cb?.Invoke(response, new ErrorResponse("Your app version is out of date.\n\nCurrent Version: " + response.serverVersion + "\nYour Version: " + gameVersion,
                                                           response.message, null, response.code));
                    break;

                case 5:
                    string accountRestoreTime = "";
                    if (response.banRestoreDate > 0)
                    {
                        accountRestoreTime = "\n\nAccount will be restored in " + DateUtility.GetFormattedTimeFromSeconds(response.banRestoreDate);
                    }
                    cb?.Invoke(response, new ErrorResponse("This account has been banned.\n\nAdmin Message:\n\"" + response.banReason + "\"" + accountRestoreTime, response.message, null, response.code));
                    break;

                case 3: cb?.Invoke(response, new ErrorResponse("Incorrect username or password", response.message, null, response.code));       break;

                case 4: cb?.Invoke(response, new ErrorResponse("Account Locked", response.message, null, response.code));                                       break;

                case 6:
                    // Down for maintenance
                    cb?.Invoke(response, new ErrorResponse(response.message, response.displayMessage, null, response.code));
                    break;

                default:
                    // Unknown code error
                    cb?.Invoke(response, WebConfig.GetUnknownError(request));
                    break;
                }
            }
        }