File size: 2,006 Bytes
8a6569b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

// Inclua a SampQueryAPI (supondo que você já tenha a biblioteca no projeto)
require "SampQueryAPI.php";  // Altere o caminho conforme a sua estrutura

// Configurações do servidor SA:MP
$server_ip = '135.148.153.108'; // Substitua pelo IP do servidor
$server_port = 7777;      // Substitua pela porta do servidor

// Inicializa os arrays
$Config['mServersOnline'] = [];
$Config['mServersPing'] = [];
$Config['mServersDoubling'] = [];
$Config['mServersIsNew'] = [];

// Conecta ao servidor SA:MP usando a SampQueryAPI e busca dados
try {
    // Cria uma instância da API
    $query = new SampQueryAPI($server_ip, $server_port);

    // Tenta conectar ao servidor
    if ($query->isOnline()) {
        // Obtém informações do servidor
        $info = $query->getInfo();
        
        if ($info !== false) {
            // Preenche os arrays com as informações obtidas
            $Config['mServersOnline'][] = $info['players'];
            $Config['mServersPing'][] = $info['ping'] ?? 128;
            $Config['mServersDoubling'][] = 1;  // Valor exemplo
            $Config['mServersIsNew'][] = 1;     // Valor exemplo

            // Formatar e imprimir como JSON no formato desejado
            $json_output = [
                "servers" => [
                    [
                        "players1" => $Config['mServersOnline'][0],
                        "ping" => $Config['mServersPing'][0],
                        "doubling" => $Config['mServersDoubling'][0],
                        "new" => $Config['mServersIsNew'][0]
                    ]
                ]
            ];

            // Exibe o JSON formatado
            echo json_encode($json_output);
        } else {
            echo "Erro: Não foi possível obter as informações do servidor.";
        }
    } else {
        echo "Erro: Não foi possível conectar ao servidor SA:MP.";
    }
} catch (Exception $e) {
    echo "Erro: " . $e->getMessage();
}
?>