Hi Guys,
I need help with server status for rust server. I want php server status which will write hostname, ip, players/max_players and world settings (size and seed). But I only found script for players who not working.
CODE:
source: GitHub - xPaw/PHP-Source-Query: PHP library to query servers that implement Source Engine Query protocol
Sorry for my englishCode:<?php header("Refresh:60"); require __DIR__ . 'SourceQuery/bootstrap.php'; use xPaw\SourceQuery\SourceQuery; define( 'SQ_SERVER_ADDR', 'rust.royalportal.eu' ); define( 'SQ_SERVER_PORT', 28016 ); define( 'SQ_TIMEOUT', 3 ); define( 'SQ_ENGINE', SourceQuery::SOURCE ); $Query = new SourceQuery( ); try{ $Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE ); $info = $Query->GetInfo( ); } catch( Exception $e ){ echo $e->getMessage( ); } finally{ $Query->Disconnect( ); } $cur_players = $info["Players"]; $max_players = $info["MaxPlayers"]; ?> <table> <tr> <td>Hra</td> <td>Názov servera</td> <td>IP Adresa</td> <td>Sloty</td> <td>Mapa</td> <td>VIP</td> </tr> <tr> <td><img src="img/ts3.png"></td> <td>RoyalPortal.eu | Teamspeak3</td> <td><code>ts.royalportal.eu</code></td> <td>50</td> <td>- - -</td> <td><a href="http://vip.royalportal.eu/ts"><span class="vip">VIP</span></a></td> </tr> <tr> <td><img src="img/rust.png"></td> <td>RoyalPortal.eu | Vanilla Wiped 28.7 15:10</td> <td><code>rust.royalportal.eu</code></td> <td><?php printf('%u/%u', $cur_players, $max_players); ?></td> <td>3000/9578</td> <td><a href="http://vip.royalportal.eu/rust/vanilla"><span class="donate">DONATE</span></a></td> </tr> </table>
Getting Rust server status in PHP?
Discussion in 'Rust Development' started by GamerSK, Jul 29, 2017.
-
The actual version of xPaw is outdated
-
Do you have some new script for server status ?
-
I'll try to upload asap
I'm not at home right now -
GitHub - sami37/SourceQuery
How to use:
First, you need RustIO dll if you want ranking and connected players.
Base code exemple :
Code:require __DIR__ . '/../api/SourceQuery/bootstrap.php'; use xPaw\SourceQuery\SourceQuery;define( 'SQ_SERVER_ADDR', 'YOUR_IP_HERE' ); define( 'SQ_SERVER_PORT', YOUR_SERVER_PORT); // udp define( 'SQ_RCON_PORT', YOUR_RCON_PORT); // tcp - only for SourceQuery::SOURCE define( 'SQ_TIMEOUT', 2 ); define( 'SQ_ENGINE', SourceQuery::SOURCE );$Rules = 'Your Server description\nAnd more detail here';$Query = new SourceQuery( ); try { $Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_RCON_PORT, SQ_TIMEOUT, SQ_ENGINE ); $Informations = $Query->GetInfo( ); require_once __DIR__ . '/../api/RustIO/apikey.php'; $connected = $Query->GetConnected($Rustapikey); $Query->Disconnect( ); } catch( Exception $e ) { echo $e->getMessage( ); }echo (($connected) ? count(json_decode($connected)) : 0).'/'.(($Informations['MaxPlayers']) ? $Informations['MaxPlayers'] : 0);
Code:<div class="slidetit" style="left:0px;width:100%;"> <center> <div class="slidetitle" style="float:none;"> <h4><?php echo (isset($Informations['HostName']) ? $Informations['HostName'] : 'RustEvolution');?></h4> </div> <h4><?php echo (isset($Informations['Map']) ? $Informations['Map'] : 0).' - '.(isset($Informations['Players']) ? $Informations['Players'] : 0).'/'.(isset($Informations['MaxPlayers']) ? $Informations['MaxPlayers'] : 0);?></h4> </center> <div class="serv_popup_content"> <p> <p> <?php $rule = str_replace('\n', '<br />', $Rules); echo $rule; ?> </p> </p> </div> <center> <input id="js-copytextarea" class="aip-address" value="connect IP:PORT"/> </center> </div>
Don't miss to configure your SourceQuery.php file -
Sorry but it not works for me. Google Chrome write me HTTP ERROR 500
Main
Code:<?php header("Refresh:60"); require __DIR__ . '/SourceQuery/bootstrap.php'; use xPaw\SourceQuery\SourceQuery; define( 'SQ_SERVER_ADDR', 'rust.royalportal.eu' ); define( 'SQ_SERVER_PORT', 28015); // udp define( 'SQ_RCON_PORT', 28016); // tcp - only for SourceQuery::SOURCE define( 'SQ_TIMEOUT', 2 ); define( 'SQ_ENGINE', SourceQuery::SOURCE ); $Query = new SourceQuery( ); try{ $Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_RCON_PORT, SQ_TIMEOUT, SQ_ENGINE ); $Informations = $Query->GetInfo( ); $connected = $Query->GetConnected($Rustapikey); $Query->Disconnect( ); } catch( Exception $e ){ echo $e->getMessage( ); } ?>
Code:const SERVER_API_ADDRESS = 'rust.royalportal.eu'; const SERVER_API_PORT = '28015';
-
Code:ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
-
I musted install XAMPP because webhosting not shows errors.
Code:Fatal error: Uncaught Error: Class 'DB' not found in C:\xampp\htdocs\SourceQuery\SourceQuery.php:114 Stack trace: #0 C:\xampp\htdocs\index.php(13): xPaw\SourceQuery\SourceQuery->__construct() #1 {main} thrown in C:\xampp\htdocs\SourceQuery\SourceQuery.php on line 114
-
-
I downloaded newest build from github but it still not working. What now ?
-
what error?
you have to correct path -
Where i need add mysql folder ?
-
Well root, but your SourceQuery api should be in the api folder to, so it's better for you to check path
-
I have all in root folder index.php and SourceQuery which I downloaded from github
-
i'll update github
[DOUBLEPOST=1501427460][/DOUBLEPOST]Code:<?php header("Refresh:60"); require __DIR__ . '/SourceQuery/bootstrap.php'; include_once(__DIR__ ."/api/mysql/Db.class.php"); use xPaw\SourceQuery\SourceQuery; define( 'SQ_SERVER_ADDR', 'rust.royalportal.eu' ); define( 'SQ_SERVER_PORT', 28015); // udp define( 'SQ_RCON_PORT', 28016); // tcp - only for SourceQuery::SOURCE define( 'SQ_TIMEOUT', 2 ); define( 'SQ_ENGINE', SourceQuery::SOURCE ); $Query = new SourceQuery( ); try{ $Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_RCON_PORT, SQ_TIMEOUT, SQ_ENGINE ); $Informations = $Query->GetInfo( ); $connected = $Query->GetConnected($Rustapikey); $Query->Disconnect( ); } catch( Exception $e ){ echo $e->getMessage( ); } ?>
-
Here is another error
Code:Unhandled Exception. SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. You can find the error back in the log. Fatal error: Uncaught Error: Call to a member function Close() on null in C:\xampp\htdocs\SourceQuery\SourceQuery.php:178 Stack trace: #0 C:\xampp\htdocs\SourceQuery\SourceQuery.php(120): xPaw\SourceQuery\SourceQuery->Disconnect() #1 [internal function]: xPaw\SourceQuery\SourceQuery->__destruct() #2 {main} thrown in C:\xampp\htdocs\SourceQuery\SourceQuery.php on line 178
-
-
Sorry but i have another error: Failed to read any data from socket
-
-
@GamerSK did you solved your problem?