diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index b1298ebeb..be04a7891 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -620,12 +620,15 @@ namespace Barotrauma.Networking if (!newPermissions.HasFlag(permission) || permission == ClientPermissions.None) continue; System.Reflection.FieldInfo fi = typeof(ClientPermissions).GetField(permission.ToString()); DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); - msg += " - " + attributes[0].Description+"\n"; + msg += " - " + attributes[0].Description + "\n"; } } permissions = newPermissions; new GUIMessageBox("Permissions changed", msg).UserData = "permissions"; + GameMain.NetLobbyScreen.SubList.Enabled = Voting.AllowSubVoting || HasPermission(ClientPermissions.SelectSub); + GameMain.NetLobbyScreen.ModeList.Enabled = Voting.AllowModeVoting || HasPermission(ClientPermissions.SelectMode); + endRoundButton.Visible = HasPermission(ClientPermissions.EndRound); } @@ -1326,6 +1329,51 @@ namespace Barotrauma.Networking client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); } + /// + /// Tell the server to select a submarine (permission required) + /// + public void RequestSelectSub(int subIndex) + { + if (!HasPermission(ClientPermissions.SelectSub)) return; + if (subIndex < 0 || subIndex >= GameMain.NetLobbyScreen.SubList.CountChildren) + { + DebugConsole.ThrowError("Submarine index out of bounds (" + subIndex + ")\n" + Environment.StackTrace); + return; + } + + NetOutgoingMessage msg = client.CreateMessage(); + msg.Write((byte)ClientPacketHeader.SERVER_COMMAND); + msg.Write((byte)ClientPermissions.SelectSub); + msg.Write((UInt16)subIndex); + msg.Write((byte)ServerNetObject.END_OF_MESSAGE); + + client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); + } + + /// + /// Tell the server to select a submarine (permission required) + /// + public void RequestSelectMode(int modeIndex) + { + if (!HasPermission(ClientPermissions.SelectMode)) return; + if (modeIndex < 0 || modeIndex >= GameMain.NetLobbyScreen.ModeList.CountChildren) + { + DebugConsole.ThrowError("Gamemode index out of bounds (" + modeIndex + ")\n" + Environment.StackTrace); + return; + } + + NetOutgoingMessage msg = client.CreateMessage(); + msg.Write((byte)ClientPacketHeader.SERVER_COMMAND); + msg.Write((byte)ClientPermissions.SelectMode); + msg.Write((UInt16)modeIndex); + msg.Write((byte)ServerNetObject.END_OF_MESSAGE); + + client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); + } + + /// + /// Tell the server to end the round (permission required) + /// public void RequestRoundEnd() { NetOutgoingMessage msg = client.CreateMessage(); diff --git a/Barotrauma/BarotraumaClient/Source/Networking/Voting.cs b/Barotrauma/BarotraumaClient/Source/Networking/Voting.cs index a8070cdec..807e77cfa 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/Voting.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/Voting.cs @@ -14,7 +14,8 @@ namespace Barotrauma { if (value == allowSubVoting) return; allowSubVoting = value; - GameMain.NetLobbyScreen.SubList.Enabled = value || GameMain.Server != null; + GameMain.NetLobbyScreen.SubList.Enabled = value || GameMain.Server != null || + (GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectSub)); GameMain.NetLobbyScreen.InfoFrame.FindChild("subvotes", true).Visible = value; if (GameMain.Server != null) @@ -36,7 +37,10 @@ namespace Barotrauma { if (value == allowModeVoting) return; allowModeVoting = value; - GameMain.NetLobbyScreen.ModeList.Enabled = value || GameMain.Server != null; + GameMain.NetLobbyScreen.ModeList.Enabled = + value || GameMain.Server != null || + (GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectMode)); + GameMain.NetLobbyScreen.InfoFrame.FindChild("modevotes", true).Visible = value; //gray out modes that can't be voted diff --git a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs index ccef467e4..75b8afefa 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs @@ -112,6 +112,7 @@ namespace Barotrauma public Submarine SelectedSub { get { return subList.SelectedData as Submarine; } + set { subList.Select(value); } } public Submarine SelectedShuttle @@ -384,10 +385,14 @@ namespace Barotrauma Character.Controlled = null; //GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; - subList.Enabled = GameMain.Server != null || GameMain.NetworkMember.Voting.AllowSubVoting; + subList.Enabled = GameMain.Server != null || GameMain.NetworkMember.Voting.AllowSubVoting || + (GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectSub)); shuttleList.Enabled = subList.Enabled; - //playerList.Enabled = GameMain.Server != null; - modeList.Enabled = GameMain.Server != null || GameMain.NetworkMember.Voting.AllowModeVoting; + + modeList.Enabled = + GameMain.Server != null || GameMain.NetworkMember.Voting.AllowModeVoting || + (GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectMode)); + seedBox.Enabled = GameMain.Server != null; serverMessage.Enabled = GameMain.Server != null; autoRestartBox.Enabled = GameMain.Server != null; @@ -549,7 +554,6 @@ namespace Barotrauma jobList = new GUIListBox(new Rectangle(0, 150, 0, 0), "", myPlayerFrame); jobList.Enabled = false; - int i = 1; foreach (string jobName in GameMain.Config.JobNamePreferences) { @@ -757,13 +761,29 @@ namespace Barotrauma VoteType voteType; if (component.Parent == GameMain.NetLobbyScreen.SubList) { - if (!GameMain.Client.Voting.AllowSubVoting) return false; + if (!GameMain.Client.Voting.AllowSubVoting) + { + if (GameMain.Client.HasPermission(ClientPermissions.SelectSub)) + { + GameMain.Client.RequestSelectSub(component.Parent.children.IndexOf(component)); + return true; + } + return false; + } voteType = VoteType.Sub; } else if (component.Parent == GameMain.NetLobbyScreen.ModeList) { - if (!GameMain.Client.Voting.AllowModeVoting) return false; if (!((GameModePreset)userData).Votable) return false; + if (!GameMain.Client.Voting.AllowModeVoting) + { + if (GameMain.Client.HasPermission(ClientPermissions.SelectMode)) + { + GameMain.Client.RequestSelectMode(component.Parent.children.IndexOf(component)); + return true; + } + return false; + } voteType = VoteType.Mode; } @@ -843,7 +863,7 @@ namespace Barotrauma new GUITextBlock(new Rectangle(0, 25, 150, 15), selectedClient.Connection.RemoteEndPoint.Address.ToString(), "", playerFrameInner); - var permissionsBox = new GUIFrame(new Rectangle(0, 60, 0, 90), "", playerFrameInner); + var permissionsBox = new GUIFrame(new Rectangle(0, 60, 0, 90), null, playerFrameInner); permissionsBox.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); permissionsBox.UserData = selectedClient; @@ -858,7 +878,7 @@ namespace Barotrauma string permissionStr = attributes.Length > 0 ? attributes[0].Description : permission.ToString(); - var permissionTick = new GUITickBox(new Rectangle(x, y + 20, 15, 15), permissionStr, Alignment.TopLeft, GUI.SmallFont, permissionsBox); + var permissionTick = new GUITickBox(new Rectangle(x, y + 25, 15, 15), permissionStr, Alignment.TopLeft, GUI.SmallFont, permissionsBox); permissionTick.UserData = permission; permissionTick.Selected = selectedClient.HasPermission(permission); diff --git a/Barotrauma/BarotraumaShared/Source/Networking/Client.cs b/Barotrauma/BarotraumaShared/Source/Networking/Client.cs index 5bf7d3cf4..6be80e69f 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/Client.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/Client.cs @@ -16,8 +16,12 @@ namespace Barotrauma.Networking Kick = 2, [Description("Ban")] Ban = 4, + [Description("Select submarine")] + SelectSub = 8, + [Description("Select game mode")] + SelectMode = 16, [Description("Manage campaign")] - ManageCampaign = 8 + ManageCampaign = 32 } class Client diff --git a/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs b/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs index 1a9e07eec..f09e2632e 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs @@ -770,6 +770,22 @@ namespace Barotrauma.Networking EndGame(); } break; + case ClientPermissions.SelectSub: + UInt16 subIndex = inc.ReadUInt16(); + var subList = GameMain.NetLobbyScreen.GetSubList(); + if (subIndex >= subList.Count) + { + DebugConsole.NewMessage("Client \"" + sender.name + "\" attempted to select a sub, index out of bounds (" + subIndex + ")", Color.Red); + } + else + { + GameMain.NetLobbyScreen.SelectedSub = subList[subIndex]; + } + break; + case ClientPermissions.SelectMode: + UInt16 modeIndex = inc.ReadUInt16(); + var modeList = GameMain.NetLobbyScreen.SelectedModeIndex = modeIndex; + break; case ClientPermissions.ManageCampaign: MultiplayerCampaign campaign = GameMain.GameSession.GameMode as MultiplayerCampaign; if (campaign != null)