1 | using System.Collections.Generic;
|
---|
2 | using System.Text.RegularExpressions;
|
---|
3 | using JetBrains.Annotations;
|
---|
4 | using Platform.EOS;
|
---|
5 | using Platform.Steam;
|
---|
6 | using Webserver.Permissions;
|
---|
7 |
|
---|
8 | namespace Webserver.Commands {
|
---|
9 | [UsedImplicitly]
|
---|
10 | public class CreateWebUser : ConsoleCmdAbstract {
|
---|
11 | private static readonly Regex validNameTokenMatcher = new Regex (@"^\w+$");
|
---|
12 |
|
---|
13 | protected override string[] getCommands () {
|
---|
14 | return new[] {"createwebusermanual"};
|
---|
15 | }
|
---|
16 |
|
---|
17 | protected override string getDescription () {
|
---|
18 | return "Create a web dashboard user account - manual for testing";
|
---|
19 | }
|
---|
20 |
|
---|
21 | protected override string getHelp () {
|
---|
22 | return ""; // TODO
|
---|
23 | }
|
---|
24 |
|
---|
25 | public override bool IsExecuteOnClient => true;
|
---|
26 |
|
---|
27 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
|
---|
28 | // if (GameManager.IsDedicatedServer) {
|
---|
29 | // SdtdConsole.Instance.Output ("Command can only be executed on game clients or listen servers.");
|
---|
30 | // return;
|
---|
31 | // }
|
---|
32 |
|
---|
33 | // TODO
|
---|
34 |
|
---|
35 | if (_params.Count < 2) {
|
---|
36 | SdtdConsole.Instance.Output ($"Wrong number of arguments");
|
---|
37 | return;
|
---|
38 | }
|
---|
39 |
|
---|
40 | string name = _params [0];
|
---|
41 | string pass = _params [1];
|
---|
42 |
|
---|
43 | if (string.IsNullOrEmpty (name)) {
|
---|
44 | SdtdConsole.Instance.Output ("Argument 'name' is empty.");
|
---|
45 | return;
|
---|
46 | }
|
---|
47 |
|
---|
48 | if (!validNameTokenMatcher.IsMatch (name)) {
|
---|
49 | SdtdConsole.Instance.Output (
|
---|
50 | "Argument 'name' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_).");
|
---|
51 | return;
|
---|
52 | }
|
---|
53 |
|
---|
54 | if (string.IsNullOrEmpty (pass)) {
|
---|
55 | SdtdConsole.Instance.Output ("Argument 'password' is empty.");
|
---|
56 | return;
|
---|
57 | }
|
---|
58 |
|
---|
59 | if (!validNameTokenMatcher.IsMatch (pass)) {
|
---|
60 | SdtdConsole.Instance.Output (
|
---|
61 | "Argument 'password' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_).");
|
---|
62 | return;
|
---|
63 | }
|
---|
64 |
|
---|
65 | AdminWebUsers.Instance.AddUser (name, pass, new UserIdentifierSteam (76561198066968172ul),
|
---|
66 | new UserIdentifierEos ("0002bc29a5624774b4b0dc27e60b974f"));
|
---|
67 |
|
---|
68 | SdtdConsole.Instance.Output ($"User added");
|
---|
69 | }
|
---|
70 |
|
---|
71 | }
|
---|
72 | }
|
---|