From f6abd78a29270059923547d681b6bda0bdac25bd Mon Sep 17 00:00:00 2001 From: sasheg dev <152582704+SashegDev@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:38:54 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BA=D1=80=D0=B8=D0=BF=D1=82:=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BF=D1=83=D1=81=D1=82=D0=B8=D1=82=D1=8C=20=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D0=B2=D0=B5=D1=80=20=D0=B8=20=D0=B8=D0=B3=D1=80=D1=83=20?= =?UTF-8?q?=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=B5,=20=D1=87=D1=82=D0=BE?= =?UTF-8?q?=D0=B1=D1=8B=20=D1=81=D0=BC=D0=BE=D1=82=D1=80=D0=B5=D1=82=D1=8C?= =?UTF-8?q?=20=D0=BF=D0=BE=20=D1=83=D0=B4=D0=B0=D0=BB=D1=91=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=D0=BC=D1=83=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B5=D0=BC?= =?UTF-8?q?=D1=83=20=D1=81=D1=82=D0=BE=D0=BB=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/watch-game.ps1 | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 tools/watch-game.ps1 diff --git a/tools/watch-game.ps1 b/tools/watch-game.ps1 new file mode 100644 index 0000000..754b515 --- /dev/null +++ b/tools/watch-game.ps1 @@ -0,0 +1,96 @@ +# Runs the server and the client together, in the session that starts it. +# +# tools\watch-game.ps1 [-Port 25599] [-User Player] [-ServerOnly] +# +# The point of the script is a remote desktop: the game window appears on the +# desktop of whoever runs the script, so the game can be watched as it is +# played. The server gets its own console window, so its log is visible too. +# +# ASCII only: PowerShell 5.1 reads a .ps1 without a byte order mark using the +# system ANSI code page. + +param( + [int]$Port = 25599, + [string]$User = 'Player', + [switch]$ServerOnly, + [switch]$Fresh +) + +$ErrorActionPreference = 'Stop' +$Root = Split-Path -Parent $PSScriptRoot +if (-not $Root) { $Root = 'G:\RustNotMC' } + +$LogDir = Join-Path $Root 'logs' +New-Item -ItemType Directory -Force -Path $LogDir | Out-Null +$ServerLog = Join-Path $LogDir 'server.log' +$ClientLog = Join-Path $LogDir 'client.log' + +# the classpath of the server: the protocol, the accounts, the plugins and the +# server itself +$serverCp = @( + (Join-Path $Root 'rsx-protocol\build\classes') + (Join-Path $Root 'rsx-auth\build\classes') + (Join-Path $Root 'rsx-plugin-api\build\classes') + (Join-Path $Root 'rsx-server-core\build\classes') +) -join ';' + +# the old server goes first, and only the one that holds the port +$line = netstat -ano | Select-String ":$Port" | Select-String 'LISTENING' | Select-Object -First 1 +if ($line) { + Write-Host "stopping the old server on $Port" + Stop-Process -Id (($line -split '\s+')[-1]) -Force -ErrorAction SilentlyContinue + Start-Sleep -Seconds 2 +} + +$tokenFile = Join-Path $Root 'rsx-server-core\world\dev-token.txt' +if ($Fresh -and (Test-Path $tokenFile)) { Remove-Item $tokenFile -Force } + +Write-Host 'starting the server' +$serverArgs = @( + '-cp', $serverCp, 'net.rustnotmc.server.ServerMain', + '--port', "$Port", + '--accounts', (Join-Path $Root 'rsx-server-core\accounts.txt'), + '--world', (Join-Path $Root 'rsx-server-core\world'), + '--dev-token', $User +) +$java = 'D:\jdk-21\bin\java.exe' +if (-not (Test-Path $java)) { $java = (Get-Command java).Source } +$server = Start-Process -FilePath $java -ArgumentList $serverArgs ` + -RedirectStandardOutput $ServerLog -RedirectStandardError "$ServerLog.err" -PassThru +Write-Host "server pid $($server.Id), log $ServerLog" + +# the server writes its own token, and the client needs it +$token = $null +for ($i = 0; $i -lt 40; $i++) { + Start-Sleep -Milliseconds 500 + if (Test-Path $tokenFile) { + $token = (Get-Content $tokenFile -Raw).Trim() + if ($token) { break } + } +} +if (-not $token) { + Write-Host 'the server did not write its token - look at the server log' + exit 1 +} +Write-Host "token ready for $User" + +if ($ServerOnly) { + Write-Host 'server only, the client is not started. Ctrl+C stops nothing here.' + while ($true) { Start-Sleep -Seconds 5 } +} + +Write-Host 'starting the client' +$runGame = Join-Path $Root 'rsx-client\scripts\run-game.ps1' +$clientArgs = @('-NoExit', '-Command', "& '$runGame' -Token '$token'") +Start-Process -FilePath 'powershell.exe' -ArgumentList $clientArgs -PassThru | Out-Null +Write-Host 'the client is starting in its own window' +Write-Host "the client log is in $ClientLog" + +# stay alive while the game runs +while ($true) { + Start-Sleep -Seconds 5 + if ($server.HasExited) { + Write-Host 'the server has stopped' + break + } +}