]> ruin.nu Git - ndwebbie.git/blob - launchConfirmation.pl
oops, guess I had forgotten about this file
[ndwebbie.git] / launchConfirmation.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 use warnings FATAL => 'all';
22 no warnings qw(uninitialized);
23
24 $ND::TEMPLATE->param(TITLE => 'Launch Confirmation');
25
26 our $BODY;
27 our $DBH;
28 our $LOG;
29 my $error;
30
31
32
33 die "You don't have access" unless isMember();
34
35 if (param('cmd') eq 'submit'){
36         my $missions = param('mission');
37         my $findplanet = $DBH->prepare("SELECT planetid(?,?,?,?)");
38         my $findattacktarget = $DBH->prepare(q{SELECT c.target,c.wave,c.launched FROM  raid_claims c
39                 JOIN raid_targets t ON c.target = t.id
40                 JOIN raids r ON t.raid = r.id
41                 WHERE c.uid = ? AND r.tick+c.wave-1 = ? AND t.planet = ?
42                 AND r.open AND not r.removed});
43         my $finddefensetarget = $DBH->prepare(q{SELECT NULL});
44         my $addattackpoint = $DBH->prepare('UPDATE users SET attack_points = attack_points + 1 WHERE uid = ?');
45         my $launchedtarget = $DBH->prepare('UPDATE raid_claims SET launched = True WHERE uid = ? AND target = ? AND wave = ?');
46         my $addfleet = $DBH->prepare(qq{INSERT INTO fleets (uid,target,mission,landing_tick,fleet,eta,back) VALUES (?,?,?,?,(SELECT max(fleet)+1 from fleets WHERE uid = ?),?,?)});
47         my $addships = $DBH->prepare('INSERT INTO fleet_ships (fleet,ship,amount) VALUES (?,?,?)');
48
49         my $fleet = $DBH->prepare("SELECT id FROM fleets WHERE uid = ? AND fleet = 0");
50         my ($basefleet) = $DBH->selectrow_array($fleet,undef,$ND::UID);
51         unless ($basefleet){
52                 my $insert = $DBH->prepare(q{INSERT INTO fleets (uid,target,mission,landing_tick,fleet,eta,back) VALUES (?,?,'Full fleet',0,0,0,0)});
53                 $insert->execute($ND::UID,$ND::PLANET);
54         }
55         my @missions;
56         $DBH->begin_work;
57         while ($missions =~ m/\S+\s+(\d+):(\d+):(\d+)\s+(\d+):(\d+):(\d+)\s+\((?:(\d+)\+)?(\d+)\).*?(?:\d+hrs\s+)?\d+mins\s+(Attack|Defend|Return|Fake Attack|Fake Defend)(.*?)(?:Launching in tick (\d+), arrival in tick (\d+)|ETA: \d+, Return ETA: (\d+))/sg){
58                 my %mission;
59
60                 my $tick = $ND::TICK+$7+$8;
61                 my $eta = $8;
62                 my $mission = $9;
63                 my $x = $4;
64                 my $y = $5;
65                 my $z = $6;
66                 $mission{Tick} = $tick;
67                 $mission{Mission} = $mission;
68                 $mission{Target} = "$x:$y:$z";
69                 if ($12){
70                         $tick = $12;
71                 }elsif ($13){
72                         $eta += $13;
73                 }
74
75                 my ($planet_id) = $DBH->selectrow_array($findplanet,undef,$x,$y,$z,$ND::TICK);
76
77                 my $findtarget = $finddefensetarget;
78                 if ($mission eq 'Attack'){
79                         $findtarget = $findattacktarget;
80                 }elsif ($mission eq 'Defend'){
81                         $findtarget = $finddefensetarget;
82                 }
83
84                 $findtarget->execute($ND::UID,$tick,$planet_id);
85
86                 if ($findtarget->rows == 0){
87                         $mission{Warning} = "YOU DON'T HAVE A TARGET WITH THAT LANDING TICK";
88                 }elsif ($mission eq 'Attack'){
89                         my $claim = $findtarget->fetchrow_hashref;
90                         if ($claim->{launched}){
91                                 $mission{Warning} = "Already launched on this target:$claim->{target},$claim->{wave},$claim->{launched}";
92                         }else{
93                                 $addattackpoint->execute($ND::UID);
94                                 $launchedtarget->execute($ND::UID,$claim->{target},$claim->{wave});
95                                 $mission{Warning} = "OK:$claim->{target},$claim->{wave},$claim->{launched}";
96                                 $LOG->execute($ND::UID,"Gave attack point for confirmation on $mission mission to $x:$y:$z, landing tick $tick");
97                         }
98                 }
99
100                 $addfleet->execute($ND::UID,$planet_id,$mission,$tick,$ND::UID,$eta,$tick+$eta-1) or $error .= '<p>'.$DBH->errstr.'</p>';
101                 my $fleet = $DBH->last_insert_id(undef,undef,undef,undef,"fleets_id_seq");
102                 $mission{Fleet} = $fleet;
103                 $mission{Back} = $tick+$eta-1;
104                 my $ships = $10;
105                 my @ships;
106                 while ($ships =~ m/((?:\w+ )*\w+)\s+\w+\s+\w+\s+(?:Steal|Normal|Emp|Normal\s+Cloaked|Pod|Struc)\s+(\d+)/g){
107                         $addships->execute($fleet,$1,$2);
108                         push @ships,{Ship => $1, Amount => $2};
109                 }
110                 $mission{Ships} = \@ships;
111                 $LOG->execute($ND::UID,"Pasted confirmation for $mission mission to $x:$y:$z, landing tick $tick");
112                 push @missions,\%mission;
113         }
114         $DBH->commit or $error .= '<p>'.$DBH->errstr.'</p>';
115         $BODY->param(Missions => \@missions);
116 }
117 $BODY->param(Error => $error);
118
119
120 1;