Skip to content

Commit

Permalink
Merge branch 'master' into eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko committed Jan 23, 2025
2 parents bf3a6ed + 89b2f71 commit 523ca29
Show file tree
Hide file tree
Showing 606 changed files with 7,681 additions and 1,545 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ CLIENT_CHECK_VERSION=false
# SCORES_EXPERIMENTAL_RANK_AS_EXTRA=false
# SCORES_PROCESSING_QUEUE=osu-queue:score-statistics
# SCORES_SUBMISSION_ENABLED=1
# SCORE_INDEX_MAX_ID_DISTANCE=10_000_000

# BANCHO_BOT_USER_ID=

Expand Down
27 changes: 27 additions & 0 deletions app/Casts/TimestampOrZero.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Casts;

use Carbon\Carbon;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

/**
* For columns which use unix timestamp as its value and repurpose 0 as null.
*/
class TimestampOrZero implements CastsAttributes
{
public function get($model, string $key, $value, array $attributes)
{
return $value === null || $value === 0 ? null : Carbon::createFromTimestamp($value);
}

public function set($model, string $key, $value, array $attributes)
{
return $value === null ? 0 : $value->getTimestamp();
}
}
16 changes: 0 additions & 16 deletions app/Http/Controllers/BeatmapTagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ public function __construct()
'destroy',
],
]);

$this->middleware('require-scopes:public', ['only' => 'index']);
}

public function index($beatmapId)
{
$topBeatmapTags = cache_remember_mutexed(
"beatmap_tags:{$beatmapId}",
$GLOBALS['cfg']['osu']['tags']['beatmap_tags_cache_duration'],
[],
fn () => Tag::topTags($beatmapId),
);

return [
'beatmap_tags' => $topBeatmapTags,
];
}

public function destroy($beatmapId, $tagId)
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/BeatmapsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class BeatmapsController extends Controller
{
const DEFAULT_API_INCLUDES = ['beatmapset.ratings', 'failtimes', 'max_combo'];
const DEFAULT_SCORE_INCLUDES = ['user', 'user.country', 'user.cover'];
const DEFAULT_SCORE_INCLUDES = ['user', 'user.country', 'user.cover', 'user.team'];

public function __construct()
{
Expand Down Expand Up @@ -74,7 +74,7 @@ private static function beatmapScores(string $id, ?string $scoreTransformerType,
'type' => $type,
'user' => $currentUser,
]);
$scores = $esFetch->all()->loadMissing(['beatmap', 'user.country', 'processHistory']);
$scores = $esFetch->all()->loadMissing(['beatmap', 'user.country', 'user.team', 'processHistory']);
$userScore = $esFetch->userBest();
$scoreTransformer = new ScoreTransformer($scoreTransformerType);

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/BeatmapsetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ private function showJson($beatmapset)
'beatmaps.failtimes',
'beatmaps.max_combo',
'beatmaps.owners',
'beatmaps.top_tag_ids',
'converts',
'converts.failtimes',
'converts.owners',
Expand All @@ -415,6 +416,7 @@ private function showJson($beatmapset)
'pack_tags',
'ratings',
'recent_favourites',
'related_tags',
'related_users',
'user',
]);
Expand Down
47 changes: 26 additions & 21 deletions app/Http/Controllers/Chat/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,39 +89,44 @@ public function ack()
* @bodyParam uuid string client-side message identifier which will be sent back in response and websocket json. Example: some-uuid-string
*
* @response {
* "channel": [
* {
* "channel_id": 1234,
* "current_user_attributes": {
* "can_message": true,
* "can_message_error": null,
* "last_read_id": 9150005005
* },
* "name": "peppy",
* "description": "",
* "type": "PM",
* "last_read_id": 9150005005,
* "last_message_id": 9150005005
* }
* ],
* "channel": {
* "channel_id": 1234,
* "description": "",
* "icon": "https://a.ppy.sh/102?1500537068"
* "message_length_limit": 450,
* "moderated": false,
* "name": "peppy",
* "type": "PM",
* "uuid": null,
* "last_message_id": 9150005005,
* "users": [
* 101,
* 102
* ]
* },
* "message": {
* "message_id": 9150005005,
* "sender_id": 102,
* "channel_id": 1234,
* "timestamp": "2018-07-06T06:33:42+00:00",
* "content": "i can haz featured artist plz?",
* "is_action": false,
* "message_id": 9150005005,
* "sender_id": 102,
* "timestamp": "2024-12-23T01:23:45+00:00",
* "type": "plain",
* "uuid": "some-uuid-string",
* "sender": {
* "id": 102,
* "username": "nekodex",
* "profile_colour": "#333333",
* "avatar_url": "https://a.ppy.sh/102?1500537068",
* "country_code": "AU",
* "default_group": "default",
* "id": 102,
* "is_active": true,
* "is_bot": false,
* "is_deleted": false,
* "is_online": true,
* "is_supporter": true
* "last_visit": "2024-12-23T01:23:45+00:00",
* "pm_friends_only": false,
* "profile_colour": "#333333",
* "username": "nekodex",
* }
* },
* "new_channel_id": 1234,
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Forum/TopicsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ public function show($id)
'user.country',
'user.rank',
'user.supporterTagPurchases',
'user.team',
'user.userGroups',
]);

