mirror of
https://github.com/onyx-and-iris/q3rcon-ps.git
synced 2026-04-18 02:43:30 +00:00
initial commit
This commit is contained in:
39
examples/cli.ps1
Normal file
39
examples/cli.ps1
Normal 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
26
examples/commands.ps1
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user