Completed
Push — work-fleets ( d1f99e...fc0000 )
by SuperNova.WS
06:40
created

galaxy.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

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
 * galaxy.php
5
 *
6
 * Galaxy view
7
 */
8
9
use DBStatic\DBStaticAlly;
10
use DBStatic\DBStaticPlanet;
11
use DBStatic\DBStaticUser;
12
use Vector\Vector;
13
14
include('common.' . substr(strrchr(__FILE__, '.'), 1));
15
16
lng_include('universe');
17
lng_include('stat');
18
19
$mode = sys_get_param_str('mode');
20
$uni_galaxy = sys_get_param_int('galaxy', $planetrow['galaxy']);
21
$uni_system = sys_get_param_int('system', $planetrow['system']);
22
$planet = sys_get_param_int('planet', $planetrow['planet']);
23
24
if($mode == 'name') {
25
  require_once('includes/includes/uni_rename.php');
26
}
27
28
require_once('includes/includes/flt_functions.php');
29
30
$CurrentPlanetID = sys_get_param_id('current');
31
$POST_galaxyLeft = sys_get_param_str('galaxyLeft');
32
$POST_galaxyRight = sys_get_param_str('galaxyRight');
33
$POST_systemLeft = sys_get_param_str('systemLeft');
34
$POST_systemRight = sys_get_param_str('systemRight');
35
36
$fleetmax = GetMaxFleets($user);
37
$CurrentPlID = $planetrow['id'];
38
$CurrentMIP = mrc_get_level($user, $planetrow, UNIT_DEF_MISSILE_INTERPLANET, false, true);
39
$HavePhalanx = mrc_get_level($user, $planetrow, STRUC_MOON_PHALANX);
40
$CurrentSystem = $planetrow['system'];
41
$CurrentGalaxy = $planetrow['galaxy'];
42
43
$flying_fleet_count = FleetList::fleet_count_flying($user['id']);
44
45
if($mode == 1) {
46
} elseif($mode == 2 || $mode == 3) {
47
  $planet = $planetrow['planet'];
48
} else {
49
  $uni_galaxy = $planetrow['galaxy'];
50
  $uni_system = $planetrow['system'];
51
  $planet = $planetrow['planet'];
52
}
53
54
$uni_galaxy = $uni_galaxy < 1 ? 1 : ($uni_galaxy > Vector::$knownGalaxies? Vector::$knownGalaxies: $uni_galaxy);
55
$uni_system = $uni_system < 1 ? 1 : ($uni_system > Vector::$knownSystems ? Vector::$knownSystems : $uni_system);
56
$planet = $planet < 1 ? 1 : ($planet > Vector::$knownPlanets + 1 ? Vector::$knownPlanets + 1 : $planet);
57
58
$planetcount = 0;
59
$lunacount = 0;
60
$CurrentRC = $planetrow['recycler'];
61
$cached = array('users' => array(), 'allies' => array());
62
63
64
$template = gettemplate('universe', true);
65
66
$CurrentPoints = $user['total_points'];
67
68
$MissileRange = flt_get_missile_range($user);
69
$PhalanxRange = GetPhalanxRange($HavePhalanx);
70
71
$planet_precache_query = DBStaticPlanet::db_planet_list_in_system($uni_galaxy, $uni_system);
72
if(!empty($planet_precache_query)) {
73
  foreach($planet_precache_query as $planet_row) {
74
    $planet_list[$planet_row['planet']][$planet_row['planet_type']] = $planet_row;
75
  }
76
}
77
78
79
//$system_fleet_list = FleetList::fleet_list_by_planet_coords($uni_galaxy, $uni_system);
80
//foreach($system_fleet_list as $fleet_row) {
81
//  $fleet_planet = $fleet_row['fleet_mess'] == 0 ? $fleet_row['fleet_end_planet'] : $fleet_row['fleet_start_planet'];
82
//  $fleet_type = $fleet_row['fleet_mess'] == 0 ? $fleet_row['fleet_end_type'] : $fleet_row['fleet_start_type'];
83
//  $fleet_list[$fleet_planet][$fleet_type][] = $fleet_row;
84
//}
85
86
$system_fleet_list = FleetList::dbGetFleetListByCoordinates($uni_galaxy, $uni_system);
87
/**
88
 * @var Fleet[][][] $fleet_list
89
 */
