XGProyect / XG-Proyect-v3.x.x

XG Proyect is an OGame clone open-source web application framework designed for creating game clones, particularly those inspired by the popular game OGame, set in a vast and captivating space-themed universe.
https://xgproyect.org
GNU General Public License v3.0
147 stars 101 forks source link

Repaired Defense overrides all players after attack #131

Closed Bustux closed 7 years ago

Bustux commented 8 years ago

After a attack the repaired defenses of the attacked player overrides the defense of all players.

application\libraries\missions\attack.php Line 773-781 original : parent::$db->query( "UPDATE" . PLANETS . "," . SHIPS . "," . DEFENSES . "SET " . $fleetArray. " planet_metal=planet_metal- " . $steal['metal'] . ", planet_crystal=planet_crystal- " . $steal['crystal'] . ", planet_deuterium=planet_deuterium- " . $steal['deuterium'] . " WHEREplanet_id= '" . $target_planet['planet_id'] . "' AND ship_planet_id= '" . $target_planet['planet_id'] . "'" );

fix : parent::$db->query( "UPDATE" . PLANETS . "," . SHIPS . "," . DEFENSES . "SET " . $fleetArray. " planet_metal=planet_metal- " . $steal['metal'] . ", planet_crystal=planet_crystal- " . $steal['crystal'] . ", planet_deuterium=planet_deuterium- " . $steal['deuterium'] . " WHEREplanet_id= '" . $target_planet['planet_id'] . "' AND ship_planet_id= '" . $target_planet['planet_id'] . "' AND defense_planet_id= '" . $target_planet['planet_id'] . "'" );

Jorch95 commented 8 years ago

And this fix resolved the problem ? Because I hace a similar bug.

Jorch95 commented 8 years ago

Hello @Bustux !! I had the same bug like you and i replace the fix that you've posted here. After this, i send an attack to see if everything was ok, but after the attack, the Battle Report didn't appear and the defenses of the attacked planet didn't change at all.

Forgive my writting, my english is rusty.

FedePuratich commented 8 years ago

Hello, im working with @Jorch95 and we tested this fix, at first time with this code we have this error and the battle didn't happen

Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATExgp_planets,xgp_ships,xgp_defensesSETdefense_rocket_launcher= 5,' at line 1 Last SQL Query: UPDATExgp_planets,xgp_ships,xgp_defensesSET defense_rocket_launcher = 5, defense_light_laser = 1, ship_espionage_probe = 1, ship_solar_satellite = 1, planet_metal=planet_metal- 0, planet_crystal=planet_crystal- 0, planet_deuterium=planet_deuterium- 0 WHERE planet_id= '18' AND ship_planet_id= '18' AND defense_planet_id= '18'`

at second time we change the code for

parent::$db->query( "UPDATE" . PLANETS . "," . SHIPS . "," . DEFENSES . "SET " . $fleetArray. " planet_metal=planet_metal- " . $steal['metal'] . ", planet_crystal=planet_crystal- " . $steal['crystal'] . ", planet_deuterium=planet_deuterium- " . $steal['deuterium'] . " WHEREplanet_id= '" . $target_planet['planet_id'] . "' AND ship_planet_id= '" . $target_planet['planet_id'] . "' AND defense_planet_id= '" . $target_planet['planet_id'] . "'" //FIX );

and the battle went well but we have this error in the log

Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATExgp_planets,xgp_ships,xgp_defensesSETdefense_rocket_launcher= 1,' at line 1 Last SQL Query: UPDATExgp_planets,xgp_ships,xgp_defensesSET defense_rocket_launcher = 1, defense_light_laser = 1, ship_small_cargo_ship = 0, ship_light_fighter = 0, ship_solar_satellite = 0, planet_metal=planet_metal- 4649.3284708378, planet_crystal=planet_crystal- 2533.9406055383, planet_deuterium=planet_deuterium- 1758.6564847222 WHERE planet_id= '19' AND ship_planet_id= '19' AND defense_planet_id= '19'`

sorry for my troglodit english

FedePuratich commented 8 years ago

We tryed again and it's work.. idk the reason because the second error.

Bustux commented 8 years ago

@FedePuratich Ok i cant say 100% want went wrong with your implementation. Here is the php file as we use it on our server and until now we had no problems with it: http://pastebin.com/4j7iqiQr . After i write this fix i got a pm with a better fix. I haven't tested it but my be it will help you. parent::$db->query( "UPDATE " . PLANETS . ", " . SHIPS . ", " . DEFENSES . " SET " . $fleetArray. " planet_metal = planet_metal - " . $steal['metal'] . ", planet_crystal = planet_crystal - " . $steal['crystal'] . ", planet_deuterium = planet_deuterium - " . $steal['deuterium'] . " WHERE planet_id = '" . $target_planet['planet_id'] . "' AND ship_planet_id = '" . $target_planet['planet_id'] . "' AND defense_planet_id= '" . $target_planet['planet_id'] . "'" );