q3rcon-ps/lib/packet.ps1

38 lines
826 B
PowerShell
Raw Permalink Normal View History

2023-11-29 16:18:03 +00:00
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()
}