]> ruin.nu Git - ndwebbie.git/blob - NDWeb/Pages/AddIntel.pm
Top members converted
[ndwebbie.git] / NDWeb / Pages / AddIntel.pm
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 package NDWeb::Pages::AddIntel;
21 use strict;
22 use warnings;
23 use CGI qw/:standard/;
24 use NDWeb::Forum;
25 use NDWeb::Include;
26
27 use base qw/NDWeb::XMLPage/;
28
29 $NDWeb::Page::PAGES{addintel} = 'NDWeb::Pages::AddIntel';
30
31 sub render_body {
32         my $self = shift;
33         my ($BODY) = @_;
34
35         my $DBH = $self->{DBH};
36
37         $self->{TITLE} = 'Add Intel and Scans';
38
39         my $error;
40
41         return $self->noAccess unless $self->isMember;
42
43         if (defined param('cmd')){
44                 if (param('cmd') eq 'submit' || param('cmd') eq 'submit_message'){
45                         my $findscan = $DBH->prepare(q{SELECT scan_id FROM scans WHERE scan_id = ? AND tick >= tick() - 168 AND groupscan = ?});
46                         my $addscan = $DBH->prepare(q{INSERT INTO scans (scan_id,tick,uid,groupscan) VALUES (?,tick(),?,?)});
47                         my $addpoint = $DBH->prepare(q{UPDATE users SET scan_points = scan_points + 1 WHERE uid = ? });
48                         my $intel = param('intel');
49                         my @scans;
50                         while ($intel =~ m{http://[\w.]+/.+?scan(_id|_grp)?=(\d+)}g){
51                                 my $groupscan = (defined $1 && $1 eq '_grp') || 0;
52                                 my %scan;
53                                 $scan{Scan} = $2;
54                                 $scan{Message} = ($groupscan ? b 'Group':'')."Scan $2: ";
55                                 $findscan->execute($2,$groupscan);
56                                 if ($findscan->rows == 0){
57                                         if ($addscan->execute($2,$ND::UID,$groupscan)){
58                                                 $addpoint->execute($ND::UID) unless $groupscan;
59                                                 $scan{Message} .= '<i>added</i>';
60                                         }else{
61                                                 $scan{Message} .= "<b>something went wrong:</b> <i>$DBH->errstr</i>";
62                                         }
63                                 }else{
64                                         $scan{Message} .= '<b>already exists</b>';
65                                 }
66                                 push @scans,\%scan;
67                         }
68                         $BODY->param(Scans => \@scans);
69                         my $tick = $self->{TICK};
70                         $tick = param('tick') if defined param('tick') 
71                                 && param('tick') =~ /^(\d+)$/;
72                         my $addintel = $DBH->prepare(q{INSERT INTO fleets 
73                                 (name,mission,tick,target,sender,eta,amount,ingal,back,uid)
74                                 VALUES($1,$2,$3,planetid($4,$5,$6,$10),planetid($7,$8,$9,$10)
75                                         ,$11,$12,$13,$14,$15)
76                         });
77                         my $findplanet = $DBH->prepare(q{SELECT planetid(?,?,?,?)});
78                         while ($intel =~ m/(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)
79                                 \*?\s+(.+)(?:Ter|Cat|Xan|Zik|Etd)?
80                                 \s+(\d+)\s+(Attack|Defend)\s+(\d+)/gx){
81                                 my $ingal = ($1 == $4 && $2 == $5) || 0;
82                                 my $lt = $tick + $10;
83                                 my $back = ($ingal ? $lt + 4 : undef);
84                                 warn "Added: $&\n";
85                                 $addintel->execute($7,$9,$lt,$1,$2,$3,$4,$5,$6,$tick,$10,$8
86                                         ,$ingal,$back, $ND::UID) or warn $DBH->errstr;
87                         }
88                 }
89                 if (param('cmd') eq 'submit_message'){
90                         my $board = {id => 12};
91                         my $subject = param('subject');
92                         unless ($subject){
93                                 if (param('intel') =~ /(.*\w.*)/){
94                                         $subject = $1;
95                                 }
96                         }
97                         if (my $thread = addForumThread $DBH,$board,$ND::UID,$subject){
98                                 $error .= 'Intel message added' if addForumPost $DBH,$thread,$ND::UID,param('intel')
99                         }
100                 }
101         }
102         $BODY->param(Tick => $self->{TICK});
103         $BODY->param(Error => $error);
104         return $BODY;
105 }
106 1;