Issues (1369)

flying_fleets.php (1 issue)

Severity
1
<?php
2
3
use DBAL\db_mysql;
4
use Fleet\DbFleetStatic;
5
6
include('common.' . substr(strrchr(__FILE__, '.'), 1));
7
8
global $user, $debug;
9
10
lng_include('overview');
11
lng_include('fleet');
12
13
/**
14
 * @param int|string $userId
15
 * @param debug      $debug
16
 *
17
 * @throws Exception
18
 */
19
function flyingFleetsModel($userId, $debug) {
20
  if (empty($_POST['return']) || !is_array($_POST['return'])) {
21
    return;
22
  }
23
24
  foreach ($_POST['return'] as $fleet_id) {
25
    if (empty($fleet_id = idval($fleet_id))) {
26
      continue;
27
    }
28
29
    db_mysql::db_transaction_start();
30
    if (empty($fleet = SN::$gc->repoV2->getFleet($fleet_id))) {
31
      db_mysql::db_transaction_rollback();
32
      continue;
33
    }
34
35
    if (!$fleet->returnForce($userId)) {
36
      $debug->warning('Trying to return fleet that not belong to user', 'Hack attempt', 302, ['base_dump' => true, 'fleet_row' => $fleet->asArray()]);
37
      db_mysql::db_transaction_rollback();
38
      die('Hack attempt 302');
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
39
    }
40
    db_mysql::db_transaction_commit();
41
  }
42
}
43
44
/** @noinspection PhpUnhandledExceptionInspection */
45
flyingFleetsModel($user['id'], $debug);
46
47
if (!$planetrow) {
48
  SnTemplate::messageBox($lang['fl_noplanetrow'], $lang['fl_error']);
49
}
50
51
$template = SnTemplate::gettemplate('flying_fleets', true);
52
53
$i = 0;
54
$fleet_list = DbFleetStatic::fleet_list_by_owner_id($user['id']);
55
foreach ($fleet_list as $fleet_id => $fleet_row) {
56
  $i++;
57
  $fleet_data = tpl_parse_fleet_db($fleet_row, $i, $user);
58
59
  $template->assign_block_vars('fleets', $fleet_data['fleet']);
60
61
  foreach ($fleet_data['ships'] as $ship_data) {
62
    $template->assign_block_vars('fleets.ships', $ship_data);
63
  }
64
}
65
66
$MaxExpeditions = get_player_max_expeditons($user);
67
$FlyingExpeditions = DbFleetStatic::fleet_count_flying($user['id'], MT_EXPLORE);
68
$fleet_flying_amount = DbFleetStatic::fleet_count_flying($user['id'], MT_NONE);
69
70
$template->assign_vars(array(
71
  'FLEETS_FLYING'      => $fleet_flying_amount,
72
  'FLEETS_MAX'         => GetMaxFleets($user),
73
  'EXPEDITIONS_FLYING' => $FlyingExpeditions,
74
  'EXPEDITIONS_MAX'    => $MaxExpeditions,
75
));
76
77
SnTemplate::display($template, $lang['fl_title']);
78