]> ruin.nu Git - ndwebbie.git/blob - scripts/ndreport.pl
encoder was used in a bad way
[ndwebbie.git] / scripts / ndreport.pl
1 #!/usr/bin/perl
2 q{
3 /***************************************************************************
4  *   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  *   This program is distributed in the hope that it will be useful,       *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14  *   GNU General Public License for more details.                          *
15  *                                                                         *
16  *   You should have received a copy of the GNU General Public License     *
17  *   along with this program; if not, write to the                         *
18  *   Free Software Foundation, Inc.,                                       *
19  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
20  ***************************************************************************/
21 };
22
23 use strict;
24 use warnings;
25 use DBI;
26 use DBD::Pg qw(:pg_types);
27 use CGI qw/:standard/;
28
29 use Email::Simple;
30 use Encode::Encoder qw(encoder);
31 use MIME::QuotedPrint;
32
33 use FindBin;
34 use lib "$FindBin::Bin/../lib";
35 use ND::DB;
36
37 my $dbh = ND::DB::DB();
38
39 my @text = <>;
40 my $text = join '',@text;
41
42 $text =~ /ndreport\+(.+?)\@ruin\.nu/;
43
44 my $user = $1;
45
46 my $email = Email::Simple->new($text);
47
48 my $body =  encoder($email->body,'ISO-8859-15')->utf8;
49
50 my $c = $dbh->prepare(q{
51 SELECT coords(x,y,z) FROM current_planet_stats WHERE pid = (SELECT pid FROM users WHERE username = $1)
52 });
53
54 my $a = $dbh->prepare(q{
55 SELECT race, $1 - tick() FROM current_planet_stats WHERE x = $2 AND y = $3 AND z = $4
56 });
57
58 my $report = $dbh->prepare(q{INSERT INTO irc_requests (channel,uid,message) VALUES('def',$1,$2)});
59
60 while($body =~ /jumpgate from (.+?), located at (\d+):(\d+):(\d+).+?our system in tick (\d+) and appears to have (\d+)/sg){
61         my ($fleet, $x,$y,$z,$tick, $amount) = ($1,$2,$3,$4,$5,$6);
62
63         my ($coords) = $dbh->selectrow_array($c, undef, $user);
64
65         $coords //= '(no coords entered)';
66
67         my ($race,$eta) = $dbh->selectrow_array($a,undef, $tick,$x,$y,$z);
68
69         $report->execute(-5,"$user has incs: $coords $x:$y:$z $fleet $race $amount $eta");
70 }
71
72 $dbh->disconnect;
73
74 system 'killall','-USR1', 'ndbot.pl';