Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ CACHE_DRIVER=file
SESSION_DRIVER=database
SESSION_LIFETIME=720
QUEUE_DRIVER=sync
QUEUE_CONNECTION=sync

REDIS_HOST=127.0.0.1
REDIS_HOST=ogamex-redis
REDIS_PASSWORD=null
REDIS_PORT=6379
Comment on lines +31 to 33

@lanedirt lanedirt Nov 25, 2025

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change here means all existing deployments who want to upgrade also need to change their .env, correct?

I tested this PR locally without making this .env change, but as the docker-compose.yml (dev) does expose a port it works via the old 127.0.0.1 connection. But on production deployments this won't work.

I'm thinking we may want to add some sort of initialize script somewhere during docker container start to check for and update default .env values. Such an initialization script does not exist yet, but it would be helpful for future (default) changes too. Because right now without instructions, if someone follows the current upgrade instructions in the README.md, the fleet queue will break.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a script could overwrite the user's custom values. I think updating the README.md would be a better approach. Something like:
"If you are upgrading from version 0.13.0 or earlier, please add REDIS_HOST=ogamex-redis to your .env file."


Expand Down
6 changes: 4 additions & 2 deletions .env.example-prod
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=database
SESSION_LIFETIME=720
QUEUE_DRIVER=sync
QUEUE_DRIVER=redis
QUEUE_CONNECTION=redis

REDIS_HOST=127.0.0.1

REDIS_HOST=ogamex-redis
REDIS_PASSWORD=null
REDIS_PORT=6379

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/run-tests-sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
# Laravel setup steps
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Set APP_ENV to testing │
run: sed -i 's/APP_ENV=.*/APP_ENV=testing/' .env
- name: Composer update
run: composer update --lock
- name: Install Dependencies
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ RUN apt-get update && apt-get install -y \
# Install extensions
RUN docker-php-ext-install ffi pdo_mysql mbstring zip exif pcntl && \
docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ && \
docker-php-ext-install gd
docker-php-ext-install gd && \
pecl install redis && \
docker-php-ext-enable redis

# Enable and configure opcache only if OPCACHE_ENABLE is set to "1"
ARG OPCACHE_ENABLE=0
Expand Down
111 changes: 111 additions & 0 deletions app/Console/Commands/TestFleetQueue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

namespace OGame\Console\Commands;

use Illuminate\Console\Command;
use OGame\Factories\PlanetServiceFactory;
use OGame\Factories\PlayerServiceFactory;
use OGame\GameMissions\AttackMission;
use OGame\GameObjects\Models\Units\UnitCollection;
use OGame\Models\Enums\PlanetType;
use OGame\Models\Planet;
use OGame\Models\Planet\Coordinate;
use OGame\Models\Resources;
use OGame\Services\ObjectService;

