PHP Query (show your server on your website)
#36

Quote:
Originally Posted by scott1
View Post
Can you upload with an another way plz?

because all "'" fucked on the code

Thank you
It's just an apostrophe, probably malformed unicode from the switch to vBulletin.


PHP Code:
<?php
require "samp_query.php";
$serverIP "91.121.209.20";
$serverPort 7777;
try
{
    
$rQuery = new QueryServer$serverIP$serverPort );
    
$aInformation $rQuery->GetInfo( );
    
$aServerRules $rQuery->GetRules( );
    
$aBasicPlayer $rQuery->GetPlayers( );
    
$aTotalPlayers $rQuery->GetDetailedPlayers( );
    
$rQuery->Close( );
}
catch (
QueryServerException $pError)
{
    echo 
'Server is offline';
}
if(isset(
$aInformation) && is_array($aInformation)){
?>
  <b>General Information</b>
  <table width="400">
      <tr>
          <td>Hostname</td>
          <td><?php echo htmlentities($aInformation['Hostname']); ?></td>
      </tr>
      <tr>
          <td>Gamemode</td>
          <td><?php echo htmlentities($aInformation['Gamemode']); ?></td>
      </tr>
      <tr>
          <td>Players</td>
          <td><?php echo $aInformation['Players']; ?> / <?php echo $aInformation['MaxPlayers']; ?></td>
      </tr>
      <tr>
          <td>Map</td>
          <td><?php echo htmlentities($aInformation['Map']); ?></td>
      </tr>
      <tr>
          <td>Weather</td>
          <td><?php echo $aServerRules['weather']; ?></td>
      </tr>
      <tr>
          <td>Time</td>
          <td><?php echo $aServerRules['worldtime']; ?></td>
      </tr>
      <tr>
          <td>Version</td>
          <td><?php echo $aServerRules['version']; ?></td>
      </tr>
      <tr>
          <td>Password</td>
          <td><?php echo $aInformation['Password'] ? 'Yes' 'No'?></td>
      </tr>
  </table>
  <br />
  <b>Online Players</b>
  <?php
  
if(!is_array($aTotalPlayers) || count($aTotalPlayers) == 0){
      echo 
'<br /><i>None</i>';
  } else {
  
?>
      <table width="400">
          <tr>
              <td><b>Player ID</b></td>
              <td><b>Nickname</b></td>
              <td><b>Score</b></td>
              <td><b>Ping</b></td>
          </tr>
      <?php
      
foreach($aTotalPlayers AS $id => $value){
      
?>
          <tr>
              <td><?php echo $value['PlayerID']; ?></td>
              <td><?php echo htmlentities($value['Nickname']); ?></td>
              <td><?php echo $value['Score']; ?></td>
              <td><?php echo $value['Ping']; ?></td>
          </tr>
      <?php
      
}
    
      echo 
'</table>';
    }
}
?>
Class:
PHP Code:
<?php
/*********************************************
*
* SA-MP Query Server Version 0.3
*
* This class provides you with an easy to use interface to query
* your SA-MP 0.2 servers. Usage is simple, but has changed a bit
* since the last version, so be sure to check out the examples
* that come along with this script. It is updated with some of
* the new SA-MP 0.2 query-techniques that can be used.
*
* Author: Peter Beverloo
*     peter@dmx-network.com
*     Ex SA-MP Developer
*
* Updated: Wouter van Eekelen
*     wouter.van.eekelen@serverffs.com
*     SA-MP Betatester
*********************************************/
class QueryServer
{
  
// Private variables used for the query-ing.
  
private $szServerIP;
  private 
$iPort;
  private 
$rSocketID;
  private 
$bStatus;
  
// The __construct function gets called automatically
  // by PHP once the class gets initialized.
  
function __construct$szServerIP$iPort )
  {
      
$this->szServerIP $this->VerifyAddress$szServerIP );
      
$this->iPort $iPort;
      if (empty( 
$this->szServerIP ) || !is_numeric$iPort )) {
          throw new 
QueryServerException'Either the ip-address or the port isn\'t filled in correctly.' );
      }
      
