示例#1
0
        //===================================================================================//
        // SERVER CONTROL:                                                                   //
        //===================================================================================//
        private void btnStartServer_Click(object sender, EventArgs e)
        {
            var currentServer = GameServerManagement.PropertyGetSet(comboboxGameserverList.Text);
            //These strings tell the process manager how exactly to start the server processes based on the engine they use.
            string engineSpecificDirectory = null;
            string engineSpecificArguments = null;

            switch (currentServer.ENGINE_type)
            {
            case "SOURCE":
                //Copy SRCDS Redirection utility (Band-Aid Redirection Fix) into working gameserver.DIR_root directory.
                string fileName   = "SrcdsConRedirect.exe";
                string sourcePath = Environment.CurrentDirectory;
                string targetPath = currentServer.DIR_install_location + @"\steamapps\common" + currentServer.DIR_root;

                // Use Path class to manipulate file and directory paths.
                string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
                string destFile   = System.IO.Path.Combine(targetPath, fileName);

                // Create a new target folder, if necessary.
                if (!System.IO.Directory.Exists(targetPath))
                {
                    System.IO.Directory.CreateDirectory(targetPath);
                }

                // overwrite the destination file if it already exists.
                System.IO.File.Copy(sourceFile, destFile, true);

                engineSpecificDirectory = currentServer.DIR_install_location + @"\steamapps\common" + currentServer.DIR_root + @"\SrcdsConRedirect.exe";
                engineSpecificArguments =
                    $"-console {currentServer.SERVER_launch_arguments} +port {currentServer.SERVER_port} +map {currentServer.GAME_map} +maxplayers {currentServer.GAME_maxplayers}";
                break;

            case "UNREAL":
                engineSpecificDirectory =
                    currentServer.DIR_install_location + @"\steamapps\common" + currentServer.DIR_root + currentServer.SERVER_executable;
                engineSpecificArguments = string.Format("{0}{1}?maxplayers={3}",
                                                        currentServer.GAME_map,
                                                        currentServer.SERVER_launch_arguments,
                                                        currentServer.GAME_maxplayers);
                break;

            case "GENERIC":
                engineSpecificDirectory = currentServer.DIR_install_location + currentServer.DIR_root + currentServer.SERVER_executable;
                engineSpecificArguments = currentServer.SERVER_launch_arguments;
                break;
            }

            if (chkRedirectInOut.Value)
            {
                //CREATE THE PROCESS
                var process = ProcessManager.GetOrCreate(currentServer.SERVER_name_friendly,
                                                         engineSpecificDirectory, engineSpecificArguments, new ProcessLaunchOptions
                {
                    ShowWindowOnStart = false
                });

                //Start the Process!
                SubscribeToProcess(process);
                ProcessManager.GetProcessByNickname(currentServer.SERVER_name_friendly)?.Start();
            }
            else
            {
                //CREATE THE PROCESS
                var process = ProcessManager.GetOrCreate(currentServer.SERVER_name_friendly,
                                                         engineSpecificDirectory, engineSpecificArguments, new ProcessLaunchOptions
                {
                    ShowWindowOnStart = true
                });

                //Start the Process!
                SubscribeToProcess(process);
                ProcessManager.GetProcessByNickname(currentServer.SERVER_name_friendly)?.Start();
            }

            btnStartServer.Enabled = false;
            btnStopServer.Enabled  = true;

            txtboxIssueCommand.Enabled = true;
            txtboxIssueCommand.Text    = "";

            //chkRedirectInOut.Enabled = false;
            //lblRedirectInOut.Enabled = false;
        }