PHP Player amount, motd, server name?

Discussion in 'Bukkit Tools' started by Sigvash, Jul 5, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Sigvash

    I have found some php scripts around at bukkit for this.
    Here is one by nisovin and edited by drakia
    PHP:
        $host "example.com";
        
    $port 25565;
     
        
    $socket = @fsockopen($host$port);
        if (
    $socket !== false) {
            @
    fwrite($socket"\xFE");
            
    $data "";
            
    $data = @fread($socket1024);
            @
    fclose($socket);
            if (
    $data !== false && substr($data01) == "\xFF") {
                
    $info explode("\xA7"mb_convert_encoding(substr($data,1), "iso-8859-1""utf-16be"));
                
    $serverName substr($info[0], 1);
                
    $playersOnline $info[1];
                
    $playersMax $info[2];
                echo 
    "Server: $serverName<br/>Players Online: $playersOnline/$playersMax";
            } else {
                
    // Server did not send back proper data, or reading from socket failed.
                
    echo "Failed to receive data";
            }
        } else {
            
    // Can't connect. Server is probably down.
            
    echo "Failed to connect";
        }
    And another one, by Bertware at bukkit
    PHP:
    <?php
     
    error_reporting
    (0); //prevent error when server can not be reached
     
    $host $_GET['ip']; //server.php?ip=IP-OR-HOST
    if ($host=="") {
    $host $_SERVER['REMOTE_ADDR'];
    }
    $port 25565;
     
    if (
    substr_count($host ".") != 4) { //If not an IP, resolve host
    $host gethostbyname($host);
    }
     
    //connect to server
     
    echo "checking $host on port $port...<br>";
    $socket socket_create(AF_INETSOCK_STREAMSOL_TCP);
    $timeout = array(sec=>3,usec=>0);
    socket_set_option($socketSOL_SOCKETSO_RCVTIMEO$timeout);
    socket_set_option($socketSOL_SOCKETSO_SNDTIMEO$timeout);
     
    $connected socket_connect($socket$host$port);
     
    if (!
    $connected) { //If not connected: die
    die("Server offline");
    }
     
    if (
    $connected) {
        
    $ping_start microtime(true);
        
    socket_send($socket"\xFE"10);
        
    $data "";
        
    $result socket_recv($socket$data1500);$ping_end microtime(true);
        
    socket_close($socket);
     
        if (
    $result != false && substr($data01) == "\xFF") { //get values
            
    $info explode("\xA7"mb_convert_encoding(substr($data,1), "iso-8859-1""utf-16be"));
            
    $serverName substr($info[0], 1);
            
    $playersOnline $info[1];
            
    $playersMax $info[2];
            
    $ping round(($ping_end $ping_start) * 1000);
    //echo values
            
    echo  "Server: $serverName<br/>
                    Address: 
    $host<br/>
                    Port: 
    $port<br/>
                    Players Online: 
    $playersOnline/$playersMax <br/>
                    Ping: 
    $ping ms<br/>";
        } else {
            echo 
    "Failed to receive data";
        }
    } else {
        echo 
    "Failed to connect";
    }
    ?>
    When i try to use the first one i get "Failed to receive data" and Code comment "Server did not send back proper data, or reading from socket failed." Anyone help me get this to work?[/PHP]
     
  2. Offline

    Bertware

    port 25565 should be open on your server. If you use webhosting, it's posible that your provider blocked this.
     
  3. Offline

    Artaex

    That won't be required, the query feature uses the GameSpy protocol which hasn't changed.
     
  4. Offline

    hawkfalcon

    Ditto.
     
  5. Offline

    Artaex

    Don't talk if you have nothing useful to say. I wrote my own script which I'm using on vote4craft.net
    It works perfectly fine.
     
  6. Offline

    lol768 Retired Staff

    KeybordPiano459 likes this.
Thread Status:
Not open for further replies.

Share This Page