From: root Date: Wed, 4 Apr 2007 18:01:05 +0000 (+0200) Subject: Put the survey data into SQL. X-Git-Url: https://git.sesse.net/?p=nms;a=commitdiff_plain;h=9725b2cf4b9f59d38b6aa2e45c2da91766c90c91 Put the survey data into SQL. --- 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};