2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-22 02:55:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-03-22 02:55:35 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Online.API
|
|
|
|
|
{
|
2019-03-22 02:55:35 +00:00
|
|
|
|
public class DummyAPIAccess : Component, IAPIProvider
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
public Bindable<User> LocalUser { get; } = new Bindable<User>(new User
|
|
|
|
|
{
|
|
|
|
|
Username = @"Dummy",
|
2019-03-13 03:56:47 +00:00
|
|
|
|
Id = 1001,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
});
|
|
|
|
|
|
2019-06-12 09:04:57 +00:00
|
|
|
|
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public bool IsLoggedIn => true;
|
|
|
|
|
|
2019-03-13 03:56:47 +00:00
|
|
|
|
public string ProvidedUsername => LocalUser.Value.Username;
|
|
|
|
|
|
2019-03-13 09:56:48 +00:00
|
|
|
|
public string Endpoint => "http://localhost";
|
2019-03-13 03:56:47 +00:00
|
|
|
|
|
2019-03-22 02:55:35 +00:00
|
|
|
|
private APIState state = APIState.Online;
|
|
|
|
|
|
|
|
|
|
private readonly List<IOnlineComponent> components = new List<IOnlineComponent>();
|
|
|
|
|
|
|
|
|
|
public APIState State
|
|
|
|
|
{
|
|
|
|
|
get => state;
|
|
|
|
|
private set
|
|
|
|
|
{
|
2019-03-22 05:20:53 +00:00
|
|
|
|
if (state == value)
|
|
|
|
|
return;
|
2019-03-22 02:55:35 +00:00
|
|
|
|
|
|
|
|
|
state = value;
|
|
|
|
|
|
2019-03-22 05:20:53 +00:00
|
|
|
|
Scheduler.Add(() => components.ForEach(c => c.APIStateChanged(this, value)));
|
2019-03-22 02:55:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-12 09:04:57 +00:00
|
|
|
|
|
|
|
|
|
public DummyAPIAccess()
|
|
|
|
|
{
|
|
|
|
|
LocalUser.BindValueChanged(u =>
|
|
|
|
|
{
|
|
|
|
|
u.OldValue?.Activity.UnbindFrom(Activity);
|
|
|
|
|
u.NewValue.Activity.BindTo(Activity);
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
public virtual void Queue(APIRequest request)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Register(IOnlineComponent component)
|
|
|
|
|
{
|
2019-03-22 02:55:35 +00:00
|
|
|
|
Scheduler.Add(delegate { components.Add(component); });
|
|
|
|
|
component.APIStateChanged(this, state);
|
2019-03-13 03:56:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unregister(IOnlineComponent component)
|
|
|
|
|
{
|
2019-03-22 02:55:35 +00:00
|
|
|
|
Scheduler.Add(delegate { components.Remove(component); });
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
2019-03-13 03:56:47 +00:00
|
|
|
|
|
|
|
|
|
public void Login(string username, string password)
|
|
|
|
|
{
|
|
|
|
|
LocalUser.Value = new User
|
|
|
|
|
{
|
2019-03-22 02:55:35 +00:00
|
|
|
|
Username = username,
|
2019-03-13 10:01:42 +00:00
|
|
|
|
Id = 1001,
|
2019-03-13 03:56:47 +00:00
|
|
|
|
};
|
2019-03-22 02:55:35 +00:00
|
|
|
|
|
|
|
|
|
State = APIState.Online;
|
2019-03-13 03:56:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Logout()
|
|
|
|
|
{
|
|
|
|
|
LocalUser.Value = new GuestUser();
|
2019-03-22 02:55:35 +00:00
|
|
|
|
State = APIState.Offline;
|
2019-03-13 03:56:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-22 02:55:35 +00:00
|
|
|
|
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(200);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|