Skip to content

Commit

Permalink
Merge pull request #11811 from smoogipoo/room-management-lio
Browse files Browse the repository at this point in the history
Add support for parting rooms via interop + adjust responses
  • Loading branch information
nanaya authored Jan 23, 2025
2 parents 83e7f98 + 15e4794 commit 7c100f9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
15 changes: 12 additions & 3 deletions app/Http/Controllers/InterOp/Multiplayer/RoomsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use App\Http\Controllers\Controller;
use App\Models\Multiplayer\Room;
use App\Models\User;
use App\Transformers\Multiplayer\RoomTransformer;

class RoomsController extends Controller
{
Expand All @@ -20,7 +19,17 @@ public function join(string $id, string $userId)
$room->assertCorrectPassword(get_string(request('password')));
$room->join($user);

return RoomTransformer::createShowResponse($room);
return response(null, 204);
}

public function part(string $id, string $userId)
{
$user = User::findOrFail($userId);
$room = Room::findOrFail($id);

$room->part($user);

return response(null, 204);
}

public function store()
Expand All @@ -30,6 +39,6 @@ public function store()

$room = (new Room())->startGame($user, $params);

return RoomTransformer::createShowResponse($room);
return $room->getKey();
}
}
6 changes: 4 additions & 2 deletions app/Http/Controllers/Multiplayer/RoomsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,14 @@ public function leaderboard($roomId)

public function part($roomId, $userId)
{
$currentUser = \Auth::user();
// this allows admins/host/whoever to remove users from games in the future
if (get_int($userId) !== auth()->user()->user_id) {
if (get_int($userId) !== $currentUser->getKey()) {
abort(403);
}

Room::findOrFail($roomId)->channel->removeUser(auth()->user());
$room = Room::findOrFail($roomId);
$room->part($currentUser);

return response([], 204);
}
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Multiplayer/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ public function join(User $user)
$this->channel->addUser($user);
}

public function part(User $user)
{
$this->channel->removeUser($user);
}

public function participants(): HasMany
{
$query = $this->userHighScores();
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@

Route::group(['as' => 'multiplayer.', 'namespace' => 'Multiplayer', 'prefix' => 'multiplayer'], function () {
Route::put('rooms/{room}/users/{user}', 'RoomsController@join')->name('rooms.join');
Route::delete('rooms/{room}/users/{user}', 'RoomsController@part')->name('rooms.part');
Route::apiResource('rooms', 'RoomsController', ['only' => ['store']]);
});

Expand Down

0 comments on commit 7c100f9

Please sign in to comment.