• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

OTClient Player Online Background

Forkz

Intermediate OT User
Joined
Jun 29, 2020
Messages
495
Solutions
15
Reaction score
121
Hi otlander,

I want to use the playeronline api in the otclient background, but I made the settings and it still has 0 online players.

Which link do I have to use in "curl_setopt($ch, CURLOPT_URL"?


LUA:
<?php
$online_otservlist = 0;
try {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://otservlist.org/ots/1659719");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Retorna os dados em vez de exibir
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Ignora verificação SSL
    curl_setopt($ch, CURLOPT_ENCODING, "");
    $site = curl_exec($ch);
    curl_close($ch);
   
    // Pega a quantidade de jogadores online
    if (preg_match('/There are <strong>([0-9]+)<\/strong>/', $site, $matches)) {
        $online_otservlist = (int)$matches[1];
    }
} catch(Exception $e) {}

$online_discord = 0;
try {
    $online_discord = json_decode(file_get_contents("-"))->presence_count;
} catch(Exception $e) {}

$response = array(
    "online" => "$online_otservlist Players online",
    "discord_online" => $online_discord,
    "discord_link" => "https://discord.com/invite/y49gpt5s9w"
);

echo json_encode($response);
?>
 
you need to propably change that
if (preg_match('/There are <strong>([0-9]+)<\/strong>/', $site, $matches)) {
to if (preg_match('/<span>Players:\s*<strong>(\d+)\s*\/\s*\d+<\/strong><\/span>/', $site, $matches)) {
 
Last edited:
you need to propably change that
if (preg_match('/There are <strong>([0-9]+)<\/strong>/', $site, $matches)) {
to if (preg_match('/<span>Players:\s*<strong>(\d+)\s*\/\s*\d+<\/strong><\/span>/', $site, $matches)) {
It's not working, it seems there is some blocking by the otserv list, because it can't "get" the data.
 
(...)
it seems there is some blocking by the otserv list,
otservlist uses CloudFlare. You cannot access it without web browser that is able to show captcha (or skip it automatically, but it still must be able to show it and process JavaScript code to check if it can skip it). With current otservlist setting you cannot access it with curl library.
 
Back
Top