private void button_Click(object sender, RoutedEventArgs e)
 {
     if (!ServerOn)
     {
         NeedEULA = false;
         handle = App.Core.Launch(App.ServerConfig).Handle;
         ServerOn = true;
         button.IsEnabled = false;
         button_kill.IsEnabled = true;
         button.Content = "正在开启服务器";
     }
     else
     {
         button.IsEnabled = false;
         button.Content = "正在关闭服务器";
         handle.Input("stop");
     }
 }
        private void ProcExited(LaunchHandle handle, int exitcode)
        {
            AppendText(Brushes.Blue, "服务器结束运行");
            ServerOn = false;
            Dispatcher.BeginInvoke(new Action(() =>
            {
                button.IsEnabled = true;
                button_kill.IsEnabled = false;
                button.Content = "开启服务器";
            }));

            if (NeedEULA)
            {
                AppendText(Brushes.Blue, "[RHW Simple Server] 检测到您未同意 EULA 协议,请在指令框键入 /rhw agreeEULA 以同意协议");
                AppendText(Brushes.Blue, "[RHW Simple Server] 注意!在您同意之前程序假设您已经得知了 EULA 协议的具体条款!");
                AppendText(Brushes.Blue, "[RHW Simple Server] https://account.mojang.com/documents/minecraft_eula");
                AppendText(Brushes.Blue, "[RHW Simple Server] 如果您违反了 EULA 协议,造成的后果不由本程序承担!");
            }
        }
 private void OutputToConsole(LaunchHandle handle,string line)
 {
     Console.WriteLine(line);
     if (!string.IsNullOrEmpty(line))
     {
         if (line.Contains("WARN"))
             AppendText(Brushes.Orange, line);
         else if (line.Contains("ERROR"))
             AppendText(Brushes.Red, line);
         else if (line.Contains("	at "))
             AppendText(Brushes.Red, line);
         else if (line.Contains("logged in"))
             AppendText(Brushes.DarkGreen, line);
         else if(line.Contains("joined the game"))
         {
             var newline = line.Replace("joined the game", "加入了游戏");
             AppendText(Brushes.DarkGreen, newline);
         }
         else if(line.Contains("For help, type"))
         {
             var newline = line.Replace("Done", "服务器启动完成").Replace("For help, type \"help\" or \"?\"", "如需帮助,键入指令 \"help\" 或 \"?\"");
             AppendText(Brushes.Blue, newline);
             Dispatcher.BeginInvoke(new Action(() =>
             {
                 button.IsEnabled = true;
                 button.Content = "关闭服务器";
             }));
         }
         else if(line.Contains(EULATips))
         {
             var newline = line.Replace(EULATips, "");
             NeedEULA = true;
             AppendText(Brushes.Blue, newline);
         }
         else
             AppendText(line);
     }
 }
 internal void Exit(LaunchHandle handle, int code)
 {
     ServerExit?.Invoke(handle, code);
 }
 private LaunchResult LaunchServer(ServerLaunchArguments args)
 {
     try
     {
         Console.WriteLine(args.ToArguments());
         var handle = new LaunchHandle
         {
             Code = CurrentCode,
             Core = this,
             Arguments = args,
             Process = Process.Start(new ProcessStartInfo(JavaPath)
             {
                 Arguments = args.ToArguments(),
                 UseShellExecute = false,
                 WorkingDirectory = ServerRootPath,
                 RedirectStandardError = true,
                 RedirectStandardOutput = true,
                 RedirectStandardInput = true,
                 CreateNoWindow = true
             })
         };
         handle.Work();
         Task.Factory.StartNew(handle.Process.WaitForExit).ContinueWith(t => Exit(handle, handle.Process.ExitCode));
         return new LaunchResult { Success = true, Handle = handle };
     }
     catch (Exception ex)
     {
         return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "启动时出现了异常", Exception = ex };
     }
 }
 internal void Log(LaunchHandle handle, string line)
 {
     ServerLog?.Invoke(handle, line);
 }