lanedirt / OGameX

Open-source OGame redesign clone built with Laravel 11.x.
https://main.ogamex.dev
MIT License
34 stars 15 forks source link

Ship production error if $time_per_unit value return 0 #209

Closed alican22 closed 4 months ago

alican22 commented 4 months ago

There is some calculating mistake in ship production time per unit in query. If you get result 0 in for $time_per_unit variable you will get en error "Division by zero"

So im fixed it by make minimum production time 0.1 second.

PlanetService.php Line : 1011 / Find the code below;

$time_per_unit = ($item->time_end - $item->time_start) / $item->object_amount;

Added this code after line 1011

if ($time_per_unit <= 0) {
   $time_per_unit = 0.1;
}
lanedirt commented 4 months ago

Hi @alican22,

Thanks for your bug report and your investigation results.

I checked the logic and I saw that the root issue was most likely caused by the building time calculation. In certain cases it was possible that the "Production duration" was shown as "0 seconds" for certain objects. In the official game the minimum building duration is always "1 second".

I have now added this 1 second minimum constraint to the building duration calculation methods. This should also fix the issue you are describing in this issue. See PR #210.

Thanks for creating the issue! I have added you as a co-author to the commit as credit.