diff --git a/client/src/pages/GameDeploymentPage.tsx b/client/src/pages/GameDeploymentPage.tsx index a27a383e..05105b69 100644 --- a/client/src/pages/GameDeploymentPage.tsx +++ b/client/src/pages/GameDeploymentPage.tsx @@ -41,6 +41,7 @@ interface GameInfo { url: string docs?: string system?: string[] + login_anonymous?: boolean supportedOnCurrentPlatform?: boolean currentPlatform?: string panelCompatibleOnCurrentPlatform?: boolean @@ -59,6 +60,14 @@ interface Games { [key: string]: GameInfo } +const quoteSteamCMDArgument = (value: string, platform?: string): string => { + if (platform === 'Windows') { + return `'${value.replace(/'/g, "''")}'` + } + + return `'${value.replace(/'/g, "'\\''")}'` +} + // 辅助函数:判断是否为 Windows 平台 const isWindowsPlatform = (systemInfo: any): boolean => { // 优先使用 rawPlatform(原始平台标识) @@ -2543,17 +2552,24 @@ const GameDeploymentPage: React.FC = () => { useEffect(() => { if (showInstallModal && selectedGame) { const forceInstallDir = `force_install_dir "${installPath.trim()}"` + const steamLoginArgs = [ + 'login', + quoteSteamCMDArgument(steamUsername.trim(), selectedGame.info.currentPlatform), + ...(steamPassword.trim() + ? [quoteSteamCMDArgument(steamPassword.trim(), selectedGame.info.currentPlatform)] + : []) + ] const loginCommand = useAnonymous ? 'login anonymous' - : `login ${steamUsername.trim()} ${steamPassword.trim()}` + : steamLoginArgs.join(' ') const appUpdateCommand = validateGameIntegrity ? `app_update ${selectedGame.info.appid} validate` : `app_update ${selectedGame.info.appid}` // force_install_dir 必须在 login 之前,否则 SteamCMD 会报错 - const fullCommand = `steamcmd +${forceInstallDir} +${loginCommand} +${appUpdateCommand} +quit` + const fullCommand = `+${forceInstallDir} +${loginCommand} +${appUpdateCommand} +quit` setSteamcmdCommand(fullCommand) } }, [showInstallModal, selectedGame, useAnonymous, steamUsername, steamPassword, validateGameIntegrity, installPath]) @@ -2628,6 +2644,12 @@ const GameDeploymentPage: React.FC = () => { // 打开安装对话框的通用函数 const openInstallModal = async (gameKey: string, gameInfo: GameInfo) => { const defaultInstanceName = gameInfo.game_nameCN + const shouldUseAnonymous = gameInfo.login_anonymous !== false + setUseAnonymous(shouldUseAnonymous) + if (shouldUseAnonymous) { + setSteamUsername('') + setSteamPassword('') + } // 检查是否存在同名实例 try { @@ -2909,11 +2931,11 @@ const GameDeploymentPage: React.FC = () => { return } - if (!useAnonymous && (!steamUsername.trim() || !steamPassword.trim())) { + if (!useAnonymous && !steamUsername.trim()) { addNotification({ type: 'error', title: '参数错误', - message: '请填写Steam账户信息' + message: '请填写Steam用户名' }) return } @@ -2946,7 +2968,7 @@ const GameDeploymentPage: React.FC = () => { instanceName: instanceName.trim(), useAnonymous, steamUsername: useAnonymous ? undefined : steamUsername.trim(), - steamPassword: useAnonymous ? undefined : steamPassword.trim(), + steamPassword: useAnonymous || !steamPassword.trim() ? undefined : steamPassword.trim(), steamcmdCommand: steamcmdCommand.trim(), existingInstanceId: currentExistingInstanceId || undefined, updateInstanceInfo: currentUpdateInstanceInfo, @@ -5763,15 +5785,18 @@ const GameDeploymentPage: React.FC = () => {
setSteamPassword(e.target.value)} className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent bg-white dark:bg-gray-700 text-gray-900 dark:text-white" - placeholder="输入Steam密码" + placeholder="留空则在终端中输入" /> +

+ 留空时 SteamCMD 会在终端提示输入密码和 Steam Guard 码 +

)} @@ -5844,18 +5869,18 @@ const GameDeploymentPage: React.FC = () => {