mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 14:12:08 +00:00
50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Rooms;
|
|
|
|
use App\Events\PaperBallThrown;
|
|
use App\Models\Player;
|
|
use App\Models\Room;
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class RoomEmoteService
|
|
{
|
|
public function throwPaperBall(Room $room, Player $player, int $targetPlayerId): void
|
|
{
|
|
if ($targetPlayerId === $player->id) {
|
|
throw ValidationException::withMessages([
|
|
'target_player_id' => 'Du kannst dich nicht selbst abwerfen.',
|
|
]);
|
|
}
|
|
|
|
$targetExists = $room->players()
|
|
->whereKey($targetPlayerId)
|
|
->exists();
|
|
|
|
if (! $targetExists) {
|
|
throw ValidationException::withMessages([
|
|
'target_player_id' => 'Dieser Spieler sitzt nicht an diesem Tisch.',
|
|
]);
|
|
}
|
|
|
|
$rateLimitKey = "room-emote:{$room->id}:{$player->id}";
|
|
|
|
abort_if(
|
|
RateLimiter::tooManyAttempts($rateLimitKey, 10),
|
|
429,
|
|
'Bitte warte kurz, bevor du erneut wirfst.',
|
|
);
|
|
|
|
RateLimiter::hit($rateLimitKey, 10);
|
|
|
|
PaperBallThrown::dispatch(
|
|
Str::uuid()->toString(),
|
|
$room->id,
|
|
$player->id,
|
|
$targetPlayerId,
|
|
);
|
|
}
|
|
}
|