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); |
||||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||||
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 = [P_FLEET_ATTACK_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( |
||||
0 ignored issues
–
show
The function
doquery() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
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 | $fleet_set = [ |
||||
146 | 'fleet_owner' => $user['id'], |
||||
147 | 'fleet_mission' => $target_mission, |
||||
148 | 'fleet_amount' => $fleet_ship_count, |
||||
149 | 'fleet_array' => $FleetDBArray, |
||||
150 | 'fleet_start_time' => $fleet_start_time, |
||||
151 | 'fleet_start_planet_id' => !empty($planetrow['id']) ? $planetrow['id'] : null, |
||||
152 | 'fleet_start_galaxy' => $planetrow['galaxy'], |
||||
153 | 'fleet_start_system' => $planetrow['system'], |
||||
154 | 'fleet_start_planet' => $planetrow['planet'], |
||||
155 | 'fleet_start_type' => $planetrow['planet_type'], |
||||
156 | 'fleet_end_time' => $fleet_end_time, |
||||
157 | 'fleet_end_planet_id' => !empty($target_row['id']) ? $target_row['id'] : null, |
||||
158 | 'fleet_end_galaxy' => $target_coord['galaxy'], |
||||
159 | 'fleet_end_system' => $target_coord['system'], |
||||
160 | 'fleet_end_planet' => $target_coord['planet'], |
||||
161 | 'fleet_end_type' => $target_planet_type, |
||||
162 | 'fleet_target_owner' => $target_row['id_owner'], |
||||
163 | 'start_time' => SN_TIME_NOW, |
||||
164 | ]; |
||||
165 | DbFleetStatic::fleet_insert_set_dbq($fleet_set); |
||||
166 | } |
||||
167 | |||||
168 | DBStaticPlanet::db_planet_set_by_id($planetrow['id'], "`deuterium` = `deuterium` - {$travel_data['consumption']}"); |
||||
169 | OldDbChangeSet::db_changeset_apply($db_changeset); |
||||
170 | sn_db_transaction_commit(); |
||||
171 | |||||
172 | $ships_sent = array(); |
||||
173 | //$ships_sent_js = array(); |
||||
174 | $ships_sent_js = 0; |
||||
175 | foreach($fleet_array as $unit_id => $unit_count) |
||||
0 ignored issues
–
show
|
|||||
176 | { |
||||
177 | $ships_sent[] = "{$unit_count} {$lang['tech'][$unit_id]}"; |
||||
178 | $ships_sent_js += mrc_get_level($user, $planetrow, $unit_id, false, true); |
||||
179 | } |
||||
180 | $ships_sent = implode(', ', $ships_sent); |
||||
181 | //$ships_sent_js = implode(',', $ships_sent_js); |
||||
182 | $ships_sent_js = "{$unit_group}={$ships_sent_js}"; |
||||
183 | |||||
184 | $ResultMessage = "{$lang['gs_sending']} {$ships_sent} {$lang['gs_to']} {$target_coord['galaxy']}:{$target_coord['system']}:{$target_coord['planet']}|{$ships_sent_js}"; |
||||
185 | |||||
186 | die($ResultMessage); |
||||
187 |