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

Last change on this file since 296 was 244, checked in by alloc, 9 years ago

Fixes intermediate state

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