# 🚀 Standalone Master GGR Control Server Documentation

This folder **`ggr_master_server/`** is a completely independent, standalone Master Control Server. You can host this folder on **ANY separate domain or server** (e.g., `https://ggr-master.yourdomain.com/`).

---

## 📁 Standalone Folder Structure

```text
ggr_master_server/
├── config.php                 # Master Server & Database credentials
├── install.php                # Database table installer for Standalone Server
├── DOCUMENTATION.md           # Deployment & Integration documentation
├── admin/                     # Super Master Admin Control Panel
│   ├── index.php              # Master Dashboard (Control ALL connected websites, Kill-Switches, Rates)
│   ├── login.php              # Master Admin Login (Default: admin / admin123)
│   └── logout.php             # Master Admin Logout
├── merchant/                  # Merchant Client Portal (For individual website owners)
│   ├── index.php              # Merchant Dashboard (View GGR Balance, Max Bet Capacity, API Keys)
│   ├── login.php              # Merchant Login (Demo: demo_merchant / demo123)
│   └── logout.php             # Merchant Logout
├── api/                       # Standalone Remote API Services
│   ├── check_ggr.php          # Pre-launch Check API (Verifies GGR balance over HTTP)
│   └── deduct_ggr.php         # Bet Deduction API (Deducts GGR on player bet/callback)
└── client_sdk/                # SDK package to upload to client casino websites
    ├── GgrClient.php          # Universal PHP Integration SDK
    └── example_integration.php# Working code example for client sites
```

---

## 🌐 1. How to Deploy on a Separate Server

1. **Upload Folder**:
   Upload the entire `ggr_master_server/` folder to your separate server / hosting domain (e.g. `https://ggr-master.yourdomain.com/`).
2. **Database Config**:
   Open `config.php` on your Master Server and set your database credentials:
   ```php
   define('GGR_MASTER_DB_HOST', 'localhost');
   define('GGR_MASTER_DB_USER', 'your_db_username');
   define('GGR_MASTER_DB_PASS', 'your_db_password');
   define('GGR_MASTER_DB_NAME', 'your_db_name');
   ```
3. **Run Installer**:
   Open installer in your web browser:
   ```text
   https://ggr-master.yourdomain.com/install.php
   ```

---

## 👑 2. Master Admin Portal (`/admin/login.php`)

- **URL**: `https://ggr-master.yourdomain.com/admin/login.php`
- **Default Credentials**: `admin` / `admin123`

### Features:
- **Register New Website**: Click "Register New Website", set Merchant Name, Username, Password, Initial GGR Points (e.g., ₹500), and Royalty Rate (e.g., 10%).
- **Instant GGR Recharge**: Add or set GGR points for any website with one click.
- **Set Royalty Rate %**: Change rate (5%, 10%, 15%) or switch between Turnover Mode (bet volume) and Net Win Mode.
- **Emergency Kill-Switch (Freeze / Unfreeze)**: Freeze any website instantly. If frozen, all game launches and bets will fail with `"Website Access Frozen by Master Admin"`.

---

## 🔌 3. How to Connect Any External Website to this Master Server

On the external casino website:

### 1. Copy `GgrClient.php`
Copy `client_sdk/GgrClient.php` to the external casino website.

### 2. Check GGR Before Game Launch (`GetGameUrl.php`):
```php
require_once __DIR__ . '/GgrClient.php';

// Point to your Standalone Master Server URL
$masterServerUrl = 'https://ggr-master.yourdomain.com';
$apiKey          = 'ggr_master_key_...'; // Get from Master Admin Panel

$ggrClient = new GgrClient($masterServerUrl, $apiKey);
$check = $ggrClient->checkGgr(10.00);

if (!$check['ok']) {
    die(json_encode([
        'code' => 403,
        'msg'  => 'Game Blocked: GGR Balance Low or Website Access Frozen.'
    ]));
}
```

### 3. Deduct GGR on Game Bet (`callback.php`):
```php
require_once __DIR__ . '/GgrClient.php';

$ggrClient = new GgrClient('https://ggr-master.yourdomain.com', 'ggr_master_key_...');
$deduct = $ggrClient->deductGgr($betAmount, $winAmount, $userId);

if (!$deduct['ok']) {
    die(json_encode([
        'code' => 403,
        'msg'  => 'Bet Failed: GGR balance low.'
    ]));
}
```
