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

jumpgate.php (2 issues)

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
 * 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
include('common.' . substr(strrchr(__FILE__, '.'), 1));
14
15
lng_include('fleet');
16
17
if($TargetPlanet = sys_get_param_id('jmpto'))
18
{
19
  sn_db_transaction_start();
20
  DBStaticUser::db_user_by_id($user['id'], true, 'id');
21
  $planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true);
22
  if(!($NextJumpTime = uni_get_time_to_jump($planetrow)))
23
  {
24
    $TargetGate = DBStaticPlanet::db_planet_by_id($TargetPlanet, true, '`id`, `last_jump_time`');
25
    if(mrc_get_level($user, $TargetGate, STRUC_MOON_GATE) > 0)
26
    {
27
      $NextDestTime = uni_get_time_to_jump ( $TargetGate );
28
      if(!$NextDestTime)
29
      {
30
        $ship_list = sys_get_param('ships');
31
        $jumpMade = false;
32
        foreach($ship_list as $ship_id => $ship_count)
33
        {
34
          if(!in_array($ship_id, Fleet::$snGroupFleet))
35
          {
36
            continue;
37
          }
38
39
          $ship_count = max(0, min(floor($ship_count), mrc_get_level($user, $planetrow, $ship_id)));
40
          if($ship_count)
41
          {
42
            $jumpMade = true;
43
            DBStaticUnit::dbUpdateOrInsertUnit($ship_id, -$ship_count, $user, $planetrow['id']);
44
            DBStaticUnit::dbUpdateOrInsertUnit($ship_id, $ship_count, $user, $TargetGate['id']);
45
          }
46
        }
47
48
        if($jumpMade)
49
        {
50
          DBStaticPlanet::db_planet_update_set_by_id(
51
            $TargetGate['id'],
52
            array(
0 ignored issues
show
array('last_jump_time' => SN_TIME_NOW) is of type array<string,integer,{"l..._jump_time":"integer"}>, 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...
53
              'last_jump_time' => SN_TIME_NOW,
54
            )
55
          );
56
          DBStaticPlanet::db_planet_update_set_by_id(
57
            $planetrow['id'],
58
            array(
0 ignored issues
show
array('last_jump_time' => SN_TIME_NOW) is of type array<string,integer,{"l..._jump_time":"integer"}>, 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...
59
              'last_jump_time' => SN_TIME_NOW,
60
            )
61
          );
62
          DBStaticUser::db_user_set_by_id(
63
            $user['id'],
64
            array(
65
              'current_planet' => $TargetGate['id'],
66
            )
67
          );
68
69
          $planetrow['last_jump_time'] = SN_TIME_NOW;
70
          $RetMessage = classLocale::$lang['gate_jump_done'] ." - ". pretty_time(uni_get_time_to_jump($planetrow));
71
        } else {
72
          $RetMessage = classLocale::$lang['gate_wait_data'];
73
        }
74
      } else {
75
        $RetMessage = classLocale::$lang['gate_wait_dest'] ." - ". pretty_time($NextDestTime);
76
      }
77
    } else {
78
      $RetMessage = classLocale::$lang['gate_no_dest_g'];
79
    }
80
  } else {
81
    $RetMessage = classLocale::$lang['gate_wait_star'] ." - ". pretty_time($NextJumpTime);
82
  }
83
  sn_db_transaction_commit();
84
  message($RetMessage, classLocale::$lang['tech'][STRUC_MOON_GATE], "jumpgate.php", 10);
85
} else {
86
  $template = gettemplate('jumpgate', true);
87
  if(mrc_get_level($user, $planetrow, STRUC_MOON_GATE) > 0)
88
  {
89
    $Combo = '';
90
    $MoonList = DBStaticPlanet::db_planet_list_moon_other($user['id'], $planetrow['id']);
91
    // while($CurMoon = db_fetch($MoonList))
92
    foreach($MoonList as $CurMoon)
93
    {
94
      if(mrc_get_level($user, $CurMoon, STRUC_MOON_GATE) >= 1)
95
      {
96
        $NextJumpTime = uni_get_time_to_jump($CurMoon);
97
        $template->assign_block_vars('moon', array(
98
          'ID'             => $CurMoon['id'],
99
          'GALAXY'         => $CurMoon['galaxy'],
100
          'SYSTEM'         => $CurMoon['system'],
101
          'PLANET'         => $CurMoon['planet'],
102
          'NAME'           => $CurMoon['name'],
103
          'NEXT_JUMP_TIME' => $NextJumpTime ? pretty_time($NextJumpTime) : '',
104
        ));
105
      }
106
    }
107
108
    foreach(Fleet::$snGroupFleet as $Ship)
109
    {
110
      if(($ship_count = mrc_get_level($user, $planetrow, $Ship)) <= 0)
111
      {
112
        continue;
113
      }
114
115
      $template->assign_block_vars('fleet', array(
116
        'SHIP_ID'         => $Ship,
117
        'SHIP_NAME'       => classLocale::$lang['tech'][$Ship],
118
        'SHIP_COUNT'      => $ship_count,
119
        'SHIP_COUNT_TEXT' => pretty_number($ship_count),
120
      ));
121
    }
122
123
    $template->assign_vars(array(
124
      'GATE_JUMP_REST_TIME' => uni_get_time_to_jump($planetrow),
125
      'gate_start_name' => $planetrow['name'],
126
      'gate_start_link' => uni_render_coordinates_href($planetrow, '', 3),
127
    ));
128
129
    display($template, classLocale::$lang['tech'][STRUC_MOON_GATE]);
130
  }
131
  else
132
  {
133
    message(classLocale::$lang['gate_no_src_ga'], classLocale::$lang['tech'][STRUC_MOON_GATE], "overview.php", 10);
134
  }
135
}
136
137
// -----------------------------------------------------------------------------------------------------------
138
// History version
139
// 1.0 - Version from scrap .. y avait pas ... bin maintenant y a !!
140