Skip to content

Commit

Permalink
Add LIO endpoint to part rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Jan 22, 2025
1 parent 160b755 commit 3fe6517
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions app/Http/Controllers/InterOp/Multiplayer/RoomsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public function join(string $id, string $userId)
return $room->getKey();
}

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

return $room->part($user);
}

public function store()
{
$params = \Request::all();
Expand Down
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 3fe6517

Please sign in to comment.