aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/Database/SQLite/dbCiphers.pm
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2016-11-20 19:30:58 +0100
committerDarkelarious <darkelarious@333networks.com>2016-11-20 19:30:58 +0100
commit702d1898b012d6d992d66b996508610890bf2963 (patch)
tree9556d890c4afdb7062f5b63277aa6b3d5c5d9d03 /lib/MasterServer/Database/SQLite/dbCiphers.pm
parentc3f8d65a4fb1f5674557ee67cf7f74369df86ad1 (diff)
downloadMasterServer-Perl-702d1898b012d6d992d66b996508610890bf2963.tar.gz
MasterServer-Perl-702d1898b012d6d992d66b996508610890bf2963.zip
Restore SQLite support
Diffstat (limited to 'lib/MasterServer/Database/SQLite/dbCiphers.pm')
-rwxr-xr-xlib/MasterServer/Database/SQLite/dbCiphers.pm57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/MasterServer/Database/SQLite/dbCiphers.pm b/lib/MasterServer/Database/SQLite/dbCiphers.pm
new file mode 100755
index 0000000..c98eb05
--- /dev/null
+++ b/lib/MasterServer/Database/SQLite/dbCiphers.pm
@@ -0,0 +1,57 @@
+
+package MasterServer::Database::SQLite::dbCiphers;
+
+use strict;
+use warnings;
+use Exporter 'import';
+
+our @EXPORT = qw| clear_ciphers
+ insert_cipher
+ get_game_props |;
+
+################################################################################
+## Clear all existing ciphers from the database
+################################################################################
+sub clear_ciphers {
+ my $self = shift;
+
+ # delete ALL entries
+ my $u = $self->{dbh}->do("DELETE FROM games");
+}
+
+################################################################################
+## Insert the list of supported games and their ciphers / default ports /
+## descriptions included from the data/supportedgames.pl file.
+################################################################################
+sub insert_cipher {
+ my ($self, %opt) = @_;
+
+ # insert a single cipher/key combo
+ my $u = $self->{dbh}->do(
+ "INSERT INTO games (
+ gamename,
+ cipher,
+ description,
+ default_qport)
+ VALUES(?, ?, ?, ?)", undef,
+ lc $opt{gamename}, $opt{cipher}, $opt{description}, $opt{default_qport});
+ return 1 if ($u and $u > 0);
+
+ # or else report error
+ $self->log("error", "An error occurred adding a cipher for $opt{gamename}");
+}
+
+################################################################################
+## get the cipher, description and default port that goes with given gamename
+################################################################################
+sub get_game_props {
+ my ($self, $gn) = @_;
+
+ # get cipher from db if gamename exists
+ return $self->{dbh}->selectall_arrayref(
+ 'SELECT * FROM games WHERE gamename = ?',
+ {Slice=>{}},
+ lc $gn)->[0];
+}
+
+1;