Completed
Push — work-fleets ( 0d1d7f...d58328 )
by SuperNova.WS
06:06
created

jumpgate.php (2 issues)

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
        // $SubQueryOri = "";
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
        // $SubQueryDes = "";
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
32
        $ship_list = sys_get_param('ships');
33
        $db_changeset = array();
34
        foreach($ship_list as $ship_id => $ship_count)
35
        {
36
          if(!in_array($ship_id, sn_get_groups('fleet')))
37
          {
38
            continue;
39
          }
40
41
          $ship_count = max(0, min(floor($ship_count), mrc_get_level($user, $planetrow, $ship_id)));
42
          if($ship_count)
43
          {
44
            $db_changeset['unit'][] = sn_db_unit_changeset_prepare($ship_id, -$ship_count, $user, $planetrow['id']);
45
            $db_changeset['unit'][] = sn_db_unit_changeset_prepare($ship_id, $ship_count, $user, $TargetGate['id']);
46
          }
47
        }
48
        // Dit monsieur, y avait quelque chose a envoyer ???
49
        if(!empty($db_changeset))
50
        {
51
          DBStaticPlanet::db_planet_set_by_id($TargetGate['id'], "`last_jump_time` = " . SN_TIME_NOW . "");
52
          DBStaticPlanet::db_planet_set_by_id($planetrow['id'], "`last_jump_time` = " . SN_TIME_NOW . "");
53
          db_changeset_apply($db_changeset);
54
55
          DBStaticUser::db_user_set_by_id($user['id'], "`current_planet` = '{$TargetGate['id']}'");
56
57
          $planetrow['last_jump_time'] = SN_TIME_NOW;
58
          $RetMessage = classLocale::$lang['gate_jump_done'] ." - ". pretty_time(uni_get_time_to_jump($planetrow));
59
        } else {
60
          $RetMessage = classLocale::$lang['gate_wait_data'];
61
        }
62
      } else {
63
        $RetMessage = classLocale::$lang['gate_wait_dest'] ." - ". pretty_time($NextDestTime);
64
      }
65
    } else {
66
      $RetMessage = classLocale::$lang['gate_no_dest_g'];
67
    }
68
  } else {
69
    $RetMessage = classLocale::$lang['gate_wait_star'] ." - ". pretty_time($NextJumpTime);
70
  }
71
  sn_db_transaction_commit();
72
  message($RetMessage, classLocale::$lang['tech'][STRUC_MOON_GATE], "jumpgate.php", 10);
73
} else {
74
  $template = gettemplate('jumpgate', true);
75
  if(mrc_get_level($user, $planetrow, STRUC_MOON_GATE) > 0)
76
  {
77
    $Combo = '';
78
    $MoonList = DBStaticPlanet::db_planet_list_moon_other($user['id'], $planetrow['id']);
79
    // while($CurMoon = db_fetch($MoonList))
80
    foreach($MoonList as $CurMoon)
81
    {
82
      if(mrc_get_level($user, $CurMoon, STRUC_MOON_GATE) >= 1)
83
      {
84
        $NextJumpTime = uni_get_time_to_jump($CurMoon);
85
        $template->assign_block_vars('moon', array(
86
          'ID'             => $CurMoon['id'],
87
          'GALAXY'         => $CurMoon['galaxy'],
88
          'SYSTEM'         => $CurMoon['system'],
89
          'PLANET'         => $CurMoon['planet'],
90
          'NAME'           => $CurMoon['name'],
91
          'NEXT_JUMP_TIME' => $NextJumpTime ? pretty_time($NextJumpTime) : '',
92
        ));
93
      }
94
    }
95
96
    foreach(sn_get_groups('fleet') as $Ship)
97
    {
98
      if(($ship_count = mrc_get_level($user, $planetrow, $Ship)) <= 0)
99
      {
100
        continue;
101
      }
102
103
      $template->assign_block_vars('fleet', array(
104
        'SHIP_ID'         => $Ship,
105
        'SHIP_NAME'       => classLocale::$lang['tech'][$Ship],
106
        'SHIP_COUNT'      => $ship_count,
107
        'SHIP_COUNT_TEXT' => pretty_number($ship_count),
108
      ));
109
    }
110
111
    $template->assign_vars(array(
112
      'GATE_JUMP_REST_TIME' => uni_get_time_to_jump($planetrow),
113
      'gate_start_name' => $planetrow['name'],
114
      'gate_start_link' => uni_render_coordinates_href($planetrow, '', 3),
115
    ));
116
117
    display($template, classLocale::$lang['tech'][STRUC_MOON_GATE]);
118
  }
119
  else
120
  {
121
    message(classLocale::$lang['gate_no_src_ga'], classLocale::$lang['tech'][STRUC_MOON_GATE], "overview.php", 10);
122
  }
123
}
124
125
// -----------------------------------------------------------------------------------------------------------
126
// History version
127
// 1.0 - Version from scrap .. y avait pas ... bin maintenant y a !!
128