Beispiel #1
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;
                    }
                }
            }
Beispiel #2
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);
     }
 }
Beispiel #3
0
 public override void Run(string[] args, PipeConsole console)
 {
     if (!Root.Server.Connected)
     {
         console.WriteLine("already disconnected");
     }
     Root.Server.Disconnect();
 }
Beispiel #4
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");
                }
            }
Beispiel #5
0
        public void HandleCommand(string cmdLine, PipeConsole console)
        {
            var args = StringUtil.SplitCommandLine(cmdLine).ToArray();

            if (args.Length == 0)
            {
                PrintHelp(console);
                return;
            }
            var cmd = GetCommand(args[0]);

            if (cmd == null)
            {
                PrintHelp(console);
                return;
            }
            cmd.Run(args, console);
        }
Beispiel #6
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));
     }
 }
        private void ClientServiceLoop()
        {
            var tmpPipeName = String.Format("{0}_tmp_{1}", PipeName, (ulong)DateTime.Now.ToBinary());

            lock (readerLock)
            {
                svPipeWriter.WriteLine(tmpPipeName);
                svPipeWriter.Flush();
                svPipe.WaitForPipeDrain();
                svPipe.Disconnect();
                // continue waiting
                svPipe.BeginWaitForConnection(OnConnection, null);
            }
            using (var pipe = new NamedPipeServerStream(tmpPipeName, PipeDirection.InOut, 1,
                                                        PipeTransmissionMode.Message, PipeOptions.Asynchronous))
            {
                object locker = 1;
                lock (locker)
                {
                    var ar       = pipe.BeginWaitForConnection(OnTempPipeConnection, locker);
                    var timedOut = !Monitor.Wait(locker, 1000);
                    pipe.EndWaitForConnection(ar);
                    if (timedOut || !pipe.IsConnected)
                    {
                        return;
                    }
                }
                var clReader = new StreamReader(pipe, true);
                var clWriter = new StreamWriter(pipe, Encoding.UTF8);
                var proxy    = new PipeConsole(clReader, clWriter);
                var cmd      = clReader.ReadLine();
                if (cmd != null)
                {
                    handler(cmd, proxy);
                }
                pipe.WaitForPipeDrain();
                pipe.Disconnect();
            }
        }
Beispiel #8
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");
                }
            }
Beispiel #9
0
 private void PrintHelp(PipeConsole console)
 {
     cmdHelp.Run(emptyHelpArgs, console);
 }
Beispiel #10
0
 public override void Run(string[] args, PipeConsole console)
 {
     Root.Server.Users.Save();
 }
Beispiel #11
0
 public abstract void Run(string[] args, PipeConsole console);
Beispiel #12
0
 public void PrintUsage(PipeConsole console)
 {
     console.WriteLine("usage: {0} {1} {2}", Root.AppName, Name, Format);
 }