sever checker html
#1

Hello, i want to put on my servers website LIVE statistics of the server i want it in html and not those crappy pictures just plain text (if cant find without pic one with pic will have to do) but i cant find a wesbite that will give me the code etc can someon link me?
Reply
#2

Get the SampQueryAPI - https://sampforum.blast.hk/showthread.php?tid=104299
Reply
#3

how do i use it? lol is there a tut or something?
Reply
#4

Yeah there's example included, https://gist.github.com/234209
Reply
#5

so how do i implement it into the web page i tried basicly coping and pasting the code from that page^ (cause im shit at php) and it returned errors
Reply
#6

Save the API and the example, add your server IP & Port in the example and upload them both - http://c-rp.net/~vimm/query/serverquery.php

PHP код:
<?php
/**
 *    This API connects directly to the server, without any need for any
 *    middlemen connections.
 *    Your server must have fsockopen enabled in order to access the 
 *    functions that have been made available from this.
 *
 *    @package sampAPI
 *    @version 1.2
 *    @author David Weston <westie@typefish.co.uk>
 *    @copyright 2010; http://www.typefish.co.uk/licences/nl668...9.45328701
 */
class SampQueryAPI
{
    
/**
     *    @ignore
     */
    
private $rSocket false;
    
    
    
/**
     *    @ignore
     */
    
private $aServer = array();
    
    
    
/**
     *    Creation of the server class.
     *
     *    @param string $sServer Server IP, or hostname.
     *    @param integer $iPort Server port
     */
    
public function __construct($sServer$iPort 7777)
    {
        
/* Fill some arrays. */
        
$this->aServer[0] = $sServer;
        
$this->aServer[1] = $iPort;
        
        
/* Start the connection. */    
        
$this->rSocket fsockopen('udp://'.$this->aServer[0], $this->aServer[1], $iError$sError2);
        
        if(!
$this->rSocket)
        {
            
$this->aServer[4] = false;
            return;
        }
        
        
socket_set_timeout($this->rSocket2);
        
        
$sPacket 'SAMP';
        
$sPacket .= chr(strtok($this->aServer[0], '.'));
        
$sPacket .= chr(strtok('.'));
        
$sPacket .= chr(strtok('.'));
        
$sPacket .= chr(strtok('.'));
        
$sPacket .= chr($this->aServer[1] & 0xFF);
        
$sPacket .= chr($this->aServer[1] >> 0xFF);
        
$sPacket .= 'p4150';
        
        
fwrite($this->rSocket$sPacket);
        
        if(
fread($this->rSocket10))
        {
            if(
fread($this->rSocket5) == 'p4150')
            {
                
$this->aServer[4] = true;
                return;
            }
        }
        
        
$this->aServer[4] = false;
    }
    
    
    
/**
     *    @ignore
     */
    
public function __destruct()
    {
        @
fclose($this->rSocket);
    }
    
    
    
/**
     *    Used to tell if the server is ready to accept queries.
     *
     *    If false is returned, then it is suggested that you remove the
     *    class from active use, so that you can reload the class if needs
     *    be.
     *
     *    @return bool true if success, false if failure.
     */
    
public function isOnline()
    {
        return isset(
$this->aServer[4]) ? $this->aServer[4] : false;
    }
    
    
    
/**
     *    This function is used to get the server information.
     *
     *    <code>
     *    Array
     *    (
     *        [password] => 0
     *        [players] => 9
     *        [maxplayers] => 500
     *        [hostname] => Everystuff Tr3s [MAD]oshi (03a Final) [FIXED]
     *        [gamemode] => Stunt/Race/DM/FR Everystuff
     *        [mapname] => Everystuff
     *    )
     *    </code>
     *
     *    @return array Array of server information.
     */
    
public function getInfo()
    {
        @
fwrite($this->rSocket$this->createPacket('i'));
        
        
fread($this->rSocket11);
    
        
$aDetails['password'] = (integer) ord(fread($this->rSocket1));
        
        
$aDetails['players'] = (integer) $this->toInteger(fread($this->rSocket2));
        
        
$aDetails['maxplayers'] = (integer) $this->toInteger(fread($this->rSocket2));
        
        
$iStrlen ord(fread($this->rSocket4));
        if(!
$iStrlen) return -1;
        
        
$aDetails['hostname'] = (string) fread($this->rSocket$iStrlen);
        
        
$iStrlen ord(fread($this->rSocket4));
        
$aDetails['gamemode'] = (string) fread($this->rSocket$iStrlen);
        
        
$iStrlen ord(fread($this->rSocket4));
        
$aDetails['mapname'] = (string) fread($this->rSocket$iStrlen);
        
        return 
$aDetails;
    }
    
    
    
/**
     *    This function gets a basic list of all the players on the server.
     *
     *    Note as of 0.3.0, the amount of players that can be retrieved is
     *    limited to 100. This means if there are more players than 100,
     *    then no data will be returned, and it will be a blank array.
     *
     *    <code>
     *    Array
     *    (
     *        [0] => Array
      *            (
     *                [nickname] => K1nNngO
     *                [score] => 72
     *            )
     *        
     *        [1] => Array
     *            (
     *                [nickname] => [kikOo]
     *                [score] => 150
     *            )
     *
     *        [and so on...]
     *    )
     *    </code>
     *
     *    @return array Array of player information.
     */
    
public function getBasicPlayers()
    {
        @
fwrite($this->rSocket$this->createPacket('c'));
        
fread($this->rSocket11);
        
        
$iPlayerCount ord(fread($this->rSocket2));
        
$aDetails = array();
        
        if(
$iPlayerCount 0)
        {
            for(
$iIndex 0$iIndex $iPlayerCount; ++$iIndex)
            {
                
$iStrlen ord(fread($this->rSocket1));
                
$aDetails[] = array
                (
                    
"nickname" => (string) fread($this->rSocket$iStrlen),
                    
"score" => (integer) $this->toInteger(fread($this->rSocket4)),
                );
            }
        }
        
        return 
$aDetails;
    }
    
    
    
/**
     *    This function gets a detailed list of all the players on the server.
     *
     *    Note as of 0.3.0, the amount of players that can be retrieved is
     *    limited to 100. This means if there are more players than 100,
     *    then no data will be returned, and it will be a blank array.
     *
     *    <code>
     *    Array
     *    (
     *        [0] => Array
     *            (
     *                [playerid] => 0
     *                [nickname] => K1nNngO
      *                [score] => 72
     *                [ping] => 195
     *            )
     *    
     *        [1] => Array
     *            (
     *                [playerid] => 1
     *                [nickname] => [kikOo]
     *                [score] => 150
     *                [ping] => 375
     *            )
     *
     *        [and so on...]
     *    )
     *    </code>
     *
     *    @return array Array of player information.
     */
    
public function getDetailedPlayers()
    {
        @
fwrite($this->rSocket$this->createPacket('d'));
        
fread($this->rSocket11);
    
        
$iPlayerCount ord(fread($this->rSocket2));
        
$aDetails = array();
        
        for(
$iIndex 0$iIndex $iPlayerCount; ++$iIndex)
        {
            
$aPlayer['playerid'] = (integer) ord(fread($this->rSocket1));
            
            
$iStrlen ord(fread($this->rSocket1));
            
$aPlayer['nickname'] = (string) fread($this->rSocket$iStrlen);
            
            
$aPlayer['score'] = (integer) $this->toInteger(fread($this->rSocket4));
            
$aPlayer['ping'] = (integer) $this->toInteger(fread($this->rSocket4));
            
            
$aDetails[] = $aPlayer;
            unset(
$aPlayer);
        }
        
        return 
$aDetails;
    }
    
    
    
/**
     *    This function gets all the server rules from the server.
     *
     *    Rules in this context are not player rules, they are client rules,
     *    like the weather of the server, time, and so on. (Custom rules,
     *    when supported by a SA-MP plugin, will be included here.) 
     *
     *    <code>
     *    Array
     *    (
     *        [gravity] => 0.007900
     *        [mapname] => Everystuff
     *        [version] => 0.3a
     *        [weather] => 0
     *        [weburl] => samp.madoshi.net
     *        [worldtime] => 12:00
     *    )
     *    </code>
     *
     *    @return array Array of server rules.
     */
    
public function getRules()
    {
        @
fwrite($this->rSocket$this->createPacket('r'));
        
fread($this->rSocket11);
        
        
$iRuleCount ord(fread($this->rSocket2));
         
$aReturn = array();
        
        for(
$iIndex 0$iIndex $iRuleCount; ++$iIndex)
        {
            
$iStrlen ord(fread($this->rSocket1));
            
$sRulename = (string) fread($this->rSocket$iStrlen);
            
            
$iStrlen ord(fread($this->rSocket1));
            
$aDetails[$sRulename] = (string) fread($this->rSocket$iStrlen);
        }
        
        return 
$aDetails;
    }
    
    
    
/**
     *    @ignore
     */
    
private function toInteger($sData)
    {
        if(
$sData === "")
        {
            return 
null;
        }
        
         
$iInteger 0;
         
$iInteger += (ord($sData[0]));
 
         if(isset(
$sData[1]))
         {
             
$iInteger += (ord($sData[1]) << 8);
         }
         
         if(isset(
$sData[2]))
         {
             
$iInteger += (ord($sData[2]) << 16);
         }
         
         if(isset(
$sData[3]))
         {
             
$iInteger += (ord($sData[3]) << 24);
         }
         
         if(
$iInteger >= 4294967294)
        {
             
$iInteger -= 4294967296;
        }
         
         return 
$iInteger;
    }
    
    
    
/**
     *    @ignore
     */
    
private function createPacket($sPayload)
    {
        
$sPacket 'SAMP';
        
$sPacket .= chr(strtok($this->aServer[0], '.'));
        
$sPacket .= chr(strtok('.'));
        
$sPacket .= chr(strtok('.'));
        
$sPacket .= chr(strtok('.'));
        
$sPacket .= chr($this->aServer[1] & 0xFF);
        
$sPacket .= chr($this->aServer[1] >> 0xFF);
        
$sPacket .= $sPayload;
    
        return 
$sPacket;
    }
}
PHP код:
<?php
require "SampQueryAPI.php";
$query = new SampQueryAPI('85.214.61.120''7777');
if(
$query->isOnline())
{
    
$aInformation $query->getInfo();
    
$aServerRules $query->getRules();
    
?>
    <b>General Information</b>
    <table width="400">
        <tr>
            <td>Hostname</td>
            <td><?= htmlentities($aInformation['hostname']) ?></td>
        </tr>
        <tr>
            <td>Gamemode</td>
            <td><?= htmlentities($aInformation['gamemode']) ?></td>
        </tr>
        <tr>
            <td>Players</td>
            <td><?= $aInformation['players'?> / <?= $aInformation['maxplayers'?></td>
        </tr>
        <tr>
            <td>Map</td>
            <td><?= htmlentities($aInformation['mapname']) ?></td>
        </tr>
        <tr>
            <td>Weather</td>
            <td><?= $aServerRules['weather'?></td>
        </tr>
        <tr>
            <td>Time</td>
            <td><?= $aServerRules['worldtime'?></td>
        </tr>
        <tr>
            <td>Version</td>
            <td><?= $aServerRules['version'?></td>
        </tr>
        <tr>
            <td>Password</td>
            <td><?= $aInformation['password'] ? 'Yes' 'No' ?></td>
        </tr>
    </table>
    <br />
    <b>Online Players</b>
    <?php
    $aPlayers 
$query->getDetailedPlayers();
    if(!
is_array($aPlayers) || count($aPlayers) == 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($aPlayers as $sValue)
        {
            
?>
            <tr>
                <td><?= $sValue['playerid'?></td>
                <td><?= htmlentities($sValue['nickname']) ?></td>
                <td><?= $sValue['score'?></td>
                <td><?= $sValue['ping'?></td>
            </tr>
            <?php
        
}
        echo 
'</table>';
    }
}
?>
Reply
#7

ok did that and got this error


PHP Error Message

Warning: fsockopen() [function.fsockopen]: UDP protocol is not allowed in /home/a9936746/public_html/SampQueryAPI.php on line 42
Reply
#8

this is line 42 $this->rSocket = fsockopen('udp://'.$this->aServer[0], $this->aServer[1], $iError, $sError, 2);
Reply
#9

You need to open UDP Port(Port of the server you try to query).
Reply
#10

hmm how to do it? lol
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)