1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 10:03:21 +08:00

Merge pull request #11271 from peppy/dev-server

Prefer connecting to dev server when running in DEBUG
This commit is contained in:
Dean Herbert 2020-12-24 23:01:19 +09:00 committed by GitHub
commit 3d28a0ccef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 199 additions and 52 deletions

View File

@ -13,6 +13,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Database;
using osu.Game.Online;
using osu.Game.Online.Spectator;
using osu.Game.Replays.Legacy;
using osu.Game.Rulesets.Osu.Scoring;
@ -87,6 +88,7 @@ namespace osu.Game.Tests.Visual.Gameplay
private readonly int totalUsers;
public TestMultiplayerStreaming(int totalUsers)
: base(new DevelopmentEndpointConfiguration())
{
this.totalUsers = totalUsers;
}

View File

@ -12,6 +12,7 @@ using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Online;
using osu.Game.Online.Spectator;
using osu.Game.Replays.Legacy;
using osu.Game.Rulesets.Osu;
@ -238,6 +239,11 @@ namespace osu.Game.Tests.Visual.Gameplay
private int beatmapId;
public TestSpectatorStreamingClient()
: base(new DevelopmentEndpointConfiguration())
{
}
protected override Task Connect()
{
return Task.CompletedTask;

View File

@ -41,6 +41,7 @@ namespace osu.Game.Tests.Visual.Online
}
[Test]
[Ignore("needs to be updated to not be so server dependent")]
public void ShowWithBuild()
{
AddStep(@"Show with Lazer 2018.712.0", () =>
@ -49,7 +50,7 @@ namespace osu.Game.Tests.Visual.Online
{
Version = "2018.712.0",
DisplayVersion = "2018.712.0",
UpdateStream = new APIUpdateStream { Id = 7, Name = OsuGameBase.CLIENT_STREAM_NAME },
UpdateStream = new APIUpdateStream { Id = 5, Name = OsuGameBase.CLIENT_STREAM_NAME },
ChangelogEntries = new List<APIChangelogEntry>
{
new APIChangelogEntry
@ -64,7 +65,7 @@ namespace osu.Game.Tests.Visual.Online
AddUntilStep(@"wait for streams", () => changelog.Streams?.Count > 0);
AddAssert(@"correct build displayed", () => changelog.Current.Value.Version == "2018.712.0");
AddAssert(@"correct stream selected", () => changelog.Header.Streams.Current.Value.Id == 7);
AddAssert(@"correct stream selected", () => changelog.Header.Streams.Current.Value.Id == 5);
}
[Test]

View File

@ -70,7 +70,7 @@ namespace osu.Game.Tests.Visual.Online
AddStep("Run command", () => Add(new NowPlayingCommand()));
if (hasOnlineId)
AddAssert("Check link presence", () => postTarget.LastMessage.Contains("https://osu.ppy.sh/b/1234"));
AddAssert("Check link presence", () => postTarget.LastMessage.Contains("/b/1234"));
else
AddAssert("Check link not present", () => !postTarget.LastMessage.Contains("https://"));
}

View File

@ -0,0 +1,19 @@
// 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.
using osu.Framework.Platform;
using osu.Framework.Testing;
namespace osu.Game.Configuration
{
[ExcludeFromDynamicCompile]
public class DevelopmentOsuConfigManager : OsuConfigManager
{
protected override string Filename => base.Filename.Replace(".ini", ".dev.ini");
public DevelopmentOsuConfigManager(Storage storage)
: base(storage)
{
}
}
}

View File

@ -26,12 +26,12 @@ namespace osu.Game.Online.API
private readonly OAuth authentication;
public string Endpoint => @"https://osu.ppy.sh";
private const string client_id = @"5";
private const string client_secret = @"FGc9GAtyHzeQDshWP5Ah7dega8hJACAJpQtw6OXk";
private readonly Queue<APIRequest> queue = new Queue<APIRequest>();
public string APIEndpointUrl { get; }
public string WebsiteRootUrl { get; }
/// <summary>
/// The username/email provided by the user when initiating a login.
/// </summary>
@ -55,11 +55,14 @@ namespace osu.Game.Online.API
private readonly Logger log;
public APIAccess(OsuConfigManager config)
public APIAccess(OsuConfigManager config, EndpointConfiguration endpointConfiguration)
{
this.config = config;
authentication = new OAuth(client_id, client_secret, Endpoint);
APIEndpointUrl = endpointConfiguration.APIEndpointUrl;
WebsiteRootUrl = endpointConfiguration.WebsiteRootUrl;
authentication = new OAuth(endpointConfiguration.APIClientID, endpointConfiguration.APIClientSecret, APIEndpointUrl);
log = Logger.GetLogger(LoggingTarget.Network);
ProvidedUsername = config.Get<string>(OsuSetting.Username);
@ -245,7 +248,7 @@ namespace osu.Game.Online.API
var req = new RegistrationRequest
{
Url = $@"{Endpoint}/users",
Url = $@"{APIEndpointUrl}/users",
Method = HttpMethod.Post,
Username = username,
Email = email,

View File

@ -57,7 +57,7 @@ namespace osu.Game.Online.API
protected virtual WebRequest CreateWebRequest() => new OsuWebRequest(Uri);
protected virtual string Uri => $@"{API.Endpoint}/api/v2/{Target}";
protected virtual string Uri => $@"{API.APIEndpointUrl}/api/v2/{Target}";
protected APIAccess API;
protected WebRequest WebRequest;

View File

@ -28,7 +28,9 @@ namespace osu.Game.Online.API
public string ProvidedUsername => LocalUser.Value.Username;
public string Endpoint => "http://localhost";
public string APIEndpointUrl => "http://localhost";
public string WebsiteRootUrl => "http://localhost";
/// <summary>
/// Provide handling logic for an arbitrary API request.

View File

@ -46,7 +46,12 @@ namespace osu.Game.Online.API
/// <summary>
/// The URL endpoint for this API. Does not include a trailing slash.
/// </summary>
string Endpoint { get; }
string APIEndpointUrl { get; }
/// <summary>
/// The root URL of of the website, excluding the trailing slash.
/// </summary>
string WebsiteRootUrl { get; }
/// <summary>
/// The current connection state of the API.

View File

@ -48,6 +48,7 @@ namespace osu.Game.Online.API.Requests.Responses
public enum ChangelogEntryType
{
Add,
Fix
Fix,
Misc
}
}

View File

@ -46,7 +46,7 @@ namespace osu.Game.Online.Chat
break;
}
var beatmapString = beatmap.OnlineBeatmapID.HasValue ? $"[https://osu.ppy.sh/b/{beatmap.OnlineBeatmapID} {beatmap}]" : beatmap.ToString();
var beatmapString = beatmap.OnlineBeatmapID.HasValue ? $"[{api.WebsiteRootUrl}/b/{beatmap.OnlineBeatmapID} {beatmap}]" : beatmap.ToString();
channelManager.PostMessage($"is {verb} {beatmapString}", true);
Expire();

View File

@ -0,0 +1,17 @@
// 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.
namespace osu.Game.Online
{
public class DevelopmentEndpointConfiguration : EndpointConfiguration
{
public DevelopmentEndpointConfiguration()
{
WebsiteRootUrl = APIEndpointUrl = @"https://dev.ppy.sh";
APIClientSecret = @"3LP2mhUrV89xxzD1YKNndXHEhWWCRLPNKioZ9ymT";
APIClientID = "5";
SpectatorEndpointUrl = $"{APIEndpointUrl}/spectator";
MultiplayerEndpointUrl = $"{APIEndpointUrl}/multiplayer";
}
}
}

View File

@ -0,0 +1,41 @@
// 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.
namespace osu.Game.Online
{
/// <summary>
/// Holds configuration for API endpoints.
/// </summary>
public class EndpointConfiguration
{
/// <summary>
/// The base URL for the website.
/// </summary>
public string WebsiteRootUrl { get; set; }
/// <summary>
/// The endpoint for the main (osu-web) API.
/// </summary>
public string APIEndpointUrl { get; set; }
/// <summary>
/// The OAuth client secret.
/// </summary>
public string APIClientSecret { get; set; }
/// <summary>
/// The OAuth client ID.
/// </summary>
public string APIClientID { get; set; }
/// <summary>
/// The endpoint for the SignalR spectator server.
/// </summary>
public string SpectatorEndpointUrl { get; set; }
/// <summary>
/// The endpoint for the SignalR multiplayer server.
/// </summary>
public string MultiplayerEndpointUrl { get; set; }
}
}

View File

@ -0,0 +1,17 @@
// 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.
namespace osu.Game.Online
{
public class ProductionEndpointConfiguration : EndpointConfiguration
{
public ProductionEndpointConfiguration()
{
WebsiteRootUrl = APIEndpointUrl = @"https://osu.ppy.sh";
APIClientSecret = @"FGc9GAtyHzeQDshWP5Ah7dega8hJACAJpQtw6OXk";
APIClientID = "5";
SpectatorEndpointUrl = "https://spectator.ppy.sh/spectator";
MultiplayerEndpointUrl = "https://spectator.ppy.sh/multiplayer";
}
}
}

View File

@ -19,8 +19,6 @@ namespace osu.Game.Online.RealtimeMultiplayer
{
public class RealtimeMultiplayerClient : StatefulMultiplayerClient
{
private const string endpoint = "https://spectator.ppy.sh/multiplayer";
public override IBindable<bool> IsConnected => isConnected;
private readonly Bindable<bool> isConnected = new Bindable<bool>();
@ -31,6 +29,13 @@ namespace osu.Game.Online.RealtimeMultiplayer
private HubConnection? connection;
private readonly string endpoint;
public RealtimeMultiplayerClient(EndpointConfiguration endpoints)
{
endpoint = endpoints.MultiplayerEndpointUrl;
}
[BackgroundDependencyLoader]
private void load()
{

View File

@ -81,6 +81,13 @@ namespace osu.Game.Online.Spectator
/// </summary>
public event Action<int, SpectatorState> OnUserFinishedPlaying;
private readonly string endpoint;
public SpectatorStreamingClient(EndpointConfiguration endpoints)
{
endpoint = endpoints.SpectatorEndpointUrl;
}
[BackgroundDependencyLoader]
private void load()
{
@ -104,8 +111,6 @@ namespace osu.Game.Online.Spectator
}
}
private const string endpoint = "https://spectator.ppy.sh/spectator";
protected virtual async Task Connect()
{
if (connection != null)

View File

@ -294,7 +294,7 @@ namespace osu.Game
public void OpenUrlExternally(string url) => waitForReady(() => externalLinkOpener, _ =>
{
if (url.StartsWith('/'))
url = $"{API.Endpoint}{url}";
url = $"{API.APIEndpointUrl}{url}";
externalLinkOpener.OpenUrlExternally(url);
});

View File

@ -30,6 +30,7 @@ using osu.Game.Database;
using osu.Game.Input;
using osu.Game.Input.Bindings;
using osu.Game.IO;
using osu.Game.Online;
using osu.Game.Online.RealtimeMultiplayer;
using osu.Game.Online.Spectator;
using osu.Game.Overlays;
@ -54,6 +55,8 @@ namespace osu.Game
public const int SAMPLE_CONCURRENCY = 6;
public bool UseDevelopmentServer { get; }
protected OsuConfigManager LocalConfig;
protected BeatmapManager BeatmapManager;
@ -132,6 +135,7 @@ namespace osu.Game
public OsuGameBase()
{
UseDevelopmentServer = DebugUtils.IsDebugBuild;
Name = @"osu!lazer";
}
@ -170,7 +174,7 @@ namespace osu.Game
dependencies.Cache(largeStore);
dependencies.CacheAs(this);
dependencies.Cache(LocalConfig);
dependencies.CacheAs(LocalConfig);
AddFont(Resources, @"Fonts/osuFont");
@ -210,10 +214,12 @@ namespace osu.Game
}
});
dependencies.CacheAs(API ??= new APIAccess(LocalConfig));
EndpointConfiguration endpoints = UseDevelopmentServer ? (EndpointConfiguration)new DevelopmentEndpointConfiguration() : new ProductionEndpointConfiguration();
dependencies.CacheAs(spectatorStreaming = new SpectatorStreamingClient());
dependencies.CacheAs(multiplayerClient = new RealtimeMultiplayerClient());
dependencies.CacheAs(API ??= new APIAccess(LocalConfig, endpoints));
dependencies.CacheAs(spectatorStreaming = new SpectatorStreamingClient(endpoints));
dependencies.CacheAs(multiplayerClient = new RealtimeMultiplayerClient(endpoints));
var defaultBeatmap = new DummyWorkingBeatmap(Audio, Textures);
@ -369,7 +375,9 @@ namespace osu.Game
// may be non-null for certain tests
Storage ??= host.Storage;
LocalConfig ??= new OsuConfigManager(Storage);
LocalConfig ??= UseDevelopmentServer
? new DevelopmentOsuConfigManager(Storage)
: new OsuConfigManager(Storage);
}
protected override Storage CreateStorage(GameHost host, Storage defaultStorage) => new OsuStorage(host, defaultStorage);

View File

@ -15,6 +15,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osu.Game.Online.API;
using osu.Game.Overlays.BeatmapListing.Panels;
using osu.Game.Overlays.BeatmapSet.Buttons;
using osu.Game.Rulesets;
@ -40,6 +41,9 @@ namespace osu.Game.Overlays.BeatmapSet
public bool DownloadButtonsVisible => downloadButtonsContainer.Any();
[Resolved]
private IAPIProvider api { get; set; }
public BeatmapRulesetSelector RulesetSelector => beatmapSetHeader.RulesetSelector;
public readonly BeatmapPicker Picker;
@ -213,7 +217,7 @@ namespace osu.Game.Overlays.BeatmapSet
Picker.Beatmap.ValueChanged += b =>
{
Details.Beatmap = b.NewValue;
externalLink.Link = $@"https://osu.ppy.sh/beatmapsets/{BeatmapSet.Value?.OnlineBeatmapSetID}#{b.NewValue?.Ruleset.ShortName}/{b.NewValue?.OnlineBeatmapID}";
externalLink.Link = $@"{api.WebsiteRootUrl}/beatmapsets/{BeatmapSet.Value?.OnlineBeatmapSetID}#{b.NewValue?.Ruleset.ShortName}/{b.NewValue?.OnlineBeatmapID}";
};
}

