DEVELOPER RESOURCES
Query API Entegrasyonu
Oyun sunucularınızı web sitenize entegre etmek için ihtiyacınız olan tüm kod yapıları aşağıdadır. API güvenliği için Referer (Whitelist) kontrolü zorunludur.
Temel PHP Entegrasyonu
Tek bir sunucuyu sorgulamak için en basit yöntem. cURL kullanarak JSON verisini çeker.
simple-query.php
<?php /** * Tickrate Query API - Basit Örnek */ $apiKey = "API_KEY_BURAYA"; $serverIp = "210.100.185.2"; $serverPort = "27015"; $game = "cs16"; // cs16, csgo, rust, fivem, ts3 // 1. Endpoint İnşası $params = http_build_query([ 'ip' => $serverIp, 'port' => $serverPort, 'game' => $game, 'apiKey' => $apiKey ]); $apiUrl = "https://query.tickrate.net/api/Query?" . $params; // 2. Curl Yapılandırması (Whitelist İçin Referer Şart!) $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $apiUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_REFERER, "https://siteniz.com"); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $data = json_decode($response, true); // 3. Sonuç Kontrolü if($httpCode == 200 && isset($data['status']) && $data['status'] == 'online') { echo "<strong>Sunucu:</strong> " . htmlspecialchars($data['name']) . "<br>"; echo "<strong>Oyuncular:</strong> " . $data['players'] . " / " . $data['maxPlayers']; } else { echo "Hata: " . ($data['error'] ?? 'Bağlantı sağlanamadı.'); } ?>
TickrateQuery.php Class
Büyük projeler için geliştirilmiş, önbellekleme (caching), oyun türü algılama ve RCON desteği sunan gelişmiş sınıf.
Bu kodu TickrateQuery.php olarak kaydedin.
class/TickrateQuery.php
<?php /** * Tickrate.net API - Optimized Class * Features: Smart Caching, RCON, Game Mapping */ class TickrateQuery { private $apiKey; private $apiUrl = "https://query.tickrate.net/api/Query"; private $ip; private $port; private $game = "cs16"; private $customGameType = null; private $memoryCache = null; private $rconPassword = ""; private $useCache = true; private $cacheTime = 30; // 30 Saniye Cache private $cacheFile = null; public function __construct($apiKey) { $this->apiKey = $apiKey; } public function Connect($ip, $port, $engine = 1) { $this->ip = $ip; $this->port = (int)$port; $this->game = ($engine == 1) ? "csgo" : "cs16"; // Cache Dizini Ayarı $cacheDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . "querycache"; if (!is_dir($cacheDir)) { @mkdir($cacheDir, 0777, true); } $this->cacheFile = $cacheDir . DIRECTORY_SEPARATOR . md5($this->ip . $this->port) . ".json"; } public function SetRconPassword($password) { $this->rconPassword = $password; } private function FetchData() { // 1. Memory Cache if ($this->memoryCache !== null) return $this->memoryCache; // 2. File Cache if ($this->useCache && file_exists($this->cacheFile)) { if ((time() - filemtime($this->cacheFile)) < $this->cacheTime) { $json = json_decode(file_get_contents($this->cacheFile), true); if ($json) { $this->memoryCache = $json; return $json; } } } // 3. API Request $ch = curl_init(); $url = $this->apiUrl . "?ip=" . $this->ip . "&port=" . $this->port . "&game=" . $this->game . "&apiKey=" . $this->apiKey; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_REFERER, "https://" . $_SERVER['HTTP_HOST']); // Whitelist curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_USERAGENT, "TickrateClient/3.0"); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $data = ($httpCode == 200) ? json_decode($response, true) : false; if ($data && isset($data['status'])) { if ($this->useCache) @file_put_contents($this->cacheFile, json_encode($data)); $this->memoryCache = $data; } return $this->memoryCache; } public function GetInfo() { $data = $this->FetchData(); if (!$data || $data['status'] !== 'online') return false; return [ 'HostName' => $data['name'], 'Map' => $data['map'], 'Players' => $data['players'], 'MaxPlayers' => $data['maxPlayers'] ]; } public function Rcon($command) { $postData = json_encode([ "ip" => $this->ip, "port" => $this->port, "password" => $this->rconPassword, "command" => $command, "apiKey" => $this->apiKey ]); $ch = curl_init($this->apiUrl . "/rcon"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_setopt($ch, CURLOPT_REFERER, "https://" . $_SERVER['HTTP_HOST']); $res = curl_exec($ch); curl_close($ch); return json_decode($res, true)['output'] ?? "Hata"; } } ?>
Nasıl Kullanılır?
require 'TickrateQuery.php'; $q = new TickrateQuery("API_KEY"); $q->Connect("210.100.185.2", 27015); $info = $q->GetInfo(); echo "Sunucu: " . $info['HostName'];
Görsel Sunucu Listesi (LGSL Tarzı)
Sunucularınızı şık bir tablo halinde listelemek ve "İncele" butonu ile detayları göstermek için bu yapıyı kullanabilirsiniz. (HTML kısmı Tailwind CSS kullanır).
server-list.php (Özet)
<!-- CSS Kısmı (Tailwind CDN) -->
<script src="https://cdn.tailwindcss.com"></script>
<div class="bg-[#1b2838] p-4 text-[#b8bcbf] font-sans">
<div class="max-w-5xl mx-auto bg-[#1b1e24] border border-[#353a42]">
<!-- Başlık -->
<div class="bg-[#171a21] p-4 border-b border-[#353a42] flex justify-between">
<h2 class="text-white font-bold">CS 1.6 Server Listesi</h2>
<span class="text-xs text-[#66c0f4]">⟳ Otomatik Güncellenir</span>
</div>
<!-- Tablo Başlıkları -->
<div class="grid grid-cols-5 gap-4 px-6 py-2 bg-[#242830] text-[11px] font-bold text-[#6b747e] uppercase">
<div>Durum</div> <div>Sunucu Adı</div> <div>Harita</div> <div>IP</div> <div class="text-right">Oyuncular</div>
</div>
<!-- Sunucu Döngüsü (PHP) -->
<?php foreach ($servers as $server): ?>
<div class="grid grid-cols-5 gap-4 px-6 py-3 border-b border-[#353a42] hover:bg-[#3d4450] transition items-center text-sm">
<!-- Durum Badge -->
<div>
<span class="bg-[#1e352f] text-[#4caf50] px-2 py-0.5 rounded text-[10px] font-bold">AKTİF</span>
</div>
<!-- İsim -->
<div class="text-[#b8bcbf] font-medium truncate"><?= $server['name'] ?></div>
<!-- Harita -->
<div class="text-[#8a929a]"><?= $server['map'] ?></div>
<!-- IP -->
<div class="text-[#8a929a] text-xs font-mono"><?= $server['ip'] ?></div>
<!-- Oyuncular -->
<div class="text-right text-white">
<?= $server['players'] ?> / <?= $server['max'] ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>