From fa02d0c65ecdf79303a53b9a05b9d7edf2ae5843 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 18 Feb 2026 11:19:09 +0000 Subject: [PATCH] the timeouts hash means we can simplify the logic in CLI, GUI examples colour codes removed from response output. --- examples/cli.ps1 | 17 ++++++----------- examples/gui.ps1 | 22 +++++++--------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/examples/cli.ps1 b/examples/cli.ps1 index 77f4d2a..8f53da4 100644 --- a/examples/cli.ps1 +++ b/examples/cli.ps1 @@ -12,20 +12,15 @@ function Read-HostUntilEmpty { break } - if ($line -in @('fast_restart', 'map_rotate', 'map_restart')) { - $cmd = $line -replace '(?:^|_)(\p{L})', { $_.Groups[1].Value.ToUpper() } - $rcon.$cmd() - } - elseif ($line.StartsWith('map mp_')) { - $mapname = $line.Split()[1] - $rcon.SetMap($mapname) - } - else { - $rcon.Send($line) - } + $resp = $rcon.Send($line) + Write-Host (Remove-ColourCodes $resp) } } +function Remove-ColourCodes($str) { + return $str -replace '\^[0-9]', '' +} + function Get-ConnFromPSD1 { $configpath = Join-Path $PSScriptRoot 'config.psd1' return Import-PowerShellDataFile -Path $configpath diff --git a/examples/gui.ps1 b/examples/gui.ps1 index a6cb5c8..5e859dc 100644 --- a/examples/gui.ps1 +++ b/examples/gui.ps1 @@ -75,27 +75,19 @@ function Send-RconCommand() { param($rcon) $line = $OTB.Text - $line | Write-Debug - if ($line -in @('fast_restart', 'map_rotate', 'map_restart')) { - $RLbl.Text = '' - $cmd = $line -replace '(?:^|_)(\p{L})', { $_.Groups[1].Value.ToUpper() } - $rcon.$cmd() - } - elseif ($line.StartsWith('map mp_')) { - $RLbl.Text = '' - $mapname = $line.Split()[1] - $rcon.SetMap($mapname) - } - else { - $resp = $rcon.Send($line) - } + Write-Debug "Sending command: $line" + $resp = $rcon.Send($line) if ($resp -match '^["](?[a-z_]+)["]\sis[:]\s["](?.*?)\^7["]\s') { - $RLbl.Text = $Matches.name + ': ' + $Matches.value + $RLbl.Text = Remove-ColourCodes "$($Matches.name): $($Matches.value)" } $OTB.Text = '' } +function Remove-ColourCodes($str) { + return $str -replace '\^[0-9]', '' +} + function Get-ConnFromPSD1 { $configpath = Join-Path $PSScriptRoot 'config.psd1'