Exemplo n.º 1
0
        public virtual void APIStateChanged(IAPIProvider api, APIState state)
        {
            switch (state)
            {
            case APIState.Offline:
                PopContentOut(Content);
                placeholder.ScaleTo(0.8f).Then().ScaleTo(1, 3 * transform_duration, Easing.OutQuint);
                placeholder.FadeInFromZero(2 * transform_duration, Easing.OutQuint);
                LoadingAnimation.Hide();
                break;

            case APIState.Online:
                PopContentIn(Content);
                placeholder.FadeOut(transform_duration / 2, Easing.OutQuint);
                LoadingAnimation.Hide();
                break;

            case APIState.Failing:
            case APIState.Connecting:
                PopContentOut(Content);
                LoadingAnimation.Show();
                placeholder.FadeOut(transform_duration / 2, Easing.OutQuint);
                break;
            }
        }
Exemplo n.º 2
0
 public void Logout()
 {
     clearCredentials();
     authentication.Clear();
     State           = APIState.Offline;
     LocalUser.Value = createGuestUser();
 }
Exemplo n.º 3
0
 public void APIStateChanged(APIAccess api, APIState state)
 {
     if (state == APIState.Online)
     {
         UpdateScores();
     }
 }
Exemplo n.º 4
0
 public void APIStateChanged(APIAccess api, APIState state)
 {
     if (state != APIState.Online)
     {
         forcefullyExit();
     }
 }
Exemplo n.º 5
0
 public void APIStateChanged(IAPIProvider api, APIState state)
 {
     if (state != APIState.Online)
     {
         Schedule(forcefullyExit);
     }
 }
Exemplo n.º 6
0
 public void Logout()
 {
     flushQueue();
     password = null;
     authentication.Clear();
     LocalUser.Value = createGuestUser();
     State           = APIState.Offline;
 }
Exemplo n.º 7
0
 public void APIStateChanged(APIAccess api, APIState state)
 {
     switch (state)
     {
     case APIState.Online:
         LocalConfig.Set(OsuSetting.Username, LocalConfig.Get <bool>(OsuSetting.SaveUsername) ? API.Username : string.Empty);
         break;
     }
 }
Exemplo n.º 8
0
        public override void APIStateChanged(IAPIProvider api, APIState state)
        {
            if (State.Value == Visibility.Hidden)
            {
                return;
            }

            header.Current.TriggerChange();
        }
Exemplo n.º 9
0
 public virtual void APIStateChanged(IAPIProvider api, APIState state)
 {
     switch (state)
     {
     case APIState.Online:
         PerformFetch();
         break;
     }
 }
Exemplo n.º 10
0
 public void APIStateChanged(IAPIProvider api, APIState state)
 {
     switch (state)
     {
     case APIState.Online:
         calculateRecommendedDifficulties();
         break;
     }
 }
Exemplo n.º 11
0
        public void Logout()
        {
            flushQueue();

            Token    = null;
            password = null;
            username = null;

            State = APIState.Offline;
        }
Exemplo n.º 12
0
 public void APIStateChanged(APIAccess api, APIState state)
 {
     switch (state)
     {
     case APIState.Online:
         Config.Set(OsuConfig.Username, Config.Get <bool>(OsuConfig.SaveUsername) ? API.Username : string.Empty);
         Config.Set(OsuConfig.Password, Config.Get <bool>(OsuConfig.SavePassword) ? API.Password : string.Empty);
         break;
     }
 }
Exemplo n.º 13
0
 public void APIStateChanged(APIAccess api, APIState state)
 {
     switch (state)
     {
         case APIState.Online:
             Config.Set(OsuConfig.Username, Config.Get<bool>(OsuConfig.SaveUsername) ? API.Username : string.Empty);
             Config.Set(OsuConfig.Password, Config.Get<bool>(OsuConfig.SavePassword) ? API.Password : string.Empty);
             break;
     }
 }
Exemplo n.º 14
0
    public void Transition(APIState state)
    {
        APIState cur;

        lock (syncLock) {
            cur = currentState;
            pendingTransitions.Enqueue(state);
        }

        Debug.Log("Queued transition from " + cur + " to " + state);
    }
