Changeset 325 for binary-improvements/MapRendering/Commands/WebTokens.cs
- Timestamp:
- Sep 4, 2018, 1:00:48 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Commands/WebTokens.cs
r244 r325 1 using System;2 1 using System.Collections.Generic; 3 using System.IO;4 2 using System.Text.RegularExpressions; 3 using AllocsFixes.NetConnections.Servers.Web; 5 4 6 using AllocsFixes.NetConnections.Servers.Web; 7 using UnityEngine; 8 9 namespace AllocsFixes.CustomCommands 10 { 5 namespace AllocsFixes.CustomCommands { 11 6 public class WebTokens : ConsoleCmdAbstract { 12 private static Regex validNameTokenMatcher = new Regex (@"^\w+$");7 private static readonly Regex validNameTokenMatcher = new Regex (@"^\w+$"); 13 8 14 9 public override string[] GetCommands () { 15 return new string[] { "webtokens"};10 return new[] {"webtokens"}; 16 11 } 17 18 public override string GetDescription () { 12 13 public override string GetDescription () { 19 14 return "Manage web tokens"; 20 15 } … … 22 17 public override string GetHelp () { 23 18 return "Set/get webtoken permission levels. A level of 0 is maximum permission.\n" + 24 25 26 27 19 "Usage:\n" + 20 " webtokens add <username> <usertoken> <level>\n" + 21 " webtokens remove <username>\n" + 22 " webtokens list"; 28 23 } 29 24 30 25 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) { 31 26 if (_params.Count >= 1) { … … 61 56 62 57 if (!validNameTokenMatcher.IsMatch (_params [1])) { 63 SdtdConsole.Instance.Output ("Argument 'username' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_)."); 58 SdtdConsole.Instance.Output ( 59 "Argument 'username' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_)."); 64 60 return; 65 61 } … … 71 67 72 68 if (!validNameTokenMatcher.IsMatch (_params [2])) { 73 SdtdConsole.Instance.Output ("Argument 'usertoken' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_)."); 69 SdtdConsole.Instance.Output ( 70 "Argument 'usertoken' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_)."); 74 71 return; 75 72 } … … 82 79 83 80 WebPermissions.Instance.AddAdmin (_params [1], _params [2], level); 84 SdtdConsole.Instance.Output (string.Format ("Web user with name={0} and password={1} added with permission level of {2}.", _params [1], _params [2], level)); 81 SdtdConsole.Instance.Output (string.Format ( 82 "Web user with name={0} and password={1} added with permission level of {2}.", _params [1], _params [2], 83 level)); 85 84 } 86 85 87 86 private void ExecuteRemove (List<string> _params) { 88 87 if (_params.Count != 2) { … … 90 89 return; 91 90 } 92 91 93 92 if (string.IsNullOrEmpty (_params [1])) { 94 93 SdtdConsole.Instance.Output ("Argument 'username' is empty."); … … 97 96 98 97 if (!validNameTokenMatcher.IsMatch (_params [1])) { 99 SdtdConsole.Instance.Output ("Argument 'username' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_)."); 98 SdtdConsole.Instance.Output ( 99 "Argument 'username' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_)."); 100 100 return; 101 101 } … … 104 104 SdtdConsole.Instance.Output (string.Format ("{0} removed from web user permissions list.", _params [1])); 105 105 } 106 106 107 107 private void ExecuteList () { 108 108 SdtdConsole.Instance.Output ("Defined webuser permissions:"); 109 109 SdtdConsole.Instance.Output (" Level: Name / Token"); 110 110 foreach (WebPermissions.AdminToken at in WebPermissions.Instance.GetAdmins ()) { 111 SdtdConsole.Instance.Output (string.Format (" {0,5}: {1} / {2}", at.permissionLevel, at.name, at.token)); 111 SdtdConsole.Instance.Output ( 112 string.Format (" {0,5}: {1} / {2}", at.permissionLevel, at.name, at.token)); 112 113 } 113 114 } 114 115 115 } 116 116 }
Note:
See TracChangeset
for help on using the changeset viewer.