From bd1cd15dd412e9061a946be9d917ba070a11560d Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 10 Jan 2018 20:43:31 +0200 Subject: [PATCH] Added votekick button to the server lobby. Closes #190 --- .../Source/Networking/GameClient.cs | 2 +- .../Source/Screens/NetLobbyScreen.cs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index c2f90ed0f..fbb360aea 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -1380,7 +1380,7 @@ namespace Barotrauma.Networking public bool VoteForKick(GUIButton button, object userdata) { - var votedClient = otherClients.Find(c => c.Character == userdata); + var votedClient = userdata is Client ? (Client)userdata : otherClients.Find(c => c.Character == userdata); if (votedClient == null) return false; votedClient.AddKickVote(new Client(name, ID)); diff --git a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs index d5d435384..585482600 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs @@ -874,11 +874,14 @@ namespace Barotrauma if (GameMain.Client != null) { if (!GameMain.Client.HasPermission(ClientPermissions.Ban) && - !GameMain.Client.HasPermission(ClientPermissions.Kick)) + !GameMain.Client.HasPermission(ClientPermissions.Kick) && + !GameMain.Client.Voting.AllowVoteKick) { return false; } } + + var selectedClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.Name == obj.ToString()); playerFrame = new GUIFrame(new Rectangle(0, 0, 0, 0), Color.Black * 0.6f); @@ -891,7 +894,6 @@ namespace Barotrauma if (GameMain.Server != null) { - var selectedClient = GameMain.Server.ConnectedClients.Find(c => c.Name == obj.ToString()); playerFrame.UserData = selectedClient; new GUITextBlock(new Rectangle(0, 25, 150, 15), selectedClient.Connection.RemoteEndPoint.Address.ToString(), "", playerFrameInner); @@ -1025,6 +1027,14 @@ namespace Barotrauma rangebanButton.OnClicked += BanPlayerRange; rangebanButton.OnClicked += ClosePlayerFrame; } + + if (GameMain.Client != null && GameMain.Client.Voting.AllowVoteKick && selectedClient != null) + { + var kickVoteButton = new GUIButton(new Rectangle(0, -30, 120, 20), "Vote to Kick", Alignment.BottomLeft, "", playerFrameInner); + kickVoteButton.Enabled = !selectedClient.HasKickVoteFromID(GameMain.Client.ID); + kickVoteButton.UserData = selectedClient; + kickVoteButton.OnClicked += GameMain.Client.VoteForKick; + } var closeButton = new GUIButton(new Rectangle(0, 0, 100, 20), TextManager.Get("Close"), Alignment.BottomRight, "", playerFrameInner); closeButton.OnClicked = ClosePlayerFrame;