PageRenderTime 58ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/VolCh/2moons
PHP | 302 lines | 225 code | 52 blank | 25 comment | 22 complexity | 3b3d23cda77c828215011b21a9cca234 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.2 (2013-03-18)
  24. * @info $Id$
  25. * @link http://2moons.cc/
  26. */
  27. class ShowFleetTablePage extends AbstractPage
  28. {
  29. public static $requireModule = MODULE_FLEET_TABLE;
  30. function __construct()
  31. {
  32. parent::__construct();
  33. }
  34. public function createACS($fleetID, $fleetData) {
  35. global $USER;
  36. $rand = mt_rand(100000, 999999999);
  37. $acsName = 'AG'.$rand;
  38. $acsCreator = $USER['id'];
  39. $db = Database::get();
  40. $sql = "INSERT INTO %%AKS%% SET name = :acsName, ankunft = :time, target = :target;";
  41. $db->insert($sql, array(
  42. ':acsName' => $acsName,
  43. ':time' => $fleetData['fleet_start_time'],
  44. ':target' => $fleetData['fleet_end_id']
  45. ));
  46. $acsID = $db->lastInsertId();
  47. $sql = "INSERT INTO %%USERS_ACS%% SET acsID = :acsID, userID = :userID;";
  48. $db->insert($sql, array(
  49. ':acsID' => $acsID,
  50. ':userID' => $acsCreator
  51. ));
  52. $sql = "UPDATE %%FLEETS%% SET fleet_group = :acsID WHERE fleet_id = :fleetID;";
  53. $db->update($sql, array(
  54. ':acsID' => $acsID,
  55. ':fleetID' => $fleetID
  56. ));
  57. return array(
  58. 'name' => $acsName,
  59. 'id' => $acsID,
  60. );
  61. }
  62. public function loadACS($fleetData) {
  63. global $USER;
  64. $db = Database::get();
  65. $sql = "SELECT id, name FROM %%USERS_ACS%% INNER JOIN %%AKS%% ON acsID = id WHERE userID = :userID AND acsID = :acsID;";
  66. $acsResult = $db->selectSingle($sql, array(
  67. ':userID' => $USER['id'],
  68. ':acsID' => $fleetData['fleet_group']
  69. ));
  70. return $acsResult;
  71. }
  72. public function getACSPageData($fleetID)
  73. {
  74. global $USER, $LNG;
  75. $db = Database::get();
  76. $sql = "SELECT fleet_start_time, fleet_end_id, fleet_group, fleet_mess FROM %%FLEETS%% WHERE fleet_id = :fleetID;";
  77. $fleetData = $db->selectSingle($sql, array(
  78. ':fleetID' => $fleetID
  79. ));
  80. if ($db->rowCount() != 1)
  81. return array();
  82. if ($fleetData['fleet_mess'] == 1 || $fleetData['fleet_start_time'] <= TIMESTAMP)
  83. return array();
  84. if ($fleetData['fleet_group'] == 0)
  85. $acsData = $this->createACS($fleetID, $fleetData);
  86. else
  87. $acsData = $this->loadACS($fleetData);
  88. if (empty($acsData))
  89. return array();
  90. $acsName = HTTP::_GP('acsName', '', UTF8_SUPPORT);
  91. if(!empty($acsName)) {
  92. if(PlayerUtil::isNameValid($acsName))
  93. {
  94. $this->sendJSON($LNG['fl_acs_newname_alphanum']);
  95. }
  96. $sql = "UPDATE %%AKS%% SET name = acsName WHERE id = :acsID;";
  97. $db->update($sql, array(
  98. ':acsName' => $acsName,
  99. ':acsID' => $acsData['id']
  100. ));
  101. $this->sendJSON(false);
  102. }
  103. $invitedUsers = array();
  104. $sql = "SELECT id, username FROM %%USERS_ACS%% INNER JOIN %%USERS%% ON userID = id WHERE acsID = :acsID;";
  105. $userResult = $db->select($sql, array(
  106. ':acsID' => $acsData['id']
  107. ));
  108. foreach($userResult as $userRow)
  109. {
  110. $invitedUsers[$userRow['id']] = $userRow['username'];
  111. }
  112. $newUser = HTTP::_GP('username', '', UTF8_SUPPORT);
  113. $statusMessage = "";
  114. if(!empty($newUser))
  115. {
  116. $sql = "SELECT id FROM %%USERS%% WHERE universe = :universe AND username = :username;";
  117. $newUserID = $db->selectSingle($sql, array(
  118. ':universe' => Universe::current(),
  119. ':username' => $newUser
  120. ), 'id');
  121. if(empty($newUserID)) {
  122. $statusMessage = $LNG['fl_player']." ".$newUser." ".$LNG['fl_dont_exist'];
  123. } elseif(isset($invitedUsers[$newUserID])) {
  124. $statusMessage = $LNG['fl_player']." ".$newUser." ".$LNG['fl_already_invited'];
  125. } else {
  126. $statusMessage = $LNG['fl_player']." ".$newUser." ".$LNG['fl_add_to_attack'];
  127. $sql = "INSERT INTO %%USERS_ACS%% SET acsID = :acsID, userID = :newUserID;";
  128. $db->insert($sql, array(
  129. ':acsID' => $acsData['id'],
  130. ':newUserID' => $newUserID
  131. ));
  132. $invitedUsers[$newUserID] = $newUser;
  133. $inviteTitle = $LNG['fl_acs_invitation_title'];
  134. $inviteMessage = $LNG['fl_player'] . $USER['username'] . $LNG['fl_acs_invitation_message'];
  135. PlayerUtil::sendMessage($newUserID, $USER['id'], TIMESTAMP, 1, $USER['username'], $inviteTitle, $inviteMessage);
  136. }
  137. }
  138. return array(
  139. 'invitedUsers' => $invitedUsers,
  140. 'acsName' => $acsData['name'],
  141. 'mainFleetID' => $fleetID,
  142. 'statusMessage' => $statusMessage,
  143. );
  144. }
  145. public function show()
  146. {
  147. global $USER, $PLANET, $reslist, $resource, $LNG;
  148. $acsData = array();
  149. $FleetID = HTTP::_GP('fleetID', 0);
  150. $GetAction = HTTP::_GP('action', "");
  151. $db = Database::get();
  152. $this->tplObj->loadscript('flotten.js');
  153. if(!empty($FleetID) && !IsVacationMode($USER))
  154. {
  155. switch($GetAction){
  156. case "sendfleetback":
  157. FleetFunctions::SendFleetBack($USER, $FleetID);
  158. break;
  159. case "acs":
  160. $acsData = $this->getACSPageData($FleetID);
  161. break;
  162. }
  163. }
  164. $techExpedition = $USER[$resource[124]];
  165. if ($techExpedition >= 1)
  166. {
  167. $activeExpedition = FleetFunctions::GetCurrentFleets($USER['id'], 15, true);
  168. $maxExpedition = floor(sqrt($techExpedition));
  169. }
  170. else
  171. {
  172. $activeExpedition = 0;
  173. $maxExpedition = 0;
  174. }
  175. $maxFleetSlots = FleetFunctions::GetMaxFleetSlots($USER);
  176. $targetGalaxy = HTTP::_GP('galaxy', (int) $PLANET['galaxy']);
  177. $targetSystem = HTTP::_GP('system', (int) $PLANET['system']);
  178. $targetPlanet = HTTP::_GP('planet', (int) $PLANET['planet']);
  179. $targetType = HTTP::_GP('planettype', (int) $PLANET['planet_type']);
  180. $targetMission = HTTP::_GP('target_mission', 0);
  181. $sql = "SELECT * FROM %%FLEETS%% WHERE fleet_owner = :userID AND fleet_mission <> 10 ORDER BY fleet_end_time ASC;";
  182. $fleetResult = $db->select($sql, array(
  183. ':userID' => $USER['id']
  184. ));
  185. $activeFleetSlots = $db->rowCount();
  186. $FlyingFleetList = array();
  187. foreach ($fleetResult as $fleetsRow)
  188. {
  189. $FleetList[$fleetsRow['fleet_id']] = FleetFunctions::unserialize($fleetsRow['fleet_array']);
  190. if($fleetsRow['fleet_mission'] == 4 && $fleetsRow['fleet_mess'] == FLEET_OUTWARD)
  191. {
  192. $returnTime = $fleetsRow['fleet_start_time'];
  193. }
  194. else
  195. {
  196. $returnTime = $fleetsRow['fleet_end_time'];
  197. }
  198. $FlyingFleetList[] = array(
  199. 'id' => $fleetsRow['fleet_id'],
  200. 'mission' => $fleetsRow['fleet_mission'],
  201. 'state' => $fleetsRow['fleet_mess'],
  202. 'startGalaxy' => $fleetsRow['fleet_start_galaxy'],
  203. 'startSystem' => $fleetsRow['fleet_start_system'],
  204. 'startPlanet' => $fleetsRow['fleet_start_planet'],
  205. 'startTime' => _date($LNG['php_tdformat'], $fleetsRow['fleet_start_time'], $USER['timezone']),
  206. 'endGalaxy' => $fleetsRow['fleet_end_galaxy'],
  207. 'endSystem' => $fleetsRow['fleet_end_system'],
  208. 'endPlanet' => $fleetsRow['fleet_end_planet'],
  209. 'endTime' => _date($LNG['php_tdformat'], $fleetsRow['fleet_end_time'], $USER['timezone']),
  210. 'amount' => pretty_number($fleetsRow['fleet_amount']),
  211. 'returntime' => $returnTime,
  212. 'resttime' => $returnTime - TIMESTAMP,
  213. 'FleetList' => $FleetList[$fleetsRow['fleet_id']],
  214. );
  215. }
  216. $FleetsOnPlanet = array();
  217. foreach($reslist['fleet'] as $FleetID)
  218. {
  219. if ($PLANET[$resource[$FleetID]] == 0)
  220. continue;
  221. $FleetsOnPlanet[] = array(
  222. 'id' => $FleetID,
  223. 'speed' => FleetFunctions::GetFleetMaxSpeed($FleetID, $USER),
  224. 'count' => $PLANET[$resource[$FleetID]],
  225. );
  226. }
  227. $this->assign(array(
  228. 'FleetsOnPlanet' => $FleetsOnPlanet,
  229. 'FlyingFleetList' => $FlyingFleetList,
  230. 'activeExpedition' => $activeExpedition,
  231. 'maxExpedition' => $maxExpedition,
  232. 'activeFleetSlots' => $activeFleetSlots,
  233. 'maxFleetSlots' => $maxFleetSlots,
  234. 'targetGalaxy' => $targetGalaxy,
  235. 'targetSystem' => $targetSystem,
  236. 'targetPlanet' => $targetPlanet,
  237. 'targetType' => $targetType,
  238. 'targetMission' => $targetMission,
  239. 'acsData' => $acsData,
  240. 'isVacation' => IsVacationMode($USER),
  241. 'bonusAttack' => $USER[$resource[109]] * 10 + (1 + abs($USER['factor']['Attack'])) * 100,
  242. 'bonusDefensive' => $USER[$resource[110]] * 10 + (1 + abs($USER['factor']['Defensive'])) * 100,
  243. 'bonusShield' => $USER[$resource[111]] * 10 + (1 + abs($USER['factor']['Shield'])) * 100,
  244. 'bonusCombustion' => $USER[$resource[115]] * 10,
  245. 'bonusImpulse' => $USER[$resource[117]] * 20,
  246. 'bonusHyperspace' => $USER[$resource[118]] * 30,
  247. ));
  248. $this->display('page.fleetTable.default.tpl');
  249. }
  250. }