View File

@ -131,33 +131,36 @@ namespace osu.Game.Overlays.Changelog
t.Padding = new MarginPadding { Left = 10 };
});
if (entry.GithubUser.UserId != null)
if (entry.GithubUser != null)
{
title.AddUserLink(new User
if (entry.GithubUser.UserId != null)
{
Username = entry.GithubUser.OsuUsername,
Id = entry.GithubUser.UserId.Value
}, t =>
title.AddUserLink(new User
{
Username = entry.GithubUser.OsuUsername,
Id = entry.GithubUser.UserId.Value
}, t =>
{
t.Font = fontMedium;
t.Colour = entryColour;
});
}
else if (entry.GithubUser.GithubUrl != null)
{
t.Font = fontMedium;
t.Colour = entryColour;
});
}
else if (entry.GithubUser.GithubUrl != null)
{
title.AddLink(entry.GithubUser.DisplayName, entry.GithubUser.GithubUrl, t =>
title.AddLink(entry.GithubUser.DisplayName, entry.GithubUser.GithubUrl, t =>
{
t.Font = fontMedium;
t.Colour = entryColour;
});
}
else
{
t.Font = fontMedium;
t.Colour = entryColour;
});
}
else
{
title.AddText(entry.GithubUser.DisplayName, t =>
{
t.Font = fontMedium;
t.Colour = entryColour;
});
title.AddText(entry.GithubUser.DisplayName, t =>
{
t.Font = fontMedium;
t.Colour = entryColour;
});
}
}
ChangelogEntries.Add(titleContainer);

