supernova-ws /
SuperNova
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 | * 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 | include('common.' . substr(strrchr(__FILE__, '.'), 1)); |
||
| 18 | |||
| 19 | define('IN_AJAX', true); |
||
| 20 | |||
| 21 | header("Content-type: text/html; charset=utf-8"); |
||
| 22 | lng_include('universe'); |
||
| 23 | lng_include('fleet'); |
||
| 24 | require_once('includes/includes/flt_functions.php'); |
||
| 25 | |||
| 26 | $target_coord = array( |
||
| 27 | 'galaxy' => $target_galaxy = sys_get_param_int('galaxy'), |
||
| 28 | 'system' => $target_system = sys_get_param_int('system'), |
||
| 29 | 'planet' => $target_planet = sys_get_param_int('planet'), |
||
| 30 | ); |
||
| 31 | |||
| 32 | if(!uni_coordinates_valid($target_coord)) |
||
| 33 | { |
||
| 34 | die($lang['gs_c02']); |
||
| 35 | } |
||
| 36 | |||
| 37 | $target_mission = sys_get_param_int('mission'); |
||
| 38 | $sn_group_missions = sn_get_groups('missions'); |
||
| 39 | if(!isset($sn_group_missions[$target_mission]['AJAX']) || !$sn_group_missions[$target_mission]['AJAX']) |
||
| 40 | { |
||
| 41 | die($lang['gs_c00']); |
||
| 42 | } |
||
| 43 | |||
| 44 | sn_db_transaction_start(); |
||
| 45 | |||
| 46 | $user = db_user_by_id($user['id'], true); |
||
| 47 | $planetrow = DBStaticPlanet::db_planet_by_id($user['current_planet'], true); |
||
| 48 | |||
| 49 | $target_planet_type = sys_get_param_int('planet_type'); |
||
| 50 | $target_planet_check = $target_planet_type == PT_DEBRIS ? PT_PLANET : $target_planet_type; |
||
| 51 | |||
| 52 | $target_coord['planet_type'] = $target_planet_check; |
||
| 53 | $target_row = DBStaticPlanet::db_planet_by_vector($target_coord); |
||
| 54 | |||
| 55 | if(empty($target_row)) |
||
| 56 | { |
||
| 57 | $target_row = array( |
||
| 58 | 'galaxy' => $target_coord['galaxy'], |
||
| 59 | 'system' => $target_coord['system'], |
||
| 60 | 'planet' => $target_coord['planet'], |
||
| 61 | 'planet_type' => $target_planet_check, |
||
| 62 | 'id_owner' => 0 |
||
| 63 | ); |
||
| 64 | } |
||
| 65 | |||
| 66 | $fleet_array = array(); |
||
| 67 | switch($target_mission) |
||
| 68 | { |
||
| 69 | case MT_SPY: |
||
| 70 | // $fleet_array[SHIP_SPY] = min(mrc_get_level($user, $planetrow, SHIP_SPY), abs($user['spio_anz'])); |
||
|
0 ignored issues
–
show
|
|||
| 71 | $fleet_array[SHIP_SPY] = min(mrc_get_level($user, $planetrow, SHIP_SPY), abs(classSupernova::$user_options[PLAYER_OPTION_FLEET_SPY_DEFAULT])); |
||
|
0 ignored issues
–
show
It seems like
$planetrow defined by \DBStaticPlanet::db_plan...current_planet'], true) on line 47 can also be of type null; however, mrc_get_level() does only seem to accept array, maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. Loading history...
|
|||
| 72 | $unit_group = 'flt_spies'; |
||
| 73 | break; |
||
| 74 | |||
| 75 | case MT_RECYCLE: |
||
| 76 | foreach(sn_get_groups('flt_recyclers') as $unit_id) |
||
| 77 | { |
||
| 78 | if($unit_count = mrc_get_level($user, $planetrow, $unit_id)) |
||
|
0 ignored issues
–
show
It seems like
$planetrow defined by \DBStaticPlanet::db_plan...current_planet'], true) on line 47 can also be of type null; however, mrc_get_level() does only seem to accept array, maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. Loading history...
|
|||
| 79 | { |
||
| 80 | $fleet_array[$unit_id] = $unit_count; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | $transport_data = flt_calculate_fleet_to_transport($fleet_array, $target_row['debris_metal'] + $target_row['debris_crystal'], $planetrow, $target_row); |
||
| 84 | $fleet_array = $transport_data['fleet']; |
||
| 85 | $unit_group = 'flt_recyclers'; |
||
| 86 | break; |
||
| 87 | |||
| 88 | case MT_MISSILE: |
||
| 89 | $fleet_array[UNIT_DEF_MISSILE_INTERPLANET] = min(mrc_get_level($user, $planetrow, UNIT_DEF_MISSILE_INTERPLANET), abs(sys_get_param_float('missiles'))); |
||
|
0 ignored issues
–
show
It seems like
$planetrow defined by \DBStaticPlanet::db_plan...current_planet'], true) on line 47 can also be of type null; however, mrc_get_level() does only seem to accept array, maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. Loading history...
|
|||
| 90 | $unit_group = 'missile'; |
||
| 91 | break; |
||
| 92 | |||
| 93 | } |
||
| 94 | |||
| 95 | $options = array('target_structure' => $target_structure = sys_get_param_int('structures')); |
||
| 96 | $cant_attack = flt_can_attack($planetrow, $target_row, $fleet_array, $target_mission, $options); |
||
|
0 ignored issues
–
show
$options is of type array<string,integer,{"t..._structure":"integer"}>, but the function expects a boolean.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 97 | |||
| 98 | |||
| 99 | if($cant_attack != ATTACK_ALLOWED) |
||
| 100 | { |
||
| 101 | die($lang['fl_attack_error'][$cant_attack]); |
||
| 102 | } |
||
| 103 | |||
| 104 | $FleetDBArray = array(); |
||
| 105 | $db_changeset = array(); |
||
| 106 | foreach($fleet_array as $unit_id => $unit_count) |
||
| 107 | { |
||
| 108 | $FleetDBArray[] = "{$unit_id},{$unit_count}"; |
||
| 109 | // $db_changeset[] = "`{$unit_db_name}` = `{$unit_db_name}` - {$unit_count}"; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
56% of this comment could be valid code. Did you maybe forget this after debugging?
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. Loading history...
|
|||
| 110 | $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, -$unit_count, $user, $planetrow); |
||
| 111 | } |
||
| 112 | $FleetDBArray = implode(';', $FleetDBArray); |
||
| 113 | // $db_changeset = implode(',', $db_changeset); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
54% of this comment could be valid code. Did you maybe forget this after debugging?
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. Loading history...
|
|||
| 114 | |||
| 115 | $fleet_ship_count = array_sum($fleet_array); |
||
| 116 | |||
| 117 | if($target_mission == MT_MISSILE) |
||
| 118 | { |
||
| 119 | $distance = abs($target_coord['system'] - $planetrow['system']); |
||
| 120 | $duration = round((30 + (60 * $distance)) / flt_server_flight_speed_multiplier()); |
||
| 121 | $arrival = SN_TIME_NOW + $duration; |
||
| 122 | $travel_data['consumption'] = 0; |
||
| 123 | |||
| 124 | doquery( |
||
| 125 | "INSERT INTO `{{iraks}}` SET |
||
| 126 | `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']}', |
||
| 127 | `fleet_owner` = '{$user['id']}', `fleet_start_galaxy` = '{$planetrow['galaxy']}', `fleet_start_system` = '{$planetrow['system']}', `fleet_start_planet` = '{$planetrow['planet']}', |
||
| 128 | `fleet_end_time` = '{$arrival}', `fleet_amount` = '{$fleet_ship_count}', `primaer` = '{$target_structure}';" |
||
| 129 | ); |
||
| 130 | } |
||
| 131 | else |
||
| 132 | { |
||
| 133 | $travel_data = flt_travel_data($user, $planetrow, $target_coord, $fleet_array, 10); |
||
| 134 | |||
| 135 | if($planetrow['deuterium'] < $travel_data['consumption']) |
||
| 136 | { |
||
| 137 | die($lang['gs_c13']); |
||
| 138 | } |
||
| 139 | |||
| 140 | $fleet_start_time = SN_TIME_NOW + $travel_data['duration']; |
||
| 141 | $fleet_end_time = $fleet_start_time + $travel_data['duration']; |
||
| 142 | |||
| 143 | // $QryInsertFleet = "INSERT INTO {{fleets}} SET "; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
39% of this comment could be valid code. Did you maybe forget this after debugging?
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. Loading history...
|
|||
| 144 | // $QryInsertFleet .= "`fleet_owner` = '{$user['id']}', "; |
||
| 145 | // $QryInsertFleet .= "`fleet_mission` = '{$target_mission}', "; |
||
| 146 | // $QryInsertFleet .= "`fleet_amount` = '{$fleet_ship_count}', "; |
||
| 147 | // $QryInsertFleet .= "`fleet_array` = '{$FleetDBArray}', "; |
||
| 148 | // $QryInsertFleet .= "`fleet_start_time` = '{$fleet_start_time}', "; |
||
| 149 | // if($planetrow['id']) |
||
| 150 | // { |
||
| 151 | // $QryInsertFleet .= "`fleet_start_planet_id` = '{$planetrow['id']}', "; |
||
| 152 | // } |
||
| 153 | // $QryInsertFleet .= "`fleet_start_galaxy` = '{$planetrow['galaxy']}', `fleet_start_system` = '{$planetrow['system']}', `fleet_start_planet` = '{$planetrow['planet']}', `fleet_start_type` = '{$planetrow['planet_type']}', "; |
||
| 154 | // $QryInsertFleet .= "`fleet_end_time` = '{$fleet_end_time}', "; |
||
| 155 | // if($target_row['id']) |
||
| 156 | // { |
||
| 157 | // $QryInsertFleet .= "`fleet_end_planet_id` = '{$target_row['id']}', "; |
||
| 158 | // } |
||
| 159 | // $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}', "; |
||
| 160 | // $QryInsertFleet .= "`fleet_target_owner` = '{$target_row['id_owner']}', "; |
||
| 161 | // $QryInsertFleet .= "`start_time` = ". SN_TIME_NOW . ";"; |
||
| 162 | // doquery($QryInsertFleet); |
||
| 163 | |||
| 164 | $fleet_set = array( |
||
| 165 | 'fleet_owner' => $user['id'], |
||
| 166 | 'fleet_mission' => $target_mission, |
||
| 167 | 'fleet_amount' => $fleet_ship_count, |
||
| 168 | 'fleet_array' => $FleetDBArray, |
||
| 169 | 'fleet_start_time' => $fleet_start_time, |
||
| 170 | 'fleet_start_planet_id' => !empty($planetrow['id']) ? $planetrow['id'] : null, |
||
| 171 | 'fleet_start_galaxy' => $planetrow['galaxy'], |
||
| 172 | 'fleet_start_system' => $planetrow['system'], |
||
| 173 | 'fleet_start_planet' => $planetrow['planet'], |
||
| 174 | 'fleet_start_type' => $planetrow['planet_type'], |
||
| 175 | 'fleet_end_time' => $fleet_end_time, |
||
| 176 | 'fleet_end_planet_id' => !empty($target_row['id']) ? $target_row['id'] : null, |
||
| 177 | 'fleet_end_galaxy' => $target_coord['galaxy'], |
||
| 178 | 'fleet_end_system' => $target_coord['system'], |
||
| 179 | 'fleet_end_planet' => $target_coord['planet'], |
||
| 180 | 'fleet_end_type' => $target_planet_type, |
||
| 181 | 'fleet_target_owner' => $target_row['id_owner'], |
||
| 182 | 'start_time' => SN_TIME_NOW, |
||
| 183 | ); |
||
| 184 | fleet_insert_set($fleet_set); |
||
| 185 | } |
||
| 186 | |||
| 187 | DBStaticPlanet::db_planet_set_by_id($planetrow['id'], "`deuterium` = `deuterium` - {$travel_data['consumption']}"); |
||
| 188 | db_changeset_apply($db_changeset); |
||
| 189 | sn_db_transaction_commit(); |
||
| 190 | |||
| 191 | $ships_sent = array(); |
||
| 192 | //$ships_sent_js = array(); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% of this comment could be valid code. Did you maybe forget this after debugging?
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. Loading history...
|
|||
| 193 | $ships_sent_js = 0; |
||
| 194 | foreach($fleet_array as $unit_id => $unit_count) |
||
| 195 | { |
||
| 196 | $ships_sent[] = "{$unit_count} {$lang['tech'][$unit_id]}"; |
||
| 197 | $ships_sent_js += mrc_get_level($user, $planetrow, $unit_id, false, true); |
||
| 198 | } |
||
| 199 | $ships_sent = implode(', ', $ships_sent); |
||
| 200 | //$ships_sent_js = implode(',', $ships_sent_js); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
59% of this comment could be valid code. Did you maybe forget this after debugging?
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. Loading history...
|
|||
| 201 | $ships_sent_js = "{$unit_group}={$ships_sent_js}"; |
||
| 202 | |||
| 203 | $ResultMessage = "{$lang['gs_sending']} {$ships_sent} {$lang['gs_to']} {$target_coord['galaxy']}:{$target_coord['system']}:{$target_coord['planet']}|{$ships_sent_js}"; |
||
| 204 | |||
| 205 | die($ResultMessage); |
||
| 206 |
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.