PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/pages/game/class.ShowFleetTablePage.php

https://bitbucket.org/VolCh/2moons
PHP | 290 lines | 211 code | 54 blank | 25 comment | 24 complexity | 5269e0254efa8408ca1af72dddf810a5 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, GPL-3.0, GPL-2.0, Apache-2.0, AGPL-3.0
  1. <?php
  2. /**
  3. * 2Moons
  4. * Copyright (C) 2012 Jan Kr??pke
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @package 2Moons
  20. * @author Jan Kr??pke <info@2moons.cc>
  21. * @copyright 2012 Jan Kr??pke <info@2moons.cc>
  22. * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
  23. * @version 1.7.1 (2013-01-18)
  24. * @info $Id$
  25. * @link http://2moons.cc/
  26. */
  27. require_once(ROOT_PATH . 'includes/classes/class.FleetFunctions.php');
  28. class ShowFleetTablePage extends AbstractPage
  29. {
  30. public static $requireModule = MODULE_FLEET_TABLE;
  31. function __construct()
  32. {
  33. parent::__construct();
  34. }
  35. public function createACS($fleetID, $fleetData) {
  36. global $USER;
  37. $rand = mt_rand(100000, 999999999);
  38. $acsName = 'AG'.$rand;
  39. $acsCreator = $USER['id'];
  40. $GLOBALS['DATABASE']->query("INSERT INTO ".AKS." SET
  41. name = '".$GLOBALS['DATABASE']->sql_escape($acsName)."',
  42. ankunft = ".$fleetData['fleet_start_time'].",
  43. target = ".$fleetData['fleet_end_id'].";");
  44. $acsID = $GLOBALS['DATABASE']->GetInsertID();
  45. $GLOBALS['DATABASE']->multi_query("INSERT INTO ".USERS_ACS." SET
  46. acsID = ".$acsID.",
  47. userID = ".$USER['id'].";
  48. UPDATE ".FLEETS." SET
  49. fleet_group = ".$acsID."
  50. WHERE fleet_id = ".$fleetID.";");
  51. return array(
  52. 'name' => $acsName,
  53. 'id' => $acsID,
  54. );
  55. }
  56. public function loadACS($fleetID, $fleetData) {
  57. global $USER;
  58. $acsResult = $GLOBALS['DATABASE']->query("SELECT id, name
  59. FROM ".USERS_ACS."
  60. INNER JOIN ".AKS." ON acsID = id
  61. WHERE userID = ".$USER['id']." AND acsID = ".$fleetData['fleet_group'].";");
  62. return $GLOBALS['DATABASE']->fetch_array($acsResult);
  63. }
  64. public function getACSPageData($fleetID)
  65. {
  66. global $USER, $PLANET, $LNG, $UNI;
  67. $fleetResult = $GLOBALS['DATABASE']->query("SELECT fleet_start_time, fleet_end_id, fleet_group, fleet_mess
  68. FROM ".FLEETS."
  69. WHERE fleet_id = ".$fleetID.";");
  70. if ($GLOBALS['DATABASE']->numRows($fleetResult) != 1)
  71. return array();
  72. $fleetData = $GLOBALS['DATABASE']->fetch_array($fleetResult);
  73. $GLOBALS['DATABASE']->free_result($fleetResult);
  74. if ($fleetData['fleet_mess'] == 1 || $fleetData['fleet_start_time'] <= TIMESTAMP)
  75. return array();
  76. if ($fleetData['fleet_group'] == 0)
  77. $acsData = $this->createACS($fleetID, $fleetData);
  78. else
  79. $acsData = $this->loadACS($fleetID, $fleetData);
  80. if (empty($acsData))
  81. return array();
  82. $acsName = HTTP::_GP('acsName', '', UTF8_SUPPORT);
  83. if(!empty($acsName)) {
  84. if(!CheckName($acsName))
  85. {
  86. $this->sendJSON($LNG['fl_acs_newname_alphanum']);
  87. }
  88. $GLOBALS['DATABASE']->query("UPDATE ".AKS." SET name = '".$GLOBALS['DATABASE']->sql_escape($acsName)."' WHERE id = ".$acsData['id'].";");
  89. $this->sendJSON(false);
  90. }
  91. $invitedUsers = array();
  92. $userResult = $GLOBALS['DATABASE']->query("SELECT id, username
  93. FROM ".USERS_ACS."
  94. INNER JOIN ".USERS." ON userID = id
  95. WHERE acsID = ".$acsData['id'].";");
  96. while($userRow = $GLOBALS['DATABASE']->fetch_array($userResult))
  97. {
  98. $invitedUsers[$userRow['id']] = $userRow['username'];
  99. }
  100. $GLOBALS['DATABASE']->free_result($userResult);
  101. $newUser = HTTP::_GP('username', '', UTF8_SUPPORT);
  102. $statusMessage = "";
  103. if(!empty($newUser))
  104. {
  105. $newUserID = $GLOBALS['DATABASE']->getFirstCell("SELECT id FROM ".USERS." WHERE universe = ".$UNI." AND username = '".$GLOBALS['DATABASE']->sql_escape($newUser)."';");
  106. if(empty($newUserID)) {
  107. $statusMessage = $LNG['fl_player']." ".$newUser." ".$LNG['fl_dont_exist'];
  108. } elseif(isset($invitedUsers[$newUserID])) {
  109. $statusMessage = $LNG['fl_player']." ".$newUser." ".$LNG['fl_already_invited'];
  110. } else {
  111. $statusMessage = $LNG['fl_player']." ".$newUser." ".$LNG['fl_add_to_attack'];
  112. $GLOBALS['DATABASE']->query("INSERT INTO ".USERS_ACS." SET acsID = ".$acsData['id'].", userID = ".$newUserID.";");
  113. $invitedUsers[$newUserID] = $newUser;
  114. $inviteTitle = $LNG['fl_acs_invitation_title'];
  115. $inviteMessage = $LNG['fl_player'] . $USER['username'] . $LNG['fl_acs_invitation_message'];
  116. SendSimpleMessage($newUserID, $USER['id'], TIMESTAMP, 1, $USER['username'], $inviteTitle, $inviteMessage);
  117. }
  118. }
  119. return array(
  120. 'invitedUsers' => $invitedUsers,
  121. 'acsName' => $acsData['name'],
  122. 'mainFleetID' => $fleetID,
  123. 'statusMessage' => $statusMessage,
  124. );
  125. }
  126. public function show()
  127. {
  128. global $USER, $PLANET, $reslist, $resource, $LNG;
  129. $acsData = array();
  130. $FleetID = HTTP::_GP('fleetID', 0);
  131. $GetAction = HTTP::_GP('action', "");
  132. $this->tplObj->loadscript('flotten.js');
  133. if(!empty($FleetID) && !IsVacationMode($USER))
  134. {
  135. switch($GetAction){
  136. case "sendfleetback":
  137. FleetFunctions::SendFleetBack($USER, $FleetID);
  138. break;
  139. case "acs":
  140. $acsData = $this->getACSPageData($FleetID);
  141. break;
  142. }
  143. }
  144. $techExpedition = $USER[$resource[124]];
  145. if ($techExpedition >= 1)
  146. {
  147. $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 15);
  148. $maxExpedition = floor(sqrt($techExpedition));
  149. }
  150. else
  151. {
  152. $activeExpedition = 0;
  153. $maxExpedition = 0;
  154. }
  155. $maxFleetSlots = FleetFunctions::GetMaxFleetSlots($USER);
  156. $targetGalaxy = HTTP::_GP('galaxy', (int) $PLANET['galaxy']);
  157. $targetSystem = HTTP::_GP('system', (int) $PLANET['system']);
  158. $targetPlanet = HTTP::_GP('planet', (int) $PLANET['planet']);
  159. $targetType = HTTP::_GP('planettype', (int) $PLANET['planet_type']);
  160. $targetMission = HTTP::_GP('target_mission', 0);
  161. $fleetResult = $GLOBALS['DATABASE']->query("SELECT * FROM ".FLEETS." WHERE fleet_owner = ".$USER['id']." AND fleet_mission <> 10 ORDER BY fleet_end_time ASC;");
  162. $activeFleetSlots = $GLOBALS['DATABASE']->numRows($fleetResult);
  163. $FlyingFleetList = array();
  164. while ($fleetsRow = $GLOBALS['DATABASE']->fetch_array($fleetResult))
  165. {
  166. $fleet = explode(";", $fleetsRow['fleet_array']);
  167. $FleetList = array();
  168. foreach ($fleet as $shipDetail)
  169. {
  170. if (empty($shipDetail))
  171. continue;
  172. $ship = explode(",", $shipDetail);
  173. $FleetList[$fleetsRow['fleet_id']][$ship[0]] = $ship[1];
  174. }
  175. if($fleetsRow['fleet_mission'] == 4 && $fleetsRow['fleet_mess'] == FLEET_OUTWARD)
  176. {
  177. $returnTime = $fleetsRow['fleet_start_time'];
  178. }
  179. else
  180. {
  181. $returnTime = $fleetsRow['fleet_end_time'];
  182. }
  183. $FlyingFleetList[] = array(
  184. 'id' => $fleetsRow['fleet_id'],
  185. 'mission' => $fleetsRow['fleet_mission'],
  186. 'state' => $fleetsRow['fleet_mess'],
  187. 'startGalaxy' => $fleetsRow['fleet_start_galaxy'],
  188. 'startSystem' => $fleetsRow['fleet_start_system'],
  189. 'startPlanet' => $fleetsRow['fleet_start_planet'],
  190. 'startTime' => _date($LNG['php_tdformat'], $fleetsRow['fleet_start_time'], $USER['timezone']),
  191. 'endGalaxy' => $fleetsRow['fleet_end_galaxy'],
  192. 'endSystem' => $fleetsRow['fleet_end_system'],
  193. 'endPlanet' => $fleetsRow['fleet_end_planet'],
  194. 'endTime' => _date($LNG['php_tdformat'], $fleetsRow['fleet_end_time'], $USER['timezone']),
  195. 'amount' => pretty_number($fleetsRow['fleet_amount']),
  196. 'returntime' => $returnTime,
  197. 'resttime' => $returnTime - TIMESTAMP,
  198. 'FleetList' => $FleetList[$fleetsRow['fleet_id']],
  199. );
  200. }
  201. $GLOBALS['DATABASE']->free_result($fleetResult);
  202. $FleetsOnPlanet = array();
  203. foreach($reslist['fleet'] as $FleetID)
  204. {
  205. if ($PLANET[$resource[$FleetID]] == 0)
  206. continue;
  207. $FleetsOnPlanet[] = array(
  208. 'id' => $FleetID,
  209. 'speed' => FleetFunctions::GetFleetMaxSpeed($FleetID, $USER),
  210. 'count' => $PLANET[$resource[$FleetID]],
  211. );
  212. }
  213. $this->tplObj->assign_vars(array(
  214. 'FleetsOnPlanet' => $FleetsOnPlanet,
  215. 'FlyingFleetList' => $FlyingFleetList,
  216. 'activeExpedition' => $activeExpedition,
  217. 'maxExpedition' => $maxExpedition,
  218. 'activeFleetSlots' => $activeFleetSlots,
  219. 'maxFleetSlots' => $maxFleetSlots,
  220. 'targetGalaxy' => $targetGalaxy,
  221. 'targetSystem' => $targetSystem,
  222. 'targetPlanet' => $targetPlanet,
  223. 'targetType' => $targetType,
  224. 'targetMission' => $targetMission,
  225. 'acsData' => $acsData,
  226. 'isVacation' => IsVacationMode($USER),
  227. 'bonusAttack' => $USER[$resource[109]] * 10 + (1 + abs($USER['factor']['Attack'])) * 100,
  228. 'bonusDefensive' => $USER[$resource[110]] * 10 + (1 + abs($USER['factor']['Defensive'])) * 100,
  229. 'bonusShield' => $USER[$resource[111]] * 10 + (1 + abs($USER['factor']['Shield'])) * 100,
  230. 'bonusCombustion' => $USER[$resource[115]] * 10,
  231. 'bonusImpulse' => $USER[$resource[117]] * 20,
  232. 'bonusHyperspace' => $USER[$resource[118]] * 30,
  233. ));
  234. $this->display('page.fleetTable.default.tpl');
  235. }
  236. }