Appearance

Język

Metin2 P-Server API

Interface for server owners: check vote status and hand out rewards automatically.

Checking a vote

To check whether a user has already voted, call the following link:

https://www.metin2pserver.to/api/{SERVERNAME}/{USERID}

Explanation:

  • {SERVERNAME}: The name of the server the user voted for.
  • {USERID}: The ID of the user account in the server database.

The API returns true or false to indicate whether the user has already voted and is therefore entitled to a reward.

Casting a vote

To cast a vote, users have to use the following link:

https://www.metin2pserver.to/vote-{SERVERNAME}.htm/{USERID}

Explanation:

  • {SERVERNAME}: The name of the server as it appears in the toplist.
  • {USERID}: The ID of the user account in the server database that voted.

PHP example code

// API-URL und Parameter definieren $serverName = 'PserverName'; $userId = 12345; $apiUrl = 'https://www.metin2pserver.to/api/' . $serverName . '/' . $userId; // cURL-Session starten $ch = curl_init(); // cURL-Optionen setzen curl_setopt($ch, CURLOPT_URL, $apiUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Antwort zurückgeben als String curl_setopt($ch, CURLOPT_TIMEOUT, 30); // Timeout auf 30 Sekunden setzen // API-Anfrage ausführen $response = curl_exec($ch); // cURL-Fehler überprüfen if (curl_errno($ch)) { echo 'cURL Error: ' . curl_error($ch); } else { // Antwort dekodieren $data = json_decode($response, true); // Überprüfen, ob der Nutzer bereits abgestimmt hat if ($data['status'] === true) { echo 'Abstimmung erfolgreich durchgeführt!'; } else { echo 'Es gab ein Problem mit der Abstimmung.'; } } // cURL schließen curl_close($ch);

Explanation of the example code:

  • $serverName: The name of the server queried in the URL.
  • $userId: The ID of the user whose vote status is checked.
  • $apiUrl: The full API URL, built from the server name and user ID parameters.
  • cURL: A PHP tool for sending HTTP requests and reaching the API.
  • json_decode($response, true): The API response arrives as JSON and is turned into a PHP array.
  • if ($data['status'] === true): Checks whether the user has already voted.