首次提交

This commit is contained in:
Dcr
2025-07-22 18:30:21 +08:00
commit 49bf855bca
3 changed files with 246 additions and 0 deletions

107
install.ps1 Normal file
View File

@@ -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