Rcon Perl Script
André Rivotti Casimiro
rivotti at netcabo.pt
Thu Oct 24 02:07:54 EDT 2002
Hi all,
I'm trying to write a perl script that connects to a mohaa server and
executes simple commands and return text. I need this because I'm developing
a tool to use the browser to show status, kick players, etc. I've been
reading a lot of documentation regarding this matter and I stardet to
script.
#!/usr/bin/perl
use IO::Socket;
use strict;
my $resp = undef;
my $num = undef;
my $addr = "193.126.109.33";
my $port = 12203;
my $pass = "";
# create socket connection to server
my $sock = IO::Socket::INET->new(
PeerAddr => $addr,
PeerPort => $port,
Proto => 'udp'
);
print "Socket could not be created: $!\n\n" unless $sock;
$sock->send("\xFF\xFF\xFF\xFFchallenge rcon\n");
if (defined($sock->recv($resp, 4096))) {
if ($resp =~ /^\xFF\xFF\xFF\xFFchallenge\s(\d+)/) {
$num = $1;
$num =~ s/^\s*//;
$num =~ s/\s*$//;
} else {
print "Error: Server returned wrong message (maybe wrong server
version)\n";
print "Received: $resp";
exit;
}
}
$sock->send("\xFF\xFF\xFF\xFFrcon $num \"$pass\" status\n");
if (defined($sock->recv($resp, 4096))) {
print "$resp\n";
$resp =~ s/\xFF\xFF\xFF\xFFl{0,1}//; # Remove header stuff
$resp =~ s/^\s*//; # Remove leading spaces
$resp =~ s/\s*$//; # Remove trailing spaces
print "$resp\n"
}
close($sock);
I think this is correct but it doesn't do nothing. Can anyone help me
please? I'm tired of trying solutions and dont get any result.
Regards
André Rivotti Casimiro
More information about the Mohaa
mailing list