1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Http\Controllers\InterOp\Multiplayer;
7
8use App\Http\Controllers\Controller;
9use App\Models\Multiplayer\Room;
10use App\Models\User;
11
12class RoomsController extends Controller
13{
14 public function join(string $id, string $userId)
15 {
16 $user = User::findOrFail($userId);
17 $room = Room::findOrFail($id);
18
19 $room->assertCorrectPassword(get_string(request('password')));
20 $room->join($user);
21
22 return response(null, 204);
23 }
24
25 public function part(string $id, string $userId)
26 {
27 $user = User::findOrFail($userId);
28 $room = Room::findOrFail($id);
29
30 $room->part($user);
31
32 return response(null, 204);
33 }
34
35 public function store()
36 {
37 $params = \Request::all();
38 $user = User::findOrFail(get_int($params['user_id'] ?? null));
39
40 $room = (new Room())->startGame($user, $params);
41
42 return $room->getKey();
43 }
44}