These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | fleet.php |
||
5 | Fleet manager |
||
6 | |||
7 | V3.3 copyright (c) 2009-2010 by Gorlum for http://supernova.ws |
||
8 | [~] Imploded fleet_back.php code |
||
9 | |||
10 | V3.2 copyright (c) 2009-2010 by Gorlum for http://supernova.ws |
||
11 | [~] separate independent chunks in INC-files |
||
12 | |||
13 | V3.1 copyright (c) 2009-2010 by Gorlum for http://supernova.ws |
||
14 | [~] Security checked & tested |
||
15 | |||
16 | V3.0 Updated by Gorlum Sep 2009 |
||
17 | [!] extracting templates from code |
||
18 | [~] some redundant code cleaning |
||
19 | |||
20 | V2.0 Updated by Chlorel. 16 Jan 2008 (String extraction, bug corrections, code uniformisation |
||
21 | |||
22 | V1.0 Created by Perberos. All rights reversed (C) 2006 |
||
23 | */ |
||
24 | |||
25 | include('common.' . substr(strrchr(__FILE__, '.'), 1)); |
||
26 | $template_result = is_array($template_result) ? $template_result : array(); |
||
27 | |||
28 | define('SN_IN_FLEET', true); |
||
29 | |||
30 | require_once('includes/includes/flt_functions.php'); |
||
31 | |||
32 | lng_include('fleet'); |
||
33 | |||
34 | //$fleet_page = ($fleet_page = sys_get_param_int('fleet_page')) ? $fleet_page : sys_get_param_int('mode'); |
||
0 ignored issues
–
show
|
|||
35 | $fleet_page = sys_get_param_int('fleet_page', sys_get_param_int('mode')); |
||
36 | |||
37 | $galaxy = sys_get_param_int('galaxy', $planetrow['galaxy']); |
||
38 | $system = sys_get_param_int('system', $planetrow['system']); |
||
39 | $planet = sys_get_param_int('planet', $planetrow['planet']); |
||
40 | |||
41 | $target_mission = sys_get_param_int('target_mission'); |
||
42 | if($target_mission == MT_COLONIZE || $target_mission == MT_EXPLORE) { |
||
43 | $planet_type = PT_PLANET; |
||
44 | } elseif($target_mission == MT_RECYCLE) { |
||
45 | $planet_type = PT_DEBRIS; |
||
46 | } elseif($target_mission == MT_DESTROY) { |
||
47 | $planet_type = PT_MOON; |
||
48 | } else { |
||
49 | $planet_type = sys_get_param_int('planet_type'); |
||
50 | if (!$planet_type) { |
||
51 | $planet_type = sys_get_param_int('planettype', $planetrow['planet_type']); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | $options = array(); |
||
56 | $options['fleets_max'] = GetMaxFleets($user); |
||
57 | |||
58 | $MaxFleets = GetMaxFleets($user); |
||
59 | $FlyingFleets = FleetList::fleet_count_flying($user['id']); |
||
60 | if($MaxFleets <= $FlyingFleets && $fleet_page && $fleet_page != 4) { |
||
61 | message(classLocale::$lang['fl_noslotfree'], classLocale::$lang['fl_error'], "fleet." . PHP_EX, 5); |
||
62 | } |
||
63 | |||
64 | $MaxExpeditions = get_player_max_expeditons($user); |
||
65 | if($MaxExpeditions) { |
||
66 | $FlyingExpeditions = FleetList::fleet_count_flying($user['id'], MT_EXPLORE); |
||
67 | } else { |
||
68 | $FlyingExpeditions = 0; |
||
69 | } |
||
70 | |||
71 | switch ($fleet_page) { |
||
72 | case 3: |
||
73 | |||
74 | case 2: |
||
75 | $fleet_group_mr = sys_get_param_id('fleet_group'); |
||
76 | $fleetarray = unserialize(base64_decode(str_rot13(sys_get_param('usedfleet')))); |
||
77 | $fleetarray = is_array($fleetarray) ? $fleetarray : array(); |
||
78 | |||
79 | foreach($fleetarray as $ship_id => &$ship_amount) { |
||
80 | if(!in_array($ship_id, sn_get_groups('fleet')) || (string)floatval($ship_amount) != $ship_amount || $ship_amount < 1) { |
||
81 | $debug->warning('Supplying wrong ship in ship list on fleet page', 'Hack attempt', 302, array('base_dump' => true)); |
||
82 | die(); |
||
83 | } |
||
84 | $ship_amount = floatval($ship_amount); |
||
85 | } |
||
86 | |||
87 | $UsedPlanet = false; |
||
88 | $YourPlanet = false; |
||
89 | $missiontype = array(); |
||
90 | if ($planet > classSupernova::$config->game_maxPlanet) { |
||
91 | $target_mission = MT_EXPLORE; |
||
92 | $missiontype[MT_EXPLORE] = classLocale::$lang['type_mission'][MT_EXPLORE]; |
||
93 | } elseif ($galaxy && $system && $planet) { |
||
94 | $check_type = $planet_type == PT_MOON ? PT_MOON : PT_PLANET; |
||
95 | |||
96 | $TargetPlanet = db_planet_by_gspt($galaxy, $system, $planet, $check_type); |
||
97 | |||
98 | if ($TargetPlanet['id_owner']) { |
||
99 | $UsedPlanet = true; |
||
100 | if ($TargetPlanet['id_owner'] == $user['id']) { |
||
101 | $YourPlanet = true; |
||
102 | } |
||
103 | } |
||
104 | |||
105 | if (!$UsedPlanet) { |
||
106 | if ($fleetarray[SHIP_COLONIZER]) { |
||
107 | $missiontype[MT_COLONIZE] = classLocale::$lang['type_mission'][MT_COLONIZE]; |
||
108 | $target_mission = MT_COLONIZE; |
||
109 | $planet_type = PT_PLANET; |
||
110 | } else { |
||
111 | message ("<font color=\"red\"><b>". classLocale::$lang['fl_no_planet_type'] ."</b></font>", classLocale::$lang['fl_error']); |
||
112 | } |
||
113 | } else { |
||
114 | $recyclers = 0; |
||
115 | foreach(sn_get_groups('flt_recyclers') as $recycler_id) { |
||
116 | $recyclers += $fleetarray[$recycler_id]; |
||
117 | } |
||
118 | if ($recyclers > 0 && $planet_type == PT_DEBRIS) { |
||
119 | $target_mission = MT_RECYCLE; |
||
120 | $missiontype[MT_RECYCLE] = classLocale::$lang['type_mission'][MT_RECYCLE]; |
||
121 | } elseif ($planet_type == PT_PLANET || $planet_type == PT_MOON) { |
||
122 | if ($YourPlanet) { |
||
123 | $missiontype[MT_RELOCATE] = classLocale::$lang['type_mission'][MT_RELOCATE]; |
||
124 | $missiontype[MT_TRANSPORT] = classLocale::$lang['type_mission'][MT_TRANSPORT]; |
||
125 | } else { |
||
126 | // Not Your Planet |
||
127 | if ($fleetarray[SHIP_SPY]) { |
||
128 | // Only spy missions if any spy |
||
129 | $missiontype[MT_SPY] = classLocale::$lang['type_mission'][MT_SPY]; |
||
130 | } else { |
||
131 | // If no spies... |
||
132 | if ($fleet_group_mr) { |
||
133 | $missiontype[MT_AKS] = classLocale::$lang['type_mission'][MT_AKS]; |
||
134 | } else { |
||
135 | $missiontype[MT_ATTACK] = classLocale::$lang['type_mission'][MT_ATTACK]; |
||
136 | $missiontype[MT_TRANSPORT] = classLocale::$lang['type_mission'][MT_TRANSPORT]; |
||
137 | |||
138 | $missiontype[MT_HOLD] = classLocale::$lang['type_mission'][MT_HOLD]; |
||
139 | |||
140 | if($planet_type == PT_MOON && $fleetarray[SHIP_HUGE_DEATH_STAR]) { |
||
141 | $missiontype[MT_DESTROY] = classLocale::$lang['type_mission'][MT_DESTROY]; |
||
142 | } |
||
143 | } |
||
144 | } |
||
145 | } |
||
146 | } |
||
147 | } |
||
148 | } |
||
149 | |||
150 | if (!$target_mission && is_array($missiontype)) { |
||
151 | $target_mission = MT_ATTACK; |
||
152 | } |
||
153 | |||
154 | ksort($missiontype); |
||
155 | |||
156 | $speed_percent = sys_get_param_int('speed', 10); |
||
157 | $travel_data = flt_travel_data($user, $planetrow, array('galaxy' => $galaxy, 'system' => $system, 'planet' => $planet), $fleetarray, $speed_percent); |
||
158 | |||
159 | $fleet_speed = $travel_data['fleet_speed']; |
||
160 | $distance = $travel_data['distance']; |
||
161 | $duration = $travel_data['duration']; |
||
162 | $consumption = $travel_data['consumption']; |
||
163 | // No Break |
||
164 | |||
165 | case 1: |
||
166 | if ($galaxy && $system && $planet) { |
||
167 | $check_type = $planet_type == PT_MOON ? PT_MOON : PT_PLANET; |
||
168 | |||
169 | $TargetPlanet = db_planet_by_gspt($galaxy, $system, $planet, $check_type); |
||
170 | } |
||
171 | |||
172 | case 0: |
||
173 | $template_result += array( |
||
174 | 'thisgalaxy' => $planetrow['galaxy'], |
||
175 | 'thissystem' => $planetrow['system'], |
||
176 | 'thisplanet' => $planetrow['planet'], |
||
177 | 'thisplanet_type' => $planetrow['planet_type'], |
||
178 | ); |
||
179 | // no break |
||
180 | |||
181 | } |
||
182 | |||
183 | $template_result += array( |
||
184 | 'galaxy' => $galaxy, |
||
185 | 'system' => $system, |
||
186 | 'planet' => $planet, |
||
187 | 'planet_type' => $planet_type, |
||
188 | 'target_mission' => $target_mission ? $target_mission : 0, |
||
189 | 'MISSION_NAME' => $target_mission ? classLocale::$lang['type_mission'][$target_mission] : '', |
||
190 | ); |
||
191 | |||
192 | $is_transport_missions = false; |
||
193 | if($missiontype) { |
||
0 ignored issues
–
show
The expression
$missiontype of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
194 | $sn_group_missions = sn_get_groups('missions'); |
||
195 | foreach($missiontype as $mission_data_id => $mission_data) { |
||
196 | $is_transport_missions = $is_transport_missions || (isset($sn_group_missions[$mission_data_id]['transport']) && $sn_group_missions[$mission_data_id]['transport']); |
||
197 | } |
||
198 | } |
||
199 | |||
200 | switch($fleet_page) { |
||
201 | case 1: |
||
202 | require('includes/includes/flt_page1.inc'); |
||
203 | break; |
||
204 | |||
205 | case 2: |
||
206 | require_once('includes/includes/flt_page2.inc'); |
||
207 | sn_fleet_page2(); |
||
208 | break; |
||
209 | |||
210 | case 3: |
||
211 | require_once('includes/includes/flt_page3.inc'); |
||
212 | sn_fleet_page3($duration); |
||
213 | break; |
||
214 | |||
215 | case 4: |
||
216 | require('includes/includes/flt_page4.inc'); |
||
217 | break; |
||
218 | |||
219 | case 5: |
||
220 | require('includes/includes/flt_page5.inc'); |
||
221 | break; |
||
222 | |||
223 | default: |
||
224 | define('SN_RENDER_NAVBAR_PLANET', true); |
||
225 | |||
226 | require('includes/includes/flt_page0.inc'); |
||
227 | break; |
||
228 | } |
||
229 |
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.