mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Merge remote-tracking branch 'upstream/master' into ranks-section
This commit is contained in:
@ -101,18 +101,16 @@ namespace osu.Game.Online.API
|
||||
}
|
||||
break;
|
||||
case APIState.Offline:
|
||||
case APIState.Connecting:
|
||||
//work to restore a connection...
|
||||
if (!HasLogin)
|
||||
{
|
||||
//OsuGame.Scheduler.Add(() => { OsuGame.ShowLogin(); });
|
||||
|
||||
State = APIState.Offline;
|
||||
Thread.Sleep(500);
|
||||
Thread.Sleep(50);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (State < APIState.Connecting)
|
||||
State = APIState.Connecting;
|
||||
State = APIState.Connecting;
|
||||
|
||||
if (!authentication.HasValidAccessToken && !authentication.AuthenticateWithLogin(Username, Password))
|
||||
{
|
||||
@ -125,7 +123,8 @@ namespace osu.Game.Online.API
|
||||
|
||||
|
||||
var userReq = new GetUserRequest();
|
||||
userReq.Success += u => {
|
||||
userReq.Success += u =>
|
||||
{
|
||||
LocalUser.Value = u;
|
||||
//we're connected!
|
||||
State = APIState.Online;
|
||||
@ -133,16 +132,14 @@ namespace osu.Game.Online.API
|
||||
};
|
||||
|
||||
if (!handleRequest(userReq))
|
||||
{
|
||||
State = APIState.Failing;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//hard bail if we can't get a valid access token.
|
||||
if (authentication.RequestAccessToken() == null)
|
||||
{
|
||||
Logout(false);
|
||||
State = APIState.Offline;
|
||||
continue;
|
||||
}
|
||||
@ -162,20 +159,12 @@ namespace osu.Game.Online.API
|
||||
}
|
||||
}
|
||||
|
||||
private void clearCredentials()
|
||||
{
|
||||
Username = null;
|
||||
Password = null;
|
||||
}
|
||||
|
||||
public void Login(string username, string password)
|
||||
{
|
||||
Debug.Assert(State == APIState.Offline);
|
||||
|
||||
Username = username;
|
||||
Password = password;
|
||||
|
||||
State = APIState.Connecting;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -204,7 +193,7 @@ namespace osu.Game.Online.API
|
||||
switch (statusCode)
|
||||
{
|
||||
case HttpStatusCode.Unauthorized:
|
||||
State = APIState.Offline;
|
||||
Logout(false);
|
||||
return true;
|
||||
case HttpStatusCode.RequestTimeout:
|
||||
failureCount++;
|
||||
@ -215,6 +204,7 @@ namespace osu.Game.Online.API
|
||||
return false;
|
||||
|
||||
State = APIState.Failing;
|
||||
flushQueue();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -235,33 +225,21 @@ namespace osu.Game.Online.API
|
||||
public APIState State
|
||||
{
|
||||
get { return state; }
|
||||
set
|
||||
private set
|
||||
{
|
||||
APIState oldState = state;
|
||||
APIState newState = value;
|
||||
|
||||
state = value;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case APIState.Failing:
|
||||
case APIState.Offline:
|
||||
flushQueue();
|
||||
break;
|
||||
}
|
||||
|
||||
if (oldState != newState)
|
||||
{
|
||||
//OsuGame.Scheduler.Add(delegate
|
||||
log.Add($@"We just went {newState}!");
|
||||
Scheduler.Add(delegate
|
||||
{
|
||||
//NotificationOverlay.ShowMessage($@"We just went {newState}!", newState == APIState.Online ? Color4.YellowGreen : Color4.OrangeRed, 5000);
|
||||
log.Add($@"We just went {newState}!");
|
||||
Scheduler.Add(delegate
|
||||
{
|
||||
components.ForEach(c => c.APIStateChanged(this, newState));
|
||||
OnStateChange?.Invoke(oldState, newState);
|
||||
});
|
||||
}
|
||||
components.ForEach(c => c.APIStateChanged(this, newState));
|
||||
OnStateChange?.Invoke(oldState, newState);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -292,11 +270,12 @@ namespace osu.Game.Online.API
|
||||
}
|
||||
}
|
||||
|
||||
public void Logout()
|
||||
public void Logout(bool clearUsername = true)
|
||||
{
|
||||
clearCredentials();
|
||||
flushQueue();
|
||||
if (clearUsername) Username = null;
|
||||
Password = null;
|
||||
authentication.Clear();
|
||||
State = APIState.Offline;
|
||||
LocalUser.Value = createGuestUser();
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.IO.Network;
|
||||
|
||||
namespace osu.Game.Online.API
|
||||
@ -70,13 +69,11 @@ namespace osu.Game.Online.API
|
||||
|
||||
protected virtual string Uri => $@"{API.Endpoint}/api/v2/{Target}";
|
||||
|
||||
private double remainingTime => Math.Max(0, Timeout - (DateTime.Now.TotalMilliseconds() - (startTime ?? 0)));
|
||||
private double remainingTime => Math.Max(0, Timeout - (DateTimeOffset.UtcNow - (startTime ?? DateTimeOffset.MinValue)).TotalMilliseconds);
|
||||
|
||||
public bool ExceededTimeout => remainingTime == 0;
|
||||
|
||||
private double? startTime;
|
||||
|
||||
public double StartTime => startTime ?? -1;
|
||||
private DateTimeOffset? startTime;
|
||||
|
||||
protected APIAccess API;
|
||||
protected WebRequest WebRequest;
|
||||
@ -96,7 +93,7 @@ namespace osu.Game.Online.API
|
||||
return;
|
||||
|
||||
if (startTime == null)
|
||||
startTime = DateTime.Now.TotalMilliseconds();
|
||||
startTime = DateTimeOffset.UtcNow;
|
||||
|
||||
if (remainingTime <= 0)
|
||||
throw new TimeoutException(@"API request timeout hit");
|
||||
|
@ -4,7 +4,6 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Extensions;
|
||||
|
||||
namespace osu.Game.Online.API
|
||||
{
|
||||
@ -22,12 +21,12 @@ namespace osu.Game.Online.API
|
||||
{
|
||||
get
|
||||
{
|
||||
return AccessTokenExpiry - DateTime.Now.ToUnixTimestamp();
|
||||
return AccessTokenExpiry - DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
AccessTokenExpiry = DateTime.Now.AddSeconds(value).ToUnixTimestamp();
|
||||
AccessTokenExpiry = DateTimeOffset.Now.AddSeconds(value).ToUnixTimeSeconds();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
private readonly BeatmapInfo beatmap;
|
||||
|
||||
private string lookupString => beatmap.OnlineBeatmapID > 0 ? beatmap.OnlineBeatmapID.ToString() : $@"lookup?checksum={beatmap.Hash}&filename={beatmap.Path}";
|
||||
private string lookupString => beatmap.OnlineBeatmapID > 0 ? beatmap.OnlineBeatmapID.ToString() : $@"lookup?checksum={beatmap.Hash}&filename={System.Uri.EscapeUriString(beatmap.Path)}";
|
||||
|
||||
public GetBeatmapDetailsRequest(BeatmapInfo beatmap)
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ using osu.Game.Beatmaps;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Direct;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
@ -49,6 +50,12 @@ namespace osu.Game.Online.API.Requests
|
||||
[JsonProperty(@"id")]
|
||||
private int onlineId { get; set; }
|
||||
|
||||
[JsonProperty(@"creator")]
|
||||
private string creatorUsername { get; set; }
|
||||
|
||||
[JsonProperty(@"user_id")]
|
||||
private long creatorId = 1;
|
||||
|
||||
[JsonProperty(@"beatmaps")]
|
||||
private IEnumerable<GetBeatmapSetsBeatmapResponse> beatmaps { get; set; }
|
||||
|
||||
@ -60,6 +67,11 @@ namespace osu.Game.Online.API.Requests
|
||||
Metadata = this,
|
||||
OnlineInfo = new BeatmapSetOnlineInfo
|
||||
{
|
||||
Author = new User
|
||||
{
|
||||
Id = creatorId,
|
||||
Username = creatorUsername,
|
||||
},
|
||||
Covers = covers,
|
||||
Preview = preview,
|
||||
PlayCount = playCount,
|
||||
|
@ -96,7 +96,7 @@ namespace osu.Game.Online.API.Requests
|
||||
}
|
||||
|
||||
[JsonProperty(@"statistics")]
|
||||
private Dictionary<string, dynamic> jsonStats
|
||||
private Dictionary<string, object> jsonStats
|
||||
{
|
||||
set
|
||||
{
|
||||
|
@ -23,6 +23,7 @@ namespace osu.Game.Online.API.Requests
|
||||
req.Method = HttpMethod.POST;
|
||||
req.AddParameter(@"target_type", message.TargetType.GetDescription());
|
||||
req.AddParameter(@"target_id", message.TargetId.ToString());
|
||||
req.AddParameter(@"is_action", message.IsAction.ToString().ToLower());
|
||||
req.AddParameter(@"message", message.Content);
|
||||
|
||||
return req;
|
||||
@ -30,4 +31,4 @@ namespace osu.Game.Online.API.Requests
|
||||
|
||||
protected override string Target => @"chat/messages";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user