Created
March 8, 2019 08:41
-
-
Save FCO/da5f95e4a4be7b5f278e8e57f3778b3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit class Net::RCON; | |
use IO::Socket::INET; | |
use experimental :pack; | |
has Str $.host = "localhost"; | |
has UInt $.port = 27015; | |
has Str $.password is required; | |
has $!connection; | |
enum ServerData ( | |
RESPONSE_VALUE => 0, | |
AUTH_RESPONSE => 1, | |
EXECCOMMAND => 2, | |
AUTH => 3 | |
); | |
method connect { | |
my $socket = IO::Socket::INET.new: :$hostname, :$port; | |
$!connection = $socket.accept; | |
self.authenticate | |
} | |
method authenticate { | |
self.send: :type(AUTH), :data($!password) | |
} | |
method send(ServerData :$type, Str() :$data) { | |
my $payload = "{ pack "VV", 1, $type }{ $data }{ pack "xx" }"; | |
$payload [R~]= pack "V", $payload.bytes; | |
$!connection.write($payload); | |
} | |
method recieve() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment