mirror of
https://github.com/onyx-and-iris/q3rcon-ps.git
synced 2026-02-21 00:59:11 +00:00
run formatter on examples
This commit is contained in:
parent
2800cbbcd2
commit
1d09c015c3
@ -3,20 +3,20 @@ param()
|
||||
|
||||
Import-Module ../lib/Q3Rcon.psm1
|
||||
|
||||
Function Read-HostUntilEmpty {
|
||||
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") {
|
||||
while (($line = Read-Host -Prompt 'Send command') -cne [string]::Empty) {
|
||||
if ($line -eq 'Q') {
|
||||
break
|
||||
}
|
||||
|
||||
if ($line -in @("fast_restart", "map_rotate", "map_restart")) {
|
||||
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_")) {
|
||||
elseif ($line.StartsWith('map mp_')) {
|
||||
$mapname = $line.Split()[1]
|
||||
$rcon.SetMap($mapname)
|
||||
}
|
||||
@ -26,8 +26,8 @@ Function Read-HostUntilEmpty {
|
||||
}
|
||||
}
|
||||
|
||||
Function Get-ConnFromPSD1 {
|
||||
$configpath = Join-Path $PSScriptRoot "config.psd1"
|
||||
function Get-ConnFromPSD1 {
|
||||
$configpath = Join-Path $PSScriptRoot 'config.psd1'
|
||||
return Import-PowerShellDataFile -Path $configpath
|
||||
}
|
||||
|
||||
|
||||
@ -3,8 +3,8 @@ param()
|
||||
|
||||
Import-Module ../lib/Q3Rcon.psm1
|
||||
|
||||
Function Get-ConnFromPSD1 {
|
||||
$configpath = Join-Path $PSScriptRoot "config.psd1"
|
||||
function Get-ConnFromPSD1 {
|
||||
$configpath = Join-Path $PSScriptRoot 'config.psd1'
|
||||
return Import-PowerShellDataFile -Path $configpath
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ try {
|
||||
|
||||
$rcon.Map()
|
||||
|
||||
"Rotating the map..."
|
||||
'Rotating the map...'
|
||||
$rcon.MapRotate()
|
||||
|
||||
Start-Sleep -Seconds 3 # wait for map to rotate
|
||||
|
||||
@ -3,8 +3,8 @@ param()
|
||||
|
||||
Import-Module ../lib/Q3Rcon.psm1
|
||||
|
||||
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
|
||||
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
|
||||
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Drawing')
|
||||
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
|
||||
|
||||
$OKB = New-Object System.Windows.Forms.Button
|
||||
$OTB = New-Object System.Windows.Forms.TextBox
|
||||
@ -12,40 +12,40 @@ $CAB = New-Object System.Windows.Forms.Button
|
||||
$Lbl = New-Object System.Windows.Forms.Label
|
||||
$RLbl = New-Object System.Windows.Forms.Label
|
||||
|
||||
Function New-Form {
|
||||
function New-Form {
|
||||
$form = New-Object System.Windows.Forms.Form
|
||||
$form.Text = "Q3Rcon Client"
|
||||
$form.Text = 'Q3Rcon Client'
|
||||
$form.Size = New-Object System.Drawing.Size(275, 200)
|
||||
$form.StartPosition = "CenterScreen"
|
||||
$form.StartPosition = 'CenterScreen'
|
||||
return $form
|
||||
}
|
||||
|
||||
Function Add-OkButton {
|
||||
function Add-OkButton {
|
||||
param($form, $rcon)
|
||||
|
||||
$OKB.Location = New-Object System.Drawing.Size(65, 100)
|
||||
$OKB.Size = New-Object System.Drawing.Size(65, 23)
|
||||
$OKB.Text = "Send"
|
||||
$OKB.Text = 'Send'
|
||||
$OKB.Add_Click({ Send-RconCommand -rcon $rcon })
|
||||
$form.Controls.Add($OKB)
|
||||
}
|
||||
|
||||
Function Add-CloseButton($form) {
|
||||
function Add-CloseButton($form) {
|
||||
$CAB.Location = New-Object System.Drawing.Size(140, 100)
|
||||
$CAB.Size = New-Object System.Drawing.Size(65, 23)
|
||||
$CAB.Text = "Close"
|
||||
$CAB.Add_Click({ Write-Host "Disconnecting from Rcon" -ForegroundColor Green; $form.Close() })
|
||||
$CAB.Text = 'Close'
|
||||
$CAB.Add_Click({ Write-Host 'Disconnecting from Rcon' -ForegroundColor Green; $form.Close() })
|
||||
$form.Controls.Add($CAB)
|
||||
}
|
||||
|
||||
Function Add-Label($form) {
|
||||
function Add-Label($form) {
|
||||
$Lbl.Location = New-Object System.Drawing.Size(10, 20)
|
||||
$Lbl.Size = New-Object System.Drawing.Size(260, 20)
|
||||
$Lbl.Text = "Input Rcon Command:"
|
||||
$Lbl.Text = 'Input Rcon Command:'
|
||||
$form.Controls.Add($Lbl)
|
||||
}
|
||||
|
||||
Function Add-TextBox {
|
||||
function Add-TextBox {
|
||||
param($form, $rcon)
|
||||
|
||||
$OTB.Location = New-Object System.Drawing.Size(10, 50)
|
||||
@ -58,31 +58,31 @@ Function Add-TextBox {
|
||||
$form.Controls.Add($OTB)
|
||||
}
|
||||
|
||||
Function Add-ResponseLabel($form) {
|
||||
function Add-ResponseLabel($form) {
|
||||
$RLbl.Location = New-Object System.Drawing.Size(10, 75)
|
||||
$RLbl.Size = New-Object System.Drawing.Size(260, 20)
|
||||
$RLbl.Text = ""
|
||||
$RLbl.Text = ''
|
||||
$form.Controls.Add($RLbl)
|
||||
}
|
||||
|
||||
Function Start-Form($form) {
|
||||
function Start-Form($form) {
|
||||
$form.Topmost = $true
|
||||
$form.Add_Shown({ $form.Activate() })
|
||||
[void] $form.ShowDialog()
|
||||
}
|
||||
|
||||
Function Send-RconCommand() {
|
||||
function Send-RconCommand() {
|
||||
param($rcon)
|
||||
|
||||
$line = $OTB.Text
|
||||
$line | Write-Debug
|
||||
if ($line -in @("fast_restart", "map_rotate", "map_restart")) {
|
||||
$RLbl.Text = ""
|
||||
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 = ""
|
||||
elseif ($line.StartsWith('map mp_')) {
|
||||
$RLbl.Text = ''
|
||||
$mapname = $line.Split()[1]
|
||||
$rcon.SetMap($mapname)
|
||||
}
|
||||
@ -91,19 +91,19 @@ Function Send-RconCommand() {
|
||||
}
|
||||
|
||||
if ($resp -match '^["](?<name>[a-z_]+)["]\sis[:]\s["](?<value>.*?)\^7["]\s') {
|
||||
$RLbl.Text = $Matches.name + ": " + $Matches.value
|
||||
$RLbl.Text = $Matches.name + ': ' + $Matches.value
|
||||
}
|
||||
$OTB.Text = ""
|
||||
$OTB.Text = ''
|
||||
}
|
||||
|
||||
|
||||
Function Get-ConnFromPSD1 {
|
||||
$configpath = Join-Path $PSScriptRoot "config.psd1"
|
||||
function Get-ConnFromPSD1 {
|
||||
$configpath = Join-Path $PSScriptRoot 'config.psd1'
|
||||
return Import-PowerShellDataFile -Path $configpath
|
||||
}
|
||||
|
||||
Function Main {
|
||||
BEGIN {
|
||||
function Main {
|
||||
begin {
|
||||
$conn = Get-ConnFromPSD1
|
||||
$rcon = Connect-Rcon -hostname $conn.host -port $conn.port -passwd $conn.passwd
|
||||
Write-Host $rcon.base.ToString() -ForegroundColor Green
|
||||
@ -115,10 +115,10 @@ Function Main {
|
||||
Add-ResponseLabel($form)
|
||||
Add-TextBox -form $form -rcon $rcon
|
||||
}
|
||||
PROCESS {
|
||||
process {
|
||||
Start-Form($form)
|
||||
}
|
||||
END {
|
||||
end {
|
||||
Disconnect-Rcon -rcon $rcon
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,16 +3,16 @@ param()
|
||||
|
||||
Import-Module ../lib/Q3Rcon.psm1
|
||||
|
||||
Function Get-ConnFromPSD1 {
|
||||
$configpath = Join-Path $PSScriptRoot "config.psd1"
|
||||
function Get-ConnFromPSD1 {
|
||||
$configpath = Join-Path $PSScriptRoot 'config.psd1'
|
||||
return Import-PowerShellDataFile -Path $configpath
|
||||
}
|
||||
|
||||
Function Get-DadJoke {
|
||||
Invoke-WebRequest -Uri "https://icanhazdadjoke.com" -Headers @{accept = "application/json" } | Select-Object -ExpandProperty Content | ConvertFrom-Json | Select-Object -ExpandProperty Joke
|
||||
function Get-DadJoke {
|
||||
Invoke-WebRequest -Uri 'https://icanhazdadjoke.com' -Headers @{accept = 'application/json' } | Select-Object -ExpandProperty Content | ConvertFrom-Json | Select-Object -ExpandProperty Joke
|
||||
}
|
||||
|
||||
Function Send-Message {
|
||||
function Send-Message {
|
||||
param($rcon)
|
||||
|
||||
$msg = Get-DadJoke
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user