mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 10:17:19 +08: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>
|
/// <param name="user">The user.</param>
|
||||||
Task UserLeft(MultiplayerRoomUser user);
|
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>
|
/// <summary>
|
||||||
/// Signal that the host of the room has changed.
|
/// Signal that the host of the room has changed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -190,7 +190,8 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
return joinOrLeaveTaskChain.Add(async () =>
|
return joinOrLeaveTaskChain.Add(async () =>
|
||||||
{
|
{
|
||||||
await scheduledReset.ConfigureAwait(false);
|
await scheduledReset.ConfigureAwait(false);
|
||||||
await LeaveRoomInternal().ConfigureAwait(false);
|
if (Room != null)
|
||||||
|
await LeaveRoomInternal().ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,6 +390,18 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
return Task.CompletedTask;
|
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)
|
Task IMultiplayerClient.HostChanged(int userId)
|
||||||
{
|
{
|
||||||
if (Room == null)
|
if (Room == null)
|
||||||
|
@ -50,6 +50,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
connection.On<MultiplayerRoomState>(nameof(IMultiplayerClient.RoomStateChanged), ((IMultiplayerClient)this).RoomStateChanged);
|
connection.On<MultiplayerRoomState>(nameof(IMultiplayerClient.RoomStateChanged), ((IMultiplayerClient)this).RoomStateChanged);
|
||||||
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserJoined), ((IMultiplayerClient)this).UserJoined);
|
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserJoined), ((IMultiplayerClient)this).UserJoined);
|
||||||
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserLeft), ((IMultiplayerClient)this).UserLeft);
|
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<int>(nameof(IMultiplayerClient.HostChanged), ((IMultiplayerClient)this).HostChanged);
|
||||||
connection.On<MultiplayerRoomSettings>(nameof(IMultiplayerClient.SettingsChanged), ((IMultiplayerClient)this).SettingsChanged);
|
connection.On<MultiplayerRoomSettings>(nameof(IMultiplayerClient.SettingsChanged), ((IMultiplayerClient)this).SettingsChanged);
|
||||||
connection.On<int, MultiplayerUserState>(nameof(IMultiplayerClient.UserStateChanged), ((IMultiplayerClient)this).UserStateChanged);
|
connection.On<int, MultiplayerUserState>(nameof(IMultiplayerClient.UserStateChanged), ((IMultiplayerClient)this).UserStateChanged);
|
||||||
|
@ -274,7 +274,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
isConnected.BindValueChanged(connected =>
|
isConnected.BindValueChanged(connected =>
|
||||||
{
|
{
|
||||||
if (!connected.NewValue)
|
if (!connected.NewValue)
|
||||||
Schedule(this.Exit);
|
handleRoomLost();
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
currentRoom.BindValueChanged(room =>
|
currentRoom.BindValueChanged(room =>
|
||||||
@ -284,7 +284,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
// the room has gone away.
|
// the room has gone away.
|
||||||
// this could mean something happened during the join process, or an external connection issue occurred.
|
// 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)
|
// 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);
|
}, true);
|
||||||
}
|
}
|
||||||
@ -448,9 +448,24 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
|
|
||||||
private void onRoomUpdated()
|
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);
|
Scheduler.AddOnce(UpdateMods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleRoomLost() => Schedule(() =>
|
||||||
|
{
|
||||||
|
if (this.IsCurrentScreen())
|
||||||
|
this.Exit();
|
||||||
|
else
|
||||||
|
ValidForResume = false;
|
||||||
|
});
|
||||||
|
|
||||||
private void onLoadRequested()
|
private void onLoadRequested()
|
||||||
{
|
{
|
||||||
if (BeatmapAvailability.Value.State != DownloadState.LocallyAvailable)
|
if (BeatmapAvailability.Value.State != DownloadState.LocallyAvailable)
|
||||||
|
@ -178,7 +178,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
Debug.Assert(Room != null);
|
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)
|
public override async Task ChangeSettings(MultiplayerRoomSettings settings)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user