All pastes #747859 Raw Edit

Stuff

public text v1 · immutable
·published 2007-10-24 12:36 UTC
rendered paste body
<?php
/*********************************************
 *
 * SA-MP Query Server Version 0.2
 *
 * This file is an example on how to use the sampQuery tool
 * to get information about your server in PHP. There are a
 * couple of things to keep in mind. First off; always
 * run this tool inside of a try-/catch statement, because
 * the class will throw errors if something goes wrong.
 *
 * Secondly, errors about failing connections might come
 * later then the actual connection taking place. This is
 * because the UDP protocol is "connectionless".
 *
 * Author:  Peter Beverloo
 *          peter@dmx-network.com
 *          SA-MP Developer
 *
 *********************************************/

include( 'sampQuery.php' );
define( "NL", "\n" );

$szServerIP = $_GET["ip"];	
$iPort      = $_GET["port"];	

try
{
	$rQuery = new QueryServer( $szServerIP, $iPort );
	
	$aInformation  = $rQuery->GetInfo( );
	$aServerRules  = $rQuery->GetRules( );
	$aBasicPlayer  = $rQuery->GetPlayers( );
	$aTotalPlayers = $rQuery->GetDetailedPlayers( );
	
	$rQuery->Close( );
	
	echo 'General Information' . NL . NL;
	echo 'Hostname: ' . $aInformation[ 'Hostname'] . NL;
	echo 'Gamemode: ' . $aInformation[ 'Gamemode'] . NL;
	echo 'Players:  ' . $aInformation[ 'Players'] . ' / ' . $aInformation[ 'MaxPlayers'] . NL;
	echo 'Password: ' . ( $aInformation[ 'Password' ] == 1 ? 'Yes' : 'No' ) . NL . NL;
	
	echo 'Server Rules' . NL . NL;
	foreach( $aServerRules as $szRule => $szValue ) {
		echo $szRule . ': ' . $szValue . NL;
	}
	
	echo NL . 'Basic Player Information' . NL . NL;
	foreach( $aBasicPlayer as $aPlayer ) {
		echo $aPlayer[ 'Nickname' ] . ' (' . $aPlayer[ 'Score' ] . ')' . NL;
	}
	
	echo NL . 'Extended Player Information' . NL . NL;
	foreach( $aTotalPlayers as $aPlayer ) {
		echo '[' . $aPlayer[ 'PlayerID' ] . '] ' . $aPlayer[ 'Nickname' ] . ' ';
		echo '(' . $aPlayer[ 'Score' ] . ') Ping: ' . $aPlayer[ 'Ping' ] . NL;
	}
	
}
catch (QueryServerException $pError)
{
	echo 'An error has occured!' . NL;
	echo $pError->toString( );
}

// Finish the page off with another newline.
echo NL;
?>