aboutsummaryrefslogtreecommitdiff
path: root/client/clientcmp.pl
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2020-12-30 18:05:53 +0000
committerDarkelarious <darkelarious@333networks.com>2020-12-30 18:05:53 +0000
commita9bb59b5179ae029f9f85ae794709bc207198df6 (patch)
tree076a08066a72023ad0963647d59da7cb41a50d29 /client/clientcmp.pl
parent1f894307ede92602f1615dcf8fb0ab75e3ea6447 (diff)
downloadSimulation-Tools-a9bb59b5179ae029f9f85ae794709bc207198df6.tar.gz
Simulation-Tools-a9bb59b5179ae029f9f85ae794709bc207198df6.zip
game client with compressed/plain list request and authenticationHEADmaster
Diffstat (limited to 'client/clientcmp.pl')
-rwxr-xr-xclient/clientcmp.pl106
1 files changed, 106 insertions, 0 deletions
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;