aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/Database/Pg/dbServerlist.pm
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2015-02-09 07:58:06 +0100
committerDarkelarious <darkelarious@333networks.com>2015-02-09 07:58:06 +0100
commit5057ec47aa9a1702b2483e0a0b3ba325bb0b7abb (patch)
treeb1a394f64ec7ec2cf69f33bceb54a5b51199c0a4 /lib/MasterServer/Database/Pg/dbServerlist.pm
parent6ac9d390e417b868b6ed79441b8cc6e1b2ebeb13 (diff)
downloadMasterServer-Perl-5057ec47aa9a1702b2483e0a0b3ba325bb0b7abb.tar.gz
MasterServer-Perl-5057ec47aa9a1702b2483e0a0b3ba325bb0b7abb.zip
receive UDP beacons, validate them and store with country indicator
Diffstat (limited to 'lib/MasterServer/Database/Pg/dbServerlist.pm')
-rwxr-xr-xlib/MasterServer/Database/Pg/dbServerlist.pm44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/MasterServer/Database/Pg/dbServerlist.pm b/lib/MasterServer/Database/Pg/dbServerlist.pm
new file mode 100755
index 0000000..8d1a2b2
--- /dev/null
+++ b/lib/MasterServer/Database/Pg/dbServerlist.pm
@@ -0,0 +1,44 @@
+
+package MasterServer::Database::Pg::dbServerlist;
+
+use strict;
+use warnings;
+use Exporter 'import';
+
+our @EXPORT = qw| add_to_serverlist |;
+
+## beacon was verified or otherwise accepted and will noe now be added to the
+## serverlist.
+sub add_to_serverlist {
+ my ($self, $ip, $port, $gamename) = @_;
+
+ # update or add server to serverlist
+ my $u = $self->{dbh}->do("UPDATE serverlist
+ SET updated = NOW()
+ WHERE ip = ?
+ AND port = ?",
+ undef, $ip, $port);
+
+ # notify
+ $self->log("updated", "$ip:$port timestamp updated") if ($u > 0);
+
+ # if found, updated; done
+ return 0 if ($u > 0);
+
+ # if not found, add it.
+ $u = $self->{dbh}->do("INSERT INTO serverlist (ip, port, gamename, country)
+ SELECT ?, ?, ?, ?",
+ undef, $ip, $port, $gamename, $self->ip2country($ip));
+
+ # notify
+ $self->log("added", "$ip:$port added to serverlist") if ($u > 0);
+
+ # return added
+ return 1 if ($u > 0);
+
+ # or else report error
+ $self->log("error", "an error occurred adding server $ip:$port ($gamename) to the serverlist");
+ return -1;
+}
+
+1;