Re-enabled client permission settings in NetLobbyScreen, fixed clients not setting their permissions when receiving PacketTypes.Permissions

This commit is contained in:
Regalis
2016-11-21 17:46:03 +02:00
parent 4cef011131
commit c3b84ca835
3 changed files with 43 additions and 40 deletions
+2 -2
View File
@@ -119,12 +119,12 @@ namespace Barotrauma.Networking
public void GivePermission(ClientPermissions permission) public void GivePermission(ClientPermissions permission)
{ {
this.Permissions |= permission; if (!this.Permissions.HasFlag(permission)) this.Permissions |= permission;
} }
public void RemovePermission(ClientPermissions permission) public void RemovePermission(ClientPermissions permission)
{ {
this.Permissions &= ~permission; if (this.Permissions.HasFlag(permission)) this.Permissions &= ~permission;
} }
public bool HasPermission(ClientPermissions permission) public bool HasPermission(ClientPermissions permission)
+2 -1
View File
@@ -613,7 +613,7 @@ namespace Barotrauma.Networking
msg = "Your current permissions:\n"; msg = "Your current permissions:\n";
foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) 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()); System.Reflection.FieldInfo fi = typeof(ClientPermissions).GetField(permission.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
@@ -622,6 +622,7 @@ namespace Barotrauma.Networking
} }
} }
permissions = newPermissions;
new GUIMessageBox("Permissions changed", msg).UserData = "permissions"; new GUIMessageBox("Permissions changed", msg).UserData = "permissions";
} }
+38 -36
View File
@@ -9,6 +9,8 @@ using FarseerPhysics.Dynamics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection;
using System.ComponentModel;
namespace Barotrauma 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); 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, GUI.Style, Alignment.TopLeft, Alignment.TopLeft,
playerFrameInner, false, GUI.LargeFont); 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); 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); 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.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
//permissionsBox.UserData = selectedClient; permissionsBox.UserData = selectedClient;
//new GUITextBlock(new Rectangle(0, 0, 0, 15), "Permissions:", GUI.Style, permissionsBox); new GUITextBlock(new Rectangle(0, 0, 0, 15), "Permissions:", GUI.Style, permissionsBox);
//int x = 0, y = 0; int x = 0, y = 0;
//foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions)))
//{ {
// if (permission == ClientPermissions.None) continue; if (permission == ClientPermissions.None) continue;
// FieldInfo fi = typeof(ClientPermissions).GetField(permission.ToString()); FieldInfo fi = typeof(ClientPermissions).GetField(permission.ToString());
// DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
// string permissionStr = attributes.Length > 0 ? attributes[0].Description : permission.ToString(); 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 + 20, 15, 15), permissionStr, Alignment.TopLeft, GUI.SmallFont, permissionsBox);
// permissionTick.UserData = permission; permissionTick.UserData = permission;
// permissionTick.Selected = selectedClient.HasPermission(permission); permissionTick.Selected = selectedClient.HasPermission(permission);
// permissionTick.OnSelected = (tickBox) => permissionTick.OnSelected = (tickBox) =>
// { {
// var client = tickBox.Parent.UserData as Client; var client = tickBox.Parent.UserData as Client;
// if (client == null) return false; if (client == null) return false;
// var thisPermission = (ClientPermissions)tickBox.UserData; var thisPermission = (ClientPermissions)tickBox.UserData;
// if (tickBox.Selected) if (tickBox.Selected)
// client.GivePermission(thisPermission); client.GivePermission(thisPermission);
// else else
// client.RemovePermission(thisPermission); client.RemovePermission(thisPermission);
// GameMain.Server.UpdateClientPermissions(client); GameMain.Server.UpdateClientPermissions(client);
// return true; return true;
// }; };
// y += 20; y += 20;
// if (y >= permissionsBox.Rect.Height -20) if (y >= permissionsBox.Rect.Height-40)
// { {
// y = 0; y = 0;
// x += 100; x += 100;
// } }
//} }
} }
if (GameMain.Server != null || GameMain.Client.HasPermission(ClientPermissions.Kick)) if (GameMain.Server != null || GameMain.Client.HasPermission(ClientPermissions.Kick))