]> ruin.nu Git - ndwebbie.git/blob - addintel.pl
2d023f74d85c2dd57b40606df0ad71df0638a61a
[ndwebbie.git] / addintel.pl
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
4 #   This program is free software; you can redistribute it and/or modify  *
5 #   it under the terms of the GNU General Public License as published by  *
6 #   the Free Software Foundation; either version 2 of the License, or     *
7 #   (at your option) any later version.                                   *
8 #                                                                         *
9 #   This program is distributed in the hope that it will be useful,       *
10 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 #   GNU General Public License for more details.                          *
13 #                                                                         *
14 #   You should have received a copy of the GNU General Public License     *
15 #   along with this program; if not, write to the                         *
16 #   Free Software Foundation, Inc.,                                       *
17 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
18 #**************************************************************************/
19
20 use strict;
21
22 $ND::TEMPLATE->param(TITLE => 'Add Intel and Scans');
23
24 our $BODY;
25 our $DBH;
26 our $LOG;
27
28
29
30 die "You don't have access" unless isMember();
31
32 if (param('cmd') eq 'submit' || param('cmd') eq 'submit_message'){
33                 my $findscan = $DBH->prepare("SELECT scan_id FROM scans WHERE scan_id = ? AND tick >= tick() - 48");
34                 my $addscan = $DBH->prepare('INSERT INTO scans (scan_id,tick,"type") VALUES (?,tick(),?)');
35                 my $addpoint = $DBH->prepare('UPDATE users SET scan_points = scan_points + 1 WHERE uid = ? ');
36         my $intel = param('intel');
37         my @scans;
38         while ($intel =~ m/http:\/\/game.planetarion.com\/showscan.pl\?scan_id=(\d+)/g){
39                 my %scan;
40                 $scan{Scan} = $1;
41                 $findscan->execute($1);
42                 if ($findscan->rows == 0){
43                         if ($addscan->execute($1,$ND::UID)){
44                                 $addpoint->execute($ND::UID);
45                                 $scan{Message} = '<i>added</i>';
46                         }else{
47                                 $scan{Message} = "<b>something went wrong:</b> <i>$DBH->errstr</i>";
48                         }
49                 }else{
50                                 $scan{Message} = '<b>already exists</b>';
51                 }
52                 push @scans,\%scan;
53         }
54         $BODY->param(Scans => \@scans);
55         my $tick = $ND::TICK;
56         $tick = param('tick') if $tick =~ /^(\d+)$/;
57         my $addintel = $DBH->prepare(qq{SELECT add_intel(?,?,?,?,?,?,?,?,?,?,?)});
58         while ($intel =~ m/(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)\*?\s+.+(?:Ter|Cat|Xan|Zik)?\s+(\d+)\s+(Attack|Defend)\s+(\d+)/g){
59                 $addintel->execute($tick,$9, $1,$2,$3,$4,$5,$6,$7,$8,$ND::UID) or print $DBH->errstr;
60         }
61 }
62 if (param('cmd') eq 'submit_message'){
63         my $query = $DBH->prepare(q{INSERT INTO intel_messages (uid,message) VALUES(?,?)});
64         $query->execute($ND::UID,escapeHTML(param('intel'))) or print $DBH->errstr;
65 }
66
67
68 1;