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

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

A21 preparations.
NOT COMPATIBLE WITH A20 ANYMORE!

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