From a9bb59b5179ae029f9f85ae794709bc207198df6 Mon Sep 17 00:00:00 2001 From: Darkelarious Date: Wed, 30 Dec 2020 18:05:53 +0000 Subject: game client with compressed/plain list request and authentication --- client/clientcmp.pl | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100755 client/clientcmp.pl diff --git a/client/clientcmp.pl b/client/clientcmp.pl new file mode 100755 index 0000000..29735f2 --- /dev/null +++ b/client/clientcmp.pl @@ -0,0 +1,106 @@ +#!/usr/bin/perl + +################################################################################ +# Simulate a game client +# - open TCP connection +# - authenticate +# - request plain/compressed serverlist +# +################################################################################ + +use strict; +use warnings; +use AnyEvent; +use AnyEvent::Handle; +use Data::Dumper 'Dumper'; +$|++; + +our %S; +require "../common/supportedgames.pl"; +require "../common/auth.pl"; + +# set masterserver +my $masteraddress = "rhea.333networks.com"; +my $masterport = 28900; + +# set (our) simulated game client +my $gamename = "ut"; +my $cmp = 0 ? "cmp" : ""; # 1 for compressed, 0 for plain + +# loop +my $cv = AnyEvent->condvar; + +my $buf = ""; +my $handle; $handle = new AnyEvent::Handle( + connect => [$masteraddress => $masterport], + timeout => 15, + poll => 'r', + on_error => sub + { + print Dumper $!; + $handle->destroy; + $cv->send; + }, + on_eof => sub + { # connection closed, assuming list was received + $buf =~ s/\\final\\//ig; + my @serverlist; + + # process serverlist for compressed/plain + if ($cmp eq "cmp") + { # compressed list + while (length $buf >= 6) + { + my $caddr = substr $buf, 0, 6, ''; + my ($A, $B, $C, $D, $E, $F) = split //, $caddr; + my $addr = ord($A).".".ord($B).".".ord($C).".".ord($D); + my $port = (ord($E) << 8) + ord($F); + push @serverlist, "$addr:$port"; + } + } + else + { # plain list + my @list = split /\\ip\\/, $buf; + shift @list; # remove empty first element + for my $l (@list) + { + push(@serverlist, $l) if ($l =~ m/:/); + } + } + + # report result + print "Received ".(scalar @serverlist)." [$gamename] games from $masteraddress.\n"; + #print Dumper \@serverlist; + + $handle->destroy; + $cv->send; + }, + on_read => sub + { + $buf .= $_[0]->rbuf; + $_[0]->rbuf = ""; + + # part 1: receive \basic\\secure\$key + if ($buf =~ m/\\basic\\\\secure\\/) + { + # parse received data + my @a = split /\\/, ($buf||""); + shift @a; + my %r = (@a, (scalar @a % 2 == 1) ? "dummy" : () ); + $buf = ""; + + # respond to challenge + my $validate = get_validate_string( + $S{game}->{$gamename}->{key}, + $r{secure}, + $r{enctype}||0 + ); + + # print and send response + $handle->push_write("\\gamename\\$gamename\\location\\0\\validate\\$validate\\final\\"); + $handle->push_write("\\list\\$cmp\\gamename\\$gamename\\final\\"); + } + } +); + +$cv->recv; -- cgit v1.2.3