X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mbd%2Fmbd.pl;fp=mbd%2Fmbd.pl;h=4b73ac9b4e1e484a1b20b28cc4d288664e657b6b;hb=9725b2cf4b9f59d38b6aa2e45c2da91766c90c91;hp=e1f9824de481b7acb121296ad9e6254b8d472df7;hpb=5d0a12aca506c2a2d1a92a03d007836859da5011;p=nms diff --git a/mbd/mbd.pl b/mbd/mbd.pl index e1f9824..4b73ac9 100644 --- a/mbd/mbd.pl +++ b/mbd/mbd.pl @@ -9,6 +9,12 @@ require './access_list.pl'; require './nets.pl'; require './survey.pl'; require './mbd.pm'; +use lib '../include'; +use nms; +use strict; +use warnings; + +my ($dbh, $q); sub fhbits { my $bits = 0; @@ -78,8 +84,16 @@ while (1) { my $age = Time::HiRes::tv_interval($active_surveys{$sport}{start}, $now); if ($age > $Config::survey_time && $active_surveys{$sport}{active}) { print "Survey for '" . $Config::access_list[$active_surveys{$sport}{entry}]->{name} . "'/" . - $active_surveys{$sport}{dport} . ": " . $active_surveys{$sport}{num} . " active servers.\n"; + $active_surveys{$sport}{dport} . ": " . $active_surveys{$sport}{num} . " active servers.\n"; $active_surveys{$sport}{active} = 0; + + # (re)connect to the database if needed + if (!defined($dbh) || !$dbh->ping) { + $dbh = nms::db_connect(); + $q = $dbh->prepare("INSERT INTO mbd_log (ts,game,port,description,active_servers) VALUES (CURRENT_TIMESTAMP,?,?,?,?)") + or die "Couldn't prepare query"; + } + $q->execute($active_surveys{$sport}{entry}, $active_surveys{$sport}{dport}, $Config::access_list[$active_surveys{$sport}{entry}]->{name}, $active_surveys{$sport}{num}); } if ($age > $Config::survey_time * 3.0) { delete $active_surveys{$sport};