diff --git a/app/Http/Controllers/InterOp/Multiplayer/RoomsController.php b/app/Http/Controllers/InterOp/Multiplayer/RoomsController.php index 27e08dfbb9c..cd317a92077 100644 --- a/app/Http/Controllers/InterOp/Multiplayer/RoomsController.php +++ b/app/Http/Controllers/InterOp/Multiplayer/RoomsController.php @@ -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 { @@ -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() @@ -30,6 +39,6 @@ public function store() $room = (new Room())->startGame($user, $params); - return RoomTransformer::createShowResponse($room); + return $room->getKey(); } } diff --git a/app/Http/Controllers/Multiplayer/RoomsController.php b/app/Http/Controllers/Multiplayer/RoomsController.php index 00d0bdd7c13..d0d8bd748b4 100644 --- a/app/Http/Controllers/Multiplayer/RoomsController.php +++ b/app/Http/Controllers/Multiplayer/RoomsController.php @@ -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); } diff --git a/app/Models/Multiplayer/Room.php b/app/Models/Multiplayer/Room.php index 47e6dcad85e..15bc27784f5 100644 --- a/app/Models/Multiplayer/Room.php +++ b/app/Models/Multiplayer/Room.php @@ -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(); diff --git a/routes/web.php b/routes/web.php index b601b239d58..4e86b47085f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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']]); });