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
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Net;
|
2018-12-05 08:13:22 +00:00
|
|
|
|
using System.Net.Http;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using System.Threading;
|
2019-11-29 11:03:14 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2018-12-05 08:13:22 +00:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-12-03 11:20:49 +00:00
|
|
|
|
using osu.Framework.Extensions.ExceptionExtensions;
|
2020-06-09 13:13:48 +00:00
|
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Logging;
|
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Online.API
|
|
|
|
|
{
|
|
|
|
|
public class APIAccess : Component, IAPIProvider
|
|
|
|
|
{
|
2020-02-14 15:18:56 +00:00
|
|
|
|
private readonly OsuConfigManager config;
|
2020-02-14 13:27:21 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private readonly OAuth authentication;
|
|
|
|
|
|
2019-03-13 03:56:47 +00:00
|
|
|
|
public string Endpoint => @"https://osu.ppy.sh";
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private const string client_id = @"5";
|
|
|
|
|
private const string client_secret = @"FGc9GAtyHzeQDshWP5Ah7dega8hJACAJpQtw6OXk";
|
|
|
|
|
|
2018-09-01 03:55:11 +00:00
|
|
|
|
private readonly Queue<APIRequest> queue = new Queue<APIRequest>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The username/email provided by the user when initiating a login.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ProvidedUsername { get; private set; }
|
|
|
|
|
|
|
|
|
|
private string password;
|
|
|
|
|
|
|
|
|
|
public Bindable<User> LocalUser { get; } = new Bindable<User>(createGuestUser());
|
|
|
|
|
|
2019-06-12 09:04:57 +00:00
|
|
|
|
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
|
|
|
|
|
|
2019-06-11 08:28:16 +00:00
|
|
|
|
protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
private readonly CancellationTokenSource cancellationToken = new CancellationTokenSource();
|
|
|
|
|
|
|
|
|
|
private readonly Logger log;
|
|
|
|
|
|
|
|
|
|
public APIAccess(OsuConfigManager config)
|
|
|
|
|
{
|
|
|
|
|
this.config = config;
|
|
|
|
|
|
|
|
|
|
authentication = new OAuth(client_id, client_secret, Endpoint);
|
|
|
|
|
log = Logger.GetLogger(LoggingTarget.Network);
|
|
|
|
|
|
|
|
|
|
ProvidedUsername = config.Get<string>(OsuSetting.Username);
|
|
|
|
|
|
|
|
|
|
authentication.TokenString = config.Get<string>(OsuSetting.Token);
|
|
|
|
|
authentication.Token.ValueChanged += onTokenChanged;
|
|
|
|
|
|
2019-06-12 09:04:57 +00:00
|
|
|
|
LocalUser.BindValueChanged(u =>
|
|
|
|
|
{
|
|
|
|
|
u.OldValue?.Activity.UnbindFrom(Activity);
|
|
|
|
|
u.NewValue.Activity.BindTo(Activity);
|
|
|
|
|
}, true);
|
|
|
|
|
|
2018-09-01 04:00:55 +00:00
|
|
|
|
var thread = new Thread(run)
|
|
|
|
|
{
|
|
|
|
|
Name = "APIAccess",
|
|
|
|
|
IsBackground = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
thread.Start();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
private void onTokenChanged(ValueChangedEvent<OAuthToken> e) => config.Set(OsuSetting.Token, config.Get<bool>(OsuSetting.SavePassword) ? authentication.TokenString : string.Empty);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
private readonly List<IOnlineComponent> components = new List<IOnlineComponent>();
|
|
|
|
|
|
|
|
|
|
internal new void Schedule(Action action) => base.Schedule(action);
|
|
|
|
|
|
2019-03-08 03:00:38 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Register a component to receive API events.
|
2019-03-08 03:44:33 +00:00
|
|
|
|
/// Fires <see cref="IOnlineComponent.APIStateChanged"/> once immediately to ensure a correct state.
|
2019-03-08 03:00:38 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="component"></param>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public void Register(IOnlineComponent component)
|
|
|
|
|
{
|
2019-05-09 04:33:18 +00:00
|
|
|
|
Schedule(() => components.Add(component));
|
2019-03-08 03:00:38 +00:00
|
|
|
|
component.APIStateChanged(this, state);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unregister(IOnlineComponent component)
|
|
|
|
|
{
|
2019-05-09 04:33:18 +00:00
|
|
|
|
Schedule(() => components.Remove(component));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string AccessToken => authentication.RequestAccessToken();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Number of consecutive requests which failed due to network issues.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int failureCount;
|
|
|
|
|
|
|
|
|
|
private void run()
|
|
|
|
|
{
|
|
|
|
|
while (!cancellationToken.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
switch (State)
|
|
|
|
|
{
|
|
|
|
|
case APIState.Failing:
|
|
|
|
|
//todo: replace this with a ping request.
|
|
|
|
|
log.Add(@"In a failing state, waiting a bit before we try again...");
|
|
|
|
|
Thread.Sleep(5000);
|
2019-01-09 06:29:27 +00:00
|
|
|
|
|
|
|
|
|
if (!IsLoggedIn) goto case APIState.Connecting;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
if (queue.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
log.Add(@"Queueing a ping request");
|
2018-12-18 11:19:40 +00:00
|
|
|
|
Queue(new GetUserRequest());
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
2018-09-01 03:55:11 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
break;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
case APIState.Offline:
|
|
|
|
|
case APIState.Connecting:
|
2020-05-05 01:31:11 +00:00
|
|
|
|
// work to restore a connection...
|
2018-04-13 09:19:50 +00:00
|
|
|
|
if (!HasLogin)
|
|
|
|
|
{
|
|
|
|
|
State = APIState.Offline;
|
|
|
|
|
Thread.Sleep(50);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
State = APIState.Connecting;
|
|
|
|
|
|
|
|
|
|
// save the username at this point, if the user requested for it to be.
|
|
|
|
|
config.Set(OsuSetting.Username, config.Get<bool>(OsuSetting.SaveUsername) ? ProvidedUsername : string.Empty);
|
|
|
|
|
|
|
|
|
|
if (!authentication.HasValidAccessToken && !authentication.AuthenticateWithLogin(ProvidedUsername, password))
|
|
|
|
|
{
|
|
|
|
|
//todo: this fails even on network-related issues. we should probably handle those differently.
|
|
|
|
|
//NotificationOverlay.ShowMessage("Login failed!");
|
|
|
|
|
log.Add(@"Login failed!");
|
|
|
|
|
password = null;
|
|
|
|
|
authentication.Clear();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userReq = new GetUserRequest();
|
|
|
|
|
userReq.Success += u =>
|
|
|
|
|
{
|
|
|
|
|
LocalUser.Value = u;
|
2019-12-18 05:07:03 +00:00
|
|
|
|
|
|
|
|
|
// todo: save/pull from settings
|
|
|
|
|
LocalUser.Value.Status.Value = new UserStatusOnline();
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
failureCount = 0;
|
|
|
|
|
|
|
|
|
|
//we're connected!
|
|
|
|
|
State = APIState.Online;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!handleRequest(userReq))
|
|
|
|
|
{
|
2018-12-26 07:06:39 +00:00
|
|
|
|
if (State == APIState.Connecting)
|
|
|
|
|
State = APIState.Failing;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The Success callback event is fired on the main thread, so we should wait for that to run before proceeding.
|
|
|
|
|
// Without this, we will end up circulating this Connecting loop multiple times and queueing up many web requests
|
|
|
|
|
// before actually going online.
|
2018-06-26 11:13:44 +00:00
|
|
|
|
while (State > APIState.Offline && State < APIState.Online)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Thread.Sleep(500);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 01:31:11 +00:00
|
|
|
|
// hard bail if we can't get a valid access token.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
if (authentication.RequestAccessToken() == null)
|
|
|
|
|
{
|
2018-12-22 08:54:19 +00:00
|
|
|
|
Logout();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 08:38:15 +00:00
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
APIRequest req;
|
2018-09-01 03:55:11 +00:00
|
|
|
|
|
2018-09-06 08:38:15 +00:00
|
|
|
|
lock (queue)
|
|
|
|
|
{
|
|
|
|
|
if (queue.Count == 0) break;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-09-01 03:55:11 +00:00
|
|
|
|
req = queue.Dequeue();
|
2018-09-06 08:38:15 +00:00
|
|
|
|
}
|
2018-09-01 03:55:11 +00:00
|
|
|
|
|
|
|
|
|
handleRequest(req);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-01 03:55:11 +00:00
|
|
|
|
Thread.Sleep(50);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-29 11:03:14 +00:00
|
|
|
|
public void Perform(APIRequest request)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
request.Perform(this);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
// todo: fix exception handling
|
|
|
|
|
request.Fail(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task PerformAsync(APIRequest request) =>
|
|
|
|
|
Task.Factory.StartNew(() => Perform(request), TaskCreationOptions.LongRunning);
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public void Login(string username, string password)
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(State == APIState.Offline);
|
|
|
|
|
|
|
|
|
|
ProvidedUsername = username;
|
|
|
|
|
this.password = password;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-05 08:13:22 +00:00
|
|
|
|
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password)
|
2018-12-04 11:33:29 +00:00
|
|
|
|
{
|
|
|
|
|
Debug.Assert(State == APIState.Offline);
|
2018-12-05 04:08:35 +00:00
|
|
|
|
|
2018-12-05 08:13:22 +00:00
|
|
|
|
var req = new RegistrationRequest
|
|
|
|
|
{
|
|
|
|
|
Url = $@"{Endpoint}/users",
|
|
|
|
|
Method = HttpMethod.Post,
|
|
|
|
|
Username = username,
|
|
|
|
|
Email = email,
|
|
|
|
|
Password = password
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
req.Perform();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-06-09 13:13:48 +00:00
|
|
|
|
return JObject.Parse(req.GetResponseString()).SelectToken("form_error", true).AsNonNull().ToObject<RegistrationRequest.RegistrationRequestErrors>();
|
2018-12-05 08:13:22 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// if we couldn't deserialize the error message let's throw the original exception outwards.
|
2019-12-03 11:20:49 +00:00
|
|
|
|
e.Rethrow();
|
2018-12-05 08:13:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-05 04:08:35 +00:00
|
|
|
|
|
2018-12-05 08:13:22 +00:00
|
|
|
|
return null;
|
2018-12-04 11:33:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handle a single API request.
|
2018-12-18 11:19:40 +00:00
|
|
|
|
/// Ensures all exceptions are caught and dealt with correctly.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req">The request.</param>
|
2018-12-17 05:29:11 +00:00
|
|
|
|
/// <returns>true if the request succeeded.</returns>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private bool handleRequest(APIRequest req)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
req.Perform(this);
|
|
|
|
|
|
2020-05-05 01:31:11 +00:00
|
|
|
|
// we could still be in initialisation, at which point we don't want to say we're Online yet.
|
2018-12-18 11:19:40 +00:00
|
|
|
|
if (IsLoggedIn) State = APIState.Online;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
failureCount = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (WebException we)
|
|
|
|
|
{
|
2018-12-18 11:19:40 +00:00
|
|
|
|
handleWebException(we);
|
2018-12-17 05:29:11 +00:00
|
|
|
|
return false;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
2019-06-15 15:31:14 +00:00
|
|
|
|
catch (Exception ex)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-06-15 15:31:14 +00:00
|
|
|
|
Logger.Error(ex, "Error occurred while handling an API request.");
|
2018-12-17 05:29:11 +00:00
|
|
|
|
return false;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private APIState state;
|
2018-09-01 03:55:11 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public APIState State
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => state;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private set
|
|
|
|
|
{
|
2019-03-22 05:31:54 +00:00
|
|
|
|
if (state == value)
|
|
|
|
|
return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-22 05:31:54 +00:00
|
|
|
|
APIState oldState = state;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
state = value;
|
|
|
|
|
|
2019-03-22 05:31:54 +00:00
|
|
|
|
log.Add($@"We just went {state}!");
|
2019-05-09 04:33:18 +00:00
|
|
|
|
Schedule(() =>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-03-22 05:31:54 +00:00
|
|
|
|
components.ForEach(c => c.APIStateChanged(this, state));
|
|
|
|
|
OnStateChange?.Invoke(oldState, state);
|
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-14 06:48:34 +00:00
|
|
|
|
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:
|
2018-12-22 08:54:19 +00:00
|
|
|
|
Logout();
|
2018-12-14 06:48:34 +00:00
|
|
|
|
return true;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-12-14 06:48:34 +00:00
|
|
|
|
case HttpStatusCode.RequestTimeout:
|
|
|
|
|
failureCount++;
|
|
|
|
|
log.Add($@"API failure count is now {failureCount}");
|
|
|
|
|
|
|
|
|
|
if (failureCount < 3)
|
2020-05-05 01:31:11 +00:00
|
|
|
|
// we might try again at an api level.
|
2018-12-14 06:48:34 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2018-12-19 05:32:43 +00:00
|
|
|
|
if (State == APIState.Online)
|
|
|
|
|
{
|
|
|
|
|
State = APIState.Failing;
|
|
|
|
|
flushQueue();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-14 06:48:34 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public bool IsLoggedIn => LocalUser.Value.Id > 1;
|
|
|
|
|
|
2018-09-01 03:55:11 +00:00
|
|
|
|
public void Queue(APIRequest request)
|
|
|
|
|
{
|
|
|
|
|
lock (queue) queue.Enqueue(request);
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
public event StateChangeDelegate OnStateChange;
|
|
|
|
|
|
|
|
|
|
public delegate void StateChangeDelegate(APIState oldState, APIState newState);
|
|
|
|
|
|
|
|
|
|
private void flushQueue(bool failOldRequests = true)
|
|
|
|
|
{
|
2018-09-01 03:55:11 +00:00
|
|
|
|
lock (queue)
|
|
|
|
|
{
|
|
|
|
|
var oldQueueRequests = queue.ToArray();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-01 03:55:11 +00:00
|
|
|
|
queue.Clear();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-01 03:55:11 +00:00
|
|
|
|
if (failOldRequests)
|
|
|
|
|
{
|
|
|
|
|
foreach (var req in oldQueueRequests)
|
|
|
|
|
req.Fail(new WebException(@"Disconnected from server"));
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-22 08:54:19 +00:00
|
|
|
|
public void Logout()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
flushQueue();
|
2019-05-09 04:32:18 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
password = null;
|
|
|
|
|
authentication.Clear();
|
2019-05-09 04:32:18 +00:00
|
|
|
|
|
2019-05-09 04:42:04 +00:00
|
|
|
|
// Scheduled prior to state change such that the state changed event is invoked with the correct user present
|
2019-05-09 04:32:18 +00:00
|
|
|
|
Schedule(() => LocalUser.Value = createGuestUser());
|
2019-05-09 04:42:04 +00:00
|
|
|
|
|
|
|
|
|
State = APIState.Offline;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 02:06:29 +00:00
|
|
|
|
private static User createGuestUser() => new GuestUser();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
|
|
flushQueue();
|
|
|
|
|
cancellationToken.Cancel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 02:06:29 +00:00
|
|
|
|
internal class GuestUser : User
|
|
|
|
|
{
|
|
|
|
|
public GuestUser()
|
|
|
|
|
{
|
|
|
|
|
Username = @"Guest";
|
|
|
|
|
Id = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public enum APIState
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// We cannot login (not enough credentials).
|
|
|
|
|
/// </summary>
|
|
|
|
|
Offline,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// We are having connectivity issues.
|
|
|
|
|
/// </summary>
|
|
|
|
|
Failing,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// We are in the process of (re-)connecting.
|
|
|
|
|
/// </summary>
|
|
|
|
|
Connecting,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// We are online.
|
|
|
|
|
/// </summary>
|
|
|
|
|
Online
|
|
|
|
|
}
|
|
|
|
|
}
|