aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/UDP/BeaconChecker.pm
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2017-08-22 11:00:13 +0200
committerDarkelarious <darkelarious@333networks.com>2017-08-22 11:00:13 +0200
commitc06322da38b4cb76b2036af1a5448083adb8ff20 (patch)
tree189c9f0fec3325be927f763aba23cf18aa68cfe4 /lib/MasterServer/UDP/BeaconChecker.pm
parente0d727670cbeda0db0812c5c9efc503d75f8d0a4 (diff)
downloadMasterServer-Perl-2.4.0.tar.gz
MasterServer-Perl-2.4.0.zip
new server checking mechanism, complete recode of major functionsv2.4.0
Diffstat (limited to 'lib/MasterServer/UDP/BeaconChecker.pm')
-rwxr-xr-xlib/MasterServer/UDP/BeaconChecker.pm80
1 files changed, 26 insertions, 54 deletions
diff --git a/lib/MasterServer/UDP/BeaconChecker.pm b/lib/MasterServer/UDP/BeaconChecker.pm
index 73220cf..9c95455 100755
--- a/lib/MasterServer/UDP/BeaconChecker.pm
+++ b/lib/MasterServer/UDP/BeaconChecker.pm
@@ -4,80 +4,52 @@ use strict;
use warnings;
use AnyEvent::Handle::UDP;
use Exporter 'import';
-
our @EXPORT = qw| query_udp_server |;
################################################################################
## Get the server status from any server over UDP and store the received
## information in the database. $secure determines the type of query:
## secure/pending or information.
+## options: ip, port, need_validate, direct_uplink
################################################################################
sub query_udp_server {
- my ($self, $id, $ip, $port, $secure, $message_type) = @_;
- my $buf = "";
-
- # debug logging
- # $self->log("debug", "Query server $id ($ip:$port)");
+ my ($self, %o) = @_;
+ my $buffer = "";
+
+ # if a secure/validate challenge is still required, generate secure string
+ my $secure = $self->secure_string if $o{need_validate};
# connect with UDP server
my $udp_client; $udp_client = AnyEvent::Handle::UDP->new(
- connect => [$ip, $port],
- timeout => $self->{timeout_time},
- on_timeout => sub {$udp_client->destroy();}, # do not report timeouts
- on_error => sub {$udp_client->destroy();}, # or errors
+ connect => [$o{ip}, $o{port}],
+ timeout => $self->{timeout_time},
+ on_timeout => sub {$udp_client->destroy;},
+ on_error => sub {$udp_client->destroy;},
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.
+ # add received data to buffer
+ $buffer .= $_[0];
- # 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);
+ # buffer completed receiving all relevant information?
+ if ($buffer =~ m/\\final\\/) {
+
+ # try to process datagram
+ $self->process_datagram(
+ ip => $o{ip},
+ port => $o{port},
+ rxbuf => $buffer,
+ secure => $secure,
+ direct => $o{direct_uplink},
+ );
}
- # message type 0: \basic\\info\
- # if gamename, ver, hostname and hostport are available, but NOT the value
- # "listenserver", it would have been \basic\info
- if ($buf =~ m/\\gamename\\/ &&
- $buf =~ m/\\hostname\\/ &&
- $buf =~ m/\\hostport\\/ &&
- $buf !~ m/\\listenserver\\/ ) {
- $self->process_query_response($buf, $ip, $port);
- }
-
- # message type 2: \status\
- # contains same info as \basic\\info, but also "listenserver". Only for UT.
- if ($buf =~ m/\\gamename\\ut/ &&
- $buf =~ m/\\hostname\\/ &&
- $buf =~ m/\\hostport\\/ &&
- $buf =~ m/\\listenserver\\/ ) {
- $self->process_status_response($buf, $ip, $port);
- }
-
# else partial information received. wait for more.
# else { }
},
);
- #
- # Send secure message or status, depending on provided variables
- # Message types can be
- # 0: \basic\\info\
- # 1: \basic\\secure\wookie
- # 2: \status\
- #
-
- # determine the message
- my $message = "\\basic\\\\info\\"; # default 0
- $message = "\\basic\\\\secure\\$secure" if ($secure ne "" && $self->{require_secure_beacons} > 0); # message_type 1
- $message = "\\status\\" if ($message_type == 2);
-
- # send selected message
- $udp_client->push_send($message);
+ # determine the requests and send message
+ $udp_client->push_send("\\secure\\$secure") if $o{need_validate};
+ $udp_client->push_send("\\status\\");
}
1;