Support for the Jump Fleet.

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Support for the Jump Fleet.

      Hello,
      Unfortunately, the code I use to teleport fleets from one planet to another isn't working as expected. Everything seems to be running without errors, but instead of teleporting, the ships from the current planet are being deleted and not transferred to the destination planet. Your assistance in resolving this would be greatly appreciated.

      Best regards,

      2MOON 2.0
      PHP : 7.2.34

      PHP Source Code

      1. <?php
      2. class ShowJumpFleetPage extends AbstractGamePage {
      3. public static $requireModule = 0;
      4. function __construct() {
      5. parent::__construct();
      6. }
      7. function show() {
      8. global $CONF, $LNG, $PLANET, $USER, $resource, $UNI;
      9. $db = Database::get();
      10. $act = HTTP::_GP('act', '');
      11. $transCoasts = 2000;
      12. if ($act == "take") {
      13. if (!isset($_POST['check_planet']) && !isset($_POST['check_moons']))
      14. $this->redirectTo('game.php?page=harvest');
      15. if($transCoasts > $USER['darkmatter']){$this->printMessage($LNG['error_3'], true, array('game.php?page=JumpFleet', 4));}
      16. else
      17. $USER['darkmatter'] -= $transCoasts;
      18. if(!isset($_POST['check_planet']))
      19. $_POST['check_planet'] = array();
      20. foreach($_POST['check_planet'] as $ID => $Value) {
      21. $sur = $db->uniquequery("SELECT small_ship_cargo, big_ship_cargo, light_hunter, heavy_hunter, crusher, battle_ship, colonizer, recycler, spy_sonde, bomber_ship, destructor, dearth_star, battleship, lune_noir, ev_transporter, star_crasher, giga_recykler, dm_ship FROM %%PLANETS%% where `id` = '".$Value."';");
      22. $db->multi_query("LOCK TABLE %%PLANETS%% WRITE; UPDATE %%PLANETS%% SET `small_ship_cargo` = small_ship_cargo - ".$sur['small_ship_cargo'].", `big_ship_cargo` = big_ship_cargo - ".$sur['big_ship_cargo'].", `light_hunter` = light_hunter - ".$sur['light_hunter'].", `heavy_hunter` = heavy_hunter - ".$sur['heavy_hunter'].", `crusher` = crusher - ".$sur['crusher'].", `battle_ship` = battle_ship - ".$sur['battle_ship'].", `colonizer` = colonizer - ".$sur['colonizer'].", `recycler` = recycler - ".$sur['recycler'].", `spy_sonde` = spy_sonde - ".$sur['spy_sonde'].", `bomber_ship` = bomber_ship - ".$sur['bomber_ship'].", `destructor` = destructor - ".$sur['destructor'].", `dearth_star` = dearth_star - ".$sur['dearth_star'].", `battleship` = battleship - ".$sur['battleship'].", `lune_noir` = lune_noir - ".$sur['lune_noir'].", `ev_transporter` = ev_transporter - ".$sur['ev_transporter'].", `star_crasher` = star_crasher - ".$sur['star_crasher'].", `giga_recykler` = giga_recykler - ".$sur['giga_recykler'].", `dm_ship` = dm_ship - ".$sur['dm_ship']." WHERE `id` = '".$Value."'; UNLOCK TABLES;");
      23. $PLANET['small_ship_cargo'] += $sur['small_ship_cargo'];
      24. $PLANET['big_ship_cargo'] += $sur['big_ship_cargo'];
      25. $PLANET['light_hunter'] += $sur['light_hunter'];
      26. $PLANET['heavy_hunter'] += $sur['heavy_hunter'];
      27. $PLANET['crusher'] += $sur['crusher'];
      28. $PLANET['battle_ship'] += $sur['battle_ship'];
      29. $PLANET['colonizer'] += $sur['colonizer'];
      30. $PLANET['recycler'] += $sur['recycler'];
      31. $PLANET['dearth_star'] += $sur['dearth_star'];
      32. $PLANET['battleship'] += $sur['battleship'];
      33. $PLANET['lune_noir'] += $sur['lune_noir'];
      34. $PLANET['ev_transporter'] += $sur['ev_transporter'];
      35. $PLANET['star_crasher'] += $sur['star_crasher'];
      36. $PLANET['giga_recykler'] += $sur['giga_recykler'];
      37. $PLANET['dm_ship'] += $sur['dm_ship'];
      38. }
      39. if(!isset($_POST['check_moons']))
      40. $_POST['check_moons'] = array();
      41. foreach($_POST['check_moons'] as $ID => $Value) {
      42. $sur = $db->uniquequery("SELECT small_ship_cargo, big_ship_cargo, light_hunter, heavy_hunter, crusher, battle_ship, colonizer, recycler, spy_sonde, bomber_ship, destructor, dearth_star, battleship, lune_noir, ev_transporter, star_crasher, giga_recykler, dm_ship FROM %%PLANETS%% where `id` = '".$Value."';");
      43. $db->multi_query("LOCK TABLE %%PLANETS%% WRITE; UPDATE %%PLANETS%% SET `small_ship_cargo` = small_ship_cargo - ".$sur['small_ship_cargo'].", `big_ship_cargo` = big_ship_cargo - ".$sur['big_ship_cargo'].", `light_hunter` = light_hunter - ".$sur['light_hunter'].", `heavy_hunter` = heavy_hunter - ".$sur['heavy_hunter'].", `crusher` = crusher - ".$sur['crusher'].", `battle_ship` = battle_ship - ".$sur['battle_ship'].", `colonizer` = colonizer - ".$sur['colonizer'].", `recycler` = recycler - ".$sur['recycler'].", `spy_sonde` = spy_sonde - ".$sur['spy_sonde'].", `bomber_ship` = bomber_ship - ".$sur['bomber_ship'].", `destructor` = destructor - ".$sur['destructor'].", `dearth_star` = dearth_star - ".$sur['dearth_star'].", `battleship` = battleship - ".$sur['battleship'].", `lune_noir` = lune_noir - ".$sur['lune_noir'].", `ev_transporter` = ev_transporter - ".$sur['ev_transporter'].", `star_crasher` = star_crasher - ".$sur['star_crasher'].", `giga_recykler` = giga_recykler - ".$sur['giga_recykler'].", `dm_ship` = dm_ship - ".$sur['dm_ship']." WHERE `id` = '".$Value."'; UNLOCK TABLES;");
      44. $PLANET['small_ship_cargo'] += $sur['small_ship_cargo'];
      45. $PLANET['big_ship_cargo'] += $sur['big_ship_cargo'];
      46. $PLANET['light_hunter'] += $sur['light_hunter'];
      47. $PLANET['heavy_hunter'] += $sur['heavy_hunter'];
      48. $PLANET['crusher'] += $sur['crusher'];
      49. $PLANET['battle_ship'] += $sur['battle_ship'];
      50. $PLANET['colonizer'] += $sur['colonizer'];
      51. $PLANET['recycler'] += $sur['recycler'];
      52. $PLANET['dearth_star'] += $sur['dearth_star'];
      53. $PLANET['battleship'] += $sur['battleship'];
      54. $PLANET['lune_noir'] += $sur['lune_noir'];
      55. $PLANET['ev_transporter'] += $sur['ev_transporter'];
      56. $PLANET['star_crasher'] += $sur['star_crasher'];
      57. $PLANET['giga_recykler'] += $sur['giga_recykler'];
      58. $PLANET['dm_ship'] += $sur['dm_ship'];
      59. }
      60. $this->printMessage($LNG['h_ok'], true, array('game.php?page=JumpFleet', 4));
      61. } else {
      62. $Planets = array();
      63. $Moons = array();
      64. if (isset($USER['PLANETS'])) {
      65. $USER['PLANETS'] = getPlanets($USER);
      66. }
      67. foreach($USER['PLANETS'] as $ID => $PlanetQuery) {
      68. if ($ID == $PLANET['id']) continue;
      69. if ($PlanetQuery['planet_type'] == 3) {
      70. $Moons[$PlanetQuery['id']] = $PlanetQuery['name'] . " [" . $PlanetQuery['galaxy'] . ":" . $PlanetQuery['system'] . ":" . $PlanetQuery['planet'] . "]";
      71. } elseif ($PlanetQuery['planet_type'] == 1) {
      72. $Planets[$PlanetQuery['id']] = $PlanetQuery['name'] . " [".$PlanetQuery['galaxy'] . ":" . $PlanetQuery['system'] . ":" . $PlanetQuery['planet'] . "]";
      73. }
      74. }
      75. // $this->tplObj->loadscript("jquery.countdown.js");
      76. $this->tplObj->assign_vars(array(
      77. 'PlanetsList' => $Planets,
      78. 'MoonsList' => $Moons,
      79. ));
      80. $this->display('page.JumpFleet.default.tpl');
      81. }
      82. }
      83. }
      84. ?>
      Display All

      The post was edited 1 time, last by denizuga ().

    • Try to use code from Jump Gate.

      PHP Source Code

      1. public function sendFleet()
      2. {
      3. global $PLANET, $USER, $resource, $LNG, $reslist;
      4. $db = Database::get();
      5. $NextJumpTime = self::getNextJumpWaitTime($PLANET['last_jump_time']);
      6. if (TIMESTAMP < $NextJumpTime)
      7. {
      8. $this->sendJSON(array(
      9. 'message' => $LNG['in_jump_gate_already_used'].' '.pretty_time($NextJumpTime - TIMESTAMP),
      10. 'error' => true
      11. ));
      12. }
      13. $TargetPlanet = HTTP::_GP('jmpto', (int) $PLANET['id']);
      14. $sql = "SELECT id, last_jump_time FROM %%PLANETS%% WHERE id = :targetID AND id_owner = :userID AND sprungtor > 0;";
      15. $TargetGate = $db->selectSingle($sql, array(
      16. ':targetID' => $TargetPlanet,
      17. ':userID' => $USER['id']
      18. ));
      19. if (!isset($TargetGate) || $TargetPlanet == $PLANET['id'])
      20. {
      21. $this->sendJSON(array(
      22. 'message' => $LNG['in_jump_gate_doesnt_have_one'],
      23. 'error' => true
      24. ));
      25. }
      26. $NextJumpTime = self::getNextJumpWaitTime($TargetGate['last_jump_time']);
      27. if (TIMESTAMP < $NextJumpTime)
      28. {
      29. $this->sendJSON(array(
      30. 'message' => $LNG['in_jump_gate_not_ready_target'].' '.pretty_time($NextJumpTime - TIMESTAMP),
      31. 'error' => true
      32. ));
      33. }
      34. $ShipArray = array();
      35. $SubQueryOri = "";
      36. $SubQueryDes = "";
      37. $Ships = HTTP::_GP('ship', array());
      38. foreach($reslist['fleet'] as $Ship)
      39. {
      40. if(!isset($Ships[$Ship]) || $Ship == 212)
      41. continue;
      42. $ShipArray[$Ship] = max(0, min($Ships[$Ship], $PLANET[$resource[$Ship]]));
      43. if(empty($ShipArray[$Ship]))
      44. continue;
      45. $SubQueryOri .= $resource[$Ship]." = ".$resource[$Ship]." - ".$ShipArray[$Ship].", ";
      46. $SubQueryDes .= $resource[$Ship]." = ".$resource[$Ship]." + ".$ShipArray[$Ship].", ";
      47. $PLANET[$resource[$Ship]] -= $ShipArray[$Ship];
      48. }
      49. if (empty($SubQueryOri))
      50. {
      51. $this->sendJSON(array(
      52. 'message' => $LNG['in_jump_gate_error_data'],
      53. 'error' => true
      54. ));
      55. }
      56. $array_merge = array(':planetID' => $PLANET['id'],':jumptime' => TIMESTAMP);
      57. $sql = "UPDATE %%PLANETS%% SET ".$SubQueryOri." `last_jump_time` = :jumptime WHERE id = :planetID;";
      58. $db->update($sql,$array_merge);
      59. $sql = "UPDATE %%PLANETS%% SET ".$SubQueryDes." `last_jump_time` = :jumptime WHERE id = :targetID;";
      60. $db->update($sql, array(
      61. ':targetID' => $TargetPlanet,
      62. ':jumptime' => TIMESTAMP,
      63. ));
      64. $PLANET['last_jump_time'] = TIMESTAMP;
      65. $NextJumpTime = self::getNextJumpWaitTime($PLANET['last_jump_time']);
      66. $this->sendJSON(array(
      67. 'message' => sprintf($LNG['in_jump_gate_done'], pretty_time($NextJumpTime - TIMESTAMP)),
      68. 'error' => false
      69. ));
      70. }
      Display All

      Regards.

      The post was edited 1 time, last by Zuno ().

    • *The code works perfectly. now with 2moon 2.0, it is possible to do Fleet teleportation in exchange for Dark matter.


      ShowJumpFleetPage.class.php

      PHP Source Code

      1. <?php
      2. class ShowJumpFleetPage extends AbstractGamePage {
      3. public static $requireModule = 0;
      4. function __construct() {
      5. parent::__construct();
      6. }
      7. function show() {
      8. global $CONF, $LNG, $PLANET, $USER, $resource, $UNI;
      9. $db = Database::get();
      10. $act = HTTP::_GP('act', '');
      11. $transCoasts = 2000;
      12. if ($act == "take") {
      13. if (!isset($_POST['check_planet']) && !isset($_POST['check_moons'])) {
      14. $this->redirectTo('game.php?page=harvest');
      15. }
      16. if ($transCoasts > $USER['darkmatter']) {
      17. $this->printMessage($LNG['error_3'], true, array('game.php?page=JumpFleet', 4));
      18. } else {
      19. $USER['darkmatter'] -= $transCoasts;
      20. }
      21. if (!isset($_POST['check_planet'])) {
      22. $_POST['check_planet'] = array();
      23. }
      24. foreach ($_POST['check_planet'] as $ID => $Value) {
      25. $sur = $db->selectSingle("SELECT * FROM %%PLANETS%% WHERE `id` = :planetID;", array(':planetID' => $Value));
      26. if (!$sur) {
      27. $this->sendJSON(array(
      28. 'message' => $LNG['error_invalid_coordinates'],
      29. 'error' => true
      30. ));
      31. return;
      32. }
      33. $ShipArray = array();
      34. $SubQueryOri = "";
      35. $SubQueryDes = "";
      36. $reslist = $GLOBALS['reslist'];
      37. foreach ($reslist['fleet'] as $Ship) {
      38. if (!isset($sur[$resource[$Ship]]) || $Ship == 212) {
      39. continue;
      40. }
      41. $ShipArray[$Ship] = max(0, $sur[$resource[$Ship]]);
      42. if (empty($ShipArray[$Ship])) {
      43. continue;
      44. }
      45. $SubQueryOri .= $resource[$Ship] . " = " . $resource[$Ship] . " - " . $ShipArray[$Ship] . ", ";
      46. $SubQueryDes .= $resource[$Ship] . " = " . $resource[$Ship] . " + " . $ShipArray[$Ship] . ", ";
      47. $PLANET[$resource[$Ship]] += $ShipArray[$Ship];
      48. }
      49. if (empty($SubQueryOri)) {
      50. $this->sendJSON(array(
      51. 'message' => $LNG['in_jump_gate_error_data'],
      52. 'error' => true
      53. ));
      54. return;
      55. }
      56. $SubQueryOri = rtrim($SubQueryOri, ', ');
      57. $SubQueryDes = rtrim($SubQueryDes, ', ');
      58. $sql = "UPDATE %%PLANETS%% SET $SubQueryOri WHERE id = :planetID;";
      59. $db->update($sql, array(':planetID' => $Value));
      60. $sql = "UPDATE %%PLANETS%% SET $SubQueryDes WHERE id = :targetID;";
      61. $db->update($sql, array(':targetID' => $PLANET['id']));
      62. }
      63. if (!isset($_POST['check_moons'])) {
      64. $_POST['check_moons'] = array();
      65. }
      66. foreach ($_POST['check_moons'] as $ID => $Value) {
      67. $sur = $db->selectSingle("SELECT * FROM %%PLANETS%% WHERE `id` = :planetID;", array(':planetID' => $Value));
      68. if (!$sur) {
      69. $this->sendJSON(array(
      70. 'message' => $LNG['error_invalid_coordinates'],
      71. 'error' => true
      72. ));
      73. return;
      74. }
      75. $ShipArray = array();
      76. $SubQueryOri = "";
      77. $SubQueryDes = "";
      78. $reslist = $GLOBALS['reslist'];
      79. foreach ($reslist['fleet'] as $Ship) {
      80. if (!isset($sur[$resource[$Ship]]) || $Ship == 212) {
      81. continue;
      82. }
      83. $ShipArray[$Ship] = max(0, $sur[$resource[$Ship]]);
      84. if (empty($ShipArray[$Ship])) {
      85. continue;
      86. }
      87. $SubQueryOri .= $resource[$Ship] . " = " . $resource[$Ship] . " - " . $ShipArray[$Ship] . ", ";
      88. $SubQueryDes .= $resource[$Ship] . " = " . $resource[$Ship] . " + " . $ShipArray[$Ship] . ", ";
      89. $PLANET[$resource[$Ship]] += $ShipArray[$Ship];
      90. }
      91. if (empty($SubQueryOri)) {
      92. $this->sendJSON(array(
      93. 'message' => $LNG['in_jump_gate_error_data'],
      94. 'error' => true
      95. ));
      96. return;
      97. }
      98. $SubQueryOri = rtrim($SubQueryOri, ', ');
      99. $SubQueryDes = rtrim($SubQueryDes, ', ');
      100. $sql = "UPDATE %%PLANETS%% SET $SubQueryOri WHERE id = :planetID;";
      101. $db->update($sql, array(':planetID' => $Value));
      102. $sql = "UPDATE %%PLANETS%% SET $SubQueryDes WHERE id = :targetID;";
      103. $db->update($sql, array(':targetID' => $PLANET['id']));
      104. }
      105. $this->printMessage($LNG['h_ok'], true, array('game.php?page=JumpFleet', 4));
      106. } else {
      107. $Planets = array();
      108. $Moons = array();
      109. if (isset($USER['PLANETS'])) {
      110. $USER['PLANETS'] = getPlanets($USER);
      111. }
      112. foreach ($USER['PLANETS'] as $ID => $PlanetQuery) {
      113. if ($ID == $PLANET['id']) continue;
      114. if ($PlanetQuery['planet_type'] == 3) {
      115. $Moons[$PlanetQuery['id']] = $PlanetQuery['name'] . " [" . $PlanetQuery['galaxy'] . ":" . $PlanetQuery['system'] . ":" . $PlanetQuery['planet'] . "]";
      116. } elseif ($PlanetQuery['planet_type'] == 1) {
      117. $Planets[$PlanetQuery['id']] = $PlanetQuery['name'] . " [" . $PlanetQuery['galaxy'] . ":" . $PlanetQuery['system'] . ":" . $PlanetQuery['planet'] . "]";
      118. }
      119. }
      120. $this->tplObj->assign_vars(array(
      121. 'PlanetsList' => $Planets,
      122. 'MoonsList' => $Moons,
      123. ));
      124. $this->display('page.JumpFleet.default.tpl');
      125. }
      126. }
      127. }
      128. ?>
      Display All
    • The first code you provided, probably written by a person who tries to avoid resource loss issues in Steemnova. But he had wrong approach and he tried to solve the problem on MySQL level by locking tables. That code won't work for all conditions and will cause issues whenever someone try to implement it in their works.

      In order to avoid resource loses, Check Yaro's work ( i guess it was Newstar or XNova not sure ). He kinda solved issue with better approach ( atomic update and version controll ).

      If you want to avoide class.PlanetRessUpdate to overwrite Fleet Actions and Fleet Teleport ( in your case ) , you should add "version" column in %%PLANETS%% table. And you should modify your planetRessUpdate like update planets ....... where version = version, also you should change your fleethandler in a way update planets ...... Set x,y,z, ... version = version + 1.

      By this way, when a fleet reaches to your planet to trade goods, it will trade and it will update planet version to 1 higher. If ResourceUpdater wants to overwrite it, it cannot because now version is higher. It is not 100% correct solution but with this way probably you will loose production instead of fleets or traded goods.

      Your second code will fail someday if you don't have PlanetResourceUpdate fix in Yaro's work. So check that and try to implement it to your work

      EDIT : I implemented atomic update for the work on my sign steemnova 1.8x, you can check it from github.

      check : install.sql , planets table, i added version column there
      check : class.MissionFunctions.php, update planets with version + 1
      check : class.PlanetRessUpdate.php update planets where version = version

      to do : add version update on your Jump page like in missionfunctions update version = version + 1
      to do : if you have darkmatter trading fleet functions apply this steps for user table as well, go to instal.sql add version column into users, and modify in a way that it also updates user version.
      to do further : write a cronjob which resets user and planet tables sometimes like once in a year, if you have really active game
      to do big : With this way of version controll your users wont lose traded resources however, they will some time lose "production" because their traded resourcess will exceed their planet's storage capacity, so planetressupdate will think, capacity is full and won't add production, it is still smaller issue than losing fleet or losing all goods transported with that fleet. Maybe you can avoid it with PHP transactions, but never try to solve that issue on MySQL level by locking tables, transactions and rollback is probably what Ogame uses nowadays.

      Another Edit: Do this for MissionCaseRecycling, or debris will lost sometimes, update planet with version = version + 1,
      ogniter.net

      for a slightly better version of steemnova

      github.com/koraykarakus/steemnova-1.8-x

      The post was edited 3 times, last by amamoslavida ().