From 2c7d62f38944f61e7eafea155c6128521d16aed9 Mon Sep 17 00:00:00 2001 From: Darkelarious Date: Tue, 19 May 2015 22:00:40 +0200 Subject: Beta with support for Pg and SQLite --- lib/MasterServer/Database/Pg/dbServerlist.pm | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'lib/MasterServer/Database/Pg/dbServerlist.pm') 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 -- cgit v1.2.3