Skip to content

Commit 847921a

Browse files
committed
proof of concept pseudocode
1 parent 25c8f63 commit 847921a

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

META6.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"license": "BSD-3-Clause",
3+
"repo-type": "git",
4+
"source-url": "git@github.com:shuppet/p6-net-rcon.git",
5+
"auth": "github:shuppet",
6+
"depends": [
7+
"IO::Socket::INET"
8+
],
9+
"provides": {
10+
"Net::RCON": "lib/API/RCON.pm6"
11+
},
12+
"name": "Net::RCON",
13+
"description": "Perl 6 module for interacting with the Source RCON (remote console) protocol.",
14+
"perl": "6.c",
15+
"version": "0.0.1",
16+
"authors": [
17+
"Kane 'kawaii' Valentine <kane@cute.im>"
18+
]
19+
}

lib/Net/RCON.pm6

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
unit class Net::RCON;
2+
3+
use IO::Socket::INET;
4+
use experimental :pack;
5+
6+
constant {
7+
SERVERDATA_RESPONSE_VALUE => 0,
8+
SERVERDATA_AUTH_RESPONSE => 2,
9+
SERVERDATA_EXECCOMMAND => 2,
10+
SERVERDATA_AUTH => 3
11+
};
12+
13+
sub connect(:$hostname, :$port, :$password) {
14+
15+
my %arguments = host => $hostname || "localhost",
16+
port => $port || 27015,
17+
id => 0,
18+
;
19+
20+
my $socket = IO::Socket::INET.new(:%arguments<hostname>, :%arguments<port>);
21+
my $connection = $socket.accept;
22+
23+
authenticate(:$connection, :$password);
24+
}
25+
26+
sub authenticate(:$connection, :$password) {
27+
28+
my $type = SERVERDATA_AUTH;
29+
my $data = $password;
30+
31+
send(:$connection, :$type, :$data);
32+
}
33+
34+
sub send(:$connection, :$type, :$data) {
35+
36+
my $payload = pack("VV", 1, $type) ~ $data ~ pack("xx");
37+
$payload = pack("V", $payload.bytes) ~ $payload;
38+
39+
$connection.write($payload);
40+
}
41+
42+
sub recieve() {
43+
44+
}

0 commit comments

Comments
 (0)