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