aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/Database/Pg/dbServerlist.pm
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2015-05-19 22:00:40 +0200
committerDarkelarious <darkelarious@333networks.com>2015-05-19 22:00:40 +0200
commit2c7d62f38944f61e7eafea155c6128521d16aed9 (patch)
treebd473e6fb9dbbf8e0fdc67b87f0a4ac251fada7b /lib/MasterServer/Database/Pg/dbServerlist.pm
parent534626943a0a5e251e5465376f3de3fb71b25e91 (diff)
downloadMasterServer-Perl-2c7d62f38944f61e7eafea155c6128521d16aed9.tar.gz
MasterServer-Perl-2c7d62f38944f61e7eafea155c6128521d16aed9.zip
Beta with support for Pg and SQLite
Diffstat (limited to 'lib/MasterServer/Database/Pg/dbServerlist.pm')
-rwxr-xr-xlib/MasterServer/Database/Pg/dbServerlist.pm55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/MasterServer/Database/Pg/dbServerlist.pm b/lib/MasterServer/Database/Pg/dbServerlist.pm
index 832a08f..5a58717 100755
--- a/lib/MasterServer/Database/Pg/dbServerlist.pm
+++ b/lib/MasterServer/Database/Pg/dbServerlist.pm
@@ -7,6 +7,7 @@ use Exporter 'import';
our @EXPORT = qw| add_to_serverlist
update_serverlist
+ syncer_add
get_next_server |;
################################################################################
@@ -77,6 +78,60 @@ sub update_serverlist {
return -1;
}
+
+################################################################################
+## add new addresses to the pending list, but do not update timestamps. masters
+## that sync with each other would otherwise update the timestamp for a server
+## which is no longer online.
+################################################################################
+sub syncer_add {
+ my ($self, $ip, $port, $gamename, $secure) = @_;
+
+ # if address is in list, update the timestamp
+ my $u = $self->{dbh}->do(
+ "SELECT * FROM serverlist
+ WHERE ip = ?
+ AND port = ?",
+ undef, $ip, $port);
+
+ # notify
+ $self->log("read","syncer found entry for $ip:$port") if ($u > 0);
+
+ # if found, return 0
+ return 0 if ($u > 0);
+
+ # if it is already in the pending list, update it with a new challenge
+ $u = $self->{dbh}->do(
+ "UPDATE pending
+ SET secure = ?
+ WHERE ip = ?
+ AND heartbeat = ?",
+ undef, $secure, $ip, $port);
+
+ # notify
+ $self->log("update","$ip:$port was updated by syncer",
+ $self->{log_settings}->{db_updated}) if ($u > 0);
+
+ # return 1 if found
+ return 1 if ($u > 0);
+
+ # if not found, add it
+ $u = $self->{dbh}->do(
+ "INSERT INTO pending (ip, heartbeat, gamename, secure)
+ SELECT ?, ?, ?, ?",
+ undef, $ip, $port, $gamename, $secure);
+
+ # notify
+ $self->log("add","beacon: $ip:$port was added for $gamename after sync") if ($u > 0);
+
+ # return 2 if added new
+ return 2 if ($u > 0);
+
+ # or else report error
+ $self->log("error", "an error occurred adding $ip:$port after sync");
+ return -1;
+}
+
################################################################################
## get a server address of the next server in line to be queried for game info.
## query must be older than 30 seconds (in case it just got added) and not