Exemplo n.º 15
0
 public void APIStateChanged(APIAccess api, APIState state)
 {
     switch (state)
     {
         case APIState.Online:
             initializeChannels();
             break;
         default:
             messageRequest?.Cancel();
             break;
     }
 }
Exemplo n.º 16
0
 public void Logout(bool clearUsername = true)
 {
     flushQueue();
     if (clearUsername)
     {
         ProvidedUsername = null;
     }
     password = null;
     authentication.Clear();
     LocalUser.Value = createGuestUser();
     State           = APIState.Offline;
 }
Exemplo n.º 17
0
        public void APIStateChanged(APIAccess api, APIState state)
        {
            form = null;

            switch (state)
            {
            case APIState.Offline:
                Children = new Drawable[]
                {
                    form = new LoginForm()
                };
                break;

            case APIState.Failing:
                Children = new Drawable[]
                {
                    new OsuSpriteText
                    {
                        Text = "Connection failing :(",
                    },
                };
                break;

            case APIState.Connecting:
                Children = new Drawable[]
                {
                    new OsuSpriteText
                    {
                        Text = "Connecting...",
                    },
                };
                break;

            case APIState.Online:
                Children = new Drawable[]
                {
                    new OsuSpriteText
                    {
                        Text = $"Connected as {api.Username}!",
                    },
                    new OsuButton
                    {
                        RelativeSizeAxes = Axes.X,
                        Text             = "Sign out",
                        Action           = api.Logout
                    }
                };
                break;
            }

            form?.TriggerFocus();
        }
Exemplo n.º 18
0
        public void APIStateChanged(APIAccess api, APIState state)
        {
            switch (state)
            {
            case APIState.Online:
                initializeChannels();
                break;

            default:
                messageRequest?.Cancel();
                break;
            }
        }
Exemplo n.º 19
0
        public void APIStateChanged(APIAccess api, APIState state)
        {
            switch (state)
            {
            case APIState.Online:
                reloadUsers(api);
                break;

            default:
                Users = null;
                break;
            }
        }
Exemplo n.º 20
0
        private void handleApiStateChange(APIState oldState, APIState newState)
        {
            if (Scope == LeaderboardScope.Local)
            {
                // No need to respond to API state change while current scope is local
                return;
            }

            if (newState == APIState.Online)
            {
                updateScores();
            }
        }
Exemplo n.º 21
0
        protected virtual void InitPlayerData(string filename)
        {
            _data.LoadPlayerData(filename);

            APIState state = _data.Player.GetModel <APIState>();

            if (state != null)
            {
                API.UseAPIStateModel(state);
            }

            _data.Player.AchievementsTracker.SetCustomConditionDelegate(OnCheckCustomAchievementCondition);
        }
Exemplo n.º 22
0
    public void Update()
    {
        while (pendingTransitions.Count > 0)
        {
            currentState = pendingTransitions.Dequeue();
            Debug.Log("websocket Transitioned to state " + currentState);

            Handler handler;
            if (handlers.TryGetValue(currentState, out handler))
            {
                handler();
            }
        }
    }
Exemplo n.º 23
0
        public void APIStateChanged(APIAccess api, APIState state)
        {
            switch (state)
            {
            case APIState.Online:
                fetchUpdates();
                break;

            default:
                fetchMessagesScheduleder?.Cancel();
                fetchMessagesScheduleder = null;
                break;
            }
        }
Exemplo n.º 24
0
 public void APIStateChanged(APIAccess api, APIState state)
 {
     switch (state)
     {
         default:
             Text = @"Guest";
             avatar.UserId = 1;
             break;
         case APIState.Online:
             Text = api.Username;
             avatar.UserId = api.LocalUser.Value.Id;
             break;
     }
 }
Exemplo n.º 25
0
        public void APIStateChanged(APIAccess api, APIState state)
        {
            switch (state)
            {
            case APIState.Online:
                Scheduler.AddOnce(updateSearch);
                break;

            default:
                Users = null;
                clearPanels();
                break;
            }
        }
