RhysBennett Posted February 10, 2017 Share Posted February 10, 2017 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! Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted February 10, 2017 Share Posted February 10, 2017 What does “not work” mean? Be more specific. Quote Link to comment Share on other sites More sharing options...
RhysBennett Posted February 10, 2017 Author Share Posted February 10, 2017 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? Quote Link to comment Share on other sites More sharing options...
RhysBennett Posted February 10, 2017 Author Share Posted February 10, 2017 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 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted February 10, 2017 Share Posted February 10, 2017 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. Quote Link to comment Share on other sites More sharing options...
RhysBennett Posted February 11, 2017 Author Share Posted February 11, 2017 Could you give me an example? I wasn't throwing them both in the same script, I was calling them on the webpage as two different scripts as two different includes. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.