mirror of
https://github.com/onyx-and-iris/q3rcon-ps.git
synced 2025-04-20 04:23:47 +01:00
Compare commits
No commits in common. "ea776fd93f124dcebbe9772571cdff03bcbacd0a" and "0e5ee0e52309fccf669d47e74b1229c5cfd4f468" have entirely different histories.
ea776fd93f
...
0e5ee0e523
@ -12,7 +12,7 @@ $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 InitForm {
|
||||
$form = New-Object System.Windows.Forms.Form
|
||||
$form.Text = "Q3Rcon Client"
|
||||
$form.Size = New-Object System.Drawing.Size(275, 200)
|
||||
@ -20,17 +20,17 @@ Function New-Form {
|
||||
return $form
|
||||
}
|
||||
|
||||
Function Add-OkButton {
|
||||
Function AddOkButton {
|
||||
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.Add_Click({ Send-RconCommand -rcon $rcon })
|
||||
$OKB.Add_Click({ SendRconCommand -rcon $rcon })
|
||||
$form.Controls.Add($OKB)
|
||||
}
|
||||
|
||||
Function Add-CloseButton($form) {
|
||||
Function AddCloseButton($form) {
|
||||
$CAB.Location = New-Object System.Drawing.Size(140, 100)
|
||||
$CAB.Size = New-Object System.Drawing.Size(65, 23)
|
||||
$CAB.Text = "Close"
|
||||
@ -38,40 +38,39 @@ Function Add-CloseButton($form) {
|
||||
$form.Controls.Add($CAB)
|
||||
}
|
||||
|
||||
Function Add-Label($form) {
|
||||
Function AddLabel($form) {
|
||||
$Lbl.Location = New-Object System.Drawing.Size(10, 20)
|
||||
$Lbl.Size = New-Object System.Drawing.Size(260, 20)
|
||||
$Lbl.Text = "Input Rcon Command:"
|
||||
$form.Controls.Add($Lbl)
|
||||
}
|
||||
|
||||
Function Add-TextBox {
|
||||
Function AddTextBox {
|
||||
param($form, $rcon)
|
||||
|
||||
$OTB.Location = New-Object System.Drawing.Size(10, 50)
|
||||
$OTB.Size = New-Object System.Drawing.Size(240, 20)
|
||||
$OTB.Add_KeyDown({
|
||||
if ($_.KeyCode -eq [System.Windows.Forms.Keys]::Enter) {
|
||||
Send-RconCommand -rcon $rcon
|
||||
SendRconCommand -rcon $rcon
|
||||
}
|
||||
})
|
||||
$form.Controls.Add($OTB)
|
||||
}
|
||||
|
||||
Function Add-ResponseLabel($form) {
|
||||
Function AddResponseLabel($form) {
|
||||
$RLbl.Location = New-Object System.Drawing.Size(10, 75)
|
||||
$RLbl.Size = New-Object System.Drawing.Size(260, 20)
|
||||
$RLbl.Text = ""
|
||||
$form.Controls.Add($RLbl)
|
||||
}
|
||||
|
||||
Function Start-Form($form) {
|
||||
Function FinalizeForm($form) {
|
||||
$form.Topmost = $true
|
||||
$form.Add_Shown({ $form.Activate() })
|
||||
[void] $form.ShowDialog()
|
||||
$form.Add_Shown({ $form.Activate() })
|
||||
}
|
||||
|
||||
Function Send-RconCommand() {
|
||||
Function SendRconCommand() {
|
||||
param($rcon)
|
||||
|
||||
$line = $OTB.Text
|
||||
@ -90,7 +89,7 @@ Function Send-RconCommand() {
|
||||
$resp = $rcon.Send($line)
|
||||
}
|
||||
|
||||
if ($resp -match '^["](?<name>[a-z_]+)["]\sis[:]\s["](?<value>.*?)\^7["]\s') {
|
||||
if ($resp -match '^["](?<name>[a-z_]+)["]\sis[:]\s["](?<value>[A-Za-z_]+)\^7["]\s') {
|
||||
$RLbl.Text = $Matches.name + ": " + $Matches.value
|
||||
}
|
||||
$OTB.Text = ""
|
||||
@ -103,22 +102,22 @@ Function Get-ConnFromPSD1 {
|
||||
}
|
||||
|
||||
Function Main {
|
||||
BEGIN {
|
||||
try {
|
||||
$conn = Get-ConnFromPSD1
|
||||
$rcon = Connect-Rcon -hostname $conn.host -port $conn.port -passwd $conn.passwd
|
||||
Write-Host $rcon.base.ToString() -ForegroundColor Green
|
||||
|
||||
$form = New-Form
|
||||
Add-OkButton -form $form -rcon $rcon
|
||||
Add-CloseButton($form)
|
||||
Add-Label($form)
|
||||
Add-ResponseLabel($form)
|
||||
Add-TextBox -form $form -rcon $rcon
|
||||
$form = InitForm
|
||||
AddOkButton -form $form -rcon $rcon
|
||||
AddCloseButton($form)
|
||||
AddLabel($form)
|
||||
AddResponseLabel($form)
|
||||
AddTextBox -form $form -rcon $rcon
|
||||
FinalizeForm($form)
|
||||
|
||||
[void] $form.ShowDialog()
|
||||
}
|
||||
PROCESS {
|
||||
Start-Form($form)
|
||||
}
|
||||
END {
|
||||
finally {
|
||||
Disconnect-Rcon -rcon $rcon
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
[cmdletbinding()]
|
||||
param()
|
||||
|
||||
Import-Module ../lib/Q3Rcon.psm1
|
||||
|
||||
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 Send-Message {
|
||||
param($rcon)
|
||||
|
||||
$msg = Get-DadJoke
|
||||
$msg | Write-Debug
|
||||
$rcon.Say($msg)
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$conn = Get-ConnFromPSD1
|
||||
$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
|
||||
Start-Sleep -Seconds 10
|
||||
} until ($stopWatch.Elapsed -ge $timeSpan)
|
||||
$stopWatch.Stop()
|
||||
}
|
||||
finally {
|
||||
Disconnect-Rcon -rcon $rcon
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user