Skip to content

Commit 8bbd172

Browse files
authored
Merge branch 'master' into user-country-check
2 parents 699a00e + 3efdafb commit 8bbd172

File tree

11 files changed

+116
-47
lines changed

11 files changed

+116
-47
lines changed

app/Http/Controllers/Multiplayer/RoomsController.php

+22-30
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function join($roomId, $userId)
118118

119119
$room->join(auth()->user());
120120

121-
return response([], 204);
121+
return $this->createJoinedRoomResponse($room);
122122
}
123123

124124
public function leaderboard($roomId)
@@ -168,21 +168,7 @@ public function show($id)
168168
}
169169

170170
if (is_api_request()) {
171-
return json_item(
172-
$room
173-
->load('host.country')
174-
->load('playlist.beatmap.beatmapset')
175-
->load('playlist.beatmap.baseMaxCombo'),
176-
'Multiplayer\Room',
177-
[
178-
'current_user_score.playlist_item_attempts',
179-
'host.country',
180-
'playlist.beatmap.beatmapset',
181-
'playlist.beatmap.checksum',
182-
'playlist.beatmap.max_combo',
183-
'recent_participants',
184-
]
185-
);
171+
return $this->createJoinedRoomResponse($room);
186172
}
187173

188174
if ($room->category === 'daily_challenge') {
@@ -217,22 +203,28 @@ public function store()
217203
try {
218204
$room = (new Room())->startGame(auth()->user(), request()->all());
219205

220-
return json_item(
221-
$room
222-
->load('host.country')
223-
->load('playlist.beatmap.beatmapset')
224-
->load('playlist.beatmap.baseMaxCombo'),
225-
'Multiplayer\Room',
226-
[
227-
'host.country',
228-
'playlist.beatmap.beatmapset',
229-
'playlist.beatmap.checksum',
230-
'playlist.beatmap.max_combo',
231-
'recent_participants',
232-
]
233-
);
206+
return $this->createJoinedRoomResponse($room);
234207
} catch (InvariantException $e) {
235208
return error_popup($e->getMessage(), $e->getStatusCode());
236209
}
237210
}
211+
212+
private function createJoinedRoomResponse($room)
213+
{
214+
return json_item(
215+
$room
216+
->load('host.country')
217+
->load('playlist.beatmap.beatmapset')
218+
->load('playlist.beatmap.baseMaxCombo'),
219+
'Multiplayer\Room',
220+
[
221+
'current_user_score.playlist_item_attempts',
222+
'host.country',
223+
'playlist.beatmap.beatmapset',
224+
'playlist.beatmap.checksum',
225+
'playlist.beatmap.max_combo',
226+
'recent_participants',
227+
]
228+
);
229+
}
238230
}