Expand Down
14 changes: 7 additions & 7 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Models\NewsPost;
use App\Models\UserDonation;
use App\Transformers\MenuImageTransformer;
use App\Transformers\UserCompactTransformer;
use Auth;
use Jenssegers\Agent\Agent;
use Request;
Expand Down Expand Up @@ -142,12 +143,11 @@ public function quickSearch()
$result[$mode]['total'] = $search->count();
}

$result['user']['users'] = json_collection($searches['user']->data(), 'UserCompact', [
'country',
'cover',
'groups',
'support_level',
]);
$result['user']['users'] = json_collection(
$searches['user']->data(),
new UserCompactTransformer(),
[...UserCompactTransformer::CARD_INCLUDES, 'support_level'],
);
$result['beatmapset']['beatmapsets'] = json_collection($searches['beatmapset']->data(), 'Beatmapset', ['beatmaps']);
}

Expand Down Expand Up @@ -210,7 +210,7 @@ public function setLocale()
]);
}

return ext_view('layout.ujs-reload', [], 'js')
return ext_view('layout.ujs_full_reload', [], 'js')
->withCookie(cookie()->forever('locale', $newLocale));
}

Expand Down
19 changes: 19 additions & 0 deletions app/Http/Controllers/InterOp/BeatmapsetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Models\BeatmapDiscussion;
use App\Models\BeatmapDiscussionPost;
use App\Models\Beatmapset;
use App\Models\Event;
use App\Models\User;

class BeatmapsetsController extends Controller
Expand All @@ -22,6 +23,10 @@ public function broadcastNew($id)

(new UserBeatmapsetNew($beatmapset))->dispatch();

if (request()->boolean('create_event')) {
Event::generate('beatmapsetUpload', ['beatmapset' => $beatmapset]);
}

return response(null, 204);
}

Expand All @@ -31,6 +36,20 @@ public function broadcastRevive($id)

(new UserBeatmapsetRevive($beatmapset))->dispatch();

if (request()->boolean('create_event')) {
Event::generate('beatmapsetRevive', ['beatmapset' => $beatmapset]);
}

return response(null, 204);
}

public function broadcastUpdate($id)
{
$beatmapset = Beatmapset::findOrFail($id);
$user = User::findOrFail(request()->integer('user_id'));

Event::generate('beatmapsetUpdate', ['beatmapset' => $beatmapset, 'user' => $user]);

return response(null, 204);
}

Expand Down
35 changes: 35 additions & 0 deletions app/Http/Controllers/InterOp/Multiplayer/RoomsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace App\Http\Controllers\InterOp\Multiplayer;

