Completed
Push — work-fleets ( 45d3a1...6724fd )
by SuperNova.WS
09:14 queued 03:18
created

galaxy.php (1 issue)

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 Vector\Vector;
10
11
include('common.' . substr(strrchr(__FILE__, '.'), 1));
12
13
lng_include('universe');
14
lng_include('stat');
15
16
$mode = sys_get_param_str('mode');
17
$uni_galaxy = sys_get_param_int('galaxy', $planetrow['galaxy']);
18
$uni_system = sys_get_param_int('system', $planetrow['system']);
19
$planet = sys_get_param_int('planet', $planetrow['planet']);
20
21
if($mode == 'name') {
22
  require_once('includes/includes/uni_rename.php');
23
}
24
25
require_once('includes/includes/flt_functions.php');
26
27
$CurrentPlanetID = sys_get_param_id('current');
28
$POST_galaxyLeft = sys_get_param_str('galaxyLeft');
29
$POST_galaxyRight = sys_get_param_str('galaxyRight');
30
$POST_systemLeft = sys_get_param_str('systemLeft');
31
$POST_systemRight = sys_get_param_str('systemRight');
32
33
$fleetmax = GetMaxFleets($user);
34
$CurrentPlID = $planetrow['id'];
35
$CurrentMIP = mrc_get_level($user, $planetrow, UNIT_DEF_MISSILE_INTERPLANET, false, true);
36
$HavePhalanx = mrc_get_level($user, $planetrow, STRUC_MOON_PHALANX);
37
$CurrentSystem = $planetrow['system'];
38
$CurrentGalaxy = $planetrow['galaxy'];
39
40
$flying_fleet_count = FleetList::fleet_count_flying($user['id']);
41
42
if($mode == 1) {
43
} elseif($mode == 2 || $mode == 3) {
44
  $planet = $planetrow['planet'];
45
} else {
46
  $uni_galaxy = $planetrow['galaxy'];
47
  $uni_system = $planetrow['system'];
48
  $planet = $planetrow['planet'];
49
}
50
51
$uni_galaxy = $uni_galaxy < 1 ? 1 : ($uni_galaxy > Vector::$knownGalaxies? Vector::$knownGalaxies: $uni_galaxy);
52
$uni_system = $uni_system < 1 ? 1 : ($uni_system > Vector::$knownSystems ? Vector::$knownSystems : $uni_system);
53
$planet = $planet < 1 ? 1 : ($planet > Vector::$knownPlanets + 1 ? Vector::$knownPlanets + 1 : $planet);
54
55
$planetcount = 0;
56
$lunacount = 0;
57
$CurrentRC = $planetrow['recycler'];
58
$cached = array('users' => array(), 'allies' => array());
59
60
61
$template = gettemplate('universe', true);
62
63
$CurrentPoints = $user['total_points'];
64
65
$MissileRange = flt_get_missile_range($user);
66
$PhalanxRange = GetPhalanxRange($HavePhalanx);
67
68
$planet_precache_query = DBStaticPlanet::db_planet_list_in_system($uni_galaxy, $uni_system);
69
if(!empty($planet_precache_query)) {
70
  foreach($planet_precache_query as $planet_row) {
71
    $planet_list[$planet_row['planet']][$planet_row['planet_type']] = $planet_row;
72
  }
73
}
74
75
76
//$system_fleet_list = FleetList::fleet_list_by_planet_coords($uni_galaxy, $uni_system);
77
//foreach($system_fleet_list as $fleet_row) {
78
//  $fleet_planet = $fleet_row['fleet_mess'] == 0 ? $fleet_row['fleet_end_planet'] : $fleet_row['fleet_start_planet'];
79
//  $fleet_type = $fleet_row['fleet_mess'] == 0 ? $fleet_row['fleet_end_type'] : $fleet_row['fleet_start_type'];
80
//  $fleet_list[$fleet_planet][$fleet_type][] = $fleet_row;
81
//}
82
83
$system_fleet_list = FleetList::dbGetFleetListByCoordinates($uni_galaxy, $uni_system);
84
/**
85
 * @var Fleet[][][] $fleet_list
86
 */
87
$fleet_list = array();
88
foreach($system_fleet_list->_container as $objFleetSystem) {
89
  if(!$objFleetSystem->isReturning()) {
90
    $fleet_planet = $objFleetSystem->fleet_end_planet;
91
    $fleet_type = $objFleetSystem->fleet_end_type;
92
  } else {
93
    $fleet_planet = $objFleetSystem->fleet_start_planet;
94
    $fleet_type = $objFleetSystem->fleet_start_type;
95
  }
96
  $fleet_list[$fleet_planet][$fleet_type][] = $objFleetSystem;
97
}
98
99
$time_now_parsed = getdate(SN_TIME_NOW);
100
101
$recycler_info = array();
102
$planet_recyclers_orbiting = 0;
103
$recyclers_fleet = array();
104
foreach(Fleet::$snGroupRecyclers as $recycler_id) {
105
  $recycler_info[$recycler_id] = get_ship_data($recycler_id, $user);
106
  $recyclers_fleet[$recycler_id] = mrc_get_level($user, $planetrow, $recycler_id);
107
  $planet_recyclers_orbiting += $recyclers_fleet[$recycler_id];
108
}
109
110
$user_skip_list = sys_stat_get_user_skip_list();
111
$fleet_id = 1;
112
$fleets = array();
113
$config_game_max_planet = Vector::$knownPlanets + 1;
114
for($Planet = 1; $Planet < $config_game_max_planet; $Planet++) {
115
  unset($uni_galaxyRowPlanet);
116
  unset($uni_galaxyRowMoon);
117
  unset($uni_galaxyRowUser);
118
  unset($uni_galaxyRowAlly);
119
  unset($allyquery);
120
121
  $uni_galaxyRowPlanet = $planet_list[$Planet][PT_PLANET];
122
123
  $planet_fleet_id = 0;
124
  if($uni_galaxyRowPlanet['destruyed']) {
125
    CheckAbandonPlanetState($uni_galaxyRowPlanet);
126
  } elseif($uni_galaxyRowPlanet['id']) {
127
    if($cached['users'][$uni_galaxyRowPlanet['id_owner']]) {
128
      $uni_galaxyRowUser = $cached['users'][$uni_galaxyRowPlanet['id_owner']];
129
    } else {
130
      $uni_galaxyRowUser = DBStaticUser::db_user_by_id($uni_galaxyRowPlanet['id_owner']);
131
      $cached['users'][$uni_galaxyRowUser['id']] = $uni_galaxyRowUser;
132
    }
133
134
    if(!$uni_galaxyRowUser['id']) {
135
      classSupernova::$debug->warning("Planet '{$uni_galaxyRowPlanet['name']}' [{$uni_galaxy}:{$uni_system}:{$Planet}] has no owner!", 'Userless planet', 503);
136
      $uni_galaxyRowPlanet['destruyed'] = SN_TIME_NOW + 60 * 60 * 24;
137
      $uni_galaxyRowPlanet['id_owner'] = 0;
138
      DBStaticPlanet::db_planet_update_set_by_id(
139
        $uni_galaxyRowPlanet['id'],
140
        array(
0 ignored issues
show
array('id_owner' => 0, '...RowPlanet['destruyed']) is of type array<string,?,{"id_owne...eger","destruyed":"?"}>, but the function expects a string.

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