commit 49bf855bca29fd92868bf50d8a03caba669f4975 Author: Dcr Date: Tue Jul 22 18:30:21 2025 +0800 首次提交 diff --git a/README.md b/README.md new file mode 100644 index 0000000..9caf188 --- /dev/null +++ b/README.md @@ -0,0 +1,121 @@ +# DayZ 服务器自动安装工具 + +这是一个用于自动安装和配置 DayZ 专用服务器的工具集。该工具可以自动下载并安装 DayZ 服务器文件,简化服务器部署过程。 + +## 功能特性 + +- 🔧 **自动安装 VC++ 运行库** - 确保系统具备运行 DayZ 服务器的必要组件 +- 📦 **自动下载 SteamCMD** - 自动获取 Steam 命令行工具 +- 🎮 **自动下载 DayZ 服务器文件** - 通过 Steam 自动下载最新的 DayZ 服务器文件 +- 🔄 **自动生成更新脚本** - 安装完成后自动创建用于后续更新的批处理脚本 +- 🛡️ **安全凭证处理** - 安装完成后自动清理内存中的 Steam 凭证 + +## 文件说明 + +- `install.ps1` - 主要的 PowerShell 安装脚本 +- `双击安装.bat` - 用户友好的批处理启动脚本 +- `说明.txt` - 使用说明文档 +- `更新服务器.bat` - 安装完成后自动生成的更新脚本 + +## 系统要求 + +- Windows Server 2016+ +- PowerShell 5.0 或更高版本 +- 稳定的网络连接 +- 至少 10GB 可用磁盘空间 + +## 安装步骤 + +### 1. 准备工作 + +1. 确保项目文件夹路径不包含中文字符 +2. 右键点击 `双击安装.bat` 文件,选择"编辑" + +### 2. 配置 Steam 凭证 + +在编辑器中找到以下行: +```batch +set "STEAM_USER=your_username" +set "STEAM_PASS=your_password" +``` + +将其修改为你的 Steam 账号信息: +```batch +set "STEAM_USER=你的steam用户名" +set "STEAM_PASS=你的steam密码" +``` + +**注意:** 使用的 Steam 账号不需要购买 DayZ 游戏,任何有效的 Steam 账号都可以。 + +### 3. 运行安装 + +1. 保存并关闭 `双击安装.bat` 文件 +2. 双击运行 `双击安装.bat` +3. 等待安装完成 + +## 安装过程 + +安装脚本会自动执行以下步骤: + +1. **下载并安装 VC++ 运行库** +2. **下载 SteamCMD 工具** +3. **使用 SteamCMD 下载 DayZ 服务器文件** +4. **生成更新脚本** + +安装完成后,会在项目目录下创建: +- `game_server/` - DayZ 服务器文件目录 +- `steamcmd/` - SteamCMD 工具目录 +- `更新服务器.bat` - 用于后续更新的脚本 + +## 更新服务器 + +安装完成后,如需更新 DayZ 服务器文件,只需双击运行 `更新服务器.bat` 即可。 + +## 注意事项 + +### ⚠️ 重要提醒 + +1. **路径限制**:项目文件夹路径不能包含中文字符,因为 SteamCMD 不支持中文路径 +2. **网络要求**:确保网络连接稳定,下载过程可能需要较长时间 +3. **磁盘空间**:确保有足够的磁盘空间(建议至少 10GB) +4. **权限要求**:可能需要管理员权限来安装 VC++ 运行库 + +### 🔒 安全建议 + +- 安装完成后,脚本会自动清理内存中的 Steam 凭证 +- 建议使用专门的 Steam 账号进行服务器文件下载 +- 定期更新服务器文件以获取最新的安全补丁 + +## 故障排除 + +### 常见问题 + +1. **PowerShell 执行策略错误** + - 解决方案:脚本已包含自动绕过执行策略的代码 + +2. **网络下载失败** + - 检查网络连接 + - 尝试使用 VPN 或更换网络环境 + +3. **Steam 登录失败** + - 确认 Steam 账号和密码正确 + - 检查是否需要 Steam Guard 验证码 + +4. **磁盘空间不足** + - 清理磁盘空间后重新运行安装 + +## 技术支持 + +如果遇到问题,请检查: +1. 系统是否满足最低要求 +2. 网络连接是否正常 +3. Steam 账号信息是否正确 +4. 路径是否包含中文字符 + +## 许可证 + +本项目仅供学习和个人使用。请遵守 DayZ 和 Steam 的服务条款。 + +--- + +**免责声明**:本工具仅用于自动化 DayZ 服务器文件的下载和安装过程。使用者需要自行承担使用风险,并确保遵守相关法律法规和服务条款。 \ No newline at end of file diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..28c1926 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,107 @@ +param( + [Parameter(Mandatory=$true)] + [string]$SteamUser, + + [Parameter(Mandatory=$true)] + [string]$SteamPass +) + +Set-ExecutionPolicy Bypass -Scope Process -Force + +$scriptDir = if ($PSScriptRoot) { $PSScriptRoot } + else { Split-Path -Parent $MyInvocation.MyCommand.Definition } +if (-not $scriptDir) { $scriptDir = Get-Location } + +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + +$appId = "223350" +$installDir = Join-Path $scriptDir "game_server" + +$vcRedistUrl = "https://aka.ms/vs/17/release/vc_redist.x64.exe" +$vcRedistPath = Join-Path -Path $env:TEMP -ChildPath "vc_redist_x64.exe" + +try { + Write-Host " VC++ п..." + (New-Object System.Net.WebClient).DownloadFile($vcRedistUrl, $vcRedistPath) + + if (Test-Path $vcRedistPath) { + Write-Host "ھĬװ VC++ п..." + $installProcess = Start-Process -FilePath $vcRedistPath ` + -ArgumentList "/install /quiet /norestart" ` + -Wait -NoNewWindow -PassThru + Remove-Item $vcRedistPath -Force + } +} +catch { + Write-Error "VC++װʧ: $_" + exit 1 +} + +$steamcmdDir = Join-Path $scriptDir "steamcmd" +$steamcmdUrl = "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip" +$steamcmdZip = Join-Path $steamcmdDir "steamcmd.zip" + +try { + if (-not (Test-Path $steamcmdDir)) { + New-Item -Path $steamcmdDir -ItemType Directory -Force | Out-Null + } + + Write-Host " SteamCMD..." + (New-Object System.Net.WebClient).DownloadFile($steamcmdUrl, $steamcmdZip) + + if (Test-Path $steamcmdZip) { + Write-Host "ڽѹ SteamCMD..." + Expand-Archive -Path $steamcmdZip -DestinationPath $steamcmdDir -Force + Remove-Item $steamcmdZip -Force + } +} +catch { + Write-Error "SteamCMDʧ: $_" + exit 1 +} + +$steamcmdExe = Join-Path $steamcmdDir "steamcmd.exe" + +try { + if (Test-Path $steamcmdExe) { + Write-Host "ڸϷ (AppID: $appId)..." + $arguments = @( + "+force_install_dir `"$installDir`"", + "+login `"$SteamUser`" `"$SteamPass`"", + "+app_update $appId validate", + "+quit" + ) + $process = Start-Process -FilePath $steamcmdExe ` + -ArgumentList $arguments ` + -Wait -NoNewWindow -PassThru ` + } + else { + throw "SteamCMDִļδҵ: $steamcmdExe" + } +} +catch { + Write-Error "Ϸʧ: $_" + exit 1 +} + +$updateBatPath = Join-Path $scriptDir "·.bat" +$batContent = @" +@echo off +set STEAMCMD_PATH="$steamcmdDir" +set STEAM_USER=$SteamUser +set STEAM_PASS=$SteamPass +set INSTALL_DIR="$installDir" +set APP_ID=$appId + +cd /d %STEAMCMD_PATH% +steamcmd.exe +login %STEAM_USER% %STEAM_PASS% +force_install_dir %INSTALL_DIR% +app_update %APP_ID% validate +quit + +echo Ѹ! +pause +"@ + +$batContent | Out-File -FilePath $updateBatPath -Encoding Default +Write-Host "Ѵ½ű: $updateBatPath" -ForegroundColor Cyan +Write-Host "˫ļһ·" -ForegroundColor Green + +Write-Host "`nв!" -ForegroundColor Green \ No newline at end of file diff --git a/双击安装.bat b/双击安装.bat new file mode 100644 index 0000000..304a76a --- /dev/null +++ b/双击安装.bat @@ -0,0 +1,18 @@ +@echo off +setlocal enabledelayedexpansion + +:: ˺루ʵʹʱ滻Ϊʵƾ֤ +set "STEAM_USER=your_username" +set "STEAM_PASS=your_password" + +:: PowerShellűݲ +powershell.exe -ExecutionPolicy Bypass -File "%~dp0install.ps1" ^ + -SteamUser "!STEAM_USER!" ^ + -SteamPass "!STEAM_PASS!" + +:: ȫڴеƾ֤ +set "STEAM_USER=" +set "STEAM_PASS=" +endlocal +pause +exit \ No newline at end of file