aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/Database/Pg
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2017-07-06 12:21:45 +0200
committerDarkelarious <darkelarious@333networks.com>2017-07-06 12:21:45 +0200
commite0d727670cbeda0db0812c5c9efc503d75f8d0a4 (patch)
tree3c4a5c2aa2b065e5458ea30e86c30ed30f7bac8d /lib/MasterServer/Database/Pg
parent34a2c7390ea9662d33258d384e72fff1912343ff (diff)
downloadMasterServer-Perl-e0d727670cbeda0db0812c5c9efc503d75f8d0a4.tar.gz
MasterServer-Perl-e0d727670cbeda0db0812c5c9efc503d75f8d0a4.zip
Support for \status\ query, deprecated \about\ query
Diffstat (limited to 'lib/MasterServer/Database/Pg')
-rwxr-xr-xlib/MasterServer/Database/Pg/dbCiphers.pm54
-rwxr-xr-xlib/MasterServer/Database/Pg/dbGetServers.pm16
2 files changed, 50 insertions, 20 deletions
diff --git a/lib/MasterServer/Database/Pg/dbCiphers.pm b/lib/MasterServer/Database/Pg/dbCiphers.pm
index e099f88..5343065 100755
--- a/lib/MasterServer/Database/Pg/dbCiphers.pm
+++ b/lib/MasterServer/Database/Pg/dbCiphers.pm
@@ -7,7 +7,8 @@ use Exporter 'import';
our @EXPORT = qw| check_cipher_count
clear_ciphers
insert_cipher
- get_game_props |;
+ get_game_props
+ get_gamenames |;
################################################################################
## Check if ciphers exist
@@ -51,13 +52,56 @@ sub insert_cipher {
################################################################################
## get the cipher, description and default port that goes with given gamename
-## returns only the first item if multiple items
+##
################################################################################
sub get_game_props {
- my ($self, $gn) = @_;
+ my $s = shift;
+ my %o = (
+ sort => '',
+ @_
+ );
- # get cipher from db if gamename exists
- return $self->db_all('SELECT * FROM games WHERE gamename = ?', lc $gn)->[0];
+ my %where = (
+ $o{gamename} ? ('gamename = ?' => lc $o{gamename}) : (),
+ $o{cipher} ? ('cipher = ?' => $o{cipher}) : (),
+ $o{description} ? ('description = ?' => $o{description}) : (),
+ $o{default_qport} ? ('default_qport = ?' => $o{default_qport}) : (),
+ $o{num_uplink} ? ('num_uplink = ?' => $o{num_uplink}) : (),
+ $o{num_total} ? ('num_total = ?' => $o{num_total}) : (),
+ $o{num_gt} ? ('num_total >= ?' => $o{num_gt}) : (),
+ );
+
+ my @select = ( qw| gamename cipher description default_qport num_uplink num_total|,);
+ my $order = sprintf {
+ gamename => 'gamename %s',
+ cipher => 'cipher %s',
+ description => 'description %s',
+ default_qport => 'default_qport %s',
+ num_uplink => 'num_uplink %s',
+ num_total => 'num_total %s',
+ }->{ $o{sort}||'gamename' }, $o{reverse} ? 'DESC' : 'ASC';
+
+ return $s->db_all( q|
+ SELECT !s FROM games
+ !W
+ ORDER BY !s|
+ .($o{limit} ? " LIMIT ?" : ""),
+ join(', ', @select), \%where, $order, ($o{limit} ? $o{limit} : ()),
+ );
+}
+
+
+################################################################################
+## 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.
+################################################################################
+sub get_gamenames {
+ my $self = shift;
+
+ return $self->{dbh}->selectall_arrayref(
+ "SELECT distinct gamename
+ FROM serverlist");
}
1;
diff --git a/lib/MasterServer/Database/Pg/dbGetServers.pm b/lib/MasterServer/Database/Pg/dbGetServers.pm
index a33582a..e9bfaec 100755
--- a/lib/MasterServer/Database/Pg/dbGetServers.pm
+++ b/lib/MasterServer/Database/Pg/dbGetServers.pm
@@ -5,8 +5,7 @@ use warnings;
use Exporter 'import';
our @EXPORT = qw| get_server
- get_pending
- get_gamenames |;
+ get_pending |;
################################################################################
## get server details for one or multiple servers
@@ -123,17 +122,4 @@ sub get_pending {
);
}
-################################################################################
-## 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.
-################################################################################
-sub get_gamenames {
- my $self = shift;
-
- return $self->{dbh}->selectall_arrayref(
- "SELECT distinct gamename
- FROM serverlist");
-}
-
1;