90
$fleet_list = array();
91
foreach($system_fleet_list->_container as $objFleetSystem) {
92
  if(!$objFleetSystem->isReturning()) {
93
    $fleet_planet = $objFleetSystem->fleet_end_planet;
94
    $fleet_type = $objFleetSystem->fleet_end_type;
95
  } else {
96
    $fleet_planet = $objFleetSystem->fleet_start_planet;
97
    $fleet_type = $objFleetSystem->fleet_start_type;
98
  }
99
  $fleet_list[$fleet_planet][$fleet_type][] = $objFleetSystem;
100
}
101
102
$time_now_parsed = getdate(SN_TIME_NOW);
103
104
$recycler_info = array();
105
$planet_recyclers_orbiting = 0;
106
$recyclers_fleet = array();
107
foreach(classSupernova::$gc->groupRecyclers as $recycler_id) {
0 ignored issues
show
The expression \classSupernova::$gc->groupRecyclers of type array|object<Closure> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
108
  $recycler_info[$recycler_id] = get_ship_data($recycler_id, $user);
109
  $recyclers_fleet[$recycler_id] = mrc_get_level($user, $planetrow, $recycler_id);
110
  $planet_recyclers_orbiting += $recyclers_fleet[$recycler_id];
111
}
112
113
$user_skip_list = sys_stat_get_user_skip_list();
114
$fleet_id = 1;
115
$fleets = array();
116
$config_game_max_planet = Vector::$knownPlanets + 1;
117
for($Planet = 1; $Planet < $config_game_max_planet; $Planet++) {
118
  unset($uni_galaxyRowPlanet);
119
  unset($uni_galaxyRowMoon);
120
  unset($uni_galaxyRowUser);
121
  unset($uni_galaxyRowAlly);
122
  unset($allyquery);
123
124
  $uni_galaxyRowPlanet = $planet_list[$Planet][PT_PLANET];
125
126
  $planet_fleet_id = 0;
127
  if($uni_galaxyRowPlanet['destruyed']) {
128
    CheckAbandonPlanetState($uni_galaxyRowPlanet);
129
  } elseif($uni_galaxyRowPlanet['id']) {
130
    if($cached['users'][$uni_galaxyRowPlanet['id_owner']]) {
131
      $uni_galaxyRowUser = $cached['users'][$uni_galaxyRowPlanet['id_owner']];
132
    } else {
133
      $uni_galaxyRowUser = DBStaticUser::db_user_by_id($uni_galaxyRowPlanet['id_owner']);
134
      $cached['users'][$uni_galaxyRowUser['id']] = $uni_galaxyRowUser;
135
    }
136
137
    if(!$uni_galaxyRowUser['id']) {
138
      classSupernova::$debug->warning("Planet '{$uni_galaxyRowPlanet['name']}' [{$uni_galaxy}:{$uni_system}:{$Planet}] has no owner!", 'Userless planet', 503);
139
      $uni_galaxyRowPlanet['destruyed'] = SN_TIME_NOW + 60 * 60 * 24;
140
      $uni_galaxyRowPlanet['id_owner'] = 0;
141
      DBStaticPlanet::db_planet_update_set_by_id(
142
        $uni_galaxyRowPlanet['id'],
143
        array(
144
          'id_owner'  => 0,
145
          'destruyed' => $uni_galaxyRowPlanet['destruyed'],
146
        )
147
      );
148
    }
149
150
    if($uni_galaxyRowUser['id']) {
151
      $planetcount++;
152
      if($uni_galaxyRowUser['ally_id']) {
153
        if($cached['allies'][$uni_galaxyRowUser['ally_id']]) {
154
          $allyquery = $cached['allies'][$uni_galaxyRowUser['ally_id']];
155
        } else {
156
          $allyquery = DBStaticAlly::db_ally_get_by_id($uni_galaxyRowUser['ally_id']);
157
          $cached['allies'][$uni_galaxyRowUser['ally_id']] = $allyquery;
158
        }
159
      }
160
161
      $fleets_to_planet = flt_get_fleets_to_planet_by_array_of_Fleet($fleet_list[$Planet][PT_PLANET]);
162
      if(!empty($fleets_to_planet['own']['count'])) {
163
        $planet_fleet_id = $fleet_id;
164
        $fleets[] = tpl_parse_fleet_sn($fleets_to_planet['own']['total'], $fleet_id);
165
        $fleet_id++;
166
      }
167
168
      $uni_galaxyRowMoon = $planet_list[$Planet][PT_MOON];
169
      if($uni_galaxyRowMoon['destruyed']) {
170
        CheckAbandonPlanetState($uni_galaxyRowMoon);
171
      } else {
172
        $moon_fleet_id = 0;
173
        $fleets_to_planet = flt_get_fleets_to_planet_by_array_of_Fleet($fleet_list[$Planet][PT_MOON]);
174
        if(!empty($fleets_to_planet['own']['count'])) {
175
          $moon_fleet_id = $fleet_id;
176
          $fleets[] = tpl_parse_fleet_sn($fleets_to_planet['own']['total'], $fleet_id);
177
          $fleet_id++;
178
        }
179
      }
180
    }
181
  }
182
183
  $recyclers_incoming_capacity = 0;
184
  $uni_galaxyRowPlanet['debris'] = $uni_galaxyRowPlanet['debris_metal'] + $uni_galaxyRowPlanet['debris_crystal'];
185
  if($uni_galaxyRowPlanet['debris']) {
186
    if(!empty($fleet_list[$Planet][PT_DEBRIS])) {
187
      foreach($fleet_list[$Planet][PT_DEBRIS] as $objFleetToDebris) {
188
        if($objFleetToDebris->playerOwnerId == $user['id']) {
189
          $recyclers_incoming_capacity += $objFleetToDebris->shipsGetCapacityRecyclers($recycler_info);
190
        }
191
      }
192
    }
193
194
    $uni_galaxyRowPlanet['debris_reserved'] = $recyclers_incoming_capacity;
195
    $uni_galaxyRowPlanet['debris_reserved_percent'] = min(100, floor($uni_galaxyRowPlanet['debris_reserved'] / $uni_galaxyRowPlanet['debris'] * 100));
196
197
    $uni_galaxyRowPlanet['debris_to_gather'] = max(0, $uni_galaxyRowPlanet['debris'] - $recyclers_incoming_capacity);
198
    $uni_galaxyRowPlanet['debris_to_gather_percent'] = 100 - $uni_galaxyRowPlanet['debris_reserved_percent'];
199
200
    $recyclers_fleet_data = flt_calculate_fleet_to_transport($recyclers_fleet, $uni_galaxyRowPlanet['debris_to_gather'], $planetrow, $uni_galaxyRowPlanet);
201
202
    $uni_galaxyRowPlanet['debris_will_gather'] = max(0, min($recyclers_fleet_data['capacity'], $uni_galaxyRowPlanet['debris_to_gather']));
203
    $uni_galaxyRowPlanet['debris_will_gather_percent'] = $uni_galaxyRowPlanet['debris_to_gather'] ? floor($uni_galaxyRowPlanet['debris_will_gather'] / $uni_galaxyRowPlanet['debris_to_gather'] * $uni_galaxyRowPlanet['debris_to_gather_percent']) : 0;
204
205
    $uni_galaxyRowPlanet['debris_gather_total'] = max(0, $uni_galaxyRowPlanet['debris_will_gather'] + $uni_galaxyRowPlanet['debris_reserved']);
206
    $uni_galaxyRowPlanet['debris_gather_total_percent'] = min(100, floor($uni_galaxyRowPlanet['debris_gather_total'] / $uni_galaxyRowPlanet['debris'] * 100));
207
  }
208
209
  $RowUserPoints = $uni_galaxyRowUser['total_points'];
210
  $birthday_array = $uni_galaxyRowUser['user_birthday'] ? date_parse($uni_galaxyRowUser['user_birthday']) : array();
211
  $user_activity = floor((SN_TIME_NOW - $uni_galaxyRowUser['onlinetime']) / (60 * 60 * 24));
212
  $template->assign_block_vars('galaxyrow', array(
213
    'PLANET_ID'        => $uni_galaxyRowPlanet['id'],
214
    'PLANET_NUM'       => $Planet,
215
    'PLANET_NAME'      => $uni_galaxyRowPlanet['name'],
216
    'PLANET_NAME_JS'   => js_safe_string($uni_galaxyRowPlanet['name']),
217
    'PLANET_DESTROYED' => $uni_galaxyRowPlanet["destruyed"],
218
    'PLANET_TYPE'      => $uni_galaxyRowPlanet["planet_type"],
219
    'PLANET_ACTIVITY'  => floor((SN_TIME_NOW - $uni_galaxyRowPlanet['last_update']) / 60),
220
    'PLANET_IMAGE'     => $uni_galaxyRowPlanet['image'],
221
    'PLANET_FLEET_ID'  => $planet_fleet_id,
222
    'PLANET_DIAMETER'  => number_format($uni_galaxyRowPlanet['diameter'], 0, '', '.'),
223
224
    'MOON_NAME_JS'  => js_safe_string($uni_galaxyRowMoon['name']),
225
    'MOON_IMAGE'    => $uni_galaxyRowMoon['image'],
226
    'MOON_DIAMETER' => number_format($uni_galaxyRowMoon['diameter'], 0, '', '.'),
227
    'MOON_TEMP'     => number_format($uni_galaxyRowMoon['temp_min'], 0, '', '.'),
228
    'MOON_FLEET_ID' => $moon_fleet_id,
229
230
    'DEBRIS'              => $uni_galaxyRowPlanet['debris'],
231
    'DEBRIS_METAL'        => $uni_galaxyRowPlanet['debris_metal'],
232
    'DEBRIS_CRYSTAL'      => $uni_galaxyRowPlanet['debris_crystal'],
233
    'DEBRIS_REST_PERCENT' => $uni_galaxyRowPlanet["debris_rest_percent"],
234
235
    'DEBRIS_RESERVED'             => $uni_galaxyRowPlanet['debris_reserved'],
236
    'DEBRIS_RESERVED_PERCENT'     => $uni_galaxyRowPlanet['debris_reserved_percent'],
237
    'DEBRIS_WILL_GATHER'          => $uni_galaxyRowPlanet['debris_will_gather'],
238
    'DEBRIS_WILL_GATHER_PERCENT'  => $uni_galaxyRowPlanet['debris_will_gather_percent'],
239
    'DEBRIS_GATHER_TOTAL'         => $uni_galaxyRowPlanet['debris_gather_total'],
240
    'DEBRIS_GATHER_TOTAL_PERCENT' => $uni_galaxyRowPlanet['debris_gather_total_percent'],
241
242
    'USER_ID'         => $uni_galaxyRowUser['id'],
243
    'USER_NAME'       => player_nick_render_to_html($uni_galaxyRowUser),
244
    'USER_NAME_JS'    => js_safe_string(player_nick_render_to_html($uni_galaxyRowUser)),
245
    'USER_RANK'       => in_array($uni_galaxyRowUser['id'], $user_skip_list) ? '-' : $uni_galaxyRowUser['total_rank'],
246
    'USER_BANNED'     => $uni_galaxyRowUser['banaday'],
247
    'USER_VACATION'   => $uni_galaxyRowUser['vacation'],
248
    'USER_ACTIVITY'   => $user_activity,
249
    'USER_ATTACKABLE' => $user_activity >= 7,
250
    'USER_INACTIVE'   => $user_activity >= 28,
251
    'USER_PROTECTED'  => $RowUserPoints <= classSupernova::$config->game_noob_points,
252
    'USER_NOOB'       => $RowUserPoints * classSupernova::$config->game_noob_factor < $CurrentPoints && classSupernova::$config->game_noob_factor,
253
    'USER_STRONG'     => $CurrentPoints * classSupernova::$config->game_noob_factor < $RowUserPoints && classSupernova::$config->game_noob_factor,
254
    'USER_AUTH'       => $uni_galaxyRowUser['authlevel'],
255
    'USER_ADMIN'      => classLocale::$lang['user_level_shortcut'][$uni_galaxyRowUser['authlevel']],
256
    'USER_BIRTHDAY'   => $birthday_array['month'] == $time_now_parsed['mon'] && $birthday_array['day'] == $time_now_parsed['mday'] ? date(FMT_DATE, SN_TIME_NOW) : 0,
257
258
    'ALLY_ID'  => $uni_galaxyRowUser['ally_id'],
259
    'ALLY_TAG' => $uni_galaxyRowUser['ally_tag'],
260
  ));
261
}
262
263
tpl_assign_fleet($template, $fleets);
264
265
foreach(sn_get_groups('defense_active') as $unit_id) {
266
  $template->assign_block_vars('defense_active', array(
267
    'ID'   => $unit_id,
268
    'NAME' => classLocale::$lang['tech'][$unit_id],
269
  ));
270
}
271
272
foreach($cached['users'] as $PlanetUser) {
273
  if(!$PlanetUser) {
274
    continue;
275
  }
276
277
  $user_ally = $cached['allies'][$PlanetUser['ally_id']];
278
  if(isset($user_ally)) {
279
    if($PlanetUser['id'] == $user_ally['ally_owner']) {
280
      $user_rank_title = $user_ally['ally_owner_range'];
281
    } else {
282
      $ally_ranks = explode(';', $user_ally['ranklist']);
283
      list($user_rank_title) = explode(',', $ally_ranks[$PlanetUser['ally_rank_id']]);
284
    }
285
  } else {
286
    $user_rank_title = '';
287
  }
288
289
  $birthday_array = $PlanetUser['user_birthday'] ? date_parse($PlanetUser['user_birthday']) : array();
290
  $template->assign_block_vars('users', array(
291
    'ID'         => $PlanetUser['id'],
292
    'NAME'       => player_nick_render_to_html($PlanetUser, true),
293
    'NAME_JS'    => js_safe_string(player_nick_render_to_html($PlanetUser, true)),
294
    'RANK'       => in_array($PlanetUser['id'], $user_skip_list) ? '-' : $PlanetUser['total_rank'],
295
    'AVATAR'     => $PlanetUser['avatar'],
296
    'ALLY_ID'    => $PlanetUser['ally_id'],
297
    'ALLY_TAG'   => js_safe_string($user_ally['ally_tag']),
298
    'ALLY_TITLE' => str_replace(' ', '&nbsp', js_safe_string($user_rank_title)),
299
  ));
300
}
301
302
foreach($cached['allies'] as $PlanetAlly) {
303
  if($PlanetAlly) {
304
    $template->assign_block_vars('alliances', array(
305
      'ID'      => $PlanetAlly['id'],
306
      'NAME_JS' => js_safe_string($PlanetAlly['ally_name']),
307
      'MEMBERS' => $PlanetAlly['ally_members'],
308
      'URL'     => $PlanetAlly['ally_web'],
309
      'RANK'    => $PlanetAlly['total_rank'],
310
      'AVATAR'  => $PlanetAlly['ally_image'],
311
    ));
312
  }
313
}
314
315
$is_missile = classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_MISSILE] && ($CurrentMIP > 0) && ($uni_galaxy == $CurrentGalaxy) && ($uni_system >= $CurrentSystem - $MissileRange) && ($uni_system <= $CurrentSystem + $MissileRange);
316
$colspan = classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_SPYING] + classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_PM] + classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_BUDDY] + $is_missile;
317
318
$template->assign_vars(array(
319
    'rows'                  => $Result,
320
    'userCount'             => classSupernova::$config->users_amount,
321
//    'ALLY_COUNT'            => $ally_count['ally_count'],
322
    'ALLY_COUNT'            => DBStaticAlly::db_ally_count(),
323
    'PLANET_EXPEDITION'     => Vector::$knownPlanets + 1,
324
    'curPlanetID'           => $planetrow['id'],
325
    'curPlanetG'            => $planetrow['galaxy'],
326
    'curPlanetS'            => $planetrow['system'],
327
    'curPlanetP'            => $planetrow['planet'],
328
    'curPlanetPT'           => $planetrow['planet_type'],
329
    'deathStars'            => mrc_get_level($user, $planetrow, SHIP_HUGE_DEATH_STAR, false, true),
330
    'galaxy'                => $uni_galaxy,
331
    'system'                => $uni_system,
332
    'planet'                => $planet,
333
    'MIPs'                  => round($CurrentMIP),
334
    'MODE'                  => $mode,
335
    'planets'               => $planetcount,
336
    'SPs'                   => pretty_number(mrc_get_level($user, $planetrow, SHIP_SPY, false, true)),
337
    'SHOW_ADMIN'            => SHOW_ADMIN,
338
    'fleet_count'           => $flying_fleet_count,
339
    'fleet_max'             => $fleetmax,
340
    'ALLY_ID'               => $user['ally_id'],
341
    'USER_ID'               => $user['id'],
342
    'ACT_SPIO'              => classSupernova::$user_options[PLAYER_OPTION_FLEET_SPY_DEFAULT],
343
    'ACT_SPY'               => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_SPYING],
344
    'ACT_WRITE'             => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_PM],