$this->rSocketID = @fsockopen'udp://' $this->szServerIP$iPort$iErrorNo$szErrorStr);
      if (!
$this->rSocketID) {
          throw new 
QueryServerException'Cannot connect to the server: ' $szErrorStr );
      }
      
socket_set_timeout$this->rSocketID0500000 );
      
$this->bStatus true;
  }
  
// The VerifyAddress function verifies the given hostname/
  // IP address and returns the actual IP Address.
  
function VerifyAddress$szServerIP )
  {
      if (
ip2long$szServerIP ) !== false && 
        
long2ipip2long$szServerIP ) ) == $szServerIP ) {
          return 
$szServerIP;
      }
      
$szAddress gethostbyname$szServerIP );
      if (
$szAddress == $szServerIP) {
          return 
"";
      }
      return 
$szAddress;
  }
  
// The SendPacket function sends a packet to the server which
  // requests information, based on the type of packet send.
  
function SendPacket$cPacket )
  {
      
$szPacket 'SAMP';
      
$aIpChunks explode'.'$this->szServerIP );
      foreach( 
$aIpChunks as $szChunk ) {
          
$szPacket .= chr$szChunk );
      }
      
$szPacket .= chr$this->iPort 0xFF );
      
$szPacket .= chr$this->iPort >> 0xFF );
      
$szPacket .= $cPacket;
      return 
fwrite$this->rSocketID$szPacketstrlen$szPacket ) );
  }
  
// The GetPacket() function returns a specific number of bytes
  // read from the socket. This uses a special way of getting stuff.
  
function GetPacket$iBytes )
  {
      
$iResponse fread$this->rSocketID$iBytes );
      if (
$iResponse === false) {
          throw new 
QueryServerException'Connection to ' $this->szServerIP ' failed or has dropped.' );
      }
      
$iLength ord$iResponse );
      if (
$iLength 0)
          return 
fread$this->rSocketID$iLength );
      return 
"";
  }
  
// After we're done, the connection needs to be closed using
  // the Close() function. Otherwise stuff might go wrong.
  
function Close( )
  {
      if (
$this->rSocketID !== false) {
          
fclose$this->rSocketID );
      }
  }
  
// A little function that's needed to properly convert the
  // four bytes we're recieving to integers to an actual PHP
  // integer. ord() can't handle value's higher then 255.
  
function toInteger$szData )
  {
      
$iInteger 0;
      
$iInteger += ( ord( @$szData] ) );
      
$iInteger += ( ord( @$szData] ) << );
      
$iInteger += ( ord( @$szData] ) << 16 );
      
$iInteger += ( ord( @$szData] ) << 24 );
      if( 
$iInteger >= 4294967294 )
          
$iInteger -= 4294967296;
      return 
$iInteger;
  }
  
// The GetInfo() function returns basic information about the
  // server, like the hostname, number of players online etc.
  
function GetInfo( )
  {
      if (
$this->SendPacket('i') === false) {
          throw new 
QueryServerException'Connection to ' $this->szServerIP ' failed or has dropped.' );
      }
      
$szFirstData fread$this->rSocketID);
      if (empty( 
$szFirstData ) || $szFirstData != 'SAMP') {
          throw new 
QueryServerException'The server at ' $this->szServerIP ' is not an SA-MP Server.' );
      }
      
// Pop the first seven characters returned.
      
fread$this->rSocketID);
      return array (
          
'Password'  =>  ordfread$this->rSocketID) ),
          
'Players'  =>  $this->toIntegerfread$this->rSocketID) ),
          
'MaxPlayers' =>  $this->toIntegerfread$this->rSocketID) ),
          
'Hostname'  =>  $this->GetPacket),
          
'Gamemode'  =>  $this->GetPacket),
          
'Map'    =>  $this->GetPacket)
      );
  }
  
// The GetRules() function returns the rules which are set
  // on the server, e.g. the gravity, version etcetera.
  
function GetRules( )
  {
      if (
$this->SendPacket('r') === false) {
          throw new 
QueryServerException'Connection to ' $this->szServerIP ' failed or has dropped.' );
      }
      
// Pop the first 11 bytes from the response;
      
fread$this->rSocketID11 );
      
