<?php
/**
 * Developer: Molla Samser
 * Organization: RSK World
 * Website: https://rskworld.in
 * Email: help@rskworld.in, support@rskworld.in
 * Phone/WhatsApp: +91 93305 39277
 * Address: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147
 * Copyright © 2026 RSK World. All rights reserved.
 */
?>
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(204); exit; }
header('Content-Type: application/json');
header('Cache-Control: no-store');
try {
	$raw = file_get_contents('php://input');
	$input = json_decode($raw, true);
	if (!is_array($input)) { $input = $_POST; }
	$key = isset($input['key']) ? trim($input['key']) : '';
	$gameId = isset($input['gameId']) ? trim($input['gameId']) : '';
	if ($key === '' || $gameId === '') { echo json_encode(['valid' => false, 'message' => 'Missing key or gameId.']); exit; }
	$remoteUrl = getenv('LICENSE_VERIFY_URL');
	if (!$remoteUrl) { $remoteUrl = 'https://rskworld.in/games/html5-games/verify-license.php'; }
	$payload = json_encode(['key' => $key, 'gameId' => $gameId]);
	$ch = curl_init($remoteUrl);
	curl_setopt_array($ch, [
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_POST => true,
		CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Accept: application/json' ],
		CURLOPT_POSTFIELDS => $payload,
		CURLOPT_TIMEOUT => 10,
		CURLOPT_FOLLOWLOCATION => true,
	]);
	$response = curl_exec($ch);
	$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	$err = curl_error($ch);
	curl_close($ch);
	if ($response === false || $httpCode < 200 || $httpCode >= 300) { echo json_encode(['valid' => false, 'message' => 'Proxy error: ' . ($err ?: ('HTTP ' . $httpCode))]); exit; }
	$data = json_decode($response, true);
	if (!is_array($data)) { echo json_encode(['valid' => false, 'message' => 'Proxy error: invalid JSON from server']); exit; }
	echo json_encode($data); exit;
} catch (Exception $e) { echo json_encode(['valid' => false, 'message' => 'Proxy exception.']); exit; }
?>

