mirror of
https://github.com/onyx-and-iris/q3rcon-ps.git
synced 2025-04-19 20:13:48 +01:00
Compare commits
3 Commits
cb7c7b2e04
...
61f7afb9f7
Author | SHA1 | Date | |
---|---|---|---|
61f7afb9f7 | |||
4966bee0b8 | |||
a9ccdb0c19 |
@ -1,3 +1,8 @@
|
||||
[cmdletbinding()]
|
||||
param()
|
||||
|
||||
Import-Module ../lib/Q3Rcon.psm1
|
||||
|
||||
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
|
||||
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
|
||||
|
||||
@ -9,7 +14,7 @@ $Lbl = New-Object System.Windows.Forms.Label
|
||||
Function InitForm {
|
||||
$form = New-Object System.Windows.Forms.Form
|
||||
$form.Text = "Q3Rcon Client"
|
||||
$form.Size = New-Object System.Drawing.Size(300, 200)
|
||||
$form.Size = New-Object System.Drawing.Size(275, 200)
|
||||
$form.StartPosition = "CenterScreen"
|
||||
return $form
|
||||
}
|
||||
@ -20,7 +25,7 @@ Function AddOkButton {
|
||||
$OKB.Location = New-Object System.Drawing.Size(65, 100)
|
||||
$OKB.Size = New-Object System.Drawing.Size(65, 23)
|
||||
$OKB.Text = "Send"
|
||||
$OKB.Add_Click({ $rcon.Send($OTB.Text) })
|
||||
$OKB.Add_Click({ SendRconCommand -rcon $rcon })
|
||||
$form.Controls.Add($OKB)
|
||||
}
|
||||
|
||||
@ -39,9 +44,16 @@ Function AddLabel($form) {
|
||||
$form.Controls.Add($Lbl)
|
||||
}
|
||||
|
||||
Function AddTextBox($form) {
|
||||
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) {
|
||||
SendRconCommand -rcon $rcon
|
||||
}
|
||||
})
|
||||
$form.Controls.Add($OTB)
|
||||
}
|
||||
|
||||
@ -50,6 +62,12 @@ Function FinalizeForm($form) {
|
||||
$form.Add_Shown({ $form.Activate() })
|
||||
}
|
||||
|
||||
Function SendRconCommand() {
|
||||
param($rcon)
|
||||
|
||||
$rcon.Send($OTB.Text)
|
||||
$OTB.Text = ""
|
||||
}
|
||||
|
||||
|
||||
Function Get-ConnFromPSD1 {
|
||||
@ -57,20 +75,27 @@ Function Get-ConnFromPSD1 {
|
||||
return Import-PowerShellDataFile -Path $configpath
|
||||
}
|
||||
|
||||
try {
|
||||
$conn = Get-ConnFromPSD1
|
||||
$rcon = Connect-Rcon -hostname $conn.host -port $conn.port -passwd $conn.passwd
|
||||
Write-Host $rcon.base.ToString() -ForegroundColor Green
|
||||
Function Main {
|
||||
try {
|
||||
$conn = Get-ConnFromPSD1
|
||||
$rcon = Connect-Rcon -hostname $conn.host -port $conn.port -passwd $conn.passwd
|
||||
Write-Host $rcon.base.ToString() -ForegroundColor Green
|
||||
|
||||
$form = InitForm
|
||||
AddOkButton -form $form -rcon $rcon
|
||||
AddCloseButton($form)
|
||||
AddLabel($form)
|
||||
AddTextBox($form)
|
||||
FinalizeForm($form)
|
||||
$form = InitForm
|
||||
AddOkButton -form $form -rcon $rcon
|
||||
AddCloseButton($form)
|
||||
AddLabel($form)
|
||||
AddTextBox -form $form -rcon $rcon
|
||||
FinalizeForm($form)
|
||||
|
||||
[void] $form.ShowDialog()
|
||||
}
|
||||
finally {
|
||||
Disconnect-Rcon -rcon $rcon
|
||||
[void] $form.ShowDialog()
|
||||
}
|
||||
finally {
|
||||
Disconnect-Rcon -rcon $rcon
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($MyInvocation.InvocationName -ne '.') {
|
||||
Main
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user