Completed
Push — trunk ( 91a948...0e7a2e )
by SuperNova.WS
05:44
created
1
<?php
2
3
/*
4
  fleet.php
5
  Fleet manager
6
7
  V3.3 copyright (c) 2009-2010 by Gorlum for http://supernova.ws
8
    [~] Imploded fleet_back.php code
9
10
  V3.2 copyright (c) 2009-2010 by Gorlum for http://supernova.ws
11
    [~] separate independent chunks in INC-files
12
13
  V3.1 copyright (c) 2009-2010 by Gorlum for http://supernova.ws
14
    [~] Security checked & tested
15
16
  V3.0 Updated by Gorlum Sep 2009
17
    [!] extracting templates from code
18
    [~] some redundant code cleaning
19
20
  V2.0 Updated by Chlorel. 16 Jan 2008 (String extraction, bug corrections, code uniformisation
21
22
  V1.0 Created by Perberos. All rights reversed (C) 2006
23
*/
24
25
global $user, $planetrow, $lang;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
26
27
use Planet\DBStaticPlanet;
28
29
include('common.' . substr(strrchr(__FILE__, '.'), 1));
30
$template_result = is_array($template_result) ? $template_result : array();
31
32
define('SN_IN_FLEET', true);
33
34
require_once('includes/includes/flt_functions.php');
35
36
lng_include('fleet');
37
38
//$fleet_page = ($fleet_page = sys_get_param_int('fleet_page')) ? $fleet_page : sys_get_param_int('mode');
39
$fleet_page = sys_get_param_int('fleet_page', sys_get_param_int('mode'));
40
41
$galaxy = sys_get_param_int('galaxy', $planetrow['galaxy']);
42
$system = sys_get_param_int('system', $planetrow['system']);
43
$planet = sys_get_param_int('planet', $planetrow['planet']);
44
45
$target_mission = sys_get_param_int('target_mission');
46
if($target_mission == MT_COLONIZE || $target_mission == MT_EXPLORE) {
47
  $planet_type = PT_PLANET;
48
} elseif($target_mission == MT_RECYCLE) {
49
  $planet_type = PT_DEBRIS;
50
} elseif($target_mission == MT_DESTROY) {
51
  $planet_type = PT_MOON;
52
} else {
53
  $planet_type = sys_get_param_int('planet_type');
54
  if (!$planet_type) {
55
    $planet_type = sys_get_param_int('planettype', $planetrow['planet_type']);
56
  }
57
}
58
59
$options = array();
60
$options['fleets_max'] = GetMaxFleets($user);
61
62
$MaxFleets = GetMaxFleets($user);
63
//$FlyingFleets = doquery("SELECT COUNT(fleet_id) as Number FROM {{fleets}} WHERE `fleet_owner`='{$user['id']}'", true);
64
//$FlyingFleets = $FlyingFleets['Number'];
65
$FlyingFleets = fleet_count_flying($user['id']);
66
if($MaxFleets <= $FlyingFleets && $fleet_page && $fleet_page != 4) {
67
  messageBox($lang['fl_noslotfree'], $lang['fl_error'], "fleet." . PHP_EX, 5);
68
}
69
70
$MaxExpeditions = get_player_max_expeditons($user);
71
if($MaxExpeditions) {
72
//  $FlyingExpeditions  = doquery("SELECT COUNT(fleet_owner) AS `expedi` FROM {{fleets}} WHERE `fleet_owner` = {$user['id']} AND `fleet_mission` = '" . MT_EXPLORE . "';", '', true);
73
//  $FlyingExpeditions  = $FlyingExpeditions['expedi'];
74
  $FlyingExpeditions  = fleet_count_flying($user['id'], MT_EXPLORE);
75
} else {
76
  $FlyingExpeditions = 0;
77
}
78
79
switch ($fleet_page) {
80
  case 3:
81
82
  case 2:
83
    $fleet_group_mr = sys_get_param_id('fleet_group');
84
    $fleetarray     = json_decode(base64_decode(str_rot13(sys_get_param('usedfleet'))), true);
85
    $fleetarray = is_array($fleetarray) ? $fleetarray : array();
86
87
    foreach($fleetarray as $ship_id => &$ship_amount) {
88
      if(!in_array($ship_id, sn_get_groups('fleet')) || (string)floatval($ship_amount) != $ship_amount || $ship_amount < 1) {
89
        $debug->warning('Supplying wrong ship in ship list on fleet page', 'Hack attempt', 302, array('base_dump' => true));
90
        die();
91
      }
92
      $ship_amount = floatval($ship_amount);
93
    }
94
95
    $UsedPlanet = false;
96
    $YourPlanet = false;
97
    $missiontype = array();
98
    if ($planet > SN::$config->game_maxPlanet) {
99
      $target_mission = MT_EXPLORE;
100
      $missiontype[MT_EXPLORE] = $lang['type_mission'][MT_EXPLORE];
101
    } elseif ($galaxy && $system && $planet) {
102
      $check_type = $planet_type == PT_MOON ? PT_MOON : PT_PLANET;
103
104
      $TargetPlanet = DBStaticPlanet::db_planet_by_gspt($galaxy, $system, $planet, $check_type);
105
106
      if ($TargetPlanet['id_owner']) {
107
        $UsedPlanet = true;
108
        if ($TargetPlanet['id_owner'] == $user['id']) {
109
          $YourPlanet = true;
110
        }
111
      }
112
113
      if (!$UsedPlanet) {
114
        if ($fleetarray[SHIP_COLONIZER]) {
115
          $missiontype[MT_COLONIZE] = $lang['type_mission'][MT_COLONIZE];
116
          $target_mission = MT_COLONIZE;
117
          $planet_type = PT_PLANET;
118
        } else {
119
          messageBox ("<font color=\"red\"><b>". $lang['fl_no_planet_type'] ."</b></font>", $lang['fl_error']);
120
        }
121
      } else {
122
        $recyclers = 0;
123
        foreach(sn_get_groups('flt_recyclers') as $recycler_id) {
124
          $recyclers += $fleetarray[$recycler_id];
125
        }
126
        if ($recyclers > 0 && $planet_type == PT_DEBRIS) {
127
          $target_mission = MT_RECYCLE;
128
          $missiontype[MT_RECYCLE] = $lang['type_mission'][MT_RECYCLE];
129
        } elseif ($planet_type == PT_PLANET || $planet_type == PT_MOON) {
130
          if ($YourPlanet) {
131
            $missiontype[MT_RELOCATE] = $lang['type_mission'][MT_RELOCATE];
132
            $missiontype[MT_TRANSPORT] = $lang['type_mission'][MT_TRANSPORT];
133
          } else {
134
            // Not Your Planet
135
            if ($fleetarray[SHIP_SPY]) {
136
              // Only spy missions if any spy
137
              $missiontype[MT_SPY] = $lang['type_mission'][MT_SPY];
138
            } else {
139
              // If no spies...
140
              if ($fleet_group_mr) {
141
                $missiontype[MT_AKS] = $lang['type_mission'][MT_AKS];
142
              } else {
143
                $missiontype[MT_ATTACK] = $lang['type_mission'][MT_ATTACK];
144
                $missiontype[MT_TRANSPORT] = $lang['type_mission'][MT_TRANSPORT];
145
146
                $missiontype[MT_HOLD] = $lang['type_mission'][MT_HOLD];
147
148
                if($planet_type == PT_MOON && $fleetarray[SHIP_HUGE_DEATH_STAR]) {
149
                  $missiontype[MT_DESTROY] = $lang['type_mission'][MT_DESTROY];
150
                }
151
              }
152
            }
153
          }
154
        }
155
      }
156
    }
157
158
    if (!$target_mission && is_array($missiontype)) {
159
      $target_mission = MT_ATTACK;
160
    }
161
162
//    $sn_group_missions = sn_get_groups('missions');
163
//    foreach($sn_group_missions as $mission_id => $cork) {
164
//      $missiontype[$mission_id] = $lang['type_mission'][$mission_id];
165
//    }
166
//
167
//
168
    ksort($missiontype);
169
170
    $speed_percent = sys_get_param_int('speed', 10);
171
    $travel_data   = flt_travel_data($user, $planetrow, array('galaxy' => $galaxy, 'system' => $system, 'planet' => $planet), $fleetarray, $speed_percent);
172
173
//    $fleet_speed   = flt_fleet_speed($user, $fleetarray);
174
    $fleet_speed   = $travel_data['fleet_speed'];
175
    $distance      = $travel_data['distance'];
176
    $duration      = $travel_data['duration'];
177
    $consumption   = $travel_data['consumption'];
178
  // No Break
179
180
  case 1:
181
    if ($galaxy && $system && $planet) {
182
      $check_type = $planet_type == PT_MOON ? PT_MOON : PT_PLANET;
183
184
      $TargetPlanet = DBStaticPlanet::db_planet_by_gspt($galaxy, $system, $planet, $check_type);
185
    }
186
187
  case 0:
188
    $template_result += array(
189
      'thisgalaxy'      => $planetrow['galaxy'],
190
      'thissystem'      => $planetrow['system'],
191
      'thisplanet'      => $planetrow['planet'],
192
      'thisplanet_type' => $planetrow['planet_type'],
193
    );
194
  // no break
195
196
}
197
198
$template_result += array(
199
  'galaxy' => $galaxy,
200
  'system' => $system,
201
  'planet' => $planet,
202
  'planet_type' => $planet_type,
203
  'target_mission'  => $target_mission ? $target_mission : 0,
204
  'MISSION_NAME'		=> $target_mission ? $lang['type_mission'][$target_mission] : '',
205
);
206
207
$is_transport_missions = false;
208
if($missiontype) {
209
  $sn_group_missions = sn_get_groups('missions');
210
  foreach($missiontype as $mission_data_id => $mission_data) {
211
    $is_transport_missions = $is_transport_missions || (isset($sn_group_missions[$mission_data_id]['transport']) && $sn_group_missions[$mission_data_id]['transport']);
212
  }
213
}
214
215
switch($fleet_page) {
216
  case 1:
217
    require('includes/includes/flt_page1.inc');
218
  break;
219
220
  case 2:
221
    require_once('includes/includes/flt_page2.inc');
222
    sn_fleet_page2();
223
  break;
224
225
  case 3:
226
    require_once('includes/includes/flt_page3.inc');
227
    sn_fleet_page3();
228
  break;
229
230
  case 4:
231
    require('includes/includes/flt_page4.inc');
232
  break;
233
234
  case 5:
235
    $template = gettemplate('fleet5', true);
236
    $pageFleet5Gathering = new \Deprecated\PageFleet5Gathering();
237
    $pageFleet5Gathering->modelFleet5Gathering($user, $planetrow, $template);
238
    // Building list of own planets & moons
239
    $pageFleet5Gathering->viewPage5Gathering($user, $planetrow, $template);
240
  break;
241
242
  default:
243
    define('SN_RENDER_NAVBAR_PLANET', true);
244
245
    require('includes/includes/flt_page0.inc');
246
  break;
247
}
248