diff --git a/Subsurface/Source/Networking/Client.cs b/Subsurface/Source/Networking/Client.cs index 5d3e6ee96..dd4173bb5 100644 --- a/Subsurface/Source/Networking/Client.cs +++ b/Subsurface/Source/Networking/Client.cs @@ -119,12 +119,12 @@ namespace Barotrauma.Networking public void GivePermission(ClientPermissions permission) { - this.Permissions |= permission; + if (!this.Permissions.HasFlag(permission)) this.Permissions |= permission; } public void RemovePermission(ClientPermissions permission) { - this.Permissions &= ~permission; + if (this.Permissions.HasFlag(permission)) this.Permissions &= ~permission; } public bool HasPermission(ClientPermissions permission) diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index 9ea9ac820..bc2617c79 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -613,7 +613,7 @@ namespace Barotrauma.Networking msg = "Your current permissions:\n"; foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) { - if (!HasPermission(permissions) || permission == ClientPermissions.None) continue; + 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); @@ -622,6 +622,7 @@ namespace Barotrauma.Networking } } + permissions = newPermissions; new GUIMessageBox("Permissions changed", msg).UserData = "permissions"; } diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index b0f91015c..fbc55c8f8 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -9,6 +9,8 @@ using FarseerPhysics.Dynamics; using System.IO; using System.Linq; using System.Collections.Generic; +using System.Reflection; +using System.ComponentModel; namespace Barotrauma { @@ -772,12 +774,12 @@ namespace Barotrauma } } - playerFrame = new GUIFrame(new Rectangle(0, 0, 0, 0), Color.Black * 0.3f); + playerFrame = new GUIFrame(new Rectangle(0, 0, 0, 0), Color.Black * 0.6f); - var playerFrameInner = new GUIFrame(new Rectangle(0, 0, 300, 250), null, Alignment.Center, GUI.Style, playerFrame); + var playerFrameInner = new GUIFrame(new Rectangle(0, 0, 300, 280), null, Alignment.Center, GUI.Style, playerFrame); playerFrameInner.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f); - new GUITextBlock(new Rectangle(0,0,200,20), component.UserData.ToString(), + new GUITextBlock(new Rectangle(0, 0, 200, 20), component.UserData.ToString(), GUI.Style, Alignment.TopLeft, Alignment.TopLeft, playerFrameInner, false, GUI.LargeFont); @@ -787,50 +789,50 @@ namespace Barotrauma new GUITextBlock(new Rectangle(0, 25, 150, 15), selectedClient.Connection.RemoteEndPoint.Address.ToString(), GUI.Style, playerFrameInner); - //var permissionsBox = new GUIFrame(new Rectangle(0, 60, 0, 85), GUI.Style, playerFrameInner); - //permissionsBox.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); - //permissionsBox.UserData = selectedClient; + var permissionsBox = new GUIFrame(new Rectangle(0, 60, 0, 90), GUI.Style, playerFrameInner); + permissionsBox.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); + permissionsBox.UserData = selectedClient; - //new GUITextBlock(new Rectangle(0, 0, 0, 15), "Permissions:", GUI.Style, permissionsBox); - //int x = 0, y = 0; - //foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) - //{ - // if (permission == ClientPermissions.None) continue; + new GUITextBlock(new Rectangle(0, 0, 0, 15), "Permissions:", GUI.Style, permissionsBox); + int x = 0, y = 0; + foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) + { + if (permission == ClientPermissions.None) continue; - // FieldInfo fi = typeof(ClientPermissions).GetField(permission.ToString()); - // DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); + FieldInfo fi = typeof(ClientPermissions).GetField(permission.ToString()); + DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); - // 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); - // permissionTick.UserData = permission; - // permissionTick.Selected = selectedClient.HasPermission(permission); + string permissionStr = attributes.Length > 0 ? attributes[0].Description : permission.ToString(); - // permissionTick.OnSelected = (tickBox) => - // { - // var client = tickBox.Parent.UserData as Client; - // if (client == null) return false; + var permissionTick = new GUITickBox(new Rectangle(x, y + 20, 15, 15), permissionStr, Alignment.TopLeft, GUI.SmallFont, permissionsBox); + permissionTick.UserData = permission; + permissionTick.Selected = selectedClient.HasPermission(permission); - // var thisPermission = (ClientPermissions)tickBox.UserData; + permissionTick.OnSelected = (tickBox) => + { + var client = tickBox.Parent.UserData as Client; + if (client == null) return false; - // if (tickBox.Selected) - // client.GivePermission(thisPermission); - // else - // client.RemovePermission(thisPermission); + var thisPermission = (ClientPermissions)tickBox.UserData; - // GameMain.Server.UpdateClientPermissions(client); + if (tickBox.Selected) + client.GivePermission(thisPermission); + else + client.RemovePermission(thisPermission); - // return true; - // }; + GameMain.Server.UpdateClientPermissions(client); + + return true; + }; - // y += 20; - // if (y >= permissionsBox.Rect.Height -20) - // { - // y = 0; - // x += 100; - // } - //} + y += 20; + if (y >= permissionsBox.Rect.Height-40) + { + y = 0; + x += 100; + } + } } if (GameMain.Server != null || GameMain.Client.HasPermission(ClientPermissions.Kick))