$iRuleCount ordfread$this->rSocketID) );
      
$aReturnArray = array( );
      for( 
$i 0$i $iRuleCount$i ++ ) {
          
$szRuleName $this->GetPacket);
          
$aReturnArray$szRuleName ] = $this->GetPacket);
      }
      return 
$aReturnArray;
  }
  
// The GetPlayers() function is pretty much simelar to the
  // detailed function, but faster and contains less information.
  
function GetPlayers( )
  {
      if (
$this->SendPacket('c') === false) {
          throw new 
QueryServerException'Connection to ' $this->szServerIP ' failed or has dropped.' );
      }
      
// Again, pop the first eleven bytes send;
      
fread$this->rSocketID11 );
      
$iPlayerCount ordfread$this->rSocketID) );
      
$aReturnArray = array( );
      for( 
$i 0$i $iPlayerCount$i ++ )
      {
          
$aReturnArray[ ] = array (
              
'Nickname' => $this->GetPacket),
              
'Score'  => $this->toIntegerfread$this->rSocketID) )
          );
      }
      return 
$aReturnArray;
  }
  
// The GetDetailedPlayers() function returns the player list,
  // but in a detailed form inclusing the score and the ping.
  
function GetDetailedPlayers( )
  {
      if (
$this->SendPacket('d') === false) {
          throw new 
QueryServerException'Connection to ' $this->szServerIP ' failed or has dropped.' );
      }
      
// Skip the first 11 bytes of the response;
      
fread$this->rSocketID11 );
      
$iPlayerCount ordfread$this->rSocketID) );
      
$aReturnArray = array( );
      for( 
$i 0$i $iPlayerCount$i ++ ) {
          
$aReturnArray[ ] = array(
              
'PlayerID'  => $this->toIntegerfread$this->rSocketID) ),
              
'Nickname'  => $this->GetPacket),
              
'Score'   => $this->toIntegerfread$this->rSocketID) ),
              
'Ping'    => $this->toIntegerfread$this->rSocketID) )
          );
      }
      return 
$aReturnArray;
  }
function 
RCON($rcon$command)
  {
      echo 
'Password '.$rcon.' with '.$command;
      if (
$this->SendPacket('x '.$rcon.' '.$command) === false) {
          throw new 
QueryServerException'Connection to ' $this->szServerIP ' failed or has dropped.' );
      }
      
// Pop the first 11 bytes from the response;
      
$aReturnArray fread$this->rSocketID11 );
      echo 
fread$this->rSocketID11 );
      return 
$aReturnArray;
  }
}
/*********************************************
*
* The QueryServerException is used to throw errors when querying
* a specific server. That way we force the user to use proper
* error-handling, and preferably even a try-/catch statement.
*
**********************************************/
class QueryServerException extends Exception
{
  
// The actual error message is stored in this variable.
  
private $szMessage;
  
// Again, the __construct function gets called as soon
  // as the exception is being thrown, in here we copy the message.
  
function __construct$szMessage )
  {
      
$this->szMessage $szMessage;
  }
  
// In order to read the exception being thrown, we have
  // a .NET-like toString() function, which returns the message.
  
function toString( )
  {
      return 
$this->szMessage;
  }
}
?>
Reply


