internal LaunchResult LaunchInternal(ServerOptions options,params Action<ServerLaunchArguments>[] argumentsOperators)
 {
     lock (Locker)
     {
         if (!File.Exists(JavaPath))
         {
             return new LaunchResult { Success = false, ErrorType = ErrorType.NoJAVA, ErrorMessage = "指定JAVA位置不存在" };
         }
         CurrentCode = Random.Next();
         var args = new ServerLaunchArguments();
         var result = GenerateArguments(options, ref args);
         if(result != null)
         {
             return result;
         }
         if (argumentsOperators == null) return LaunchServer(args);
         foreach(var opt in argumentsOperators)
         {
             try
             {
                 opt?.Invoke(args);
             }
             catch (Exception ex)
             {
                 return new LaunchResult { Success = false, ErrorType = ErrorType.OperatorException, ErrorMessage = "指定的操作器引发了异常", Exception = ex };
             }
         }
         return LaunchServer(args);
     }
 }
Пример #2
0
 public LaunchResult Launch(ServerOptions options,params Action<ServerLaunchArguments>[] argumentsOperators)
 {
     return LaunchInternal(options, argumentsOperators);
 }
        private LaunchResult GenerateArguments(ServerOptions options,ref ServerLaunchArguments args)
        {
            try
            {
                args.CGCEnabled = true;
                args.MaxRAM = options.MaxRAM;
                args.MinRAM = options.MinRAM;
                args.JarPath = options.JarPath;
                if (!string.IsNullOrWhiteSpace(options.CustomArguments))
                {
                    var cus = options.CustomArguments.Split(' ');
                    args.CustomAruguments = cus.ToList();
                }

                return null;
            }
            catch(Exception ex)
            {
                return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "在省城启动参数时发生了意外的错误", Exception = ex };

            }
        }