From ccd496b769c86a00004b721c5650a7d508430df7 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 26 Mar 2019 14:06:40 +0200 Subject: [PATCH] (99836db69) Fixed clients being unable to end campaign rounds at all if the sub isn't at the start/end outpost (regardless if they have the permission to end the round or not), added a verification prompt when trying to end the round when the sub isn't at either outpost. --- .../Source/Networking/GameClient.cs | 88 ++++++++++++++++++- .../Source/Networking/GameServer.cs | 2 +- 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index 9d1365ce6..fb9abb67a 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -141,8 +141,23 @@ namespace Barotrauma.Networking { OnClicked = (btn, userdata) => { - if (!permissions.HasFlag(ClientPermissions.ManageRound)) return false; - RequestRoundEnd(); + if (!permissions.HasFlag(ClientPermissions.ManageRound)) { return false; } + if (!Submarine.MainSub.AtStartPosition && !Submarine.MainSub.AtEndPosition) + { + var msgBox = new GUIMessageBox("", TextManager.Get("EndRoundSubNotAtLevelEnd"), + new string[] { TextManager.Get("Yes"), TextManager.Get("No") }); + msgBox.Buttons[0].OnClicked = (_, __) => + { + GameMain.Client.RequestRoundEnd(); + return true; + }; + msgBox.Buttons[0].OnClicked += msgBox.Close; + msgBox.Buttons[1].OnClicked += msgBox.Close; + } + else + { + RequestRoundEnd(); + } return true; }, Visible = false @@ -1267,6 +1282,75 @@ namespace Barotrauma.Networking } } + private void ReadLobbyUpdate(NetIncomingMessage inc) + { + UInt16 listId = inc.ReadUInt16(); + List tempClients = new List(); + int clientCount = inc.ReadByte(); + for (int i = 0; i < clientCount; i++) + { + byte id = inc.ReadByte(); + string name = inc.ReadString(); + UInt16 characterID = inc.ReadUInt16(); + bool muted = inc.ReadBoolean(); + inc.ReadPadBits(); + + tempClients.Add(new TempClient + { + ID = id, + Name = name, + CharacterID = characterID, + Muted = muted + }); + } + + if (NetIdUtils.IdMoreRecent(listId, LastClientListUpdateID)) + { + bool updateClientListId = true; + List currentClients = new List(); + foreach (TempClient tc in tempClients) + { + //see if the client already exists + var existingClient = ConnectedClients.Find(c => c.ID == tc.ID && c.Name == tc.Name); + if (existingClient == null) //if not, create it + { + existingClient = new Client(tc.Name, tc.ID) + { + Muted = tc.Muted + }; + ConnectedClients.Add(existingClient); + GameMain.NetLobbyScreen.AddPlayer(existingClient); + } + existingClient.Character = null; + existingClient.Muted = tc.Muted; + if (tc.CharacterID > 0) + { + existingClient.Character = Entity.FindEntityByID(tc.CharacterID) as Character; + if (existingClient.Character == null) + { + updateClientListId = false; + } + } + if (existingClient.ID == myID) + { + existingClient.SetPermissions(permissions, permittedConsoleCommands); + } + currentClients.Add(existingClient); + } + //remove clients that aren't present anymore + for (int i = ConnectedClients.Count - 1; i >= 0; i--) + { + if (!currentClients.Contains(ConnectedClients[i])) + { + GameMain.NetLobbyScreen.RemovePlayer(ConnectedClients[i]); + ConnectedClients[i].Dispose(); + ConnectedClients.RemoveAt(i); + } + } + if (updateClientListId) LastClientListUpdateID = listId; + } + } + private void ReadLobbyUpdate(NetIncomingMessage inc) { ServerNetObject objHeader; diff --git a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs index e9d5f2991..202c87097 100644 --- a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs @@ -1039,7 +1039,7 @@ namespace Barotrauma.Networking if (command == ClientPermissions.ManageRound && inc.PeekBoolean() && GameMain.GameSession?.GameMode is MultiPlayerCampaign mpCampaign) { - if (!mpCampaign.AllowedToEndRound(sender.Character)) + if (!mpCampaign.AllowedToEndRound(sender.Character) && !sender.HasPermission(command)) { return; }