1 | <?php |
||
2 | |||
3 | /** |
||
4 | * flotenajax.php |
||
5 | * |
||
6 | * Fleet manager on Ajax (to work in Galaxy view) |
||
7 | * |
||
8 | * @version 2.0 Security checks by Gorlum for http://supernova.ws |
||
9 | * [!] Full rewrite |
||
10 | * [+] Added missile attack launch sequience |
||
11 | * [-] Moved almost all check code to flt_can_attack |
||
12 | * @version 1.1 Security checks by Gorlum for http://supernova.ws |
||
13 | * @version 1 |
||
14 | * @copyright 2008 By Chlorel for XNova |
||
15 | **/ |
||
16 | |||
17 | use DBAL\OldDbChangeSet; |
||
18 | use Fleet\DbFleetStatic; |
||
19 | use Planet\DBStaticPlanet; |
||
20 | |||
21 | include('common.' . substr(strrchr(__FILE__, '.'), 1)); |
||
22 | |||
23 | define('IN_AJAX', true); |
||
24 | |||
25 | setHeader("Content-type: text/html; charset=utf-8"); |
||
26 | lng_include('universe'); |
||
27 | lng_include('fleet'); |
||
28 | require_once('includes/includes/flt_functions.php'); |
||
29 | |||
30 | $target_coord = array( |
||
31 | 'galaxy' => $target_galaxy = sys_get_param_int('galaxy'), |
||
32 | 'system' => $target_system = sys_get_param_int('system'), |
||
33 | 'planet' => $target_planet = sys_get_param_int('planet'), |
||
34 | ); |
||
35 | |||
36 | if(!uni_coordinates_valid($target_coord)) |
||
37 | { |
||
38 | die($lang['gs_c02']); |
||
39 | } |
||
40 | |||
41 | $target_mission = sys_get_param_int('mission'); |
||
42 | $sn_group_missions = sn_get_groups('missions'); |
||
43 | if(!isset($sn_group_missions[$target_mission]['AJAX']) || !$sn_group_missions[$target_mission]['AJAX']) |
||
44 | { |
||
45 | die($lang['gs_c00']); |
||
46 | } |
||
47 | |||
48 | sn_db_transaction_start(); |
||
49 | |||
50 | $user = db_user_by_id($user['id'], true); |
||
51 | $planetrow = DBStaticPlanet::db_planet_by_id($user['current_planet'], true); |
||
52 | |||
53 | $target_planet_type = sys_get_param_int('planet_type'); |
||
54 | $target_planet_check = $target_planet_type == PT_DEBRIS ? PT_PLANET : $target_planet_type; |
||
55 | |||
56 | $target_coord['planet_type'] = $target_planet_check; |
||
57 | $target_row = DBStaticPlanet::db_planet_by_vector($target_coord); |
||
58 | |||
59 | if(empty($target_row)) |
||
60 | { |
||
61 | $target_row = array( |
||
62 | 'galaxy' => $target_coord['galaxy'], |
||
63 | 'system' => $target_coord['system'], |
||
64 | 'planet' => $target_coord['planet'], |
||
65 | 'planet_type' => $target_planet_check, |
||
66 | 'id_owner' => 0 |
||
67 | ); |
||
68 | } |
||
69 | |||
70 | $fleet_array = array(); |
||
71 | switch($target_mission) |
||
72 | { |
||
73 | case MT_SPY: |
||
74 | // $fleet_array[SHIP_SPY] = min(mrc_get_level($user, $planetrow, SHIP_SPY), abs($user['spio_anz'])); |
||
75 | $fleet_array[SHIP_SPY] = min(mrc_get_level($user, $planetrow, SHIP_SPY), abs(SN::$user_options[PLAYER_OPTION_FLEET_SPY_DEFAULT])); |
||
76 | $unit_group = 'flt_spies'; |
||
77 | break; |
||
78 | |||
79 | case MT_RECYCLE: |
||
80 | foreach(sn_get_groups('flt_recyclers') as $unit_id) |
||
81 | { |
||
82 | if($unit_count = mrc_get_level($user, $planetrow, $unit_id)) |
||
83 | { |
||
84 | $fleet_array[$unit_id] = $unit_count; |
||
85 | } |
||
86 | } |
||
87 | $transport_data = flt_calculate_fleet_to_transport($fleet_array, $target_row['debris_metal'] + $target_row['debris_crystal'], $planetrow, $target_row); |
||
88 | $fleet_array = $transport_data['fleet']; |
||
89 | $unit_group = 'flt_recyclers'; |
||
90 | break; |
||
91 | |||
92 | case MT_MISSILE: |
||
93 | $fleet_array[UNIT_DEF_MISSILE_INTERPLANET] = min(mrc_get_level($user, $planetrow, UNIT_DEF_MISSILE_INTERPLANET), abs(sys_get_param_float('missiles'))); |
||
94 | $unit_group = 'missile'; |
||
95 | break; |
||
96 | |||
97 | } |
||
98 | |||
99 | $options = array('target_structure' => $target_structure = sys_get_param_int('structures')); |
||
100 | $cant_attack = flt_can_attack($planetrow, $target_row, $fleet_array, $target_mission, $options); |
||
101 | |||
102 | |||
103 | if($cant_attack != ATTACK_ALLOWED) |
||
104 | { |
||
105 | die($lang['fl_attack_error'][$cant_attack]); |
||
106 | } |
||
107 | |||
108 | $FleetDBArray = array(); |
||
109 | $db_changeset = array(); |
||
110 | foreach($fleet_array as $unit_id => $unit_count) |
||
111 | { |
||
112 | $FleetDBArray[] = "{$unit_id},{$unit_count}"; |
||
113 | $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($unit_id, -$unit_count, $user, $planetrow); |
||
114 | } |
||
115 | $FleetDBArray = implode(';', $FleetDBArray); |
||
116 | |||
117 | $fleet_ship_count = array_sum($fleet_array); |
||
118 | |||
119 | if($target_mission == MT_MISSILE) |
||
120 | { |
||
121 | $distance = abs($target_coord['system'] - $planetrow['system']); |
||
122 | $duration = round((30 + (60 * $distance)) / flt_server_flight_speed_multiplier()); |
||
123 | $arrival = SN_TIME_NOW + $duration; |
||
124 | $travel_data['consumption'] = 0; |
||
125 | |||
126 | doquery( |
||
127 | "INSERT INTO `{{iraks}}` SET |
||
128 | `fleet_target_owner` = '{$target_row['id_owner']}', `fleet_end_galaxy` = '{$target_coord['galaxy']}', `fleet_end_system` = '{$target_coord['system']}', `fleet_end_planet` = '{$target_coord['planet']}', |
||
129 | `fleet_owner` = '{$user['id']}', `fleet_start_galaxy` = '{$planetrow['galaxy']}', `fleet_start_system` = '{$planetrow['system']}', `fleet_start_planet` = '{$planetrow['planet']}', |
||
130 | `fleet_end_time` = '{$arrival}', `fleet_amount` = '{$fleet_ship_count}', `primaer` = '{$target_structure}';" |
||
131 | ); |
||
132 | } |
||
133 | else |
||
134 | { |
||
135 | $travel_data = flt_travel_data($user, $planetrow, $target_coord, $fleet_array, 10); |
||
136 | |||
137 | if($planetrow['deuterium'] < $travel_data['consumption']) |
||
138 | { |
||
139 | die($lang['gs_c13']); |
||
140 | } |
||
141 | |||
142 | $fleet_start_time = SN_TIME_NOW + $travel_data['duration']; |
||
143 | $fleet_end_time = $fleet_start_time + $travel_data['duration']; |
||
144 | |||
145 | // $QryInsertFleet = "INSERT INTO {{fleets}} SET "; |
||
0 ignored issues
–
show
|
|||
146 | // $QryInsertFleet .= "`fleet_owner` = '{$user['id']}', "; |
||
147 | // $QryInsertFleet .= "`fleet_mission` = '{$target_mission}', "; |
||
148 | // $QryInsertFleet .= "`fleet_amount` = '{$fleet_ship_count}', "; |
||
149 | // $QryInsertFleet .= "`fleet_array` = '{$FleetDBArray}', "; |
||
150 | // $QryInsertFleet .= "`fleet_start_time` = '{$fleet_start_time}', "; |
||
151 | // if($planetrow['id']) |
||
152 | // { |
||
153 | // $QryInsertFleet .= "`fleet_start_planet_id` = '{$planetrow['id']}', "; |
||
154 | // } |
||
155 | // $QryInsertFleet .= "`fleet_start_galaxy` = '{$planetrow['galaxy']}', `fleet_start_system` = '{$planetrow['system']}', `fleet_start_planet` = '{$planetrow['planet']}', `fleet_start_type` = '{$planetrow['planet_type']}', "; |
||
156 | // $QryInsertFleet .= "`fleet_end_time` = '{$fleet_end_time}', "; |
||
157 | // if($target_row['id']) |
||
158 | // { |
||
159 | // $QryInsertFleet .= "`fleet_end_planet_id` = '{$target_row['id']}', "; |
||
160 | // } |
||
161 | // $QryInsertFleet .= "`fleet_end_galaxy` = '{$target_coord['galaxy']}', `fleet_end_system` = '{$target_coord['system']}', `fleet_end_planet` = '{$target_coord['planet']}', `fleet_end_type` = '{$target_planet_type}', "; |
||
162 | // $QryInsertFleet .= "`fleet_target_owner` = '{$target_row['id_owner']}', "; |
||
163 | // $QryInsertFleet .= "`start_time` = ". SN_TIME_NOW . ";"; |
||
164 | // doquery($QryInsertFleet); |
||
165 | |||
166 | $fleet_set = [ |
||
167 | 'fleet_owner' => $user['id'], |
||
168 | 'fleet_mission' => $target_mission, |
||
169 | 'fleet_amount' => $fleet_ship_count, |
||
170 | 'fleet_array' => $FleetDBArray, |
||
171 | 'fleet_start_time' => $fleet_start_time, |
||
172 | 'fleet_start_planet_id' => !empty($planetrow['id']) ? $planetrow['id'] : null, |
||
173 | 'fleet_start_galaxy' => $planetrow['galaxy'], |
||
174 | 'fleet_start_system' => $planetrow['system'], |
||
175 | 'fleet_start_planet' => $planetrow['planet'], |
||
176 | 'fleet_start_type' => $planetrow['planet_type'], |
||
177 | 'fleet_end_time' => $fleet_end_time, |
||
178 | 'fleet_end_planet_id' => !empty($target_row['id']) ? $target_row['id'] : null, |
||
179 | 'fleet_end_galaxy' => $target_coord['galaxy'], |
||
180 | 'fleet_end_system' => $target_coord['system'], |
||
181 | 'fleet_end_planet' => $target_coord['planet'], |
||
182 | 'fleet_end_type' => $target_planet_type, |
||
183 | 'fleet_target_owner' => $target_row['id_owner'], |
||
184 | 'start_time' => SN_TIME_NOW, |
||
185 | ]; |
||
186 | DbFleetStatic::fleet_insert_set_dbq($fleet_set); |
||
187 | } |
||
188 | |||
189 | DBStaticPlanet::db_planet_set_by_id($planetrow['id'], "`deuterium` = `deuterium` - {$travel_data['consumption']}"); |
||
190 | OldDbChangeSet::db_changeset_apply($db_changeset); |
||
191 | sn_db_transaction_commit(); |
||
192 | |||
193 | $ships_sent = array(); |
||
194 | //$ships_sent_js = array(); |
||
195 | $ships_sent_js = 0; |
||
196 | foreach($fleet_array as $unit_id => $unit_count) |
||
197 | { |
||
198 | $ships_sent[] = "{$unit_count} {$lang['tech'][$unit_id]}"; |
||
199 | $ships_sent_js += mrc_get_level($user, $planetrow, $unit_id, false, true); |
||
200 | } |
||
201 | $ships_sent = implode(', ', $ships_sent); |
||
202 | //$ships_sent_js = implode(',', $ships_sent_js); |
||
203 | $ships_sent_js = "{$unit_group}={$ships_sent_js}"; |
||
204 | |||
205 | $ResultMessage = "{$lang['gs_sending']} {$ships_sent} {$lang['gs_to']} {$target_coord['galaxy']}:{$target_coord['system']}:{$target_coord['planet']}|{$ships_sent_js}"; |
||
206 | |||
207 | die($ResultMessage); |
||
208 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.