aboutsummaryrefslogtreecommitdiff
path: root/util/tools/db_load_ciphers.pl
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2016-11-19 20:56:04 +0100
committerDarkelarious <darkelarious@333networks.com>2016-11-19 20:56:04 +0100
commitc3f8d65a4fb1f5674557ee67cf7f74369df86ad1 (patch)
tree92aab2a394bda28da0ed7c7c75e633fdf386fc71 /util/tools/db_load_ciphers.pl
parent1de3da4b8027508a91144639455c934fd6ccb9b7 (diff)
downloadMasterServer-Perl-c3f8d65a4fb1f5674557ee67cf7f74369df86ad1.tar.gz
MasterServer-Perl-c3f8d65a4fb1f5674557ee67cf7f74369df86ad1.zip
Massive improvements on efficiency, robustness, security, reliability and more
Diffstat (limited to 'util/tools/db_load_ciphers.pl')
-rwxr-xr-xutil/tools/db_load_ciphers.pl72
1 files changed, 72 insertions, 0 deletions
diff --git a/util/tools/db_load_ciphers.pl b/util/tools/db_load_ciphers.pl
new file mode 100755
index 0000000..b047b77
--- /dev/null
+++ b/util/tools/db_load_ciphers.pl
@@ -0,0 +1,72 @@
+#!/usr/bin/perl
+
+################################################################################
+## Supported Games list ciphers
+## Clear the Supported Games table and insert the list of supported games AND
+## their ciphers / default ports / descriptions included from the
+## data/supportedgames.pl file.
+##
+## Only config files after 5 October 2015 work with this script.
+##
+## It is generally not necessary to run this script at all. Normally, the
+## masterserver performs the same action on startup. With this script it is
+## possible to add new game/cipher pairs or reload the game descriptions
+## without having to restart the masterserver.
+## Doing so while the masterserver is running MAY lead to missed queries or
+## failed secure/validate queries in your logs/output. This is undesirable,
+## but always better than being offline while restarting the masterserver.
+##
+## Use with care!
+##
+##
+## Note: set database name / user / password manually in the code below.
+################################################################################
+
+use strict;
+use warnings;
+use DBI;
+use Data::Dumper 'Dumper';
+
+use Cwd 'abs_path';
+
+our $ROOT;
+BEGIN { ($ROOT = abs_path $0) =~ s{/util/ciphers\.pl$}{}; }
+use lib $ROOT.'/lib';
+
+use MasterServer;
+
+our %S;
+require "$ROOT/data/supportedgames.pl";
+
+
+# open db connection
+my $dbh = DBI->connect('dbi:Pg:dbname=masterserver', 'user', 'password')
+ or die "Cannot connect: $DBI::errstr\n";
+
+# intro
+print "Deleting old entries... ";
+
+# check existing entries
+my $m = $dbh->do('DELETE FROM games');
+print "Deleted $m lines.\n";
+
+# announce
+print "Inserting new entries ... (this may take a while) ... ";
+my $g = $S{game};
+
+$dbh->begin_work;
+for (keys %{$g}) {
+
+ $dbh->do("INSERT INTO games (gamename, cipher, description, default_qport) VALUES(?, ?, ?, ?)", undef,
+ lc $_, $g->{$_}->{key}, $g->{$_}->{label}, $g->{$_}->{port} || 0) ;
+}
+$dbh->commit;
+
+# verify
+print "Done! ";
+my $n = $dbh->selectall_arrayref('SELECT COUNT(*) FROM games as count');
+print "$m game entries found and added. \n";
+
+
+
+# EOF