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

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