Austinb / GameQ

A PHP Gameserver Status Query Library
https://austinb.github.io/GameQ/
GNU Lesser General Public License v3.0
402 stars 136 forks source link

MTA trouble with response #346

Closed andrey-shostik closed 7 years ago

andrey-shostik commented 7 years ago

HI i have script

<?php
require_once 'GameQ/Autoloader.php';

$servers = [
    [
        'type' => 'mta',
        'host' => '5.254.104.178:22126',
    ],
];

$GameQ = new \GameQ\GameQ(); // or $GameQ = \GameQ\GameQ::factory();
$GameQ->addServers($servers);
$GameQ->setOption('timeout', 5); // seconds

$info = $GameQ->process();
print_r($results);

This script outputs

Array
(
    [5.254.104.178:22126] => Array
        (
            [gq_address] => 5.254.104.178
            [gq_dedicated] =>
            [gq_gametype] =>
            [gq_hostname] =>
            [gq_joinlink] => mtasa://5.254.104.178:22126/
            [gq_mapname] =>
            [gq_maxplayers] =>
            [gq_mod] =>
            [gq_name] => Multi Theft Auto
            [gq_numplayers] =>
            [gq_online] =>
            [gq_password] =>
            [gq_port_client] => 22126
            [gq_port_query] => 22249
            [gq_protocol] => ase
            [gq_transport] => udp
            [gq_type] => mta
            [players] => Array
                (
                )
            [teams] => Array
                (
                )
        )
)

if i move on http://www.mta-resource.ru/monitoring/api/ip/5.254.104.178/port/22126 then i get full response, i need get response via GameQ. I need have string of [gq_online] . '/' . [gq_maxplayers], where all info ? what am doing wrong, help me please.

Austinb commented 7 years ago

That response shows the server as offline so most of the information will be empty. Have you checked to make sure the host you are using allows outgoing calls to other servers? Many hosting providers disable this ability. Please try with the following option and let me know if you see an error:

$GameQ->setOption('debug', true);

I ran the following code:

$gq = \GameQ\GameQ::factory();
$gq->addServer([
    'type' => 'mta',
    'host' => '5.254.104.178:22126'
]);
$results = $gq->process(); // Returns an array of results
print_r($results);

and got this response (partial paste):

Array
(
    [5.254.104.178:22126] => Array
        (
            [dedicated] => 1
            [gamename] => mta
            [gametype] => roleplay
            [gq_address] => 5.254.104.178
            [gq_dedicated] => 1
            [gq_gametype] => roleplay
            [gq_hostname] => Fotpix | BETA | От создателей SRP
            [gq_joinlink] => mtasa://5.254.104.178:22126/
            [gq_mapname] => None
            [gq_maxplayers] => 4096
            [gq_mod] =>
            [gq_name] => Multi Theft Auto
            [gq_numplayers] => 46
            [gq_online] => 1
            [gq_password] => 0
            [gq_port_client] => 22126
            [gq_port_query] => 22249
            [gq_protocol] => ase
            [gq_transport] => udp
            [gq_type] => mta
            [map] => None
            [max_players] => 4096
            [num_players] => 46
            [password] => 0
            [players] => Array
                (
                    [0] => Array
                        (
                            [name] => Sanya_Belov
                            [team] =>
                            [skin] =>
                            [score] =>
                            [ping] => 72
                            [time] =>
                            [gq_name] => Sanya_Belov
                            [gq_score] =>
                            [gq_team] =>
                            [gq_ping] => 72
                            [gq_time] =>
                        )

                    [1] => Array
                        (
                            [name] => Franklin_Evans
                            [team] =>
                            [skin] =>
                            [score] =>
                            [ping] => 69
                            [time] =>
                            [gq_name] => Franklin_Evans
                            [gq_score] =>
                            [gq_team] =>
                            [gq_ping] => 69
                            [gq_time] =>
                        )
                        ...
                  )
          )
)