the timeouts hash means we can simplify the logic in CLI, GUI examples

colour codes removed from response output.
This commit is contained in:
onyx-and-iris 2026-02-18 11:19:09 +00:00
parent 9209c705ce
commit fa02d0c65e
2 changed files with 13 additions and 26 deletions

View File

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

View File

@ -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 {
Write-Debug "Sending command: $line"
$resp = $rcon.Send($line)
}
if ($resp -match '^["](?<name>[a-z_]+)["]\sis[:]\s["](?<value>.*?)\^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'