View File

@ -12,6 +12,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Users;
using osuTK;
using osuTK.Graphics;
@ -27,6 +28,9 @@ namespace osu.Game.Overlays.Profile.Header
private Color4 iconColour;
[Resolved]
private IAPIProvider api { get; set; }
public BottomHeaderContainer()
{
AutoSizeAxes = Axes.Y;
@ -109,7 +113,7 @@ namespace osu.Game.Overlays.Profile.Header
}
topLinkContainer.AddText("Contributed ");
topLinkContainer.AddLink($@"{user.PostCount:#,##0} forum posts", $"https://osu.ppy.sh/users/{user.Id}/posts", creationParameters: embolden);
topLinkContainer.AddLink($@"{user.PostCount:#,##0} forum posts", $"{api.WebsiteRootUrl}/users/{user.Id}/posts", creationParameters: embolden);
string websiteWithoutProtocol = user.Website;

View File

@ -10,6 +10,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Overlays.Profile.Header.Components;
using osu.Game.Users;
using osu.Game.Users.Drawables;
@ -23,6 +24,9 @@ namespace osu.Game.Overlays.Profile.Header
public readonly Bindable<User> User = new Bindable<User>();
[Resolved]
private IAPIProvider api { get; set; }
private SupporterIcon supporterTag;
private UpdateableAvatar avatar;
private OsuSpriteText usernameText;
@ -166,7 +170,7 @@ namespace osu.Game.Overlays.Profile.Header
{
avatar.User = user;
usernameText.Text = user?.Username ?? string.Empty;
openUserExternally.Link = $@"https://osu.ppy.sh/users/{user?.Id ?? 0}";
openUserExternally.Link = $@"{api.WebsiteRootUrl}/users/{user?.Id ?? 0}";
userFlag.Country = user?.Country;
userCountryText.Text = user?.Country?.FullName ?? "Alien";
supporterTag.SupportLevel = user?.SupportLevel ?? 0;

View File

@ -216,7 +216,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
private void addBeatmapsetLink()
=> content.AddLink(activity.Beatmapset?.Title, LinkAction.OpenBeatmapSet, getLinkArgument(activity.Beatmapset?.Url), creationParameters: t => t.Font = getLinkFont());
private string getLinkArgument(string url) => MessageFormatter.GetLinkDetails($"{api.Endpoint}{url}").Argument;
private string getLinkArgument(string url) => MessageFormatter.GetLinkDetails($"{api.APIEndpointUrl}{url}").Argument;
private FontUsage getLinkFont(FontWeight fontWeight = FontWeight.Regular)
=> OsuFont.GetFont(size: font_size, weight: fontWeight, italics: true);