Exemplo n.º 26
0
        public void APIStateChanged(APIAccess api, APIState state)
        {
            switch (state)
            {
            default:
                Text        = @"Guest";
                avatar.User = new User();
                break;

            case APIState.Online:
                Text        = api.LocalUser.Value.Username;
                avatar.User = api.LocalUser;
                break;
            }
        }
Exemplo n.º 27
0
        public void APIStateChanged(APIAccess api, APIState state)
        {
            switch (state)
            {
            case APIState.Offline:
            case APIState.Failing:
                break;

            case APIState.Connecting:
                break;

            case APIState.Online:
                State = Visibility.Hidden;
                break;
            }
        }
        public void APIStateChanged(IAPIProvider api, APIState state)
        {
            switch (state)
            {
            case APIState.Offline:
            case APIState.Failing:
                break;

            case APIState.Connecting:
                break;

            case APIState.Online:
                Hide();
                break;
            }
        }
Exemplo n.º 29
0
        public void Logout()
        {
            flushQueue();

            var req = new LogoutRequest();

            req.Success += () =>
            {
                flushQueue();
                Token    = null;
                password = null;
                username = null;

                State = APIState.Offline;
            };
            Queue(req);
        }
Exemplo n.º 30
0
 public void APIStateChanged(APIAccess api, APIState state)
 {
     switch (state)
     {
         case APIState.Offline:
             Children = new Drawable[]
             {
                 new LoginForm()
             };
             break;
         case APIState.Failing:
             Children = new Drawable[]
             {
                 new SpriteText
                 {
                     Text = "Connection failing :(",
                 },
             };
             break;
         case APIState.Connecting:
             Children = new Drawable[]
             {
                 new SpriteText
                 {
                     Text = "Connecting...",
                 },
             };
             break;
         case APIState.Online:
             Children = new Drawable[]
             {
                 new SpriteText
                 {
                     Text = $"Connected as {api.Username}!",
                 },
                 new OsuButton
                 {
                     RelativeSizeAxes = Axes.X,
                     Text = "Sign out",
                     Action = api.Logout
                 }
             };
             break;
     }
 }
Exemplo n.º 31
0
        private bool handleWebException(WebException we)
        {
            HttpStatusCode statusCode = (we.Response as HttpWebResponse)?.StatusCode
                                        ?? (we.Status == WebExceptionStatus.UnknownError ? HttpStatusCode.NotAcceptable : HttpStatusCode.RequestTimeout);

            // special cases for un-typed but useful message responses.
            switch (we.Message)
            {
            case "Unauthorized":
            case "Forbidden":
                statusCode = HttpStatusCode.Unauthorized;
                break;
            }

            switch (statusCode)
            {
            case HttpStatusCode.Unauthorized:
                Logout();
                return(true);

            case HttpStatusCode.RequestTimeout:
                failureCount++;
                log.Add($@"API failure count is now {failureCount}");

                if (failureCount < 3)
                {
                    //we might try again at an api level.
                    return(false);
                }

                if (State == APIState.Online)
                {
                    State = APIState.Failing;
                    flushQueue();
                }

                return(true);
            }

            return(true);
        }
