コード例 #1
0
        /// <summary>
        /// 返回一个用户输入的数字
        /// </summary>
        /// <param name="tips">提示用户输入的文字</param>
        /// <param name="advice">提供输入建议</param>
        /// <param name="inputRange">发生异常时的提示信息</param>
        /// <param name="tipsColor"><param name="tips"/>的颜色</param>
        /// <param name="adviceColor"><param name="advice"/>的颜色</param>
        /// <returns></returns>
        public static int?TryGetNumberInput(
            string tips              = "请输入序号来选择", string advice = null, Tuple <int, int> inputRange = null,
            ConsoleColor tipsColor   = ConsoleColor.White,
            ConsoleColor adviceColor = ConsoleColor.Gray)
        {
            try
            {
                int i = GetNumberInput(tips, advice, tipsColor, adviceColor);
                if (inputRange != null)
                {
                    int min = Math.Min(inputRange.Item1, inputRange.Item2);
                    int max = Math.Max(inputRange.Item1, inputRange.Item2);
                    if (i < min ||
                        i > max)
                    {
                        throw new FormatException($"输入的整数必须在{min} - {max}之间");
                    }
                }
                return(i);
            }
            catch (Exception ex)
            {
                Displayer.ShowLine(
                    $"输入格式错误!请输入一个整数!{ex.Message}", 2, Displayer.ErrorColor);
                Displayer.PressAnyKeyToContinue();

                return(null);
            }
        }
コード例 #2
0
        public RayPortUser BuildPortUser()
        {
            Displayer.ShowLine("创建用户\r\n", ConsoleColor.DarkGreen);
            BuildRayPortSettings();

            return(rayPort.Settings.Clients.LastOrDefault());
        }
コード例 #3
0
        public IRayPortConfigBuilder BuildRayPort()
        {
            RayPort.Port = 0;
            try
            {
                RayPort.Port = InputHelper.GetNumberInput("端口号(0-65535)");
            }
            catch
            {
                RayPort.Port = (new Random()).Next(1, 65535);
            }
            finally
            {
                Displayer.ShowLine("设置成功! " + RayPort.Port + "\r\n", ConsoleColor.DarkGreen);
            }

            try
            {
                string type = InputHelper.GetInput("服务类型", "default - vmess");
                RayPort.Protocol = string.IsNullOrEmpty(type) ? RayPort.Protocol : type;
                Displayer.ShowLine("设置成功! " + RayPort.Protocol + "\r\n", ConsoleColor.DarkGreen);
                BuildRayPortStreamSettings();
            }
            catch (Exception)
            {
                Displayer.ShowLine("设置成功! " + RayPort.Port + "\r\n", ConsoleColor.DarkGreen);
            }

            RayPort.Tag = RayPort.StreamSettings?.NetWork ?? "tcp";
            return(this);
        }
コード例 #4
0
        public static string GetInput(
            string tips, string advice = null,
            ConsoleColor tipsColor     = ConsoleColor.White,
            ConsoleColor adviceColor   = ConsoleColor.Gray)
        {
            Displayer.Show(tips, 2, tipsColor);
            if (!string.IsNullOrEmpty(advice))
            {
                Displayer.Show("(", tipsColor);
                Displayer.Show(advice, adviceColor);
                Displayer.Show(")", tipsColor);
            }
            Displayer.Show(": ", tipsColor);
            string input = Console.ReadLine();

            Displayer.ShowLine("");
            return(input);
        }
コード例 #5
0
        public IRayPortConfigBuilder BuildClients()
        {
            RayPort.Settings         = RayPort.Settings ?? new RayPortSettings();
            RayPort.Settings.Clients = RayPort.Settings.Clients ?? new List <RayPortUser>();

            RayPortUser client = new RayPortUser();

            RayPort.Settings.Clients.Add(client);

            try
            {
                client.Email = InputHelper.GetInput("用户名", "不能包含 @ 字符");
                Displayer.ShowLine("设置成功! " + client.Email + "\r\n", ConsoleColor.DarkGreen);

                client.Email += "@t.tt";

                client.Uuid = InputHelper.GetInput("用户id", "默认 - " + client.Uuid);
                Displayer.ShowLine("设置成功! " + client.Uuid + "\r\n", ConsoleColor.DarkGreen);

                client.Uuid = string.IsNullOrEmpty(client.Uuid)
                    ? Guid.NewGuid().ToString()
                    : client.Uuid;


                client.AlterId = InputHelper.GetNumberInput("额外id", "默认 - " + client.AlterId.ToString());
            }
            catch
            {
                client.Uuid    = Guid.NewGuid().ToString();
                client.AlterId = 64;
            }
            finally
            {
                Displayer.ShowLine("设置成功! " + client.AlterId + "\r\n", ConsoleColor.DarkGreen);
            }

            return(this);
        }
コード例 #6
0
        public IRayPortConfigBuilder BuildRayPortStreamSettings()
        {
            RayPort.StreamSettings = RayPort.StreamSettings ?? new RayPortStreamSettings();

            RayPort.StreamSettings.NetWork = InputHelper.GetInput("传输协议", "tcp/kcp/ws/h2/quic, default: tcp");
            Displayer.ShowLine("设置成功! " + RayPort.StreamSettings.NetWork + "\r\n", ConsoleColor.DarkGreen);

            RayPort.StreamSettings.Security = InputHelper.GetInput("底层传输安全", "tls|\"\"");
            Displayer.ShowLine("设置成功! " + RayPort.StreamSettings.Security + "\r\n", ConsoleColor.DarkGreen);

            if (RayPort.StreamSettings.Security == string.Empty)
            {
                RayPort.StreamSettings.Security = null;
            }

            string path = InputHelper.GetInput("tls路径");

            Displayer.ShowLine("设置成功! " + path + "\r\n", ConsoleColor.DarkGreen);

            string connectionReUse = InputHelper.GetInput("连接复用", "true");

            Displayer.ShowLine("设置成功! " + connectionReUse + "\r\n", ConsoleColor.DarkGreen);

            bool reUse = false;

            if (!string.IsNullOrEmpty(connectionReUse) ||
                bool.TryParse(connectionReUse, out reUse))
            {
                RayPort.StreamSettings.WSSettings = new WSSettings
                {
                    ConnectionReuse = reUse,
                    Path            = path
                };
            }

            return(this);
        }