1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:02:55 +08:00

Handle cases when player cannot be invited.

This commit is contained in:
Marvin Schürz 2023-10-03 22:08:14 +02:00
parent a171fa7649
commit 267d1ee7d4
4 changed files with 80 additions and 4 deletions

View File

@ -104,7 +104,8 @@ namespace osu.Game.Online.Multiplayer
/// Invites a player to the current room.
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
/// <exception cref="UserBlockedException">The user has blocked or has been blocked by the invited user.</exception>
/// <exception cref="UserBlocksPMsException">The invited user does not accept private messages.</exception>
Task InvitePlayer(int userId);
}
}

View File

@ -12,6 +12,7 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Online.API;
using osu.Game.Online.Rooms;
using osu.Game.Overlays.Notifications;
namespace osu.Game.Online.Multiplayer
{
@ -107,14 +108,36 @@ namespace osu.Game.Online.Multiplayer
return connection.InvokeAsync(nameof(IMultiplayerServer.LeaveRoom));
}
public override Task InvitePlayer(int userId)
public override async Task InvitePlayer(int userId)
{
if (!IsConnected.Value)
return Task.CompletedTask;
return;
Debug.Assert(connection != null);
return connection.InvokeAsync(nameof(IMultiplayerServer.InvitePlayer), userId);
try
{
await connection.InvokeAsync(nameof(IMultiplayerServer.InvitePlayer), userId).ConfigureAwait(false);
}
catch (HubException exception)
{
switch (exception.GetHubExceptionMessage())
{
case UserBlockedException.MESSAGE:
PostNotification?.Invoke(new SimpleErrorNotification
{
Text = "User cannot be invited by someone they have blocked or are blocked by."
});
break;
case UserBlocksPMsException.MESSAGE:
PostNotification?.Invoke(new SimpleErrorNotification
{
Text = "User cannot be invited because they cannot receive private messages from people not on their friends list."
});
break;
}
}
}
public override Task TransferHost(int userId)

View File

@ -0,0 +1,26 @@
// 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 System;
using System.Runtime.Serialization;
using Microsoft.AspNetCore.SignalR;
namespace osu.Game.Online.Multiplayer
{
[Serializable]
public class UserBlockedException : HubException
{
public const string MESSAGE = "User cannot be invited by someone they have blocked or are blocked by.";
public UserBlockedException()
:
base(MESSAGE)
{
}
protected UserBlockedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}

View File

@ -0,0 +1,26 @@
// 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 System;
using System.Runtime.Serialization;
using Microsoft.AspNetCore.SignalR;
namespace osu.Game.Online.Multiplayer
{
[Serializable]
public class UserBlocksPMsException : HubException
{
public const string MESSAGE = "User cannot be invited because they have disabled private messages.";
public UserBlocksPMsException()
:
base(MESSAGE)
{
}
protected UserBlocksPMsException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}