Esempio n. 1
0
 public override void Run(string[] args, PipeConsole console)
 {
     if (args.Length == 1)
     {
         console.WriteLine("usage: {0} <command> [<args>]\r\n", Root.AppName);
         var i = Root.CmdMgr.GetEnumerator();
         while (i.MoveNext())
         {
             var cmd = i.Current;
             console.WriteLine("    {0,-16} {1}", cmd.Name, cmd.Info);
         }
     }
     else
     {
         var cmdName = args[1];
         var cmd     = Root.CmdMgr.GetCommand(cmdName);
         if (cmd == null)
         {
             console.WriteLine("{0}: unknown command: '{1}'", Root.AppName, cmdName);
             return;
         }
         console.WriteLine("{0}: {1}", cmd.Name, cmd.Info);
         cmd.PrintUsage(console);
     }
 }
Esempio n. 2
0
            public override void Run(string[] args, PipeConsole console)
            {
                // user.mod login -p pass // =4
                // user.mod login -p pass -a access // =6
                if (args.Length != 4 && args.Length != 6)
                {
                    PrintUsage(console);
                    return;
                }
                var users = Root.Server.Users;
                var login = args[1];
                var user  = users.Find(login);

                if (user == null)
                {
                    console.WriteLine("user not found");
                    return;
                }
                for (int i = 2; i + 1 < args.Length; i += 2)
                {
                    if (!ApplyUserOption(user, args[i], args[i + 1]))
                    {
                        PrintUsage(console);
                        break;
                    }
                }
            }
Esempio n. 3
0
 public override void Run(string[] args, PipeConsole console)
 {
     if (!Root.Server.Connected)
     {
         console.WriteLine("already disconnected");
     }
     Root.Server.Disconnect();
 }
Esempio n. 4
0
 public override void Run(string[] args, PipeConsole console)
 {
     if (args.Length == 1)
     {
         console.WriteLine("user count: " + Root.Server.Users.Count);
         return;
     }
     if (args.Length >= 2)
     {
         var users = Root.Server.Users;
         var login = args[1];
         var user  = users.Find(login);
         if (user == null)
         {
             console.WriteLine("user not found");
             return;
         }
         console.WriteLine("user {0} : {1}", user.Login, UserAccessUtil.ToShortString(user.Access));
     }
 }
Esempio n. 5
0
            public override void Run(string[] args, PipeConsole console)
            {
                if (args.Length < 2)
                {
                    PrintUsage(console);
                    return;
                }
                var users = Root.Server.Users;
                var login = args[1];

                if (login == "--all")
                {
                    users.Clear();
                    return;
                }
                if (users.Remove(login))
                {
                    console.WriteLine("deleted user " + login);
                }
                else
                {
                    console.WriteLine("user not found");
                }
            }
Esempio n. 6
0
            public override void Run(string[] args, PipeConsole console)
            {
                if (args.Length < 4)
                {
                    PrintUsage(console);
                    return;
                }
                var    login = args[1];
                var    pass  = args[2];
                string errMsg;

                if (!NetUtil.ValidateLogin(ref login, out errMsg))
                {
                    console.WriteLine("{0}: invalid login.\r\n{1}", Root.AppName, errMsg);
                    return;
                }
                if (!NetUtil.ValidatePassword(ref pass, out errMsg))
                {
                    console.WriteLine("{0}: invalid password.\r\n{1}", Root.AppName, errMsg);
                    return;
                }
                UserAccess access;

                if (!UserAccessUtil.FromShortString(out access, args[3]))
                {
                    console.WriteLine(Root.AppName + ": invalid user access flags.");
                    console.WriteLine("valid flags:\r\n" +
                                      "    b = banned\r\n" +
                                      "    d = default\r\n" +
                                      "    a = admin\r\n" +
                                      "    ~ = max");
                    return;
                }
                var pswHash = UserAccount.TransformPassword(pass);
                var acc     = new UserAccount(login, pswHash, access);

                if (Root.Server.Users.Add(acc))
                {
                    console.WriteLine("created user " + login);
                }
                else
                {
                    console.WriteLine("user already exists");
                }
            }
Esempio n. 7
0
 public void PrintUsage(PipeConsole console)
 {
     console.WriteLine("usage: {0} {1} {2}", Root.AppName, Name, Format);
 }