mirror of
https://github.com/ppy/osu
synced 2025-02-24 14:47:09 +00:00
Merge pull request #14225 from peppy/multiplayer-kick-support-events
Add event flow for kick handling
This commit is contained in:
commit
78ac092147
@ -31,6 +31,15 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// <param name="user">The user.</param>
|
||||
Task UserLeft(MultiplayerRoomUser user);
|
||||
|
||||
/// <summary>
|
||||
/// Signals that a user has been kicked from the room.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This will also be sent to the user that was kicked.
|
||||
/// </remarks>
|
||||
/// <param name="user">The user.</param>
|
||||
Task UserKicked(MultiplayerRoomUser user);
|
||||
|
||||
/// <summary>
|
||||
/// Signal that the host of the room has changed.
|
||||
/// </summary>
|
||||
|
@ -190,6 +190,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
return joinOrLeaveTaskChain.Add(async () =>
|
||||
{
|
||||
await scheduledReset.ConfigureAwait(false);
|
||||
if (Room != null)
|
||||
await LeaveRoomInternal().ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
@ -389,6 +390,18 @@ namespace osu.Game.Online.Multiplayer
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
Task IMultiplayerClient.UserKicked(MultiplayerRoomUser user)
|
||||
{
|
||||
if (LocalUser == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
if (user.Equals(LocalUser))
|
||||
LeaveRoom();
|
||||
|
||||
// TODO: also inform users of the kick operation.
|
||||
return ((IMultiplayerClient)this).UserLeft(user);
|
||||
}
|
||||
|
||||
Task IMultiplayerClient.HostChanged(int userId)
|
||||
{
|
||||
if (Room == null)
|
||||
|
@ -50,6 +50,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
connection.On<MultiplayerRoomState>(nameof(IMultiplayerClient.RoomStateChanged), ((IMultiplayerClient)this).RoomStateChanged);
|
||||
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserJoined), ((IMultiplayerClient)this).UserJoined);
|
||||
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserLeft), ((IMultiplayerClient)this).UserLeft);
|
||||
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserKicked), ((IMultiplayerClient)this).UserKicked);
|
||||
connection.On<int>(nameof(IMultiplayerClient.HostChanged), ((IMultiplayerClient)this).HostChanged);
|
||||
connection.On<MultiplayerRoomSettings>(nameof(IMultiplayerClient.SettingsChanged), ((IMultiplayerClient)this).SettingsChanged);
|
||||
connection.On<int, MultiplayerUserState>(nameof(IMultiplayerClient.UserStateChanged), ((IMultiplayerClient)this).UserStateChanged);
|
||||
|
@ -274,7 +274,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
isConnected.BindValueChanged(connected =>
|
||||
{
|
||||
if (!connected.NewValue)
|
||||
Schedule(this.Exit);
|
||||
handleRoomLost();
|
||||
}, true);
|
||||
|
||||
currentRoom.BindValueChanged(room =>
|
||||
@ -284,7 +284,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
// the room has gone away.
|
||||
// this could mean something happened during the join process, or an external connection issue occurred.
|
||||
// one specific scenario is where the underlying room is created, but the signalr server returns an error during the join process. this triggers a PartRoom operation (see https://github.com/ppy/osu/blob/7654df94f6f37b8382be7dfcb4f674e03bd35427/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomManager.cs#L97)
|
||||
Schedule(this.Exit);
|
||||
handleRoomLost();
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
@ -448,9 +448,24 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
|
||||
private void onRoomUpdated()
|
||||
{
|
||||
// may happen if the client is kicked or otherwise removed from the room.
|
||||
if (client.Room == null)
|
||||
{
|
||||
handleRoomLost();
|
||||
return;
|
||||
}
|
||||
|
||||
Scheduler.AddOnce(UpdateMods);
|
||||
}
|
||||
|
||||
private void handleRoomLost() => Schedule(() =>
|
||||
{
|
||||
if (this.IsCurrentScreen())
|
||||
this.Exit();
|
||||
else
|
||||
ValidForResume = false;
|
||||
});
|
||||
|
||||
private void onLoadRequested()
|
||||
{
|
||||
if (BeatmapAvailability.Value.State != DownloadState.LocallyAvailable)
|
||||
|
@ -178,7 +178,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
|
||||
return ((IMultiplayerClient)this).UserLeft(Room.Users.Single(u => u.UserID == userId));
|
||||
return ((IMultiplayerClient)this).UserKicked(Room.Users.Single(u => u.UserID == userId));
|
||||
}
|
||||
|
||||
public override async Task ChangeSettings(MultiplayerRoomSettings settings)
|
||||
|
Loading…
Reference in New Issue
Block a user