function checkTarget()
 {
     global $PLANET, $LNG, $UNI, $CONF, $USER, $resource;
     $TargetGalaxy = HTTP::_GP('galaxy', 0);
     $TargetSystem = HTTP::_GP('system', 0);
     $TargetPlanet = HTTP::_GP('planet', 0);
     $TargetPlanettype = HTTP::_GP('planet_type', 1);
     if ($TargetGalaxy == $PLANET['galaxy'] && $TargetSystem == $PLANET['system'] && $TargetPlanet == $PLANET['planet'] && $TargetPlanettype == $PLANET['planet_type']) {
         $this->sendJSON($LNG['fl_error_same_planet']);
     }
     if ($TargetPlanet != Config::get('max_planets') + 1) {
         $Data = $GLOBALS['DATABASE']->getFirstRow("SELECT u.id, u.urlaubs_modus, u.user_lastip, u.authattack, u.immunity_until, p.destruyed, p.planet_protection, p.der_metal, p.der_crystal, p.destruyed FROM " . USERS . " as u, " . PLANETS . " as p WHERE p.universe = " . $UNI . " AND p.galaxy = " . $TargetGalaxy . " AND p.system = " . $TargetSystem . " AND p.planet = " . $TargetPlanet . "  AND p.planet_type = '" . ($TargetPlanettype == 2 ? 1 : $TargetPlanettype) . "' AND u.id = p.id_owner;");
         if ($TargetPlanettype == 3 && !isset($Data)) {
             $this->sendJSON($LNG['fl_error_no_moon']);
         } elseif ($TargetPlanettype != 2 && $Data['urlaubs_modus']) {
             $this->sendJSON($LNG['fl_in_vacation_player']);
         } elseif ($TargetPlanettype != 2 && $Data['immunity_until'] > TIMESTAMP && $USER['id'] != $Data['id']) {
             $this->sendJSON($LNG['fl_in_immunity_player']);
         } elseif ($Data['id'] != $USER['id'] && Config::get('adm_attack') == 1 && $Data['authattack'] > $USER['authlevel']) {
             $this->sendJSON($LNG['fl_admin_attack']);
         } elseif ($Data['destruyed'] != 0) {
             $this->sendJSON($LNG['fl_error_not_avalible']);
         } elseif ($TargetPlanettype == 2 && $Data['der_metal'] == 0 && $Data['der_crystal'] == 0) {
             $this->sendJSON($LNG['fl_error_empty_derbis']);
         } elseif (ENABLE_MULTIALERT && $USER['id'] != $Data['id'] && $USER['authlevel'] != AUTH_ADM && $USER['user_lastip'] == $Data['user_lastip'] && $GLOBALS['DATABASE']->getFirstCell("SELECT (SELECT COUNT(*) FROM " . MULTI . " WHERE userID = " . $USER['id'] . ") + (SELECT COUNT(*) FROM " . MULTI . " WHERE userID = " . $Data['id'] . ")") != 2) {
             $this->sendJSON($LNG['fl_multi_alarm']);
         }
         $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 20);
         if ($activeExpedition >= FleetFunctions::getFortressLimit($USER)) {
             $this->sendJSON($LNG['fl_no_expedition_slot']);
         }
     } else {
         if ($USER[$resource[124]] == 0) {
             $this->sendJSON($LNG['fl_target_not_exists']);
         }
         $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 15);
         if ($activeExpedition >= FleetFunctions::getExpeditionLimit($USER)) {
             $this->sendJSON($LNG['fl_no_expedition_slot']);
         }
     }
     $this->sendJSON('OK');
 }
 public function show()
 {
     global $USER, $PLANET, $resource, $pricelist, $reslist, $CONF, $LNG, $UNI;
     $tickinicial = buscarTick();
     if (IsVacationMode($USER)) {
         FleetFunctions::GotoFleetPage(0);
     }
     $targetMission = HTTP::_GP('mission', 3);
     $TransportMetal = max(0, round(HTTP::_GP('metal', 0.0)));
     $TransportCrystal = max(0, round(HTTP::_GP('crystal', 0.0)));
     $TransportDeuterium = max(0, round(HTTP::_GP('deuterium', 0.0)));
     $stayTime = HTTP::_GP('staytime', 0);
     $token = HTTP::_GP('token', '');
     if (!isset($_SESSION['fleet'][$token])) {
         FleetFunctions::GotoFleetPage(1);
     }
     if ($_SESSION['fleet'][$token]['time'] < TIMESTAMP - 600) {
         unset($_SESSION['fleet'][$token]);
         FleetFunctions::GotoFleetPage(0);
     }
     $maxFleetSpeed = $_SESSION['fleet'][$token]['speed'];
     $distance = $_SESSION['fleet'][$token]['distance'];
     $targetGalaxy = $_SESSION['fleet'][$token]['targetGalaxy'];
     $targetSystem = $_SESSION['fleet'][$token]['targetSystem'];
     $targetPlanet = $_SESSION['fleet'][$token]['targetPlanet'];
     $targetType = $_SESSION['fleet'][$token]['targetType'];
     $fleetGroup = $_SESSION['fleet'][$token]['fleetGroup'];
     $fleetArray = $_SESSION['fleet'][$token]['fleet'];
     $fleetStorage = $_SESSION['fleet'][$token]['fleetRoom'];
     $fleetSpeed = $_SESSION['fleet'][$token]['fleetSpeed'];
     unset($_SESSION['fleet'][$token]);
     if ($targetMission != 2) {
         $fleetGroup = 0;
     }
     if ($PLANET['galaxy'] == $targetGalaxy && $PLANET['system'] == $targetSystem && $PLANET['planet'] == $targetPlanet && $PLANET['planet_type'] == $targetType) {
         $this->printMessage($LNG['fl_error_same_planet']);
     }
     if ($targetGalaxy < 1 || $targetGalaxy > Config::get('max_galaxy') || $targetSystem < 1 || $targetSystem > Config::get('max_system') || $targetPlanet < 1 || $targetPlanet > Config::get('max_planets') + 1 || $targetType !== 1 && $targetType !== 2 && $targetType !== 3 && $targetType !== 4) {
         $this->printMessage($LNG['fl_invalid_target']);
     }
     if ($targetMission == 3 && $TransportMetal + $TransportCrystal + $TransportDeuterium < 1) {
         $this->printMessage($LNG['fl_no_noresource']);
     }
     $ActualFleets = FleetFunctions::GetCurrentFleets($USER['id']);
     if (FleetFunctions::GetMaxFleetSlots($USER) <= $ActualFleets) {
         $this->printMessage($LNG['fl_no_slots']);
     }
     $ACSTime = 0;
     if (!empty($fleetGroup)) {
         $ACSTime = $GLOBALS['DATABASE']->getFirstCell("SELECT ankunft\n\t\t\tFROM " . USERS_ACS . " \n\t\t\tINNER JOIN " . AKS . " ON id = acsID\n\t\t\tWHERE acsID = " . $fleetGroup . "\n\t\t\tAND " . Config::get('max_fleets_per_acs') . " > (SELECT COUNT(*) FROM " . FLEETS . " WHERE fleet_group = " . $fleetGroup . ");");
         if (empty($ACSTime)) {
             $fleetGroup = 0;
             $targetMission = 1;
         }
     }
     $ActualFleets = FleetFunctions::GetCurrentFleets($USER['id']);
     //$targetPlanetData  	= $GLOBALS['DATABASE']->getFirstRow("SELECT id, `planet_protection`, id_owner, `planet_type`, der_metal, der_crystal, destruyed, ally_deposit FROM ".PLANETS." WHERE universe = ".$UNI." AND galaxy = ".$targetGalaxy." AND system = ".$targetSystem." AND planet = ".$targetPlanet." AND planet_type = '".$targetType."';");
     $targetPlanetData = $GLOBALS['DATABASE']->getFirstRow("SELECT id, id_owner, `planet_protection`, der_metal, `planet_type`, der_crystal, destruyed, ally_deposit FROM " . PLANETS . " WHERE universe = " . $UNI . " AND galaxy = " . $targetGalaxy . " AND system = " . $targetSystem . " AND planet = " . $targetPlanet . " AND planet_type = '" . ($targetType == 2 ? 1 : $targetType) . "';");
     if ($targetMission == 7) {
         if (isset($targetPlanetData)) {
             $this->printMessage($LNG['fl_target_exists']);
         }
         if ($targetType != 1) {
             $this->printMessage($LNG['fl_only_planets_colonizable']);
         }
     }
     if ($targetMission == 7 || $targetMission == 15) {
         $targetPlanetData = array('id' => 0, 'id_owner' => 0, 'planettype' => 1);
     } else {
         if ($targetPlanetData["destruyed"] != 0) {
             $this->printMessage($LNG['fl_no_target']);
         }
         if (!isset($targetPlanetData)) {
             $this->printMessage($LNG['fl_no_target']);
         }
     }
     foreach ($fleetArray as $Ship => $Count) {
         if ($Count > $PLANET[$resource[$Ship]]) {
             $this->printMessage($LNG['fl_not_all_ship_avalible']);
         }
     }
     if ($targetMission == 11) {
         $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 11);
         $maxExpedition = FleetFunctions::getDMMissionLimit($USER);
         if ($activeExpedition >= $maxExpedition) {
             $this->printMessage($LNG['fl_no_expedition_slot']);
         }
     } elseif ($targetMission == 15) {
         $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 15);
         $maxExpedition = FleetFunctions::getExpeditionLimit($USER);
         if ($activeExpedition >= $maxExpedition) {
             $this->printMessage($LNG['fl_no_expedition_slot']);
         }
     } elseif ($targetMission == 20) {
         $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 20);
         $maxExpedition = FleetFunctions::getFortressLimit($USER);
         if ($activeExpedition >= $maxExpedition) {
             $this->printMessage($LNG['fl_no_expedition_slot']);
         }
     }
     $usedPlanet = isset($targetPlanetData['id_owner']);
     $myPlanet = $usedPlanet && $targetPlanetData['id_owner'] == $USER['id'];
     if ($targetMission == 7 || $targetMission == 15) {
         $targetPlayerData = array('id' => 0, 'onlinetime' => TIMESTAMP, 'ally_id' => 0, 'urlaubs_modus' => 0, 'authattack' => 0, 'total_points' => 0);
     } elseif ($myPlanet) {
         $targetPlayerData = $USER;
     } elseif (!empty($targetPlanetData['id_owner'])) {
         $targetPlayerData = $GLOBALS['DATABASE']->getFirstRow("SELECT \n\t\t\tuser.id, user.onlinetime, user.ally_id, user.urlaubs_modus, user.banaday, user.immunity_until, user.authattack, \n\t\t\tstat.total_points\n\t\t\tFROM " . USERS . " as user \n\t\t\tLEFT JOIN " . STATPOINTS . " as stat ON stat.id_owner = user.id AND stat.stat_type = '1' \n\t\t\tWHERE user.id = " . $targetPlanetData['id_owner'] . ";");
     } else {
         $this->printMessage($LNG['fl_empty_target']);
     }
     $MisInfo = array();
     $MisInfo['galaxy'] = $targetGalaxy;
     $MisInfo['system'] = $targetSystem;
     $MisInfo['planet'] = $targetPlanet;
     $MisInfo['planettype'] = $targetType;
     $MisInfo['IsAKS'] = $fleetGroup;
     $MisInfo['Ship'] = $fleetArray;
     $avalibleMissions = FleetFunctions::GetFleetMissions($USER, $MisInfo, $targetPlanetData);
     if (!in_array($targetMission, $avalibleMissions['MissionSelector'])) {
         $this->printMessage($LNG['fl_invalid_mission']);
     }
     if ($targetMission != 8 && IsVacationMode($targetPlayerData)) {
         $this->printMessage($LNG['fl_target_exists']);
     }
     if ($targetMission == 1 || $targetMission == 2 || $targetMission == 9) {
         if (FleetFunctions::CheckBash($targetPlanetData['id']) && $targetPlayerData['onlinetime'] < TIMESTAMP - 7 * 24 * 60 * 60) {
             $this->printMessage($LNG['fl_bash_protection']);
         }
     }
     if ($targetMission == 1 || $targetMission == 2 || $targetMission == 5 || $targetMission == 6 || $targetMission == 9) {
         if (Config::get('adm_attack') == 1 && $targetPlayerData['authattack'] > $USER['authlevel']) {
             $this->printMessage($LNG['fl_admin_attack']);
         }
         $IsNoobProtec = CheckNoobProtec($USER, $targetPlayerData, $targetPlayerData);
         if ($IsNoobProtec['NoobPlayer']) {
             $this->printMessage($LNG['fl_player_is_noob']);
         }
         if ($IsNoobProtec['StrongPlayer']) {
             $this->printMessage($LNG['fl_player_is_strong']);
         }
     }
     $PUSHED = $GLOBALS['DATABASE']->query("SELECT * FROM " . STATPOINTS . " WHERE id_owner = " . $USER['id'] . ";");
     $PUSGHING = $GLOBALS['DATABASE']->query("SELECT * FROM " . STATPOINTS . " WHERE id_owner = " . $targetPlanetData['id_owner'] . ";");
     $ADMIN = $GLOBALS['DATABASE']->query("SELECT authlevel FROM " . USERS . " WHERE id = " . $targetPlanetData['id_owner'] . ";");
     $ADMIN = mysqli_fetch_assoc($ADMIN);
     if ($GLOBALS['DATABASE']->numRows($PUSHED) > 0) {
         while ($xkf = mysqli_fetch_assoc($PUSHED)) {
             $ACTUA = $xkf['total_points'];
             $ACTUALA = $xkf['id_ally'];
         }
     }
     if ($GLOBALS['DATABASE']->numRows($PUSGHING) > 0) {
         while ($xkkf = mysqli_fetch_assoc($PUSGHING)) {
             $ACTUAL = $xkkf['total_points'];
             $ACTUALAT = $xkkf['id_ally'];
         }
     }
     if ($USER['authlevel'] != 3 || $ADMIN['authlevel'] != 3) {
         if ($targetMission == 3 && $ACTUA < $ACTUAL) {
             $this->printMessage('Pushing');
         }
     }
     if ($targetMission == 5) {
         if ($targetPlayerData['ally_id'] != $USER['ally_id']) {
             $buddy = $GLOBALS['DATABASE']->getFirstCell("\n\t\t\t\tSELECT COUNT(*) FROM " . BUDDY . " \n\t\t\t\tWHERE id NOT IN (SELECT id FROM " . BUDDY_REQUEST . " WHERE " . BUDDY_REQUEST . ".id = " . BUDDY . ".id) AND \n\t\t\t\t(owner = " . $targetPlayerData['id'] . " AND sender = " . $USER['id'] . ") OR\n\t\t\t\t(owner = " . $USER['id'] . " AND sender = " . $targetPlayerData['id'] . ");");
             if ($buddy == 0) {
                 $this->printMessage($LNG['fl_no_same_alliance']);
             }
         }
     }
     $fleetMaxSpeed = FleetFunctions::GetFleetMaxSpeed($fleetArray, $USER);
     $SpeedFactor = FleetFunctions::GetGameSpeedFactor();
     $duration = FleetFunctions::GetMissionDuration($fleetSpeed, $fleetMaxSpeed, $distance, $SpeedFactor, $USER);
     $consumption = FleetFunctions::GetFleetConsumption($fleetArray, $duration, $distance, $fleetMaxSpeed, $USER, $SpeedFactor);
     if ($PLANET[$resource[903]] < $consumption) {
         $this->printMessage($LNG['fl_not_enough_deuterium']);
     }
     $StayDuration = 0;
     if ($targetMission == 5 || $targetMission == 11 || $targetMission == 15) {
         if (!isset($avalibleMissions['StayBlock'][$stayTime])) {
             $this->printMessage($LNG['fl_hold_time_not_exists']);
         }
         $StayDuration = round($avalibleMissions['StayBlock'][$stayTime] * 3600, 0);
     }
     $fleetStorage -= $consumption;
     $fleetRessource = array(901 => min($TransportMetal, floor($PLANET[$resource[901]])), 902 => min($TransportCrystal, floor($PLANET[$resource[902]])), 903 => min($TransportDeuterium, floor($PLANET[$resource[903]] - $consumption)));
     $StorageNeeded = array_sum($fleetRessource);
     if ($StorageNeeded > $fleetStorage) {
         $this->printMessage($LNG['fl_not_enough_space']);
     }
     $PLANET[$resource[901]] -= $fleetRessource[901];
     $PLANET[$resource[902]] -= $fleetRessource[902];
     $PLANET[$resource[903]] -= $fleetRessource[903] + $consumption;
     if (connection_aborted()) {
         exit;
     }
     $fleetStartTime = $duration + TIMESTAMP;
     $timeDifference = round(max(0, $fleetStartTime - $ACSTime));
     if ($fleetGroup != 0) {
         if ($timeDifference != 0) {
             FleetFunctions::setACSTime($timeDifference, $fleetGroup);
         } else {
             $fleetStartTime = $ACSTime;
         }
     }
     $fleetStayTime = $fleetStartTime + $StayDuration;
     $fleetEndTime = $fleetStayTime + $duration;
     if ($PLANET['system'] == $targetSystem) {
         $tickfinal = $tickinicial + 9;
     } else {
         $tickfinal = $tickinicial + 11;
     }
     FleetFunctions::sendFleet($fleetArray, $targetMission, $USER['id'], $PLANET['id'], $PLANET['galaxy'], $PLANET['system'], $PLANET['planet'], $PLANET['planet_type'], $targetPlanetData['id_owner'], $targetPlanetData['id'], $targetGalaxy, $targetSystem, $targetPlanet, $targetType, $fleetRessource, $fleetStartTime, $fleetStayTime, $fleetEndTime, $tickinicial, $tickfinal, $fleetGroup);
     foreach ($fleetArray as $Ship => $Count) {
         $fleetList[$LNG['tech'][$Ship]] = $Count;
     }
     $this->tplObj->loadscript('flotten.js');
     $this->tplObj->gotoside('game.php?page=fleetTable');
     $this->tplObj->assign_vars(array('targetMission' => $targetMission, 'distance' => $distance, 'consumption' => $consumption, 'from' => $PLANET['galaxy'] . ":" . $PLANET['system'] . ":" . $PLANET['planet'], 'destination' => $targetGalaxy . ":" . $targetSystem . ":" . $targetPlanet, 'fleetStartTime' => _date($LNG['php_tdformat'], $fleetStartTime, $USER['timezone']), 'fleetEndTime' => _date($LNG['php_tdformat'], $fleetEndTime, $USER['timezone']), 'MaxFleetSpeed' => $fleetMaxSpeed, 'FleetList' => $fleetArray));
     $this->display('page.fleetStep3.default.tpl');
 }