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