app/Models/Multiplayer/Room.php

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
/**
2929
* @property string $category
30+
* @property string $status
3031
* @property Channel $channel
3132
* @property int|null $channel_id
3233
* @property \Carbon\Carbon|null $created_at

app/Models/NewsPost.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public function firstImage($absolute = false)
255255
return;
256256
}
257257

258-
if ($absolute && !starts_with($url, ['https://', 'http://'])) {
258+
if ($absolute && !is_http($url)) {
259259
if ($url[0] === '/') {
260260
$url = $GLOBALS['cfg']['app']['url'].$url;
261261
} else {

app/Models/User.php

+7-10
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ public function setUserWebsiteAttribute($value)
707707

708708
// FIXME: this can probably be removed after old site is deactivated
709709
// as there's same check in getter function.
710-
if (present($value) && !starts_with($value, ['http://', 'https://'])) {
710+
if (present($value) && !is_http($value)) {
711711
$value = "https://{$value}";
712712
}
713713

@@ -2468,14 +2468,11 @@ private function getUserWebsite()
24682468
{
24692469
$value = presence(trim($this->getRawAttribute('user_website')));
24702470

2471-
if ($value === null) {
2472-
return null;
2473-
}
2474-
2475-
if (starts_with($value, ['http://', 'https://'])) {
2476-
return $value;
2477-
}
2478-
2479-
return "https://{$value}";
2471+
return $value === null
2472+
? null
2473+
: (is_http($value)
2474+
? $value
2475+
: "https://{$value}"
2476+
);
24802477
}
24812478
}

app/Transformers/Multiplayer/RoomTransformer.php

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function transform(Room $room)
2929
'id' => $room->id,
3030
'name' => $room->name,
3131
'category' => $room->category,
32+
'status' => $room->status,
3233
'type' => $room->type,
3334
'user_id' => $room->user_id,
3435
'starts_at' => json_time($room->starts_at),

app/helpers.php

+6
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,12 @@ function is_api_request(): bool
848848
return str_starts_with(rawurldecode(Request::getPathInfo()), '/api/');
849849
}
850850

851+
function is_http(string $url): bool
852+
{
853+
return str_starts_with($url, 'http://')
854+
|| str_starts_with($url, 'https://');
855+
}
856+
851857
function is_json_request(): bool
852858
{
853859
return is_api_request() || Request::expectsJson();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
6+
declare(strict_types=1);
7+
8+
use Illuminate\Database\Migrations\Migration;
9+
use Illuminate\Database\Schema\Blueprint;
10+
use Illuminate\Support\Facades\Schema;
11+
12+
return new class extends Migration
13+
{
14+
/**
15+
* Run the migrations.
16+
*/
17+
public function up(): void
18+
{
19+
Schema::table('multiplayer_rooms', function (Blueprint $table) {
20+
$table->enum('status', ['idle', 'playing'])->default('idle');
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*/
27+
public function down(): void
28+
{
29+
Schema::table('multiplayer_rooms', function (Blueprint $table) {
30+
$table->dropColumn('status');
31+
});
32+
}
33+
};

database/mods.json

+37-3
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@
287287
}
288288
],
289289
"IncompatibleMods": [
290-
"BL"
290+
"BL",
291+
"BM"
291292
],
292293
"RequiresConfiguration": false,
293294
"UserPlayable": true,
@@ -1016,7 +1017,9 @@
10161017
"Description": "The combo count at which the cursor becomes completely hidden"
10171018
}
10181019
],
1019-
"IncompatibleMods": [],
1020+
"IncompatibleMods": [
1021+
"BM"
1022+
],
10201023
"RequiresConfiguration": false,
10211024
"UserPlayable": true,
10221025
"ValidForMultiplayer": true,
@@ -1203,6 +1206,36 @@
12031206
"ValidForMultiplayerAsFreeMod": true,
12041207
"AlwaysValidForSubmission": false
12051208
},
1209+
{
1210+
"Acronym": "BM",
1211+
"Name": "Bloom",
1212+
"Description": "The cursor blooms into.. a larger cursor!",
1213+
"Type": "Fun",
1214+
"Settings": [
1215+
{
1216+
"Name": "max_size_combo_count",
1217+
"Type": "number",
1218+
"Label": "Max size at combo",
1219+
"Description": "The combo count at which the cursor reaches its maximum size"
1220+
},
1221+
{
1222+
"Name": "max_cursor_size",
1223+
"Type": "number",
1224+
"Label": "Final size multiplier",
1225+
"Description": "The multiplier applied to cursor size when combo reaches maximum"
1226+
}
1227+
],
1228+
"IncompatibleMods": [
1229+
"FL",
1230+
"NS",
1231+
"TD"
1232+
],
1233+
"RequiresConfiguration": false,
1234+
"UserPlayable": true,
1235+
"ValidForMultiplayer": true,
1236+
"ValidForMultiplayerAsFreeMod": true,
1237+
"AlwaysValidForSubmission": false
1238+
},
12061239
{
12071240
"Acronym": "TD",
12081241
"Name": "Touch Device",
@@ -1212,7 +1245,8 @@
12121245
"IncompatibleMods": [
12131246
"AT",
12141247
"CN",
1215-
"AP"
1248+
"AP",
1249+
"BM"
12161250
],
12171251
"RequiresConfiguration": false,
12181252
"UserPlayable": true,

docker-compose.yml

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ services:
110110
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
111111
ports:
112112
- "${MYSQL_EXTERNAL_PORT:-127.0.0.1:3306}:3306"
113-
command: --default-authentication-plugin=mysql_native_password
114113
healthcheck:
115114
# important to use 127.0.0.1 instead of localhost as mysql starts twice.
116115
# the first time it listens on sockets but isn't actually ready

resources/css/bem/input-container.less

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// See the LICENCE file in the repository root for full licence text.
33

44
.input-container {
5+
@top: input-container;
6+
57
--label-font-size: @font-size--normal;
68
--label-line-height: 1.25;
79
--label-height: calc(
@@ -16,6 +18,7 @@
1618
--input-border-hover-colour: hsl(var(--hsl-l3));
1719
--input-border-focus-colour: hsl(var(--hsl-l1));
1820
--input-border-error-colour: hsl(var(--hsl-red-2));
21+
--input-border-error-focus-colour: hsl(var(--hsl-red-3));
1922
--input-padding: var(--label-height) var(--input-padding-right)
2023
var(--input-padding-base) var(--input-padding-base);
2124
--input-padding-base: 10px;
@@ -52,6 +55,8 @@
5255

5356
&--error {
5457
--input-border-colour: var(--input-border-error-colour);
58+
--input-border-focus-colour: var(--input-border-error-focus-colour);
59+
--input-border-hover-colour: var(--input-border-error-focus-colour);
5560
}
5661

5762
&--fill {

tests/TestCase.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ protected function actAsUserWithToken(Token $token, $driver = null): static
182182
$guard = app('auth')->guard($driver);
183183
$user = $token->getResourceOwner();
184184

185-
if ($user !== null) {
186-
// guard doesn't accept null user.
185+
if ($user === null) {
186+
$guard->logout();
187+
} else {
187188
$guard->setUser($user);
188189
$user->withAccessToken($token);
189190
}

0 commit comments

Comments
 (0)