345
    'ACT_STATISTICS'        => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_STATS],
346
    'ACT_INFO'              => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_PROFILE],
347
    'ACT_FRIEND'            => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_BUDDY],
348
    'opt_uni_tooltip_time'  => classSupernova::$user_options[PLAYER_OPTION_TOOLTIP_DELAY],
349
    'opt_uni_avatar_user'   => $user['opt_uni_avatar_user'],
350
    'opt_uni_avatar_ally'   => $user['opt_uni_avatar_ally'],
351
    'ACT_MISSILE'           => $is_missile,
352
    'PLANET_PHALANX'        => $HavePhalanx && $uni_galaxy == $CurrentGalaxy && $uni_system >= $CurrentSystem - $PhalanxRange && $uni_system <= $CurrentSystem + $PhalanxRange,
353
    'PAGE_HINT'             => classLocale::$lang['gal_sys_hint'],
354
    'PLANET_RECYCLERS'      => $planet_recyclers_orbiting,
355
    'PLANET_RECYCLERS_TEXT' => pretty_number($planet_recyclers_orbiting),
356
//    'GALAXY_NAME'           => $galaxy_name['universe_name'],
357
//    'SYSTEM_NAME'           => $system_name['universe_name'],
358
    'GALAXY_NAME'           => db_universe_get_name($uni_galaxy),
359
    'SYSTEM_NAME'           => db_universe_get_name($uni_galaxy, $uni_system),
360
    'COL_SPAN'              => $colspan + 9,
361
    'COL_SPAN_PLUS'         => $colspan + 3,
362
363
    'COL_SPAN_NEW'          => $colspan + 4,
364
    'COL_SPAN_NEW_COLONIZE' => $colspan - 2,
365
366
    'PLAYER_OPTION_UNIVERSE_OLD'              => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_OLD],
367
    'PLAYER_OPTION_UNIVERSE_DISABLE_COLONIZE' => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_DISABLE_COLONIZE],
368
  )
369
);
370
371
display(parsetemplate($template), classLocale::$lang['sys_universe'], true, '', false);
372