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
b6fdf021b9
@ -3,20 +3,20 @@ param()
|
|||||||
|
|
||||||
Import-Module ../lib/Q3Rcon.psm1
|
Import-Module ../lib/Q3Rcon.psm1
|
||||||
|
|
||||||
Function Read-HostUntilEmpty {
|
function Read-HostUntilEmpty {
|
||||||
param([object]$rcon)
|
param([object]$rcon)
|
||||||
|
|
||||||
"Input 'Q' or <Enter> to exit."
|
"Input 'Q' or <Enter> to exit."
|
||||||
while (($line = Read-Host -Prompt "Send command") -cne [string]::Empty) {
|
while (($line = Read-Host -Prompt 'Send command') -cne [string]::Empty) {
|
||||||
if ($line -eq "Q") {
|
if ($line -eq 'Q') {
|
||||||
break
|
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() }
|
$cmd = $line -replace '(?:^|_)(\p{L})', { $_.Groups[1].Value.ToUpper() }
|
||||||
$rcon.$cmd()
|
$rcon.$cmd()
|
||||||
}
|
}
|
||||||
elseif ($line.StartsWith("map mp_")) {
|
elseif ($line.StartsWith('map mp_')) {
|
||||||
$mapname = $line.Split()[1]
|
$mapname = $line.Split()[1]
|
||||||
$rcon.SetMap($mapname)
|
$rcon.SetMap($mapname)
|
||||||
}
|
}
|
||||||
@ -26,8 +26,8 @@ Function Read-HostUntilEmpty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Get-ConnFromPSD1 {
|
function Get-ConnFromPSD1 {
|
||||||
$configpath = Join-Path $PSScriptRoot "config.psd1"
|
$configpath = Join-Path $PSScriptRoot 'config.psd1'
|
||||||
return Import-PowerShellDataFile -Path $configpath
|
return Import-PowerShellDataFile -Path $configpath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,8 +3,8 @@ param()
|
|||||||
|
|
||||||
Import-Module ../lib/Q3Rcon.psm1
|
Import-Module ../lib/Q3Rcon.psm1
|
||||||
|
|
||||||
Function Get-ConnFromPSD1 {
|
function Get-ConnFromPSD1 {
|
||||||
$configpath = Join-Path $PSScriptRoot "config.psd1"
|
$configpath = Join-Path $PSScriptRoot 'config.psd1'
|
||||||
return Import-PowerShellDataFile -Path $configpath
|
return Import-PowerShellDataFile -Path $configpath
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ try {
|
|||||||
|
|
||||||
$rcon.Map()
|
$rcon.Map()
|
||||||
|
|
||||||
"Rotating the map..."
|
'Rotating the map...'
|
||||||
$rcon.MapRotate()
|
$rcon.MapRotate()
|
||||||
|
|
||||||
Start-Sleep -Seconds 3 # wait for map to rotate
|
Start-Sleep -Seconds 3 # wait for map to rotate
|
||||||
|
|||||||
@ -3,8 +3,8 @@ param()
|
|||||||
|
|
||||||
Import-Module ../lib/Q3Rcon.psm1
|
Import-Module ../lib/Q3Rcon.psm1
|
||||||
|
|
||||||
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
|
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Drawing')
|
||||||
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
|
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
|
||||||
|
|
||||||
$OKB = New-Object System.Windows.Forms.Button
|
$OKB = New-Object System.Windows.Forms.Button
|
||||||
$OTB = New-Object System.Windows.Forms.TextBox
|
$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
|
$Lbl = New-Object System.Windows.Forms.Label
|
||||||
$RLbl = 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 = New-Object System.Windows.Forms.Form
|
||||||
$form.Text = "Q3Rcon Client"
|
$form.Text = 'Q3Rcon Client'
|
||||||
$form.Size = New-Object System.Drawing.Size(275, 200)
|
$form.Size = New-Object System.Drawing.Size(275, 200)
|
||||||
$form.StartPosition = "CenterScreen"
|
$form.StartPosition = 'CenterScreen'
|
||||||
return $form
|
return $form
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Add-OkButton {
|
function Add-OkButton {
|
||||||
param($form, $rcon)
|
param($form, $rcon)
|
||||||
|
|
||||||
$OKB.Location = New-Object System.Drawing.Size(65, 100)
|
$OKB.Location = New-Object System.Drawing.Size(65, 100)
|
||||||
$OKB.Size = New-Object System.Drawing.Size(65, 23)
|
$OKB.Size = New-Object System.Drawing.Size(65, 23)
|
||||||
$OKB.Text = "Send"
|
$OKB.Text = 'Send'
|
||||||
$OKB.Add_Click({ Send-RconCommand -rcon $rcon })
|
$OKB.Add_Click({ Send-RconCommand -rcon $rcon })
|
||||||
$form.Controls.Add($OKB)
|
$form.Controls.Add($OKB)
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Add-CloseButton($form) {
|
function Add-CloseButton($form) {
|
||||||
$CAB.Location = New-Object System.Drawing.Size(140, 100)
|
$CAB.Location = New-Object System.Drawing.Size(140, 100)
|
||||||
$CAB.Size = New-Object System.Drawing.Size(65, 23)
|
$CAB.Size = New-Object System.Drawing.Size(65, 23)
|
||||||
$CAB.Text = "Close"
|
$CAB.Text = 'Close'
|
||||||
$CAB.Add_Click({ Write-Host "Disconnecting from Rcon" -ForegroundColor Green; $form.Close() })
|
$CAB.Add_Click({ Write-Host 'Disconnecting from Rcon' -ForegroundColor Green; $form.Close() })
|
||||||
$form.Controls.Add($CAB)
|
$form.Controls.Add($CAB)
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Add-Label($form) {
|
function Add-Label($form) {
|
||||||
$Lbl.Location = New-Object System.Drawing.Size(10, 20)
|
$Lbl.Location = New-Object System.Drawing.Size(10, 20)
|
||||||
$Lbl.Size = New-Object System.Drawing.Size(260, 20)
|
$Lbl.Size = New-Object System.Drawing.Size(260, 20)
|
||||||
$Lbl.Text = "Input Rcon Command:"
|
$Lbl.Text = 'Input Rcon Command:'
|
||||||
$form.Controls.Add($Lbl)
|
$form.Controls.Add($Lbl)
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Add-TextBox {
|
function Add-TextBox {
|
||||||
param($form, $rcon)
|
param($form, $rcon)
|
||||||
|
|
||||||
$OTB.Location = New-Object System.Drawing.Size(10, 50)
|
$OTB.Location = New-Object System.Drawing.Size(10, 50)
|
||||||
@ -58,31 +58,31 @@ Function Add-TextBox {
|
|||||||
$form.Controls.Add($OTB)
|
$form.Controls.Add($OTB)
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Add-ResponseLabel($form) {
|
function Add-ResponseLabel($form) {
|
||||||
$RLbl.Location = New-Object System.Drawing.Size(10, 75)
|
$RLbl.Location = New-Object System.Drawing.Size(10, 75)
|
||||||
$RLbl.Size = New-Object System.Drawing.Size(260, 20)
|
$RLbl.Size = New-Object System.Drawing.Size(260, 20)
|
||||||
$RLbl.Text = ""
|
$RLbl.Text = ''
|
||||||
$form.Controls.Add($RLbl)
|
$form.Controls.Add($RLbl)
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Start-Form($form) {
|
function Start-Form($form) {
|
||||||
$form.Topmost = $true
|
$form.Topmost = $true
|
||||||
$form.Add_Shown({ $form.Activate() })
|
$form.Add_Shown({ $form.Activate() })
|
||||||
[void] $form.ShowDialog()
|
[void] $form.ShowDialog()
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Send-RconCommand() {
|
function Send-RconCommand() {
|
||||||
param($rcon)
|
param($rcon)
|
||||||
|
|
||||||
$line = $OTB.Text
|
$line = $OTB.Text
|
||||||
$line | Write-Debug
|
$line | Write-Debug
|
||||||
if ($line -in @("fast_restart", "map_rotate", "map_restart")) {
|
if ($line -in @('fast_restart', 'map_rotate', 'map_restart')) {
|
||||||
$RLbl.Text = ""
|
$RLbl.Text = ''
|
||||||
$cmd = $line -replace '(?:^|_)(\p{L})', { $_.Groups[1].Value.ToUpper() }
|
$cmd = $line -replace '(?:^|_)(\p{L})', { $_.Groups[1].Value.ToUpper() }
|
||||||
$rcon.$cmd()
|
$rcon.$cmd()
|
||||||
}
|
}
|
||||||
elseif ($line.StartsWith("map mp_")) {
|
elseif ($line.StartsWith('map mp_')) {
|
||||||
$RLbl.Text = ""
|
$RLbl.Text = ''
|
||||||
$mapname = $line.Split()[1]
|
$mapname = $line.Split()[1]
|
||||||
$rcon.SetMap($mapname)
|
$rcon.SetMap($mapname)
|
||||||
}
|
}
|
||||||
@ -91,19 +91,19 @@ Function Send-RconCommand() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 = $Matches.name + ': ' + $Matches.value
|
||||||
}
|
}
|
||||||
$OTB.Text = ""
|
$OTB.Text = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Function Get-ConnFromPSD1 {
|
function Get-ConnFromPSD1 {
|
||||||
$configpath = Join-Path $PSScriptRoot "config.psd1"
|
$configpath = Join-Path $PSScriptRoot 'config.psd1'
|
||||||
return Import-PowerShellDataFile -Path $configpath
|
return Import-PowerShellDataFile -Path $configpath
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Main {
|
function Main {
|
||||||
BEGIN {
|
begin {
|
||||||
$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
|
||||||
Write-Host $rcon.base.ToString() -ForegroundColor Green
|
Write-Host $rcon.base.ToString() -ForegroundColor Green
|
||||||
@ -115,10 +115,10 @@ Function Main {
|
|||||||
Add-ResponseLabel($form)
|
Add-ResponseLabel($form)
|
||||||
Add-TextBox -form $form -rcon $rcon
|
Add-TextBox -form $form -rcon $rcon
|
||||||
}
|
}
|
||||||
PROCESS {
|
process {
|
||||||
Start-Form($form)
|
Start-Form($form)
|
||||||
}
|
}
|
||||||
END {
|
end {
|
||||||
Disconnect-Rcon -rcon $rcon
|
Disconnect-Rcon -rcon $rcon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,16 +3,16 @@ param()
|
|||||||
|
|
||||||
Import-Module ../lib/Q3Rcon.psm1
|
Import-Module ../lib/Q3Rcon.psm1
|
||||||
|
|
||||||
Function Get-ConnFromPSD1 {
|
function Get-ConnFromPSD1 {
|
||||||
$configpath = Join-Path $PSScriptRoot "config.psd1"
|
$configpath = Join-Path $PSScriptRoot 'config.psd1'
|
||||||
return Import-PowerShellDataFile -Path $configpath
|
return Import-PowerShellDataFile -Path $configpath
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Get-DadJoke {
|
function Get-DadJoke {
|
||||||
Invoke-WebRequest -Uri "https://icanhazdadjoke.com" -Headers @{accept = "application/json" } | Select-Object -ExpandProperty Content | ConvertFrom-Json | Select-Object -ExpandProperty Joke
|
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)
|
param($rcon)
|
||||||
|
|
||||||
$msg = Get-DadJoke
|
$msg = Get-DadJoke
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user