aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/TCP
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2017-05-13 14:18:28 +0200
committerDarkelarious <darkelarious@333networks.com>2017-05-13 14:20:49 +0200
commit34a2c7390ea9662d33258d384e72fff1912343ff (patch)
treed96ea33c0107e4906a152aa1de4b5c75b81ba0a8 /lib/MasterServer/TCP
parent84af66aba26d2088d5d95c240d176f3edaf17b58 (diff)
downloadMasterServer-Perl-34a2c7390ea9662d33258d384e72fff1912343ff.tar.gz
MasterServer-Perl-34a2c7390ea9662d33258d384e72fff1912343ff.zip
revised synchronization methods, config settings and bug fixesv2.3.0
Diffstat (limited to 'lib/MasterServer/TCP')
-rwxr-xr-xlib/MasterServer/TCP/BrowserHost.pm9
-rwxr-xr-xlib/MasterServer/TCP/Handler.pm22
-rwxr-xr-xlib/MasterServer/TCP/ListCompiler.pm2
-rwxr-xr-xlib/MasterServer/TCP/Syncer.pm69
-rwxr-xr-xlib/MasterServer/TCP/UCCAppletQuery.pm16
5 files changed, 44 insertions, 74 deletions
diff --git a/lib/MasterServer/TCP/BrowserHost.pm b/lib/MasterServer/TCP/BrowserHost.pm
index 855b2c0..c53ae42 100755
--- a/lib/MasterServer/TCP/BrowserHost.pm
+++ b/lib/MasterServer/TCP/BrowserHost.pm
@@ -1,4 +1,3 @@
-
package MasterServer::TCP::BrowserHost;
use strict;
@@ -24,7 +23,7 @@ sub browser_host {
my $auth = 0;
# debug -- new connection opened
- $self->log("tcp","New connection from $a:$p");
+ #$self->log("tcp","New connection from $a:$p");
# prep a challenge
my $secure = $self->secure_string();
@@ -33,9 +32,9 @@ sub browser_host {
my $h; $h = AnyEvent::Handle->new(
fh => $fh,
poll => 'r',
- timeout => 5,
- on_eof => sub {$self->clean_tcp_handle(@_)},
- on_error => sub {$self->clean_tcp_handle(@_)},
+ timeout => $self->{timeout_time},
+ on_eof => sub {$self->log("tcp","eof on $a:$p" ); $self->clean_tcp_handle(@_)},
+ on_error => sub {$self->error($!, "browser $a:$p"); $self->clean_tcp_handle(@_)},
on_read => sub {$self->read_tcp_handle($h, $a, $p, $secure, @_)},
);
diff --git a/lib/MasterServer/TCP/Handler.pm b/lib/MasterServer/TCP/Handler.pm
index 1a075bf..4e174c2 100755
--- a/lib/MasterServer/TCP/Handler.pm
+++ b/lib/MasterServer/TCP/Handler.pm
@@ -1,4 +1,3 @@
-
package MasterServer::TCP::Handler;
use strict;
@@ -28,14 +27,12 @@ sub read_tcp_handle {
# did the client validate already?
my $val = $self->{browser_clients}->{$h}[1];
- # in case of errors, save the original message
+ # in case of errors, log the original message
my $rxbuf = $m;
+ #$self->log("debug","$a:$p sent $rxbuf");
# allow multiple blocks to add to the response string
my $response = "";
-
- # print debug values
- $self->log("debug","$a:$p sent $rxbuf");
# replace empty values for the string "undef" and replace line endings from netcatters
# parse the received data and extrapolate all the query commands found
@@ -75,14 +72,13 @@ sub read_tcp_handle {
"Contact us via 333networks.com\\final\\");
# and log it
- $self->log("error","invalid request from Browser $a:$p with unknown message \"$rxbuf\".");
+ $self->log("error","invalid request from browser $a:$p with unknown message \"$rxbuf\".");
} # end if weird query
else {
$c->push_write($response . "\\final\\") if ($response ne "");
}
}
-
################################################################################
## The master server opens the connection with the \secure\ challenge. The
## client should respond with basic information about itself and the
@@ -95,7 +91,8 @@ sub handle_validate {
my $val = 0;
# pass or fail the secure challenge
- if (exists $r->{gamename} && length $self->get_game_props(lc $r->{gamename})->{cipher} > 1 ) {
+ if (exists $r->{gamename} && $self->get_game_props($r->{gamename})) {
+
# game exists and we have the key to verify the response
$val = $self->compare_challenge(
gamename => $r->{gamename},
@@ -113,7 +110,7 @@ sub handle_validate {
$self->log("support", "received unknown gamename request \"$r->{gamename}\" from $a:$p.");
}
- # log (the spam!)
+ # log (debug)
#$self->log("secure","$a:$p validated with $val for $r->{gamename}, $secure, $r->{validate}");
# return auth status
@@ -132,6 +129,7 @@ sub handle_validate {
##
## NOTE: client does not need to validate to be allowed to perform this
## query.
+## TODO: deprecate about query -- info will now be in udp query!
################################################################################
sub handle_about {
my ($self, $about, $a, $p) = @_;
@@ -197,7 +195,7 @@ sub handle_list {
my $data = "";
# determine the return format
- if ($self->{hex_format} =~ m/$r->{gamename}/i or $r->{list} =~ /^cmp$/i) {
+ if ($r->{list} =~ /^cmp$/i) {
# return addresses as byte format (ip=ABCD port=EF)
$data .= $self->compile_list_cmp($r->{gamename});
}
@@ -216,6 +214,7 @@ sub handle_list {
$self->log("list","$a:$p successfully retrieved the list for $r->{gamename}.");
# clean and close the connection
+ #$self->log("tcp","closing $a:$p");
$self->clean_tcp_handle($c);
}
@@ -229,6 +228,7 @@ sub handle_list {
$self->log("error","browser $a:$p failed validation for $r->{gamename}");
# clean and close the connection
+ #$self->log("tcp","closing $a:$p");
$self->clean_tcp_handle($c);
}
}
@@ -256,6 +256,7 @@ sub handle_sync {
$self->log("sync-tx","$a:$p successfully synced.");
# clean and close the connection
+ #$self->log("tcp","closing $a:$p");
$self->clean_tcp_handle($c);
}
@@ -270,6 +271,7 @@ sub handle_sync {
$self->log("error","$a:$p failed synchronization.");
# clean and close the connection
+ #$self->log("tcp","closing $a:$p");
$self->clean_tcp_handle($c);
}
}
diff --git a/lib/MasterServer/TCP/ListCompiler.pm b/lib/MasterServer/TCP/ListCompiler.pm
index a5571d0..97ef541 100755
--- a/lib/MasterServer/TCP/ListCompiler.pm
+++ b/lib/MasterServer/TCP/ListCompiler.pm
@@ -1,9 +1,7 @@
-
package MasterServer::TCP::ListCompiler;
use strict;
use warnings;
-
use Exporter 'import';
our @EXPORT = qw| compile_list compile_list_cmp compile_sync |;
diff --git a/lib/MasterServer/TCP/Syncer.pm b/lib/MasterServer/TCP/Syncer.pm
index 3e903e0..d890f00 100755
--- a/lib/MasterServer/TCP/Syncer.pm
+++ b/lib/MasterServer/TCP/Syncer.pm
@@ -1,4 +1,3 @@
-
package MasterServer::TCP::Syncer;
use strict;
@@ -8,8 +7,7 @@ use AnyEvent::Handle;
use Exporter 'import';
our @EXPORT = qw| sync_with_master
- process_sync_list
- masterserver_list |;
+ process_sync_list |;
################################################################################
## Sends synchronization request to another 333networks based master server and
@@ -27,18 +25,20 @@ sub sync_with_master {
# connection handle
my $handle;
$handle = new AnyEvent::Handle(
- connect => [$ms->{ip} => $ms->{tcp}],
- timeout => 4,
+ connect => [$ms->{ip} => $ms->{hostport}],
+ timeout => $self->{timeout_time},
poll => 'r',
- on_error => sub {$self->error($!, "$ms->{ip}:$ms->{port}"); $handle->destroy;},
- on_eof => sub {$self->process_sync_list($sync_list, $ms); $handle->destroy;},
+ on_error => sub {$self->error($!, "$ms->{ip}:$ms->{hostport}"); $handle->destroy;},
+ on_eof => sub {$self->process_sync_list($sync_list, $ms); $handle->destroy;},
on_read => sub {
+
# receive and clear buffer
my $m = $_[0]->rbuf;
$_[0]->rbuf = "";
- # remove string terminator: sometimes trailing slashes are added or
- # forgotten by sender, so \secure\abcdef is actually \secure\abcdef{\0}
+ # remove string terminator: sometimes trailing slashes, line endings or
+ # string terminators are added or forgotten by sender, so \secure\abcdef
+ # is actually \secure\abcdef{\0}
chop $m if $m =~ m/secure/;
# part 1: receive \basic\\secure\$key
@@ -63,7 +63,7 @@ sub sync_with_master {
# part 3: request the list \sync\gamenames consisting of space-seperated game names or "all"
# compatibility note: old queries use "new", instead treat them as "all".
my $request = "\\sync\\"
- . (($self->{sync_games}[0] == 0) ? ("all" or "new") : $self->{sync_games}[1])
+ . (($self->{sync_games}[0] == 0) ? ("all") : $self->{sync_games}[1])
. "\\final\\";
# push the request to remote host
@@ -99,8 +99,7 @@ sub process_sync_list {
if (exists $r{echo}) {
# remote address says...
- $self->log("error", "$ms->{ip} replied: $r{echo}");
-
+ $self->log("echo", "$ms->{ip} replied: $r{echo}");
}
# iterate through the gamenames and addresses
@@ -127,8 +126,8 @@ sub process_sync_list {
# add server
$self->syncer_add($a, $p, $gn, $self->secure_string());
- # print address
- $self->log("add", "syncer added $gn\t$a\t$p");
+ # print address (debug)
+ # $self->log("add", "syncer added $gn\t$a\t$p");
}
else {
# invalid address, log
@@ -144,42 +143,14 @@ sub process_sync_list {
} # end defined $gn
} # end while
- # end message
- $self->log("sync-rx", "received $c addresses after syncing from $ms->{ip}:$ms->{tcp}");
-}
-
-################################################################################
-## Determine a list of all unique 333networks-compatible masterservers
-## and return this list. Join the brotherhood!
-################################################################################
-sub masterserver_list {
- my $self = shift;
- my %brotherhood;
+ # update this sync master in the gamelist with lastseen time
+ $self->update_server_list(
+ ip => $ms->{ip},
+ port => $ms->{port},
+ ) if ($c > 0);
- # start with the masterservers defined in our configuration file
- for my $ms (@{$self->{sync_masters}}) {
- my $ip = $self->host2ip($ms->{address});
- $brotherhood{"$ip:$ms->{port}"} = {ip => $ip, tcp => $ms->{port}, udp => $ms->{beacon}} if $ip;
- }
-
- # get the list of uplinking masterservers
- my $serverlist = $self->get_server(
- updated => 3600,
- gamename => "333networks",
- limit => 50, # more would be ridiculous.. right?..
- );
-
- # overwrite existing entries, add new
- for my $ms (@{$serverlist}) {
- $brotherhood{"$ms->{ip}:$ms->{hostport}"} = {ip => $ms->{ip}, tcp => $ms->{hostport}, udp => $ms->{port}};
- }
-
- # masterservers that sync with us can not be derived directly, but by reading
- # the server log we can add them manually. Lot of work, little gain, as those
- # syncing masterservers will most likely be uplinking as well between now and
- # a few weeks/months.
-
- return \%brotherhood;
+ # end message
+ $self->log("sync-rx", "received $c addresses after syncing from $ms->{ip}:$ms->{hostport}");
}
1;
diff --git a/lib/MasterServer/TCP/UCCAppletQuery.pm b/lib/MasterServer/TCP/UCCAppletQuery.pm
index 7637e9f..2c32de9 100755
--- a/lib/MasterServer/TCP/UCCAppletQuery.pm
+++ b/lib/MasterServer/TCP/UCCAppletQuery.pm
@@ -1,4 +1,3 @@
-
package MasterServer::TCP::UCCAppletQuery;
use strict;
@@ -18,7 +17,7 @@ sub query_applet {
my ($self, $ms) = @_;
# be nice to notify
- $self->log("tcp","start querying $ms->{ip}:$ms->{port} for '$ms->{game}' games");
+ $self->log("tcp","start querying $ms->{ip}:$ms->{port} for '$ms->{gamename}' games");
# list to store all IPs in.
my $master_list = "";
@@ -27,7 +26,7 @@ sub query_applet {
my $handle;
$handle = new AnyEvent::Handle(
connect => [$ms->{ip} => $ms->{port}],
- timeout => 5,
+ timeout => $self->{timeout_time},
poll => 'r',
on_error => sub {$self->error($!, "$ms->{ip}:$ms->{port}"); $handle->destroy;},
on_eof => sub {$self->process_ucc_applet_query($master_list, $ms); $handle->destroy;},
@@ -36,7 +35,7 @@ sub query_applet {
# receive and clear buffer
my $m = $_[0]->rbuf;
$_[0]->rbuf = "";
-
+
# remove string terminator
chop $m if $m =~ m/secure/;
@@ -48,20 +47,21 @@ sub query_applet {
$m =~ s/\\([^\\]+)\\([^\\]+)/$r{$1}=$2/eg;
# respond to challenge
- my $validate = $self->validate_string(gamename => $ms->{game},
+ my $validate = $self->validate_string(gamename => $ms->{gamename},
enctype => $r{enctype}||0,
secure => $r{secure});
# send response
- $handle->push_write("\\gamename\\$ms->{game}\\location\\0\\validate\\$validate\\final\\");
+ $handle->push_write("\\gamename\\$ms->{gamename}\\location\\0\\validate\\$validate\\final\\");
# part 3: also request the list \list\gamename\ut -- skipped in UCC applets
- $handle->push_write("\\list\\\\gamename\\$ms->{game}\\final\\");
+ $handle->push_write("\\list\\\\gamename\\$ms->{gamename}\\final\\");
}
# part 3b: receive the entire list in multiple steps.
- if ($m =~ m/\\ip\\/) {
+ # $m contains \ip\ or part of that string
+ else {
# add buffer to the list
$master_list .= $m;
}