1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
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. *
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. *
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 #**************************************************************************/
22 $ND::TEMPLATE->param(TITLE => 'Launch Confirmation');
30 die "You don't have access" unless isMember();
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 (?,?,?)');
46 my $fleet = $DBH->prepare("SELECT id FROM fleets WHERE uid = ? AND fleet = 0");
47 my ($basefleet) = $DBH->selectrow_array($fleet,undef,$ND::UID);
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);
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){
57 my $tick = $ND::TICK+$7+$8;
63 $mission{Tick} = $tick;
64 $mission{Mission} = $mission;
65 $mission{Target} = "$x:$y:$z";
72 my ($planet_id) = $DBH->selectrow_array($findplanet,undef,$x,$y,$z,$ND::TICK);
74 my $findtarget = $finddefensetarget;
75 if ($mission eq 'Attack'){
76 $findtarget = $findattacktarget;
77 }elsif ($mission eq 'Defend'){
78 $findtarget = $finddefensetarget;
81 $findtarget->execute($ND::UID,$tick,$planet_id);
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}";
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");
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;
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};
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;
111 $BODY->param(Missions => \@missions);