Jump to content

Recommended Posts

Hi, first post here. It's the first time I've been so stuck really.

 

I'm using the library below to pull server data (players, time online etc) from a Steam game through the source API, however it will not work with more than one script or server at once. For example, if I copy the script into a new file and change the connection info, and include both in my HTML, only one will work. Any ideas on how to do it, or an example would be amazing. 

 

 

http://github.com/xPaw/PHP-Source-Query

<?php
namespace web2;

require __DIR__ . '/SourceQuery/bootstrap.php';

use xpaw\SourceQuery\SourceQuery;

// For the sake of this example
Header( 'Content-Type: text/html' );
Header( 'X-Content-Type-Options: nosniff' );

// Edit this ->
define( 'SQ_SERVER_ADDR', 'iphere' );
define( 'SQ_SERVER_PORT', 27015 );
define( 'SQ_TIMEOUT',     3 );
define( 'SQ_ENGINE',      SourceQuery::SOURCE );
// Edit this <-

$Query = new SourceQuery( );

try
{
    $Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE );

    $info = $Query->GetInfo();

    /*echo "<h1>Players: ".$info['Players' 'MaxPlayers']."</h1>";
    echo "<h1>Max Players: ".$info['MaxPlayers']."<h1>"; */

var_dump($info);
echo "<p>Hostname: ".$info['HostName']."</p>";  
$players = $info['Players']; $maxplayers = $info['MaxPlayers']; echo "<p>Players: ".$players . " / " . $maxplayers."</p>";
echo "<p>Map: ".$info['Map']."</p>";
echo "<p>Port: ".$info['GamePort']."</p>";
echo "<p>Version: ".$info['Version']."</p>";
}
catch( Exception $e )
{
    echo $e->getMessage( );
}
finally
{
    $Query->Disconnect( );
}
?>

That's for one connection. It will not work with more, although you can do it, I've seen it done. Thank you in advance!  :happy-04:

If you use this script with different values, so

 

include('scriptv1')

include('scriptv2')

 

Only the first will work but apparently using a foreach to house multiple connections into one script DOES work. I just don't know how to do that. Make more sense or am I being confusing?

If you use this script with different values, so

 

include('scriptv1')

include('scriptv2')

 

Only the first will work but apparently using a foreach to house multiple connections into one script DOES work. I just don't know how to do that. Make more sense or am I being confusing?

 

Edit: Here, the first script overrides the second (at the bottom of the page where it says rustoria) https://www.ketzen.com/games/cs-go

Simply throwing two scripts together will likely cause name collisions all over the place.

 

Use one script where you create multiple SourceQuery objects (assuming you want to connect to multiple servers). You can put the connection and processing code into a function, so that it's easy to repeat the actions.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.