Revert "revert commit"

This reverts commit 641332e5ba.
This commit is contained in:
m.razaghi
2026-08-20 17:37:48 +03:30
parent 641332e5ba
commit 6a204c69ac
6 changed files with 88 additions and 69 deletions

View File

2
.gitignore vendored
View File

@@ -5,7 +5,7 @@
/public/storage /public/storage
/storage/*.key /storage/*.key
/vendor /vendor
.env.pusher .env
.env.backup .env.backup
.env.production .env.production
.phpunit.result.cache .phpunit.result.cache

View File

@@ -1,32 +1,32 @@
<?php <?php
//
//namespace App\Events; namespace App\Events;
//
//use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\InteractsWithSockets;
//use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Broadcasting\PrivateChannel;
//use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
//use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Foundation\Events\Dispatchable;
//use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
//
//class MatchEnded implements ShouldBroadcastNow class MatchEnded implements ShouldBroadcastNow
//{ {
// use Dispatchable, InteractsWithSockets, SerializesModels; use Dispatchable, InteractsWithSockets, SerializesModels;
//
// public $matchId; public $matchId;
//
// public function __construct($matchId) public function __construct($matchId)
// { {
// $this->matchId = $matchId; $this->matchId = $matchId;
// } }
//
// public function broadcastOn() public function broadcastOn()
// { {
// // ارسال پیام به کانال پرایوت بازی که هر دو نفر داخل آن هستند // ارسال پیام به کانال پرایوت بازی که هر دو نفر داخل آن هستند
// return new PrivateChannel('pvp-match.' . $this->matchId); return new PrivateChannel('pvp-match.' . $this->matchId);
// } }
//
// public function broadcastAs() public function broadcastAs()
// { {
// return 'match.ended'; return 'match.ended';
// } }
//} }

View File

@@ -1,35 +1,35 @@
<?php <?php
//
//namespace App\Events; namespace App\Events;
//
//use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\InteractsWithSockets;
//use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Broadcasting\PrivateChannel;
//use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
//use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Foundation\Events\Dispatchable;
//use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
//
//class MatchStarted implements ShouldBroadcastNow class MatchStarted implements ShouldBroadcastNow
//{ {
// use Dispatchable, InteractsWithSockets, SerializesModels; use Dispatchable, InteractsWithSockets, SerializesModels;
//
// public $matchData; public $matchData;
// public $ticketId; public $ticketId;
//
// public function __construct($matchData, $ticketId) public function __construct($matchData, $ticketId)
// { {
// $this->matchData = $matchData; $this->matchData = $matchData;
// $this->ticketId = $ticketId; $this->ticketId = $ticketId;
// } }
//
// public function broadcastOn() public function broadcastOn()
// { {
// // ارسال پیام به کانال پرایوت مختص تیکت کاربری که در صف انتظار بود // ارسال پیام به کانال پرایوت مختص تیکت کاربری که در صف انتظار بود
// return new PrivateChannel('matchmaking.' . $this->ticketId); return new PrivateChannel('matchmaking.' . $this->ticketId);
// } }
//
// public function broadcastAs() public function broadcastAs()
// { {
// // نام ایونتی که کاتلین باید به آن گوش دهد // نام ایونتی که کاتلین باید به آن گوش دهد
// return 'match.started'; return 'match.started';
// } }
//} }

View File

@@ -165,7 +165,7 @@ return [
*/ */
App\Providers\AppServiceProvider::class, App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class, App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class, App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class, App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class, App\Providers\RouteServiceProvider::class,
App\Providers\FortifyServiceProvider::class, App\Providers\FortifyServiceProvider::class,

View File

@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Broadcast;
| Broadcast Channels | Broadcast Channels
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| Here you may register all of the event broadcasting channels that your | Here you may register all of the Events broadcasting channels that your
| application supports. The given channel authorization callbacks are | application supports. The given channel authorization callbacks are
| used to check if an authenticated user can listen to the channel. | used to check if an authenticated user can listen to the channel.
| |
@@ -16,3 +16,22 @@ use Illuminate\Support\Facades\Broadcast;
Broadcast::channel('App.Models.User.{id}', function ($user, $id) { Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id; return (int) $user->id === (int) $id;
}); });
// کانال انتظار برای پیدا شدن حریف
Broadcast::channel('matchmaking.{ticketId}', function ($user, $ticketId) {
// در این مرحله، هر کاربری که لاگین باشد و تیکت خودش را داشته باشد اجازه دسترسی دارد
return true;
});
// کانال داخل بازی (برای ارسال پایان بازی یا تغییرات زنده)
Broadcast::channel('pvp-match.{matchId}', function ($user, $matchId) {
$match = \App\Models\PvpMatch::find($matchId);
if (!$match) {
return false;
}
// فقط اگر این کاربر یکی از دو بازیکنِ این مسابقه باشد، اجازه دسترسی به کانال را دارد
return $match->players()->where('user_id', $user->id)->exists();
});