class TestFleetQueue extends Command
{
protected $signature = 'fleet:test-queue
{userId : User ID}
{galaxy : Target galaxy}
{system : Target system}
{position : Target position}
{--delay=5 : Arrival delay in seconds}';

protected $description = 'Test fleet queue system by sending 3 attack missions to specified coordinates';

public function handle(): int
{
// Get arguments
$user_id = (int) $this->argument('userId');
$galaxy = (int) $this->argument('galaxy');
$system = (int) $this->argument('system');
$position = (int) $this->argument('position');
$delay = (int) $this->option('delay');

// Get planet
$planet_model = Planet::where('user_id', $user_id)->first();
if (!$planet_model) {
return 1;
}

// Setup services
$planet_factory = app(PlanetServiceFactory::class);
$source_planet = $planet_factory->make($planet_model->id);
$player_factory = app(PlayerServiceFactory::class);
$player = $player_factory->make($user_id);

// Setup test data
$target_coordinate = new Coordinate($galaxy, $system, $position);
$player->setResearchLevel('computer_technology', 10);
$source_planet->addUnit('light_fighter', 6000000);
$source_planet->addResources(new Resources(1000000000, 1000000000, 1000000000, 0));

$attack_mission = app(AttackMission::class);
$missions = [];

// Mission 1: 1M light fighters
$units1 = new UnitCollection();
$units1->addUnit(ObjectService::getUnitObjectByMachineName('light_fighter'), 1000000);
try {
$mission1 = $attack_mission->start(
$source_planet,
$target_coordinate,
PlanetType::Planet,
$units1,
new Resources(0, 0, 0, 0),
$delay
);
$missions[] = $mission1->id;
} catch (\Exception $e) {
}

// Mission 2: 2M light fighters
$units2 = new UnitCollection();
$units2->addUnit(ObjectService::getUnitObjectByMachineName('light_fighter'), 2000000);
try {
$mission2 = $attack_mission->start(
$source_planet,
$target_coordinate,
PlanetType::Planet,
$units2,
new Resources(0, 0, 0, 0),
$delay
);
$missions[] = $mission2->id;
} catch (\Exception $e) {
}

// Mission 3: 3M light fighters
$units3 = new UnitCollection();
$units3->addUnit(ObjectService::getUnitObjectByMachineName('light_fighter'), 3000000);
try {
$mission3 = $attack_mission->start(
$source_planet,
$target_coordinate,
PlanetType::Planet,
$units3,
new Resources(0, 0, 0, 0),
$delay
);
$missions[] = $mission3->id;
} catch (\Exception $e) {
}

if (empty($missions)) {
return 1;
}

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function handle(): int

// Set up the test environment.
parent::setup();

// Set up parameters for this specific test.
$this->testSetup();

Expand All @@ -57,6 +56,8 @@ public function handle(): int
'time_arrival' => time() - 1]);

// Run the parallel requests against the overview page which should start the return mission.
$this->playerService->updateFleetMissions();

$this->runParallelRequests('overview');

// Assert the database state after the test.
Expand Down
8 changes: 8 additions & 0 deletions app/GameMissions/Abstracts/GameMission.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OGame\GameMissions\Models\MissionPossibleStatus;
use OGame\GameObjects\Models\Units\UnitCollection;
use OGame\GameMissions\ExpeditionMission;
use OGame\Jobs\ProcessFleetMissions;
use OGame\Models\Enums\PlanetType;
use OGame\Models\FleetMission;
use OGame\Models\Planet\Coordinate;
Expand Down Expand Up @@ -274,6 +275,8 @@ public function start(PlanetService $planet, Coordinate $targetCoordinate, Plane
if ($mission->time_arrival < Carbon::now()->timestamp) {
$this->process($mission);
}
$arrival_time_to_carbon = Carbon::parse($mission->time_arrival);
ProcessFleetMissions::dispatch($mission, $planet->getPlayer())->delay($arrival_time_to_carbon);

return $mission;
}
Expand Down Expand Up @@ -366,6 +369,11 @@ protected function startReturn(FleetMission $parentMission, Resources $resources
// If the mission is in the past, process it immediately.
if ($mission->time_arrival < Carbon::now()->timestamp) {
$this->process($mission);
} else {
// Dispatch job for future return mission arrival
$player = $this->playerServiceFactory->make($mission->user_id);
$arrival_time_to_carbon = Carbon::parse($mission->time_arrival);
ProcessFleetMissions::dispatch($mission, $player)->delay($arrival_time_to_carbon);
}
}

Expand Down
5 changes: 4 additions & 1 deletion app/Http/Middleware/GlobalGame.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public function handle(Request $request, Closure $next): mixed
$player->planets->current()->update();

// Update all fleet missions of player that are associated with any of the player's planets.
$player->updateFleetMissions();

if (app()->environment('testing')) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we're only doing this during testing? Would we not expect this in prod?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't expect this in the production environment, because in production it runs through Laravel's queue system

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to refactor the feature tests so they do use the Laravel's queue system, so we can assert that the queue processing etc. works using the existing test suite?

I'm not very familiar with Laravel's queue system, but as the feature tests hit the actual database, the queue system should also be able to work normally, right?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to run assertions using Queue::fake();

So I'd expect to that that IMO.

👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use travelTo to simulate fleet events. Unfortunately, with Redis queue, we cannot trigger a battle or a fleet event using travelTo. With $player->updateFleetMissions();, we are already testing the function inside the queue anyway.

$player->updateFleetMissions();
}
}

return $next($request);
Expand Down
Loading
Loading