mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 22:56:36 +09:00
Merge pull request #14224 from peppy/multiplayer-kick-support
Add kick button (and required server shared interface updates)
This commit is contained in:
@ -155,6 +155,42 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
AddUntilStep("second user crown visible", () => this.ChildrenOfType<ParticipantPanel>().ElementAt(1).ChildrenOfType<SpriteIcon>().First().Alpha == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestKickButtonOnlyPresentWhenHost()
|
||||
{
|
||||
AddStep("add user", () => Client.AddUser(new User
|
||||
{
|
||||
Id = 3,
|
||||
Username = "Second",
|
||||
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
|
||||
}));
|
||||
|
||||
AddUntilStep("kick buttons visible", () => this.ChildrenOfType<ParticipantPanel.KickButton>().Count(d => d.IsPresent) == 1);
|
||||
|
||||
AddStep("make second user host", () => Client.TransferHost(3));
|
||||
|
||||
AddUntilStep("kick buttons not visible", () => this.ChildrenOfType<ParticipantPanel.KickButton>().Count(d => d.IsPresent) == 0);
|
||||
|
||||
AddStep("make local user host again", () => Client.TransferHost(API.LocalUser.Value.Id));
|
||||
|
||||
AddUntilStep("kick buttons visible", () => this.ChildrenOfType<ParticipantPanel.KickButton>().Count(d => d.IsPresent) == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestKickButtonKicks()
|
||||
{
|
||||
AddStep("add user", () => Client.AddUser(new User
|
||||
{
|
||||
Id = 3,
|
||||
Username = "Second",
|
||||
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
|
||||
}));
|
||||
|
||||
AddStep("kick second user", () => this.ChildrenOfType<ParticipantPanel.KickButton>().Single(d => d.IsPresent).TriggerClick());
|
||||
|
||||
AddAssert("second user kicked", () => Client.Room?.Users.Single().UserID == API.LocalUser.Value.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestManyUsers()
|
||||
{
|
||||
|
@ -27,6 +27,14 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// <exception cref="NotJoinedRoomException">If the user is not in a room.</exception>
|
||||
Task TransferHost(int userId);
|
||||
|
||||
/// <summary>
|
||||
/// As the host, kick another user from the room.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user to kick..</param>
|
||||
/// <exception cref="NotHostException">A user other than the current host is attempting to kick a user.</exception>
|
||||
/// <exception cref="NotJoinedRoomException">If the user is not in a room.</exception>
|
||||
Task KickUser(int userId);
|
||||
|
||||
/// <summary>
|
||||
/// As the host, update the settings of the currently joined room.
|
||||
/// </summary>
|
||||
|
@ -293,6 +293,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
public abstract Task TransferHost(int userId);
|
||||
|
||||
public abstract Task KickUser(int userId);
|
||||
|
||||
public abstract Task ChangeSettings(MultiplayerRoomSettings settings);
|
||||
|
||||
public abstract Task ChangeState(MultiplayerUserState newState);
|
||||
|
@ -91,6 +91,14 @@ namespace osu.Game.Online.Multiplayer
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.TransferHost), userId);
|
||||
}
|
||||
|
||||
public override Task KickUser(int userId)
|
||||
{
|
||||
if (!IsConnected.Value)
|
||||
return Task.CompletedTask;
|
||||
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.KickUser), userId);
|
||||
}
|
||||
|
||||
public override Task ChangeSettings(MultiplayerRoomSettings settings)
|
||||
{
|
||||
if (!IsConnected.Value)
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
@ -42,6 +43,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
private ModDisplay userModsDisplay;
|
||||
private StateDisplay userStateDisplay;
|
||||
|
||||
private IconButton kickButton;
|
||||
|
||||
public ParticipantPanel(MultiplayerRoomUser user)
|
||||
{
|
||||
User = user;
|
||||
@ -64,7 +67,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
{
|
||||
new Dimension(GridSizeMode.Absolute, 18),
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
new Dimension()
|
||||
new Dimension(),
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
},
|
||||
Content = new[]
|
||||
{
|
||||
@ -157,7 +161,20 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
Margin = new MarginPadding { Right = 10 },
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
kickButton = new KickButton
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Alpha = 0,
|
||||
Margin = new MarginPadding(4),
|
||||
Action = () =>
|
||||
{
|
||||
Debug.Assert(user != null);
|
||||
|
||||
Client.KickUser(user.Id);
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
@ -167,7 +184,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
{
|
||||
base.OnRoomUpdated();
|
||||
|
||||
if (Room == null)
|
||||
if (Room == null || Client.LocalUser == null)
|
||||
return;
|
||||
|
||||
const double fade_time = 50;
|
||||
@ -179,6 +196,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
|
||||
userStateDisplay.UpdateStatus(User.State, User.BeatmapAvailability);
|
||||
|
||||
if (Client.IsHost && !User.Equals(Client.LocalUser))
|
||||
kickButton.FadeIn(fade_time);
|
||||
else
|
||||
kickButton.FadeOut(fade_time);
|
||||
|
||||
if (Room.Host?.Equals(User) == true)
|
||||
crown.FadeIn(fade_time);
|
||||
else
|
||||
@ -211,13 +233,36 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
new OsuMenuItem("Give host", MenuItemType.Standard, () =>
|
||||
{
|
||||
// Ensure the local user is still host.
|
||||
if (Room.Host?.UserID != api.LocalUser.Value.Id)
|
||||
if (!Client.IsHost)
|
||||
return;
|
||||
|
||||
Client.TransferHost(targetUser);
|
||||
}),
|
||||
new OsuMenuItem("Kick", MenuItemType.Destructive, () =>
|
||||
{
|
||||
// Ensure the local user is still host.
|
||||
if (!Client.IsHost)
|
||||
return;
|
||||
|
||||
Client.KickUser(targetUser);
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class KickButton : IconButton
|
||||
{
|
||||
public KickButton()
|
||||
{
|
||||
Icon = FontAwesome.Solid.UserTimes;
|
||||
TooltipText = "Kick";
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
IconHoverColour = colours.Red;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -174,6 +174,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
public override Task TransferHost(int userId) => ((IMultiplayerClient)this).HostChanged(userId);
|
||||
|
||||
public override Task KickUser(int userId)
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
|
||||
return ((IMultiplayerClient)this).UserLeft(Room.Users.Single(u => u.UserID == userId));
|
||||
}
|
||||
|
||||
public override async Task ChangeSettings(MultiplayerRoomSettings settings)
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
|
Reference in New Issue
Block a user