From 91d5c53643a7489066a23b36e6865d67c621ddf2 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Tue, 22 Dec 2020 16:36:17 +0300 Subject: [PATCH] Add method for checking room joinability --- osu.Game.Tests/Visual/Multiplayer/TestRoomManager.cs | 2 ++ .../Visual/Multiplayer/TestSceneMatchSettingsOverlay.cs | 2 ++ .../Visual/Multiplayer/TestSceneTimeshiftRoomSubScreen.cs | 2 ++ osu.Game/Screens/Multi/Components/RoomManager.cs | 2 ++ osu.Game/Screens/Multi/IRoomManager.cs | 6 ++++++ .../Multi/RealtimeMultiplayer/RealtimeRoomManager.cs | 3 +++ 6 files changed, 17 insertions(+) diff --git a/osu.Game.Tests/Visual/Multiplayer/TestRoomManager.cs b/osu.Game.Tests/Visual/Multiplayer/TestRoomManager.cs index 9dd4aea4bd..ea8fb4ef49 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestRoomManager.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestRoomManager.cs @@ -24,6 +24,8 @@ namespace osu.Game.Tests.Visual.Multiplayer public void CreateRoom(Room room, Action onSuccess = null, Action onError = null) => Rooms.Add(room); + public bool CanJoinRoom(Room room) => true; + public void JoinRoom(Room room, Action onSuccess = null, Action onError = null) { } diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchSettingsOverlay.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchSettingsOverlay.cs index 1fcae9c709..55dbd1a7c6 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchSettingsOverlay.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchSettingsOverlay.cs @@ -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 onSuccess = null, Action onError = null) => throw new NotImplementedException(); public void PartRoom() => throw new NotImplementedException(); diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneTimeshiftRoomSubScreen.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneTimeshiftRoomSubScreen.cs index bbd7d84081..8fdb5d4093 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneTimeshiftRoomSubScreen.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneTimeshiftRoomSubScreen.cs @@ -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 onSuccess = null, Action onError = null) => onSuccess?.Invoke(room); public void PartRoom() diff --git a/osu.Game/Screens/Multi/Components/RoomManager.cs b/osu.Game/Screens/Multi/Components/RoomManager.cs index f78d0d979e..3fcfe1df25 100644 --- a/osu.Game/Screens/Multi/Components/RoomManager.cs +++ b/osu.Game/Screens/Multi/Components/RoomManager.cs @@ -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 onSuccess = null, Action onError = null) diff --git a/osu.Game/Screens/Multi/IRoomManager.cs b/osu.Game/Screens/Multi/IRoomManager.cs index 630e3af91c..a1cff129a9 100644 --- a/osu.Game/Screens/Multi/IRoomManager.cs +++ b/osu.Game/Screens/Multi/IRoomManager.cs @@ -34,6 +34,12 @@ namespace osu.Game.Screens.Multi /// An action to be invoked if an error occurred. void CreateRoom(Room room, Action onSuccess = null, Action onError = null); + /// + /// Whether the provided can be joined. + /// + /// The to check for. + bool CanJoinRoom(Room room); + /// /// Joins a . /// diff --git a/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimeRoomManager.cs b/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimeRoomManager.cs index 7ce031e0e9..d8dc5f127a 100644 --- a/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimeRoomManager.cs +++ b/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimeRoomManager.cs @@ -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 onSuccess = null, Action 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 onSuccess = null, Action onError = null) => base.JoinRoom(room, r => joinMultiplayerRoom(r, onSuccess, onError), onError);