diff --git a/dist/app/Http/Controllers/Api/Matchmaking/MatchmakingController.php b/dist/app/Http/Controllers/Api/Matchmaking/MatchmakingController.php index 4de8725..9473772 100644 --- a/dist/app/Http/Controllers/Api/Matchmaking/MatchmakingController.php +++ b/dist/app/Http/Controllers/Api/Matchmaking/MatchmakingController.php @@ -8,6 +8,7 @@ use App\Enums\Game\Matchmaking\QueueStatus; use App\Http\Controllers\Controller; use App\Http\Requests\Api\Matchmaking\QueueRequest; +use App\Http\Requests\Api\Matchmaking\RegisterMatchRequest; use App\Http\Responses\Api\Matchmaking\MatchData; use App\Http\Responses\Api\Matchmaking\MatchProperties; use App\Http\Responses\Api\Matchmaking\QueueData; @@ -31,7 +32,6 @@ public function getRegions() public function queue(QueueRequest $request) { $this->processQueue(); - $this->processGames(); if($request->checkOnly) return json_encode($this->checkQueueStatus($request)); @@ -45,25 +45,31 @@ public function matchInfo(string $matchId) if($foundGame === null) return ['status' => 'Error', 'message' => 'Match not found.']; - $response = new MatchData(); - - $response->matchId = $foundGame->id; - $response->creationDateTime = $foundGame->created_at->getTimestamp(); - $response->status = $foundGame->status; - $response->creator = $foundGame->creator?->id; - - $players = $foundGame->players; - $response->players = $players->pluck('id')->toArray(); - $response->sideA = $players->where('pivot.side', MatchmakingSide::Hunter->value)->pluck('id')->toArray(); - $response->sideB = $players->where('pivot.side', MatchmakingSide::Runner->value)->pluck('id')->toArray(); - - $response->props = new MatchProperties( - $foundGame->matchConfiguration, - ); + $response = MatchData::fromGame($foundGame); return json_encode($response); } + public function register(RegisterMatchRequest $request, string $matchId) + { + $foundGame = Game::find($matchId); + $foundGame->session_settings = $request->sessionSettings; + $foundGame->status = MatchStatus::Opened; + $foundGame->save(); + + return json_encode(MatchData::fromGame($foundGame)); + } + + public function seedFileGet() + { + + } + + public function seedFilePost() + { + + } + protected function checkQueueStatus(QueueRequest $request): QueueResponse { $user = Auth::user(); @@ -99,7 +105,6 @@ protected function checkQueueStatus(QueueRequest $request): QueueResponse /** @var Game $foundGame */ $foundGame = $foundGame->first(); $response = new QueueResponse(); - $matchData = new MatchData(); if($foundGame->status === MatchStatus::Opened) { $response->queueData = new QueueData( @@ -111,22 +116,7 @@ protected function checkQueueStatus(QueueRequest $request): QueueResponse else $response->status = QueueStatus::Matched; - $matchData->matchId = $foundGame->id; - $matchData->category = $request->category; - $matchData->creationDateTime = $foundGame->created_at->getTimestamp(); - $matchData->status = $foundGame->status; - $matchData->creator = $foundGame->creator?->id; - - $players = $foundGame->players; - $matchData->players = $players->pluck('id')->toArray(); - $matchData->sideA = $players->where('pivot.side', MatchmakingSide::Hunter->value)->pluck('id')->toArray(); - $matchData->sideB = $players->where('pivot.side', MatchmakingSide::Runner->value)->pluck('id')->toArray(); - - $matchData->props = new MatchProperties( - $foundGame->matchConfiguration, - ); - - $response->matchData = $matchData; + $response->matchData = MatchData::fromGame($foundGame); return $response; } @@ -204,7 +194,7 @@ protected function processQueue(): void rsort($hunterGroupsSet, SORT_NUMERIC); $newGame = new Game(); - $newGame->status = MatchStatus::Opened; + $newGame->status = MatchStatus::Created; $newGame->matchConfiguration()->associate($selectedConfig); $newGame->save(); @@ -223,22 +213,8 @@ protected function processQueue(): void $newGame->addQueuedPlayer($runners[$foundQueuedPlayer]); } - } - private function processGames() - { - $games = Game::where('status', '=', MatchStatus::Opened)->get(); - - foreach ($games as $game) { - if($game->remainingPlayerCount()->getTotal() == 0) { - $hunter = $game->players()->firstWhere('side', '=', MatchmakingSide::Hunter->value); - $game->creator()->associate($hunter); - $game->status = MatchStatus::Created; - $game->save(); - } - - //Todo: Handle games with missing users later - } + $newGame->determineHost(); } /** diff --git a/dist/app/Http/Requests/Api/Matchmaking/RegisterMatchRequest.php b/dist/app/Http/Requests/Api/Matchmaking/RegisterMatchRequest.php new file mode 100644 index 0000000..189b2be --- /dev/null +++ b/dist/app/Http/Requests/Api/Matchmaking/RegisterMatchRequest.php @@ -0,0 +1,36 @@ +|string> + */ + public function rules(): array + { + return [ + 'customData.SessionSettings' => 'required|string' + ]; + } + + protected function passedValidation() + { + $this->sessionSettings = $this->input('customData.SessionSettings'); + } +} diff --git a/dist/app/Http/Responses/Api/Matchmaking/MatchData.php b/dist/app/Http/Responses/Api/Matchmaking/MatchData.php index cedd1a5..0df7f1d 100644 --- a/dist/app/Http/Responses/Api/Matchmaking/MatchData.php +++ b/dist/app/Http/Responses/Api/Matchmaking/MatchData.php @@ -2,7 +2,9 @@ namespace App\Http\Responses\Api\Matchmaking; +use App\Enums\Game\Matchmaking\MatchmakingSide; use App\Enums\Game\Matchmaking\MatchStatus; +use App\Models\Game\Matchmaking\Game; class MatchData { @@ -48,4 +50,29 @@ public function __construct() $this->customData = new \stdClass(); $this->props = new \stdClass(); } + + public static function fromGame(Game &$game): MatchData { + $data = new MatchData(); + + $data->matchId = $game->id; + $data->creationDateTime = $game->created_at->getTimestamp(); + $data->status = $game->status; + $data->creator = $game->creator?->id; + + $players = $game->players; + $data->players = $players->pluck('id')->toArray(); + $data->sideA = $players->where('pivot.side', MatchmakingSide::Hunter->value)->pluck('id')->toArray(); + $data->sideB = $players->where('pivot.side', MatchmakingSide::Runner->value)->pluck('id')->toArray(); + + if($game->session_settings !== '') + $data->customData = (object)[ + 'SessionSettings' => $game->session_settings, + ]; + + $data->props = new MatchProperties( + $game->matchConfiguration, + ); + + return $data; + } } \ No newline at end of file diff --git a/dist/app/Models/Game/Matchmaking/Game.php b/dist/app/Models/Game/Matchmaking/Game.php index 2e2d365..a059368 100644 --- a/dist/app/Models/Game/Matchmaking/Game.php +++ b/dist/app/Models/Game/Matchmaking/Game.php @@ -59,6 +59,13 @@ public function addQueuedPlayer(QueuedPlayer $player): void }); } + public function determineHost(): void + { + $hunter = $this->players()->firstWhere('side', '=', MatchmakingSide::Hunter->value); + $this->creator()->associate($hunter); + $this->save(); + } + public function remainingPlayerCount(): MatchmakingPlayerCount { $players = $this->players; diff --git a/dist/database/migrations/2024_03_02_142500_create_games_table.php b/dist/database/migrations/2024_03_02_142500_create_games_table.php index b99df10..ebdc29c 100644 --- a/dist/database/migrations/2024_03_02_142500_create_games_table.php +++ b/dist/database/migrations/2024_03_02_142500_create_games_table.php @@ -19,6 +19,7 @@ public function up(): void ->cascadeOnUpdate()->cascadeOnDelete(); $table->foreignId('match_configuration_id')->constrained() ->cascadeOnUpdate()->cascadeOnDelete(); + $table->string('session_settings', 2000)->nullable(); $table->timestamps(); }); } diff --git a/dist/routes/deathgardenApi.php b/dist/routes/deathgardenApi.php index 82c04e8..e90f231 100644 --- a/dist/routes/deathgardenApi.php +++ b/dist/routes/deathgardenApi.php @@ -63,6 +63,10 @@ Route::post('queue', [MatchmakingController::class, 'queue']); Route::get('match/{matchId}', [MatchmakingController::class, 'matchInfo']); + Route::post('match/{matchId}/register', [MatchmakingController::class, 'register']); + + Route::post('file/{gameVersion}/{seed}/{mapName}', [MatchmakingController::class, 'seedFilePost']); + Route::get('file/{gameVersion}/{seed}/{mapName}', [MatchmakingController::class, 'seedFileGet']); });