mirror of
https://github.com/Deathgarden-Rebirth/Deathgarden_Rebirth-Rewrite.git
synced 2026-09-09 03:35:14 -05:00
Backend implementation of full match chat
This commit is contained in:
@@ -2,19 +2,26 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Classes\Frontend\ChatMessage;
|
||||
use App\Enums\Game\Matchmaking\MatchStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Api\Moderation\CheckChatMessageRequest;
|
||||
use App\Http\Requests\Api\Moderation\ReportPlayerRequest;
|
||||
use App\Http\Requests\Api\Player\CheckUsernameRequest;
|
||||
use App\Http\Responses\Api\Player\CheckUsernameResponse;
|
||||
use App\Models\Admin\BadChatMessage;
|
||||
use App\Models\Game\Matchmaking\Game;
|
||||
use App\Models\Game\Moderation\PlayerReport;
|
||||
use App\Models\User\User;
|
||||
use ConsoleTVs\Profanity\Builder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class ModerationController extends Controller
|
||||
{
|
||||
const CHAT_CACHE_KEY = 'chat-messages-';
|
||||
|
||||
public function checkUsername(CheckUsernameRequest $request): mixed
|
||||
{
|
||||
@@ -25,23 +32,39 @@ public function checkChatMessage(CheckChatMessageRequest $request): mixed
|
||||
{
|
||||
// Lobby Host that send the request to check the message. We log him too since only the lobby host checks the messages in teh backend.
|
||||
$hostUser = Auth::user();
|
||||
|
||||
$activeGame = $hostUser->games()->whereNotIn('status', [MatchStatus::Killed])->first();
|
||||
if($activeGame === null)
|
||||
// Don't log and check anything if the user is not in a game, we don't care about chatting in the locker room.
|
||||
return Response::json([]);
|
||||
|
||||
// User that send the chat message
|
||||
$messageUser = User::find($request->userId);
|
||||
|
||||
$gameMessages = Cache::get(static::CHAT_CACHE_KEY . $activeGame->id, []);
|
||||
$gameMessages[] = new ChatMessage(
|
||||
$activeGame->id,
|
||||
$messageUser->id,
|
||||
Carbon::now(),
|
||||
$request->message,
|
||||
);
|
||||
Cache::put(static::CHAT_CACHE_KEY . $activeGame->id, $gameMessages, 1800 /** 30 Minutes */);
|
||||
|
||||
$checker = Builder::blocker($request->message);
|
||||
|
||||
if($checker->clean())
|
||||
return response('{}');
|
||||
|
||||
$this->logBadMessage($hostUser, $messageUser, $request->message);
|
||||
$this->logBadMessage($hostUser, $messageUser, $request->message, $activeGame);
|
||||
return response('Bad Message >:(');
|
||||
}
|
||||
|
||||
public function logBadMessage(User $hostUser, User $messageUser, string $message): void {
|
||||
public function logBadMessage(User $hostUser, User $messageUser, string $message, Game $match): void {
|
||||
$badMessage = new BadChatMessage();
|
||||
$badMessage->hostUser()->associate($hostUser);
|
||||
$badMessage->user()->associate($messageUser);
|
||||
$badMessage->message = $message;
|
||||
$badMessage->match_id = $match->id;
|
||||
$badMessage->save();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user