Exemplo n.º 32
0
        public FreeRemoveAds(GameData gameData, PlayerData playerData, LocalisationManager localisation, APIManager apiManager, string videoAdID, 
            string genericPopupID, object popupHeader, object popupMessage,
            object freeRemoveButtonLabel, object paidRemoveButtonLabel, object cancelButtonLabel,
            object freeAdsRemoveSuccessMessage, object freeAdsRemoveSuccessButton,
            object freeAdsRemoveFailureMessage, object freeAdsRemoveFailureButton,
            int freeRemoveButtonColorID = 0, int paidRemoveButtonColorID = 0, int cancelButtonColorID = 0)
            : base(apiManager, localisation, genericPopupID, popupHeader, popupMessage)
        {
            _gameData = gameData.APISettings;
            _playerData = playerData.APIState;
            _videoAdID = videoAdID;

            apiManager.Ads.CacheRewardVideos(_videoAdID, true);

            CreateButtonKeys(BUTTON_FREE, freeRemoveButtonLabel, freeRemoveButtonColorID);
            CreateButtonKeys(BUTTON_PAID, paidRemoveButtonLabel, paidRemoveButtonColorID);
            CreateButtonKeys(BUTTON_CANCEL, cancelButtonLabel, cancelButtonColorID);
            CreateButtonKeys(BUTTON_SUCCESS, freeAdsRemoveSuccessButton, 0);
            CreateButtonKeys(BUTTON_FAILURE, freeAdsRemoveFailureButton, 0);

            CreateLocalisationKey(MESSAGE_SUCCESS, freeAdsRemoveSuccessMessage);
            CreateLocalisationKey(MESSAGE_FAILURE, freeAdsRemoveFailureMessage);
        }
