mirror of
https://github.com/onyx-and-iris/q3rcon-ps.git
synced 2026-02-21 00:59:11 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5192c9f694 | |||
| eeae1c76b4 | |||
| fa02d0c65e | |||
| 9209c705ce | |||
| cb90ad8030 |
@ -38,16 +38,14 @@ finally {
|
|||||||
|
|
||||||
## Rcon Class
|
## Rcon Class
|
||||||
|
|
||||||
#### `Send($cmd) | Send($cmd, $timeout)`
|
#### `Send($cmd)`
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
$rcon.Send("mapname")
|
$rcon.Send("mapname")
|
||||||
|
|
||||||
$rcon.Send("g_gametype dm")
|
$rcon.Send("g_gametype dm")
|
||||||
|
|
||||||
$rcon.Send("map_rotate", 2000)
|
$rcon.Send("map_rotate")
|
||||||
```
|
```
|
||||||
|
|
||||||
If the command returns a response it will be printed to the console.
|
If the command returns a response it will be printed to the console.
|
||||||
|
|
||||||
Pass an optional timeout (ms) for commands that return responses in fragments. (status, map_rotate etc...)
|
|
||||||
|
|||||||
15
Taskfile.yml
Normal file
15
Taskfile.yml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
bump:
|
||||||
|
desc: 'Bump the module version in the .psd1 file. Usage: "task bump -- show" or "task bump -- [patch|minor|major]".'
|
||||||
|
preconditions:
|
||||||
|
- sh: 'pwsh -c "if (Get-Command bump) { exit 0 } else { exit 1 }"'
|
||||||
|
msg: "The 'bump' command is not available. Please install the required tools to use this command."
|
||||||
|
cmds:
|
||||||
|
- |
|
||||||
|
{{if eq .CLI_ARGS "show"}}
|
||||||
|
pwsh -c "bump show -f lib/Q3Rcon.psd1 -p \"ModuleVersion\s*=\s'(\d+\.\d+\.\d+)'\""
|
||||||
|
{{else}}
|
||||||
|
pwsh -c "bump {{.CLI_ARGS}} -w -f lib/Q3Rcon.psd1 -p \"ModuleVersion\s*=\s'(\d+\.\d+\.\d+)'\""
|
||||||
|
{{end}}
|
||||||
@ -12,18 +12,13 @@ function Read-HostUntilEmpty {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($line -in @('fast_restart', 'map_rotate', 'map_restart')) {
|
$resp = $rcon.Send($line)
|
||||||
$cmd = $line -replace '(?:^|_)(\p{L})', { $_.Groups[1].Value.ToUpper() }
|
Write-Host (Remove-ColourCodes $resp)
|
||||||
$rcon.$cmd()
|
|
||||||
}
|
|
||||||
elseif ($line.StartsWith('map mp_')) {
|
|
||||||
$mapname = $line.Split()[1]
|
|
||||||
$rcon.SetMap($mapname)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$rcon.Send($line)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Remove-ColourCodes($str) {
|
||||||
|
return $str -replace '\^[0-9]', ''
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-ConnFromPSD1 {
|
function Get-ConnFromPSD1 {
|
||||||
|
|||||||
@ -75,27 +75,19 @@ function Send-RconCommand() {
|
|||||||
param($rcon)
|
param($rcon)
|
||||||
|
|
||||||
$line = $OTB.Text
|
$line = $OTB.Text
|
||||||
$line | Write-Debug
|
Write-Debug "Sending command: $line"
|
||||||
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)
|
$resp = $rcon.Send($line)
|
||||||
}
|
|
||||||
|
|
||||||
if ($resp -match '^["](?<name>[a-z_]+)["]\sis[:]\s["](?<value>.*?)\^7["]\s') {
|
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 = ''
|
$OTB.Text = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Remove-ColourCodes($str) {
|
||||||
|
return $str -replace '\^[0-9]', ''
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function Get-ConnFromPSD1 {
|
function Get-ConnFromPSD1 {
|
||||||
$configpath = Join-Path $PSScriptRoot 'config.psd1'
|
$configpath = Join-Path $PSScriptRoot 'config.psd1'
|
||||||
|
|||||||
@ -16,7 +16,7 @@ function Send-Message {
|
|||||||
param($rcon)
|
param($rcon)
|
||||||
|
|
||||||
$msg = Get-DadJoke
|
$msg = Get-DadJoke
|
||||||
$msg | Write-Debug
|
Write-Debug "Sending message: $msg"
|
||||||
$rcon.Say($msg)
|
$rcon.Say($msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,13 +25,7 @@ try {
|
|||||||
$conn = Get-ConnFromPSD1
|
$conn = Get-ConnFromPSD1
|
||||||
$rcon = Connect-Rcon -hostname $conn.host -port $conn.port -passwd $conn.passwd
|
$rcon = Connect-Rcon -hostname $conn.host -port $conn.port -passwd $conn.passwd
|
||||||
|
|
||||||
$stopWatch = [system.diagnostics.stopwatch]::StartNew()
|
|
||||||
$timeSpan = New-TimeSpan -Seconds 30
|
|
||||||
do {
|
|
||||||
Send-Message -rcon $rcon
|
Send-Message -rcon $rcon
|
||||||
Start-Sleep -Seconds 10
|
|
||||||
} until ($stopWatch.Elapsed -ge $timeSpan)
|
|
||||||
$stopWatch.Stop()
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
Disconnect-Rcon -rcon $rcon
|
Disconnect-Rcon -rcon $rcon
|
||||||
|
|||||||
@ -122,7 +122,7 @@ class Base {
|
|||||||
try {
|
try {
|
||||||
$bytesReceived = $this._socket.Receive($this._receiveBuffer)
|
$bytesReceived = $this._socket.Receive($this._receiveBuffer)
|
||||||
if ($bytesReceived -gt 0) {
|
if ($bytesReceived -gt 0) {
|
||||||
$dataStartIndex = [Math]::Min($headerLength, $bytesReceived)
|
$dataStartIndex = [Math]::Min($headerLength - 1, $bytesReceived)
|
||||||
$responseText = [System.Text.Encoding]::ASCII.GetString($this._receiveBuffer, $dataStartIndex, $bytesReceived - $dataStartIndex)
|
$responseText = [System.Text.Encoding]::ASCII.GetString($this._receiveBuffer, $dataStartIndex, $bytesReceived - $dataStartIndex)
|
||||||
$responseData.Append($responseText) | Out-Null
|
$responseData.Append($responseText) | Out-Null
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user