From 34a2c7390ea9662d33258d384e72fff1912343ff Mon Sep 17 00:00:00 2001 From: Darkelarious Date: Sat, 13 May 2017 14:18:28 +0200 Subject: revised synchronization methods, config settings and bug fixes --- lib/MasterServer/UDP/BeaconChecker.pm | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'lib/MasterServer/UDP/BeaconChecker.pm') diff --git a/lib/MasterServer/UDP/BeaconChecker.pm b/lib/MasterServer/UDP/BeaconChecker.pm index f74378d..73220cf 100755 --- a/lib/MasterServer/UDP/BeaconChecker.pm +++ b/lib/MasterServer/UDP/BeaconChecker.pm @@ -1,4 +1,3 @@ - package MasterServer::UDP::BeaconChecker; use strict; @@ -6,7 +5,7 @@ use warnings; use AnyEvent::Handle::UDP; use Exporter 'import'; -our @EXPORT = qw| query_udp_server|; +our @EXPORT = qw| query_udp_server |; ################################################################################ ## Get the server status from any server over UDP and store the received @@ -17,20 +16,28 @@ sub query_udp_server { my ($self, $id, $ip, $port, $secure, $message_type) = @_; my $buf = ""; - # debug spamming - $self->log("udp", "Query server $id ($ip:$port)"); + # debug logging + # $self->log("debug", "Query server $id ($ip:$port)"); # connect with UDP server my $udp_client; $udp_client = AnyEvent::Handle::UDP->new( - # Bind to this host and port connect => [$ip, $port], - timeout => 1, - on_timeout => sub {$udp_client->destroy();}, # don't bother reporting timeouts + timeout => $self->{timeout_time}, + on_timeout => sub {$udp_client->destroy();}, # do not report timeouts on_error => sub {$udp_client->destroy();}, # or errors - on_recv => sub { + on_recv => sub { # add packet to buffer $buf .= $_[0]; + + # FIXME: note to self: order is important when having combined queries! + # TODO: find a more elegant and long-time solution for this. + + # message type 1: \basic\\secure\wookie + # if validate, assume that we sent a \basic\secure request. + if ($buf =~ m/\\validate\\/){ + $self->process_udp_validate($buf, $ip, undef, $port); + } # message type 0: \basic\\info\ # if gamename, ver, hostname and hostport are available, but NOT the value @@ -42,12 +49,6 @@ sub query_udp_server { $self->process_query_response($buf, $ip, $port); } - # message type 1: \basic\\secure\wookie - # if validate, assume that we sent a \basic\secure request. - if ($buf =~ m/\\validate\\/){ - $self->process_udp_validate($buf, $ip, undef, $port); - } - # message type 2: \status\ # contains same info as \basic\\info, but also "listenserver". Only for UT. if ($buf =~ m/\\gamename\\ut/ && -- cgit v1.2.3