From a68fd85ab0b33ad33d15d60ac4737b0deee5f8c9 Mon Sep 17 00:00:00 2001 From: Juan Pablo Arce Date: Fri, 15 Dec 2017 11:21:37 -0300 Subject: [PATCH 1/2] Improved giveperm/revokeperm commands --- .../BarotraumaShared/Source/DebugConsole.cs | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs index 12e257202..8eebab697 100644 --- a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs @@ -369,10 +369,14 @@ namespace Barotrauma } })); - commands.Add(new Command("giveperm", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", (string[] args) => + commands.Add(new Command("giveperm|giveperms", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", (string[] args) => { if (GameMain.Server == null) return; - if (args.Length < 1) return; + if (args.Length < 1) + { + NewMessage("giveperm [id]: Grants administrative permissions to the player with the specified client ID.", Color.Cyan); + return; + } int id; int.TryParse(args[0], out id); @@ -382,7 +386,13 @@ namespace Barotrauma ThrowError("Client id \"" + id + "\" not found."); return; } - + + NewMessage("Valid permissions are:",Color.White); + NewMessage(" - all",Color.White); + foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) + { + NewMessage(" - " + permission.ToString(),Color.White); + } ShowQuestionPrompt("Permission to grant to \"" + client.Name + "\"?", (perm) => { ClientPermissions permission = ClientPermissions.None; @@ -392,7 +402,11 @@ namespace Barotrauma } else { - Enum.TryParse(perm, out permission); + if (!Enum.TryParse(perm, out permission)) + { + ThrowError("\"" + perm + "\" sn't a valid permission!"); + return; + } } client.SetPermissions(client.Permissions | permission); GameMain.Server.UpdateClientPermissions(client); @@ -400,10 +414,14 @@ namespace Barotrauma }); })); - commands.Add(new Command("revokeperm", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", (string[] args) => + commands.Add(new Command("revokeperm|revokeperms", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", (string[] args) => { if (GameMain.Server == null) return; - if (args.Length < 1) return; + if (args.Length < 1) + { + NewMessage("revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", Color.Cyan); + return; + } int id; int.TryParse(args[0], out id); @@ -414,6 +432,12 @@ namespace Barotrauma return; } + NewMessage("Valid permissions are:", Color.White); + NewMessage(" - all", Color.White); + foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) + { + NewMessage(" - " + permission.ToString(), Color.White); + } ShowQuestionPrompt("Permission to revoke from \"" + client.Name + "\"?", (perm) => { ClientPermissions permission = ClientPermissions.None; @@ -423,7 +447,11 @@ namespace Barotrauma } else { - Enum.TryParse(perm, out permission); + if (!Enum.TryParse(perm, out permission)) + { + ThrowError("\"" + perm + "\" isn't a valid permission!"); + return; + } } client.SetPermissions(client.Permissions & ~permission); GameMain.Server.UpdateClientPermissions(client); From ae344c89c595c965ad7c0402350df286722f4103 Mon Sep 17 00:00:00 2001 From: Juan Pablo Arce Date: Fri, 15 Dec 2017 11:25:21 -0300 Subject: [PATCH 2/2] Fixed indentation --- .../BarotraumaShared/Source/DebugConsole.cs | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs index 8eebab697..a403ff2ce 100644 --- a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs @@ -369,14 +369,14 @@ namespace Barotrauma } })); - commands.Add(new Command("giveperm|giveperms", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", (string[] args) => + commands.Add(new Command("giveperm", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", (string[] args) => { if (GameMain.Server == null) return; - if (args.Length < 1) - { - NewMessage("giveperm [id]: Grants administrative permissions to the player with the specified client ID.", Color.Cyan); - return; - } + if (args.Length < 1) + { + NewMessage("giveperm [id]: Grants administrative permissions to the player with the specified client ID.", Color.Cyan); + return; + } int id; int.TryParse(args[0], out id); @@ -387,12 +387,12 @@ namespace Barotrauma return; } - NewMessage("Valid permissions are:",Color.White); - NewMessage(" - all",Color.White); - foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) - { - NewMessage(" - " + permission.ToString(),Color.White); - } + NewMessage("Valid permissions are:",Color.White); + NewMessage(" - all",Color.White); + foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) + { + NewMessage(" - " + permission.ToString(),Color.White); + } ShowQuestionPrompt("Permission to grant to \"" + client.Name + "\"?", (perm) => { ClientPermissions permission = ClientPermissions.None; @@ -402,11 +402,11 @@ namespace Barotrauma } else { - if (!Enum.TryParse(perm, out permission)) - { - ThrowError("\"" + perm + "\" sn't a valid permission!"); - return; - } + if (!Enum.TryParse(perm, out permission)) + { + ThrowError("\"" + perm + "\" sn't a valid permission!"); + return; + } } client.SetPermissions(client.Permissions | permission); GameMain.Server.UpdateClientPermissions(client); @@ -414,14 +414,14 @@ namespace Barotrauma }); })); - commands.Add(new Command("revokeperm|revokeperms", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", (string[] args) => + commands.Add(new Command("revokeperm", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", (string[] args) => { if (GameMain.Server == null) return; if (args.Length < 1) - { - NewMessage("revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", Color.Cyan); - return; - } + { + NewMessage("revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", Color.Cyan); + return; + } int id; int.TryParse(args[0], out id); @@ -432,12 +432,12 @@ namespace Barotrauma return; } - NewMessage("Valid permissions are:", Color.White); - NewMessage(" - all", Color.White); - foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) - { - NewMessage(" - " + permission.ToString(), Color.White); - } + NewMessage("Valid permissions are:", Color.White); + NewMessage(" - all", Color.White); + foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) + { + NewMessage(" - " + permission.ToString(), Color.White); + } ShowQuestionPrompt("Permission to revoke from \"" + client.Name + "\"?", (perm) => { ClientPermissions permission = ClientPermissions.None; @@ -447,11 +447,11 @@ namespace Barotrauma } else { - if (!Enum.TryParse(perm, out permission)) - { - ThrowError("\"" + perm + "\" isn't a valid permission!"); - return; - } + if (!Enum.TryParse(perm, out permission)) + { + ThrowError("\"" + perm + "\" isn't a valid permission!"); + return; + } } client.SetPermissions(client.Permissions & ~permission); GameMain.Server.UpdateClientPermissions(client);