Skip to content

Instantly share code, notes, and snippets.

@FCO
Created March 8, 2019 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FCO/da5f95e4a4be7b5f278e8e57f3778b3e to your computer and use it in GitHub Desktop.
Save FCO/da5f95e4a4be7b5f278e8e57f3778b3e to your computer and use it in GitHub Desktop.
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