And yes, I am sending this over a network. I am going to
Depends on the protocol you are using. That should specify how things get
interpreted at both ends of the connection.
It's a TCP/IP connection. Here's the whole script (with my notes):
#!/usr/bin/perl -w
use strict;
use IO::Socket;
# Connect to the rcon server
print "Connecting to server ... ";
my $sock = new IO::Socket::INET(PeerAddr => '209.209.44.30', PeerPort =>
'27015', proto => 'tcp',);
if (!$sock) {
die "Unable to connect $@\n";
}
print "done\n";
# Now we send something
# The packet structure is as follows:
#
# PACKET {
# 32bits size; # This is the size of the data to follow
# # The 32 bits packet size is not included
# 32bits requestid; # The request identifier. This can be a continuously
# # incrementing value (I think) Used to map responses
# # with requests, (I think).
# 32bits commandid # This rells the server which type of request we are
# # makeing In the example it is a LOGIN #3
#
# Random amounts and types of data follow. The types are allways constant
# for a particular command id.
# };
#
# Note 1 32bit integer would be a size 4. Four * 8 bits.
# A char is 1 8 bits to represent the entire ascii table
#
# The example packet was a login packet #3 with the following structure
#
# COMMAND_LOGIN {
# 32bits size = (requestid + commandid + password + unknown)
# (4 + 4 + (8 + 1) + (0 + 1)) # We count the null char.
# 18; # * 8 bits
# 32bits request = 1; # next is 2, 3....
# 32bits command = 3; # COMMAND_LOGIN
# null terminated char = "password\0"; # \0 == null
# null terminated char = "\0"; #
# };
#
#
# Pack packs the data according to a format string
# integer,integer,integer,null terminated string,null terminated string
print "Constructing packet ... ";
my $login_packet = pack('iiiZ*Z*', 18, 1, 3, 'password', '');
print "done: $login_packet\n";
# Send on the wire
print "Sending packet ... ";
print $sock $login_packet;
print "done\n";
# Dirty hack from Alfred_Reynolds program
# sleep(1);
print "Waiting for response ... ";
my $buf;
if (!$sock->recv($buf, 4)) {
die "bad recv $@\n";
}
my $response_size = unpack("i", $buf);
if (!$sock->recv($buf, $response_size)) {
die "bad recv $@\n";
}
my ($request_id, $command_response, $string1, $string2) = unpack("iiaa",
$buf);
print "received: $request_id, $command_response, $string1, $string2\n";
exit(0);