Test Failed
Push — trunk ( 30e273...8e4860 )
by SuperNova.WS
14:08
created

jumpgate.php (5 issues)

1
<?php
2
3
/**
4
 * jumpgate.php
5
 *
6
 * Jump Gate interface, I presume
7
 *
8
 * @version 1.0st Security checks & tests by Gorlum for http://supernova.ws
9
 * @version 1
10
 * @copyright 2008 By Chlorel for XNova
11
 */
12
13
use DBAL\OldDbChangeSet;
14
use Planet\DBStaticPlanet;
15
16
include('common.' . substr(strrchr(__FILE__, '.'), 1));
17
18
lng_include('fleet');
19
20
if($TargetPlanet = sys_get_param_id('jmpto'))
21
{
22
  sn_db_transaction_start();
23
  db_user_by_id($user['id'], true, 'id');
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

23
  /** @scrutinizer ignore-deprecated */ db_user_by_id($user['id'], true, 'id');
Loading history...
24
  $planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true);
25
  if(!($NextJumpTime = uni_get_time_to_jump($planetrow)))
26
  {
27
    $TargetGate = DBStaticPlanet::db_planet_by_id($TargetPlanet, true, '`id`, `last_jump_time`');
28
    if(mrc_get_level($user, $TargetGate, STRUC_MOON_GATE) > 0)
29
    {
30
      $NextDestTime = uni_get_time_to_jump ( $TargetGate );
31
      if(!$NextDestTime)
32
      {
33
        // $SubQueryOri = "";
34
        // $SubQueryDes = "";
35
        $ship_list = sys_get_param('ships');
36
        $db_changeset = array();
37
        foreach($ship_list as $ship_id => $ship_count)
38
        {
39
          if(!in_array($ship_id, sn_get_groups('fleet')))
40
          {
41
            continue;
42
          }
43
44
          $ship_count = max(0, min(floor($ship_count), mrc_get_level($user, $planetrow, $ship_id)));
45
          if($ship_count)
46
          {
47
            $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($ship_id, -$ship_count, $user, $planetrow['id']);
48
            $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($ship_id, $ship_count, $user, $TargetGate['id']);
49
          }
50
        }
51
        // Dit monsieur, y avait quelque chose a envoyer ???
52
        if(!empty($db_changeset))
53
        {
54
          DBStaticPlanet::db_planet_set_by_id($TargetGate['id'], "`last_jump_time` = " . SN_TIME_NOW . "");
55
          DBStaticPlanet::db_planet_set_by_id($planetrow['id'], "`last_jump_time` = " . SN_TIME_NOW . "");
56
          OldDbChangeSet::db_changeset_apply($db_changeset);
57
58
          db_user_set_by_id($user['id'], "`current_planet` = '{$TargetGate['id']}'");
0 ignored issues
show
Deprecated Code introduced by
The function db_user_set_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

58
          /** @scrutinizer ignore-deprecated */ db_user_set_by_id($user['id'], "`current_planet` = '{$TargetGate['id']}'");
Loading history...
59
60
          $planetrow['last_jump_time'] = SN_TIME_NOW;
61
          $RetMessage = $lang['gate_jump_done'] ." - ". pretty_time(uni_get_time_to_jump($planetrow));
62
        } else {
63
          $RetMessage = $lang['gate_wait_data'];
64
        }
65
      } else {
66
        $RetMessage = $lang['gate_wait_dest'] ." - ". pretty_time($NextDestTime);
67
      }
68
    } else {
69
      $RetMessage = $lang['gate_no_dest_g'];
70
    }
71
  } else {
72
    $RetMessage = $lang['gate_wait_star'] ." - ". pretty_time($NextJumpTime);
73
  }
74
  sn_db_transaction_commit();
75
  messageBox($RetMessage, $lang['tech'][STRUC_MOON_GATE], "jumpgate.php", 10);
76
} else {
77
  $template = gettemplate('jumpgate', true);
0 ignored issues
show
true of type true is incompatible with the type null|template expected by parameter $template of gettemplate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

77
  $template = gettemplate('jumpgate', /** @scrutinizer ignore-type */ true);
Loading history...
78
  if(mrc_get_level($user, $planetrow, STRUC_MOON_GATE) > 0)
79
  {
80
    $Combo = '';
81
    $MoonList = DBStaticPlanet::db_planet_list_moon_other($user['id'], $planetrow['id']);
82
    // while($CurMoon = db_fetch($MoonList))
83
    foreach($MoonList as $CurMoon)
0 ignored issues
show
The expression $MoonList of type false is not traversable.
Loading history...
84
    {
85
      if(mrc_get_level($user, $CurMoon, STRUC_MOON_GATE) >= 1)
86
      {
87
        $NextJumpTime = uni_get_time_to_jump($CurMoon);
88
        $template->assign_block_vars('moon', array(
89
          'ID'             => $CurMoon['id'],
90
          'GALAXY'         => $CurMoon['galaxy'],
91
          'SYSTEM'         => $CurMoon['system'],
92
          'PLANET'         => $CurMoon['planet'],
93
          'NAME'           => $CurMoon['name'],
94
          'NEXT_JUMP_TIME' => $NextJumpTime ? pretty_time($NextJumpTime) : '',
95
        ));
96
      }
97
    }
98
99
    foreach(sn_get_groups('fleet') as $Ship)
100
    {
101
      if(($ship_count = mrc_get_level($user, $planetrow, $Ship)) <= 0)
102
      {
103
        continue;
104
      }
105
106
      $template->assign_block_vars('fleet', array(
107
        'SHIP_ID'         => $Ship,
108
        'SHIP_NAME'       => $lang['tech'][$Ship],
109
        'SHIP_COUNT'      => $ship_count,
110
        'SHIP_COUNT_TEXT' => HelperString::numberFloorAndFormat($ship_count),
0 ignored issues
show
It seems like $ship_count can also be of type boolean; however, parameter $number of HelperString::numberFloorAndFormat() does only seem to accept double|integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

110
        'SHIP_COUNT_TEXT' => HelperString::numberFloorAndFormat(/** @scrutinizer ignore-type */ $ship_count),
Loading history...
111
      ));
112
    }
113
114
    $template->assign_vars(array(
115
      'GATE_JUMP_REST_TIME' => uni_get_time_to_jump($planetrow),
116
      'gate_start_name' => $planetrow['name'],
117
      'gate_start_link' => uni_render_coordinates_href($planetrow, '', 3),
118
    ));
119
120
    display($template, $lang['tech'][STRUC_MOON_GATE]);
121
  }
122
  else
123
  {
124
    messageBox($lang['gate_no_src_ga'], $lang['tech'][STRUC_MOON_GATE], "overview.php", 10);
125
  }
126
}
127
128
// -----------------------------------------------------------------------------------------------------------
129
// History version
130
// 1.0 - Version from scrap .. y avait pas ... bin maintenant y a !!
131