source: binary-improvements/MapRendering/Commands/WebPermissionsCmd.cs@ 439

Last change on this file since 439 was 420, checked in by alloc, 20 months ago

A21 preparations.
NOT COMPATIBLE WITH A20 ANYMORE!

File size: 2.8 KB
RevLine 
[244]1using System.Collections.Generic;
2using AllocsFixes.NetConnections.Servers.Web;
3
[325]4namespace AllocsFixes.CustomCommands {
[244]5 public class WebPermissionsCmd : ConsoleCmdAbstract {
[420]6 protected override string[] getCommands () {
7 return new[] {"webpermission_legacy"};
[244]8 }
[325]9
[420]10 protected override string getDescription () {
[244]11 return "Manage web permission levels";
12 }
[325]13
[420]14 protected override string getHelp () {
[244]15 return "Set/get permission levels required to access a given web functionality. Default\n" +
[325]16 "level required for functions that are not explicitly specified is 0.\n" +
17 "Usage:\n" +
[420]18 " webpermission_legacy add <webfunction> <level>\n" +
19 " webpermission_legacy remove <webfunction>\n" +
20 " webpermission_legacy list";
[244]21 }
[325]22
[244]23 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
24 if (_params.Count >= 1) {
[326]25 if (_params [0].EqualsCaseInsensitive ("add")) {
26 ExecuteAdd (_params);
27 } else if (_params [0].EqualsCaseInsensitive ("remove")) {
28 ExecuteRemove (_params);
29 } else if (_params [0].EqualsCaseInsensitive ("list")) {
30 ExecuteList ();
31 } else {
[372]32 SdtdConsole.Instance.Output ($"Invalid sub command \"{_params [0]}\".");
[244]33 }
34 } else {
35 SdtdConsole.Instance.Output ("No sub command given.");
36 }
37 }
[325]38
[244]39 private void ExecuteAdd (List<string> _params) {
40 if (_params.Count != 3) {
[372]41 SdtdConsole.Instance.Output ($"Wrong number of arguments, expected 3, found {_params.Count}.");
[244]42 return;
43 }
[325]44
[244]45 if (!WebPermissions.Instance.IsKnownModule (_params [1])) {
[372]46 SdtdConsole.Instance.Output ($"\"{_params [1]}\" is not a valid web function.");
[244]47 return;
48 }
[325]49
[244]50 int level;
51 if (!int.TryParse (_params [2], out level)) {
[372]52 SdtdConsole.Instance.Output ($"\"{_params [2]}\" is not a valid integer.");
[244]53 return;
54 }
[325]55
[244]56 WebPermissions.Instance.AddModulePermission (_params [1], level);
[372]57 SdtdConsole.Instance.Output ($"{_params [1]} added with permission level of {level}.");
[244]58 }
[325]59
[244]60 private void ExecuteRemove (List<string> _params) {
61 if (_params.Count != 2) {
[372]62 SdtdConsole.Instance.Output ($"Wrong number of arguments, expected 2, found {_params.Count}.");
[244]63 return;
64 }
[325]65
[244]66 if (!WebPermissions.Instance.IsKnownModule (_params [1])) {
[372]67 SdtdConsole.Instance.Output ($"\"{_params [1]}\" is not a valid web function.");
[244]68 return;
69 }
[325]70
[244]71 WebPermissions.Instance.RemoveModulePermission (_params [1]);
[372]72 SdtdConsole.Instance.Output ($"{_params [1]} removed from permissions list.");
[244]73 }
[325]74
[244]75 private void ExecuteList () {
76 SdtdConsole.Instance.Output ("Defined web function permissions:");
77 SdtdConsole.Instance.Output (" Level: Web function");
78 foreach (WebPermissions.WebModulePermission wmp in WebPermissions.Instance.GetModules ()) {
[372]79 SdtdConsole.Instance.Output ($" {wmp.permissionLevel,5}: {wmp.module}");
[244]80 }
81 }
82 }
83}
Note: See TracBrowser for help on using the repository browser.