From 8b3d393e7755c167eebe4d9f7fc786074f12e9af Mon Sep 17 00:00:00 2001 From: Darkelarious Date: Sun, 8 Nov 2015 15:42:27 +0100 Subject: Full support for Postgres, MySQL and SQLite3 + minor bug fixes --- lib/MasterServer/Database/mysql/dbClientList.pm | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 lib/MasterServer/Database/mysql/dbClientList.pm (limited to 'lib/MasterServer/Database/mysql/dbClientList.pm') diff --git a/lib/MasterServer/Database/mysql/dbClientList.pm b/lib/MasterServer/Database/mysql/dbClientList.pm new file mode 100755 index 0000000..898eb28 --- /dev/null +++ b/lib/MasterServer/Database/mysql/dbClientList.pm @@ -0,0 +1,45 @@ + +package MasterServer::Database::mysql::dbClientList; + +use strict; +use warnings; +use Exporter 'import'; + +our @EXPORT = qw| get_gamenames + get_game_list |; + + +################################################################################ +## get a list of distinct gamenames currently in the database. it does not +## matter whether they are recent or old, as long as the game is currently in +## the database. +## +## returns: hashref of gamenames +################################################################################ +sub get_gamenames { + my $self = shift; + + return $self->{dbh}->selectall_arrayref( + "SELECT distinct gamename + FROM serverlist"); +} + +################################################################################ +## get the list of games of a certain $gamename, excluding the ones excempted +## via the blacklist +## only returns server addresses that are no more than 1 hours old +################################################################################ +sub get_game_list { + my ($self, $gamename) = @_; + + return $self->{dbh}->selectall_arrayref( + "SELECT ip, port + FROM serverlist + WHERE updated > NOW() - INTERVAL 10800 SECOND + AND gamename = ? + AND NOT blacklisted", + undef, lc $gamename); +} + + +1; -- cgit v1.2.3