From 2b6c8d58c81ae860fda01b4b1aa276d9405a16cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8D=E7=BE=BD=E9=9D=92=E7=A9=BA?= Date: Fri, 21 Mar 2025 13:11:46 +0800 Subject: [PATCH] Delete ServerLauncher/MainWindow.xaml.cs --- ServerLauncher/MainWindow.xaml.cs | 206 ------------------------------ 1 file changed, 206 deletions(-) delete mode 100644 ServerLauncher/MainWindow.xaml.cs diff --git a/ServerLauncher/MainWindow.xaml.cs b/ServerLauncher/MainWindow.xaml.cs deleted file mode 100644 index 239d28c..0000000 --- a/ServerLauncher/MainWindow.xaml.cs +++ /dev/null @@ -1,206 +0,0 @@ -using System.Diagnostics; -using System.Windows; -using System.Windows.Media; -using System.Windows.Threading; - -namespace ServerLauncher -{ - public partial class MainWindow : Window - { - private DispatcherTimer timer; - public MainWindow() - { - InitializeComponent(); - - // 初始化定时器 - timer = new DispatcherTimer(); - timer.Interval = TimeSpan.FromSeconds(5); // 每 5 秒检测一次 - timer.Tick += Timer_Tick; - timer.Start(); - - // 初始检测 - CheckTslGameProcess(); - - } - - //启动服务器进程 - private static void StartTSLServer() - { - try - { - Process.Start(new ProcessStartInfo - { - FileName = "TslGame.exe", - Arguments = "/Game/Maps/Erangel/Erangel_Main?listen?game=/Game/Blueprints/TSLGameMode.TSLGameMode_C -nullrhi -nosound -AllowJoinAnyMatchState -Server -port=8888 -NoVerifyGC -NoEAC -NoBattleEye", - UseShellExecute = true, - }); - } - catch (Exception ex) - { - MessageBox.Show($"An error was encountered while starting TslGame Server:{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - } - } - - //结束服务器进程 - private static void KillTSLProcess() - { - try - { - // 获取所有名为 "TslGame" 的进程 - Process[] processes = Process.GetProcessesByName("TslGame"); - - if (processes.Length > 0) - { - foreach (var process in processes) - { - process.Kill(); // 强制结束进程 - process.WaitForExit(); // 等待进程完全退出 - } - - MessageBox.Show("TslGame Server was successfully closed.", "Message", MessageBoxButton.OK, MessageBoxImage.Information); - } - else - { - MessageBox.Show("TslGame Server Not running!", "Message", MessageBoxButton.OK, MessageBoxImage.Warning); - } - } - catch (Exception ex) - { - MessageBox.Show($"Failed to end process TslGame Server: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - } - } - - //启动游戏进程 - private static void StartTSLGame() - { - try - { - Process.Start(new ProcessStartInfo - { - FileName = "TslGame.exe", - Arguments = "127.0.0.1:8888 -NoVerifyGC -NoEAC -NoBattleEye", - UseShellExecute = true, - }); - } - catch (Exception ex) - { - MessageBox.Show($"An error was encountered while starting TslGame:{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - } - } - - //监测 TslGame Server 是否正在运行(自动逻辑) - private void Timer_Tick(object sender, EventArgs e) - { - // 定时检测进程状态 - CheckTslGameProcess(); - } - private void CheckTslGameProcess() - { - // 获取所有名为 "TslGame" 的进程 - Process[] processes = Process.GetProcessesByName("TslGame"); - - if (processes.Length > 0) - { - // 如果进程存在,更新界面为“运行” - StatusText.Text = "Running"; - StatusText.Foreground = new SolidColorBrush(Colors.Green); - } - else - { - // 如果进程不存在,更新界面为“未运行” - StatusText.Text = "Not running"; - StatusText.Foreground = new SolidColorBrush(Colors.Red); - } - } - - //界面上的按钮事件 - //启动 TslGame 服务器 - private async void Button_StartTSLServer_Click(object sender, RoutedEventArgs e) - { - try - { - // 启动TslGame.exe - MessageBoxResult result = MessageBox.Show( - "Are you sure?", - "Message", - MessageBoxButton.YesNo, - MessageBoxImage.Question); - - if (result == MessageBoxResult.Yes) - { - await Task.Delay(3000); - StartTSLServer(); - } - - } - catch (Exception ex) - { - MessageBox.Show($"An error was encountered while starting TslGame Server: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - } - } - - - - //结束 TslGame 服务器 - private void Button_KillTSLServer_Click(object sender, RoutedEventArgs e) - { - try - { - MessageBoxResult result = MessageBox.Show( - "Are you sure?", - "Message", - MessageBoxButton.YesNo, - MessageBoxImage.Question); - - if (result == MessageBoxResult.Yes) - { - KillTSLProcess(); - } - - } - catch (Exception ex) - { - MessageBox.Show($"Failed to end process TslGame Server: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error); - } - } - - - //启动 TslGame - private void Button_Start_TslGame(object sender, RoutedEventArgs e) - { - try - { - MessageBoxResult result = MessageBox.Show( - "Are you sure?", - "Message", - MessageBoxButton.YesNo, - MessageBoxImage.Question); - - if (result == MessageBoxResult.Yes) - { - StartTSLGame(); - } - - } - catch (Exception ex) - { - MessageBox.Show($"An error was encountered while starting TslGame {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - } - } - - //退出应用 - private void Button_Exit_Click(object sender, RoutedEventArgs e) - { - Application.Current.Shutdown(); - } - - //关于我们 - private void Button_OpenNewWindow_Click(object sender, RoutedEventArgs e) - { - // 创建新窗口的实例 - Window2 newWindow = new Window2(); - // 显示新窗口 - newWindow.Show(); - } - } -} \ No newline at end of file