mirror of https://github.com/ppy/osu
Move all endpoint information to a configuration class
This commit is contained in:
parent
e89583d732
commit
eb795a2127
|
@ -13,6 +13,7 @@
|
|||
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 @@ public class TestMultiplayerStreaming : SpectatorStreamingClient
|
|||
private readonly int totalUsers;
|
||||
|
||||
public TestMultiplayerStreaming(int totalUsers)
|
||||
: base(new DevelopmentEndpointConfiguration())
|
||||
{
|
||||
this.totalUsers = totalUsers;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
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 @@ public class TestSpectatorStreamingClient : SpectatorStreamingClient
|
|||
|
||||
private int beatmapId;
|
||||
|
||||
public TestSpectatorStreamingClient()
|
||||
: base(new DevelopmentEndpointConfiguration())
|
||||
{
|
||||
}
|
||||
|
||||
protected override Task Connect()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,18 +26,10 @@ public class APIAccess : Component, IAPIProvider
|
|||
|
||||
private readonly OAuth authentication;
|
||||
|
||||
#if DEBUG
|
||||
public string Endpoint => @"https://dev.ppy.sh";
|
||||
private const string client_secret = @"3LP2mhUrV89xxzD1YKNndXHEhWWCRLPNKioZ9ymT";
|
||||
#else
|
||||
public string Endpoint => @"https://osu.ppy.sh";
|
||||
private const string client_secret = @"FGc9GAtyHzeQDshWP5Ah7dega8hJACAJpQtw6OXk";
|
||||
#endif
|
||||
|
||||
private const string client_id = @"5";
|
||||
|
||||
private readonly Queue<APIRequest> queue = new Queue<APIRequest>();
|
||||
|
||||
public string Endpoint { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The username/email provided by the user when initiating a login.
|
||||
/// </summary>
|
||||
|
@ -61,11 +53,13 @@ public class APIAccess : Component, IAPIProvider
|
|||
|
||||
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);
|
||||
Endpoint = endpointConfiguration.APIEndpoint;
|
||||
|
||||
authentication = new OAuth(endpointConfiguration.APIClientID, endpointConfiguration.APIClientSecret, Endpoint);
|
||||
log = Logger.GetLogger(LoggingTarget.Network);
|
||||
|
||||
ProvidedUsername = config.Get<string>(OsuSetting.Username);
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
APIEndpoint = @"https://dev.ppy.sh";
|
||||
APIClientSecret = @"3LP2mhUrV89xxzD1YKNndXHEhWWCRLPNKioZ9ymT";
|
||||
APIClientID = "5";
|
||||
SpectatorEndpoint = $"{APIEndpoint}/spectator";
|
||||
MultiplayerEndpoint = $"{APIEndpoint}/multiplayer";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
// 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 endpoint for the main (osu-web) API.
|
||||
/// </summary>
|
||||
public string APIEndpoint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The OAuth client secret.
|
||||
/// </summary>
|
||||
public string APIClientSecret { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The OAuth client ID.
|
||||
/// </summary>
|
||||
public string APIClientID { get; set; }
|
||||
|
||||
public string SpectatorEndpoint { get; set; }
|
||||
|
||||
public string MultiplayerEndpoint { get; set; }
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
{
|
||||
APIEndpoint = @"https://osu.ppy.sh";
|
||||
APIClientSecret = @"FGc9GAtyHzeQDshWP5Ah7dega8hJACAJpQtw6OXk";
|
||||
APIClientID = "5";
|
||||
SpectatorEndpoint = "https://spectator.ppy.sh/spectator";
|
||||
MultiplayerEndpoint = "https://spectator.ppy.sh/multiplayer";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,12 +19,6 @@ namespace osu.Game.Online.RealtimeMultiplayer
|
|||
{
|
||||
public class RealtimeMultiplayerClient : StatefulMultiplayerClient
|
||||
{
|
||||
#if DEBUG
|
||||
private const string endpoint = "https://dev.ppy.sh/multiplayer";
|
||||
#else
|
||||
private const string endpoint = "https://spectator.ppy.sh/multiplayer";
|
||||
#endif
|
||||
|
||||
public override IBindable<bool> IsConnected => isConnected;
|
||||
|
||||
private readonly Bindable<bool> isConnected = new Bindable<bool>();
|
||||
|
@ -35,6 +29,13 @@ public class RealtimeMultiplayerClient : StatefulMultiplayerClient
|
|||
|
||||
private HubConnection? connection;
|
||||
|
||||
private readonly string endpoint;
|
||||
|
||||
public RealtimeMultiplayerClient(EndpointConfiguration endpoints)
|
||||
{
|
||||
endpoint = endpoints.MultiplayerEndpoint;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
|
|
|
@ -81,6 +81,13 @@ public class SpectatorStreamingClient : Component, ISpectatorClient
|
|||
/// </summary>
|
||||
public event Action<int, SpectatorState> OnUserFinishedPlaying;
|
||||
|
||||
private readonly string endpoint;
|
||||
|
||||
public SpectatorStreamingClient(EndpointConfiguration endpoints)
|
||||
{
|
||||
endpoint = endpoints.SpectatorEndpoint;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
|
@ -104,12 +111,6 @@ private void apiStateChanged(ValueChangedEvent<APIState> state)
|
|||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
private const string endpoint = "https://dev.ppy.sh/spectator";
|
||||
#else
|
||||
private const string endpoint = "https://spectator.ppy.sh/spectator";
|
||||
#endif
|
||||
|
||||
protected virtual async Task Connect()
|
||||
{
|
||||
if (connection != null)
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
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 @@ public class OsuGameBase : Framework.Game, ICanAcceptFiles
|
|||
|
||||
public const int SAMPLE_CONCURRENCY = 6;
|
||||
|
||||
public bool UseDevelopmentServer { get; }
|
||||
|
||||
protected OsuConfigManager LocalConfig;
|
||||
|
||||
protected BeatmapManager BeatmapManager;
|
||||
|
@ -132,6 +135,7 @@ public virtual string Version
|
|||
|
||||
public OsuGameBase()
|
||||
{
|
||||
UseDevelopmentServer = DebugUtils.IsDebugBuild;
|
||||
Name = @"osu!lazer";
|
||||
}
|
||||
|
||||
|
@ -170,7 +174,7 @@ private void load()
|
|||
dependencies.Cache(largeStore);
|
||||
|
||||
dependencies.CacheAs(this);
|
||||
dependencies.Cache(LocalConfig);
|
||||
dependencies.CacheAs(LocalConfig);
|
||||
|
||||
AddFont(Resources, @"Fonts/osuFont");
|
||||
|
||||
|
@ -210,10 +214,12 @@ private void load()
|
|||
}
|
||||
});
|
||||
|
||||
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 @@ public override void SetHost(GameHost host)
|
|||
// 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);
|
||||
|
|
Loading…
Reference in New Issue