1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 16:52:55 +08:00

Add method for checking room joinability

This commit is contained in:
Salman Ahmed 2020-12-22 16:36:17 +03:00
parent 5c3df55cdf
commit 91d5c53643
6 changed files with 17 additions and 0 deletions

View File

@ -24,6 +24,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => Rooms.Add(room);
public bool CanJoinRoom(Room room) => true;
public void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
{
}

View File

@ -146,6 +146,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
onSuccess?.Invoke(room);
}
public bool CanJoinRoom(Room room) => true;
public void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => throw new NotImplementedException();
public void PartRoom() => throw new NotImplementedException();

View File

@ -161,6 +161,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
onSuccess?.Invoke(room);
}
public bool CanJoinRoom(Room room) => true;
public void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => onSuccess?.Invoke(room);
public void PartRoom()

View File

@ -82,6 +82,8 @@ namespace osu.Game.Screens.Multi.Components
api.Queue(req);
}
public virtual bool CanJoinRoom(Room room) => true;
private JoinRoomRequest currentJoinRoomRequest;
public virtual void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)

View File

@ -34,6 +34,12 @@ namespace osu.Game.Screens.Multi
/// <param name="onError">An action to be invoked if an error occurred.</param>
void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null);
/// <summary>
/// Whether the provided <paramref name="room"/> can be joined.
/// </summary>
/// <param name="room">The <see cref="Room"/> to check for.</param>
bool CanJoinRoom(Room room);
/// <summary>
/// Joins a <see cref="Room"/>.
/// </summary>

View File

@ -9,6 +9,7 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Logging;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Multiplayer.RoomStatuses;
using osu.Game.Online.RealtimeMultiplayer;
using osu.Game.Screens.Multi.Components;
@ -40,6 +41,8 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
public override void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
=> base.CreateRoom(room, r => joinMultiplayerRoom(r, onSuccess, onError), onError);
public override bool CanJoinRoom(Room room) => !(room.Status.Value is RoomStatusEnded);
public override void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
=> base.JoinRoom(room, r => joinMultiplayerRoom(r, onSuccess, onError), onError);