# PES League Platform

Platform kompetitif untuk komunitas **PES 6 PS2** — matchmaking ELO, Discord rooms, ranking, dan turnamen.

---

## Status: ✅ MVP Selesai

| Fitur | Status |
|-------|--------|
| Login Discord OAuth | ✅ |
| Dashboard + ELO Chart | ✅ |
| Matchmaking (±100 ELO, expand ke ±200) | ✅ |
| Match Room + Submit Score | ✅ |
| Dispute Resolution (Admin) | ✅ |
| ELO System (K=32) | ✅ |
| Leaderboard + Podium | ✅ |
| Profil Pemain + Statistik | ✅ |
| Riwayat Match | ✅ |
| Tournament (CRUD + Registrasi) | ✅ |
| Admin Panel (Players/Matches/Tournaments) | ✅ |
| REST API (untuk Desktop Launcher) | ✅ |
| ELO History tracking | ✅ |
| Permission & Role system | ✅ |

---

## Tech Stack

| Layer | Teknologi |
|-------|-----------|
| Backend | Laravel 12, PHP 8.2 |
| Frontend | Bootstrap 5, Tabler Icons, Chart.js |
| Auth | Discord OAuth (Socialite) |
| Database | MySQL (kompatibel PostgreSQL) |
| API Auth | Laravel Sanctum |
| Permissions | Spatie Laravel Permission |
| Realtime (opsional) | Laravel Reverb |

---

## Quick Start

### 1. Copy ke XAMPP htdocs

```
robocopy pes-league C:\xampp\htdocs\pes-league /E /XD node_modules vendor
```

### 2. Install dependencies

```bash
cd C:\xampp\htdocs\pes-league
composer install
```

### 3. Setup env

```bash
copy .env.example .env
php artisan key:generate
```

Edit `.env`:
```env
DB_CONNECTION=mysql
DB_DATABASE=pes_league
DB_USERNAME=root
DB_PASSWORD=

DISCORD_CLIENT_ID=xxx
DISCORD_CLIENT_SECRET=xxx
DISCORD_REDIRECT_URI=http://localhost/pes-league/public/auth/discord/callback
```

### 4. Database

```bash
mysql -u root -e "CREATE DATABASE pes_league;"
php artisan migrate
php artisan db:seed
php artisan db:seed --class=PermissionSeeder
```

### 5. Buka browser

```
http://localhost/pes-league/public
```

---

## Halaman

| URL | Akses | Deskripsi |
|-----|-------|-----------|
| `/` | Public | Landing page |
| `/login` | Public | Login via Discord |
| `/dashboard` | Auth | Dashboard + ELO chart |
| `/leaderboard` | Public | Ranking global |
| `/play` | Auth | Matchmaking |
| `/profile` | Auth | Profil sendiri |
| `/player/{id}` | Public | Profil pemain lain |
| `/match/{id}` | Auth | Match room |
| `/match/history` | Auth | Riwayat match |
| `/tournament` | Auth | Daftar turnamen |
| `/admin` | Admin | Panel admin |

---

## ELO System

- **Default:** 1200
- **K-factor:** 32
- **Formula:** `newElo = oldElo + 32 × (actual - expected)`
- `expected = 1 / (1 + 10^((opponentElo - myElo) / 400))`

### Divisi

| Divisi | Range ELO | Badge |
|--------|-----------|-------|
| Bronze | 0–999 | 🥉 |
| Silver | 1000–1299 | 🥈 |
| Gold | 1300–1599 | 🥇 |
| Platinum | 1600–1899 | 🔵 |
| Diamond | 1900–2199 | 🔷 |
| Master | 2200–2499 | 💎 |
| Legend | 2500+ | 👑 |

---

## Assign Admin

```bash
php artisan tinker
>>> App\Models\User::where('username','YourName')->first()->assignRole('admin');
```

---

## Matchmaking Scheduler

Jalankan setiap menit:
```bash
php artisan matchmaking:tick
```

Atau via Windows Task Scheduler — lihat `SETUP.md`.

---

## API untuk Desktop Launcher

```http
POST /api/login
{ "discord_token": "user_access_token" }
→ { "token": "sanctum_token", "user": {...} }

GET  /api/profile          # Bearer token
GET  /api/leaderboard      # Public
GET  /api/history          # Bearer token
POST /api/matchmaking/join # Bearer token
GET  /api/matchmaking/status
POST /api/submit-result    # Bearer token
GET  /api/season           # Public
GET  /api/tournament       # Public
```

---

## Lisensi

MIT — Platform ini tidak mendistribusikan game, BIOS PS2, atau emulator.
