Jump to content

[PHP] Query System


Recommended Posts

Yes...

Here's my code :

require_once "GameQ/GameQ.php"; 
    $query_api = new GameQ; 
    $server["mtasa"] = array("mtasa","x.x.x.x","22003"); // Some IP I took on game-monitor 
    $query_api->addServers($server); 
    try { 
        $datas = $query_api->requestData(); 
    } 
    catch (GameQ_Exception $e) { 
        echo $e; 
        exit(); 
    } 
    var_dump($datas); 
    exit(); 

And return value :

array(1) { ["mtasa"]=> array(5) { ["gq_online"]=> bool(false) ["gq_address"]=> string(13) "xx.xx.xx.xx" ["gq_port"]=> string(5) "22003" ["gq_prot"]=> string(3) "ase" ["gq_type"]=> string(5) "mtasa" } }
Link to comment
  • Scripting Moderators

require_once ('GameQ/GameQ.php'); //class 
  
$server['mtasa'] = array ('mtasa', '192.168.1.2', 22003+123); //ip & port 
$query = new GameQ; 
$query -> addServers ($server); 
$data = $query->requestData(); 
  
foreach ($server AS $server_id => $values) { 
    $info = $data[$server_id]; 
    if (!$info["servername"]) { 
        echo 'Server offline'; 
    } else { 
        echo "Server name: "; 
        echo $info["servername"]; 
        echo '<br/>'; 
        echo "Gamemode: "; 
        echo $info["gametype"]; 
        echo '<br/>'; 
        echo "Map: "; 
        echo $info["map"]; 
        echo '<br/>'; 
        echo "Players: "; 
        echo $info["num_players"] ."/". $info["max_players"]; 
        echo '<br/>'; 
        if ($info["password"] == '0') { 
            $pw = "No"; 
        } else { 
            $pw = "Yes"; 
        } 
        echo "Password: "; 
        echo $pw; 
        echo '<br/><br/>'; 
    } 
} 

:P

Link to comment
  • Scripting Moderators

One more thing, port+123 is how MTA was configured to communicate with both ASE and game-monitor servers for simplicity. It is not some magic formula.

Link to comment

I'm sorry for hi-jacking the topic but I seem to have a problem with my stats.php

<?php 
require_once ('GameQ/GameQ.php'); //class 
  
$server['mtasa'] = array ('mtasa', 'serverIP', 22003+123); //ip & port 
$query = new GameQ; 
$query -> addServers ($server); 
$data = $query->requestData(); 
  
foreach ($server AS $server_id => $values) { 
    $info = $data[$server_id]; 
    if (!$info["servername"]) { 
        echo 'Server offline'; 
    } else { 
        echo "Server name: "; 
        echo $info["servername"]; 
        echo '<br/>'; 
        echo "Gamemode: "; 
        echo $info["gametype"]; 
        echo '<br/>'; 
        echo "Map: "; 
        echo $info["map"]; 
        echo '<br/>'; 
        echo "Players: "; 
        echo $info["num_players"] ."/". $info["max_players"]; 
        echo '<br/>'; 
        if ($info["password"] == '0') { 
            $pw = "No"; 
        } else { 
            $pw = "Yes"; 
        } 
        echo "Password: "; 
        echo $pw; 
        echo '<br/><br/>'; 
    } 
?> 

result:

Parse error: syntax error, unexpected $end in /home/a6564823/public_html/php/stats.php on line 35
Link to comment
  • Scripting Moderators
result:
Parse error: syntax error, unexpected $end in /home/a6564823/public_html/php/stats.php on line 35

add '}' on line 35 :D

Link to comment
  • 4 weeks later...

I know this is a bit outdated already but I just want to say something.

Here:

        if ($info["password"] == '0') { 
            $pw = "No"; 
        } else { 
            $pw = "Yes"; 
        } 

You can simplify this to:

echo $info['password'] == '0' ? 'No' : 'Yes'; 

Isn't it easier?

Link to comment
  • 11 months later...

<?php 
require_once ('GameQ/GameQ.php'); //class 
  
$server['mtasa'] = array ('mtasa', 'serverIP', 22003+123); //ip & port 
$query = new GameQ; 
$query -> addServers ($server); 
$data = $query->requestData(); 
  
foreach ($server AS $server_id => $values) { 
    $info = $data[$server_id]; 
    if (!$info["servername"]) { 
        echo 'Server offline'; 
    } else { 
        echo "Server name: "; 
        echo $info["servername"]; 
        echo '<br/>'; 
        echo "Gamemode: "; 
        echo $info["gametype"]; 
        echo '<br/>'; 
        echo "Map: "; 
        echo $info["map"]; 
        echo '<br/>'; 
        echo "Players: "; 
        echo $info["num_players"] ."/". $info["max_players"]; 
        echo '<br/>'; 
        if ($info["password"] == '0') { 
            $pw = "No"; 
        } else { 
            $pw = "Yes"; 
        } 
        echo "Password: "; 
        echo $pw; 
        echo '<br/><br/>'; 
    } 
    } 
?> 

I want to here also shows the players who are online

Link to comment
  • 1 month later...

On SMF I am trying to use the GameQuery but I only get the 'Server offline' instead of the data.

  
<?php 
    require_once ('GameQ/GameQ.php'); //class 
      
    $server['mtasa'] = array ('mtasa', '24.131.58.234', 22003+123); //ip & port 
    $query = new GameQ; 
    $query -> addServers ($server); 
    $data = $query->requestData(); 
      
    foreach ($server AS $server_id => $values) { 
        $info = $data[$server_id]; 
        if (!$info["servername"]) { 
            echo 'Server Offline'; 
        } else { 
            echo "Server name: "; 
            echo $info["servername"]; 
            echo '<br/>'; 
            echo "Players: "; 
            echo $info["num_players"] ."/". $info["max_players"]; 
            echo '<br/>'; 
            if ($info["password"] == '0') { 
                $pw = "No"; 
            } else { 
                $pw = "Yes"; 
            } 
            echo "Password: "; 
            echo $pw; 
            echo '<br/><br/>'; 
        } 
    } 
?> 
  

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...