Messages In This Thread
PHP Query (show your server on your website) - by Woet - 29.09.2009, 10:18
Re: PHP Query (show your server on your website) - by [LL]InstabiC - 29.09.2009, 10:19
Re: PHP Query (show your server on your website) - by Fj0rtizFredde - 29.09.2009, 15:05
Re: PHP Query (show your server on your website) - by [mad]MLK - 29.09.2009, 19:48
Re: PHP Query (show your server on your website) - by eXchainZ-FoReVeR - 30.09.2009, 18:08
Re: PHP Query (show your server on your website) - by shady91 - 30.09.2009, 18:14
Re: PHP Query (show your server on your website) - by Calgon - 30.09.2009, 18:17
Re: PHP Query (show your server on your website) - by eXchainZ-FoReVeR - 30.09.2009, 18:19
Re: PHP Query (show your server on your website) - by Calgon - 30.09.2009, 18:20
Re: PHP Query (show your server on your website) - by shady91 - 30.09.2009, 18:21
Re: PHP Query (show your server on your website) - by eXchainZ-FoReVeR - 30.09.2009, 18:28
Re: PHP Query (show your server on your website) - by Mr187 - 01.10.2009, 00:07
Re: PHP Query (show your server on your website) - by [mad]MLK - 15.10.2009, 20:13
Re: PHP Query (show your server on your website) - by Woet - 15.10.2009, 20:17
Re: PHP Query (show your server on your website) - by [mad]MLK - 15.10.2009, 20:23
Re: PHP Query (show your server on your website) - by Tenshi - 18.10.2009, 22:29
Re: PHP Query (show your server on your website) - by Westie - 18.10.2009, 22:46
Re: PHP Query (show your server on your website) - by Woet - 28.10.2009, 07:54
Re: PHP Query (show your server on your website) - by Programie - 28.10.2009, 14:50
Re: PHP Query (show your server on your website) - by Westie - 28.10.2009, 17:29
Re: PHP Query (show your server on your website) - by Streetplaya - 28.10.2009, 17:56
Re: PHP Query (show your server on your website) - by Westie - 28.10.2009, 17:59
Re: PHP Query (show your server on your website) - by Streetplaya - 28.10.2009, 18:03
Re: PHP Query (show your server on your website) - by Westie - 28.10.2009, 18:07
Re: PHP Query (show your server on your website) - by Takumi.WS - 07.11.2009, 12:09
Re: PHP Query (show your server on your website) - by mini-d - 11.11.2009, 09:56
Re: PHP Query (show your server on your website) - by FrostBytez - 11.11.2009, 10:17
Re: PHP Query (show your server on your website) - by _Gangster_ - 11.11.2009, 10:57
Re: PHP Query (show your server on your website) - by Woet - 11.11.2009, 12:42
Re: PHP Query (show your server on your website) - by Westie - 11.11.2009, 16:01
Re: PHP Query (show your server on your website) - by Alec24 - 10.04.2010, 15:58
Re: PHP Query (show your server on your website) - by Westie - 10.04.2010, 21:44
Re: PHP Query (show your server on your website) - by Alec24 - 10.04.2010, 22:04
Re: PHP Query (show your server on your website) - by Westie - 10.04.2010, 22:07
Re : PHP Query (show your server on your website) - by scott1 - 15.08.2010, 11:40
Re: Re : PHP Query (show your server on your website) - by Calgon - 15.08.2010, 11:52
Re: PHP Query (show your server on your website) - by ReVo_ - 15.08.2010, 15:51
Re: PHP Query (show your server on your website) - by Agent Smith - 15.08.2010, 16:25
Re: PHP Query (show your server on your website) - by MidoTheHawk - 25.08.2010, 08:54
Re: PHP Query (show your server on your website) - by ReVo_ - 26.09.2010, 19:59
Re: PHP Query (show your server on your website) - by gamer931215 - 26.09.2010, 20:22
Re: PHP Query (show your server on your website) - by thimo - 27.01.2012, 16:07
Re: PHP Query (show your server on your website) - by Translator - 10.07.2012, 06:49
Re: PHP Query (show your server on your website) - by [MM]18240[FMB] - 25.07.2012, 03:09
Re: PHP Query (show your server on your website) - by ca2k - 25.07.2012, 13:22
Re: PHP Query (show your server on your website) - by CrossUSAAF - 25.07.2012, 14:02
Re: PHP Query (show your server on your website) - by StoNe- - 12.07.2014, 17:32
Re: PHP Query (show your server on your website) - by Sithis - 12.07.2014, 18:24
Re: PHP Query (show your server on your website) - by StoNe- - 12.07.2014, 19:12
Re: PHP Query (show your server on your website) - by Aldo. - 12.07.2014, 19:51
Re: PHP Query (show your server on your website) - by StoNe- - 13.07.2014, 13:17
Re: PHP Query (show your server on your website) - by Zekiloni - 07.11.2015, 22:53
Re: PHP Query (show your server on your website) - by NLDBrian - 16.10.2017, 18:42

Forum Jump:


Users browsing this thread: 1 Guest(s)