initial commit

This commit is contained in:
2023-11-29 16:18:03 +00:00
commit 70f76797ea
7 changed files with 415 additions and 0 deletions

39
examples/cli.ps1 Normal file
View File

@@ -0,0 +1,39 @@
[cmdletbinding()]
param()
Import-Module ../lib/Q3Rcon.psm1
Function Read-HostUntilEmpty {
param([object]$rcon)
"Input 'Q' or <Enter> to exit."
while (($line = Read-Host -Prompt "Send command") -cne [string]::Empty) {
if ($line -eq "Q") {
break
}
if ($line -in @("fast_restart", "map_rotate", "map_restart")) {
$cmd = $line -replace '(?:^|_)(\p{L})', { $_.Groups[1].Value.ToUpper() }
$resp = $rcon.$cmd()
}
else {
$resp = $rcon.Send($line)
}
$resp | Write-Host
}
}
Function Get-ConnFromPSD1 {
$configpath = Join-Path $PSScriptRoot "config.psd1"
return Import-PowerShellDataFile -Path $configpath
}
try {
$conn = Get-ConnFromPSD1
$rcon = Connect-Rcon -hostname $conn.host -port $conn.port -passwd $conn.passwd
Read-HostUntilEmpty -rcon $rcon
}
finally {
Disconnect-Rcon -rcon $rcon
}

26
examples/commands.ps1 Normal file
View File

@@ -0,0 +1,26 @@
[cmdletbinding()]
param()
Import-Module ../lib/Q3Rcon.psm1
Function Get-ConnFromPSD1 {
$configpath = Join-Path $PSScriptRoot "config.psd1"
return Import-PowerShellDataFile -Path $configpath
}
try {
$conn = Get-ConnFromPSD1
$rcon = Connect-Rcon -hostname $conn.host -port $conn.port -passwd $conn.passwd
$rcon.Map()
"Rotating the map..."
$rcon.MapRotate()
Start-Sleep -Milliseconds 3000 # wait for map to rotate
$rcon.Map()
}
finally {
Disconnect-Rcon -rcon $rcon
}