use App\Http\Controllers\Controller;
use App\Models\Multiplayer\Room;
use App\Models\User;
use App\Transformers\Multiplayer\RoomTransformer;

class RoomsController extends Controller
{
public function join(string $id, string $userId)
{
$user = User::findOrFail($userId);
$room = Room::findOrFail($id);

$room->assertCorrectPassword(get_string(request('password')));
$room->join($user);

return RoomTransformer::createShowResponse($room);
}

public function store()
{
$params = \Request::all();
$user = User::findOrFail(get_int($params['user_id'] ?? null));

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

return RoomTransformer::createShowResponse($room);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace App\Http\Controllers\Multiplayer\Rooms\Playlist;

use App\Exceptions\InvariantException;
use App\Http\Controllers\Controller as BaseController;
use App\Libraries\ClientCheck;
use App\Models\Multiplayer\PlaylistItem;
Expand Down Expand Up @@ -182,15 +181,11 @@ public function store($roomId, $playlistId)
$playlistItem = $room->playlist()->findOrFail($playlistId);
$user = \Auth::user();
$request = \Request::instance();
$params = $request->all();

if (get_string($params['beatmap_hash'] ?? null) !== $playlistItem->beatmap->checksum) {
throw new InvariantException(osu_trans('score_tokens.create.beatmap_hash_invalid'));
}

$buildId = ClientCheck::parseToken($request)['buildId'];

$scoreToken = $room->startPlay($user, $playlistItem, $buildId);
$scoreToken = $room->startPlay($user, $playlistItem, [
...$request->all(),
'build_id' => ClientCheck::parseToken($request)['buildId'],
]);

return json_item($scoreToken, new ScoreTokenTransformer());
}
Expand Down
47 changes: 8 additions & 39 deletions app/Http/Controllers/Multiplayer/RoomsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace App\Http\Controllers\Multiplayer;

use App\Exceptions\InvariantException;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Ranking\DailyChallengeController;
use App\Models\Model;
Expand Down Expand Up @@ -101,24 +100,18 @@ public function index()

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

$room = Room::findOrFail($roomId);
$room->assertCorrectPassword(get_string(request('password')));

if ($room->password !== null) {
$password = get_param_value(request('password'), null);

if ($password === null || !hash_equals(hash('sha256', $room->password), hash('sha256', $password))) {
abort(403, osu_trans('multiplayer.room.invalid_password'));
}
}

$room->join(auth()->user());
$room->join($currentUser);

return $this->createJoinedRoomResponse($room);
return RoomTransformer::createShowResponse($room);
}

public function leaderboard($roomId)
Expand Down Expand Up @@ -168,7 +161,7 @@ public function show($id)
}

if (is_api_request()) {
return $this->createJoinedRoomResponse($room);
return RoomTransformer::createShowResponse($room);
}

if ($room->category === 'daily_challenge') {
Expand Down Expand Up @@ -200,32 +193,8 @@ public function show($id)

public function store()
{
try {
$room = (new Room())->startGame(auth()->user(), request()->all());

return $this->createJoinedRoomResponse($room);
} catch (InvariantException $e) {
return error_popup($e->getMessage(), $e->getStatusCode());
}
}
$room = (new Room())->startGame(\Auth::user(), \Request::all());

private function createJoinedRoomResponse($room)
{
return json_item(
$room->loadMissing([
'host',
'playlist.beatmap.beatmapset',
'playlist.beatmap.baseMaxCombo',
]),
'Multiplayer\Room',
[
'current_user_score.playlist_item_attempts',
'host.country',
'playlist.beatmap.beatmapset',
'playlist.beatmap.checksum',
'playlist.beatmap.max_combo',
'recent_participants',
]
);
return RoomTransformer::createShowResponse($room);
}
}
Loading

0 comments on commit 523ca29

Please sign in to comment.