Exemplo n.º 33
0
        private bool handleRequest(APIRequest req)
        {
            try
            {
                req.Perform(this);

                if (isLoggedIn)
                {
                    State = APIState.Online;
                }

                failureCount = 0;
                return(true);
            }
            catch (WebException we)
            {
                handleWebException(we);
                return(false);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 34
0
        private void handleWebException(WebException we)
        {
            HttpStatusCode statusCode = (we.Response as HttpWebResponse)?.StatusCode ?? (we.Status == WebExceptionStatus.UnknownError ? HttpStatusCode.NotAcceptable : HttpStatusCode.RequestTimeout);

            switch (we.Message)
            {
            case "Unauthorized":
            case "Forbidden":
                statusCode = HttpStatusCode.Unauthorized;
                break;
            }

            switch (statusCode)
            {
            case HttpStatusCode.Unauthorized:
                Logout();
                return;

            case HttpStatusCode.RequestTimeout:
                failureCount++;

                if (failureCount < 3)
                {
                    return;
                }

                if (State != APIState.Online)
                {
                    return;
                }
                State = APIState.Failing;
                flushQueue();

                return;
            }
        }
Exemplo n.º 35
0
        public APIState getAccessAndRefreshTokens(string device_code)
        {
            try
            {
                HttpWebRequest req = null;
                HttpWebResponse res = null;
                Stream sout = null;
                StreamReader sin = null;
                string text = null;
                string post_data = null;
                object data = null;
                Hashtable hash_data = null;
                Byte[] bytes = null;
                bool result = false;
                string error = null;

                if (string.IsNullOrEmpty(client_id))
                    throw new OAuth2Exception("client_id is required");

                if (string.IsNullOrEmpty(client_secret))
                    throw new OAuth2Exception("client_secret is required");

                if (string.IsNullOrEmpty(device_code))
                    throw new OAuth2Exception("device_code is required");

                post_data = "client_id=" + AtomBansFeed.UrlEncode(client_id) + "&" +
                            "client_secret=" + AtomBansFeed.UrlEncode(client_secret) + "&" +
                            "code=" + AtomBansFeed.UrlEncode(device_code) + "&" +
                            "grant_type=" + AtomBansFeed.UrlEncode(device_grant_type);

                bytes = (new ASCIIEncoding()).GetBytes(post_data);

                req = (HttpWebRequest)WebRequest.Create(token_endpoint);
                req.Method = "POST";
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = bytes.Length;

                sout = req.GetRequestStream();
                sout.Write(bytes, 0, bytes.Length);

                res = (HttpWebResponse)req.GetResponse();

                if (res == null || res.StatusCode != HttpStatusCode.OK)
                    throw new OAuth2Exception("Request for access token at the Google OAuth 2.0 token end-point failed. " + HttpResponseError(res));

                sin = new StreamReader(res.GetResponseStream());
                text = sin.ReadToEnd();

                data = JSON.JsonDecode(text);

                if (!(data != null && data.GetType() == typeof(Hashtable)))
                    throw new OAuth2Exception("Error parsing JSON response from the Google OAuth 2.0 token end-point");

                hash_data = (Hashtable)data;
                if (hash_data.ContainsKey("error") && !string.IsNullOrEmpty(error = hash_data["error"].ToString()))
                {
                    if (error == "authorization_pending")
                        return (state = APIState.AccessPending);
                    else if (error == "access_denied")
                        return (state = APIState.AccessDenied);
                    else
                    {
                        state = APIState.Unknown;
                        throw new OAuth2Exception("The Google OAuth 2.0 token end-point returned unexpected error \"" + error + "\"");
                    }
                }
                else if (hash_data.ContainsKey("access_token") &&
                         hash_data.ContainsKey("refresh_token"))
                {
                    access_token = hash_data["access_token"].ToString();
                    refresh_token = hash_data["refresh_token"].ToString();

                    return (state = APIState.AccessGranted);
                }
                else
                    throw new OAuth2Exception("The Google OAuth 2.0 token end-point returned malformed JSON reply");
            }
            catch (WebException e)
            {
                throw new OAuth2Exception(HttpResponseError((HttpWebResponse)e.Response));
            }
        }
Exemplo n.º 36
0
        public void getUserCode(out string user_code, out string device_code, out string verification_url, out int interval)
        {
            try
            {
                HttpWebRequest req = null;
                HttpWebResponse res = null;
                StreamReader sin = null;
                String post_data = null;
                String text = null;
                Stream sout = null;
                bool result = false;
                Object data = null;
                Hashtable hash_data = null;

                if (string.IsNullOrEmpty(client_id))
                    throw new OAuth2Exception("client_id is required");

                if (string.IsNullOrEmpty(scope))
                    throw new OAuth2Exception("scope is required");

                // Setup the POST Request body for getting the verificaiton URL, and the device code
                post_data = "client_id=" + AtomBansFeed.UrlEncode(client_id) + "&scope=" + AtomBansFeed.UrlEncode(scope);
                ASCIIEncoding ascii = new ASCIIEncoding();
                Byte[] bytes = ascii.GetBytes(post_data);

                // Create the Http POST request
                req = (HttpWebRequest)WebRequest.Create(auth_endpoint);
                req.Method = "POST";
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = bytes.Length;

                sout = req.GetRequestStream();
                sout.Write(bytes, 0, bytes.Length);

                //Get the reply to the Http POST request
                res = (HttpWebResponse)req.GetResponse();

                if (res == null || res.StatusCode != HttpStatusCode.OK)
                    throw new OAuth2Exception("Request to get device user code and verification url at the Google OAuth 2.0 end-point failed. " + HttpResponseError(res));

                sin = new StreamReader(res.GetResponseStream());
                text = sin.ReadToEnd();

                //Parse the JSON response to the POST request
                data = JSON.JsonDecode(text);
                if (!(data != null && data.GetType() == typeof(Hashtable)))
                    throw new OAuth2Exception("Error parsing JSON response from the Google OAuth 2.0 auth end-point");

                hash_data = (Hashtable)data;

                //Verify that the required fields are available in the JSON response
                Dictionary<String, Object> required_keys = new Dictionary<String, Object>();
                required_keys.Add("device_code", "");
                required_keys.Add("user_code", "");
                required_keys.Add("verification_url", "");
                required_keys.Add("expires_in", 0);
                required_keys.Add("interval", 0);

                List<String> keys = new List<String>(required_keys.Keys);

                foreach (String key in keys)
                {
                    if (!hash_data.ContainsKey(key))
                        throw new OAuth2Exception("The Google OAuth 2.0 auth end-point did not reply with required \"" + key + "\" key");

                    required_keys[key] = hash_data[key];
                }

                if (!int.TryParse(required_keys["interval"].ToString(), out interval))
                    throw new OAuth2Exception("The Google OAuth 2.0 poll interval field in the reply is not a valid number");

                user_code = required_keys["user_code"].ToString();
                verification_url = required_keys["verification_url"].ToString();
                device_code = required_keys["device_code"].ToString();
                state = APIState.AccessPending;
            }
            catch (WebException e)
            {
                throw new OAuth2Exception(HttpResponseError((HttpWebResponse)e.Response));
            }
        }