mirror of
https://github.com/onyx-and-iris/q3rcon-ps.git
synced 2026-02-21 00:59:11 +00:00
Base class now implements the IDisposable interface improved error handling
38 lines
826 B
PowerShell
38 lines
826 B
PowerShell
class Packet {
|
|
[System.Byte[]]$MAGIC = @(, 0xFF * 4)
|
|
|
|
[string] Header() {
|
|
throw 'method not implemented'
|
|
}
|
|
}
|
|
|
|
class RequestPacket : Packet {
|
|
[string]$passwd
|
|
|
|
RequestPacket([string]$passwd) {
|
|
$this.passwd = $passwd
|
|
}
|
|
|
|
[System.Byte[]] Header() {
|
|
return $this.MAGIC + [System.Text.Encoding]::ASCII.GetBytes('rcon')
|
|
}
|
|
|
|
[System.Byte[]] Payload([string]$msg) {
|
|
return $this.Header() + [System.Text.Encoding]::ASCII.GetBytes($(' {0} {1}' -f $this.passwd, $msg))
|
|
}
|
|
}
|
|
|
|
class ResponsePacket : Packet {
|
|
[System.Byte[]] Header() {
|
|
return $this.MAGIC + [System.Text.Encoding]::ASCII.GetBytes('print\n')
|
|
}
|
|
}
|
|
|
|
function New-RequestPacket([string]$passwd) {
|
|
[RequestPacket]::new($passwd)
|
|
}
|
|
|
|
function New-ResponsePacket {
|
|
[ResponsePacket]::new()
|
|
}
|