示例#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;
            }
        }
示例#2
0
 public void Logout()
 {
     clearCredentials();
     authentication.Clear();
     State           = APIState.Offline;
     LocalUser.Value = createGuestUser();
 }
示例#3
0
文件: Leaderboard.cs 项目: nbayt/osu
 public void APIStateChanged(APIAccess api, APIState state)
 {
     if (state == APIState.Online)
     {
         UpdateScores();
     }
 }
示例#4
0
 public void APIStateChanged(APIAccess api, APIState state)
 {
     if (state != APIState.Online)
     {
         forcefullyExit();
     }
 }
示例#5
0
 public void APIStateChanged(IAPIProvider api, APIState state)
 {
     if (state != APIState.Online)
     {
         Schedule(forcefullyExit);
     }
 }
示例#6
0
 public void Logout()
 {
     flushQueue();
     password = null;
     authentication.Clear();
     LocalUser.Value = createGuestUser();
     State           = APIState.Offline;
 }
示例#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;
     }
 }
示例#8
0
        public override void APIStateChanged(IAPIProvider api, APIState state)
        {
            if (State.Value == Visibility.Hidden)
            {
                return;
            }

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

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

            State = APIState.Offline;
        }
示例#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;
     }
 }
示例#13
0
文件: OsuGameBase.cs 项目: yheno/osu
 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;
     }
 }
    public void Transition(APIState state)
    {
        APIState cur;

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

        Debug.Log("Queued transition from " + cur + " to " + state);
    }
示例#15
0
文件: ChatOverlay.cs 项目: yheno/osu
 public void APIStateChanged(APIAccess api, APIState state)
 {
     switch (state)
     {
         case APIState.Online:
             initializeChannels();
             break;
         default:
             messageRequest?.Cancel();
             break;
     }
 }
示例#16
0
文件: APIAccess.cs 项目: vbe0201/osu
 public void Logout(bool clearUsername = true)
 {
     flushQueue();
     if (clearUsername)
     {
         ProvidedUsername = null;
     }
     password = null;
     authentication.Clear();
     LocalUser.Value = createGuestUser();
     State           = APIState.Offline;
 }
示例#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();
        }
示例#18
0
文件: ChatOverlay.cs 项目: revam/osu
        public void APIStateChanged(APIAccess api, APIState state)
        {
            switch (state)
            {
            case APIState.Online:
                initializeChannels();
                break;

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

            default:
                Users = null;
                break;
            }
        }
示例#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();
            }
        }
示例#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);
        }
    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();
            }
        }
    }
示例#23
0
        public void APIStateChanged(APIAccess api, APIState state)
        {
            switch (state)
            {
            case APIState.Online:
                fetchUpdates();
                break;

            default:
                fetchMessagesScheduleder?.Cancel();
                fetchMessagesScheduleder = null;
                break;
            }
        }
示例#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;
     }
 }
示例#25
0
        public void APIStateChanged(APIAccess api, APIState state)
        {
            switch (state)
            {
            case APIState.Online:
                Scheduler.AddOnce(updateSearch);
                break;

            default:
                Users = null;
                clearPanels();
                break;
            }
        }
示例#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;
            }
        }
示例#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;
            }
        }
示例#29
0
        public void Logout()
        {
            flushQueue();

            var req = new LogoutRequest();

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

                State = APIState.Offline;
            };
            Queue(req);
        }
示例#30
0
文件: LoginOptions.cs 项目: yheno/osu
 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;
     }
 }
示例#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);
        }
示例#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);
        }
示例#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);
            }
        }
示例#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;
            }
        }
示例#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));
            }
        }
示例#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));
            }
        }