aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/Database/mysql/dbClientList.pm
blob: 898eb282219220653006b0a4801ebd6a84318c3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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;