PHP : Server status script doesn't work for 1.4.2

Discussion in 'Bukkit Help' started by Phoenix901, Oct 28, 2012.

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

    Phoenix901

    Hi there folks.
    I'm currently using a php script to get the motd, players online and max amount of player slots available and it have been working fine up till today.
    I'm guessing i need to send the package in some other way then from the 1.3.2 version however i'm not very good with Java and don't really know where to look to find the new "code".

    If anyone know, please let me know as i'm stuck in this hole right now.
    Here is my source code by the way:

    Main class file:
    PHP:
    <?php
     
    class MCServerStatus {
     
     
        public 
    $server;
        public 
    $online$motd$online_players$max_players$ping;
        public 
    $error "OK";
     
     
     
        function 
    __construct($url$port '25565') {
     
            
    $this->server = array(
                
    "url" => $url,
                
    "port" => $port
            
    );
     
            if ( 
    $sock = @stream_socket_client('tcp://'.$url.':'.$port$errno$errstr1) ) {
     
                
    $this->online true;
     
                
    fwrite($sock"\xfe");
                
    $h fread($sock2048);
                
    $h str_replace("\x00"''$h);
                
    $h substr($h2);
                
    $data explode("\xa7"$h);
                unset(
    $h);
                
    fclose($sock);
     
                if (
    sizeof($data) == 3) {
     
                    
    $this->motd $data[0];
                    
    $this->online_players = (int) $data[1];
                    
    $this->max_players = (int) $data[2];
                }
                else {
                    
    $this->error "Cannot retrieve server info.";
                }
     
            }
            else {
                
    $this->online false;
                
    $this->error "Cannot connect to server.";
            }
     
        }
     
     
     
    }
    My display file:
    PHP:
    <?php
                    
    include "MCServerStatus.php";
                    
    $servers = array(
                        
    "Server IP Goes here"
                    
    );
                    foreach (
    $servers as $server) {
                        if (
    strpos($server':') !== false) {
                            
    $parts explode(':'$server);
                            
    $port $parts[1];
                        }
                        else {
                            
    $port '25565';
                        }
                        
    $s = new MCServerStatus($server$port);
                        
    $status = ($s->online) ? '<span class="badge badge-success"><i class="icon-ok icon-white"></i></span>' '<span class="badge badge-important"><i class="icon-remove icon-white"></i></span>';
                        
    $players = ($s->online_players) ? $s->online_players ;
                        
    $max_players = ($s->max_players) ? $s->max_players ;
                        echo 
    "<tr>";
                        echo 
    "<td>".$status."</td>";
                        echo 
    "<td class='motd'>".$s->motd." <code>".$server."</code></td>";
                        echo 
    "<td>".$players."/".$max_players."</td>";
                        echo 
    "</tr>";
                    }
                
    ?>
    If anyone has a fix for it or even better, could tell me how I could find the "code" upcoming updates of bukkit, that would be extremely helpful.

    Thank you in advance!
     
  2. Offline

    DarthSalamon

  3. Offline

    Phoenix901

    Awesome, thanks! I'll take a look at it and see what I can find.
     
  4. Offline

    DarthSalamon

    No problem, sorry about the uninformative response, I'm not a PhP guy :p
     
  5. Offline

    Phoenix901

    Here is what I came up with (Using a new code)
    test-again.jpg

    Every array is a new try, just smashed it together with photoshop.
    Here is the code:

    PHP:
        $host "pvp.cursecraft.net";
        
    $port 25565;
     
        
    $socket = @fsockopen($host$port);
        if (
    $socket !== false) {
            @
    fwrite($socket"\xFE");
            
    $data "";
            
    $data = [USER=90736681]Fread[/USER]($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];
     
                
    var_dump($info);
                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";
        }
    Anyone knows why it comes out so random?
    If anyone can tell me how to find the the code for the ping to retrieve the motd, players and max players etc i still need that :p
    Any help is greatly appreciated.

    *Bump* Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  6. Offline

    HGjksfhnsiPID

    ;)
    PHP:
    $handle = @fsockopen("your-minecraft-server.net"25565$errno$errstr$timeout);
        if(
    $handle) {
            
    fwrite($handle"\xFE\x01");
     
            
    $d fread($handle1024);
            if (
    $d != false AND substr($d01) == "\xFF") {
                
    $d substr($d3);
                
    $d mb_convert_encoding($d'auto''UCS-2');
                
    $d explode("\x00"$d);
               
                
    print_r($d);
               
                
    // Output:
                // Array
                // (
                    // [0] => §1
                    // [1] => 47           
                    // [2] => 1.4.2               << Server version
                    // [3] => mincraft.net  << MOTD
                    // [4] => 106                 << Players online
                    // [5] => 150                  << Slots
                // )
     
                
    fclose($handle);
            }
        }
     
    Phoenix901 and DarthSalamon like this.
  7. Offline

    Phoenix901

    Thank you so much for the code!
    I played around with it a little bit and got it to work with the rest of my script, i own you one:p
     
  8. Offline

    JasonLasse

    Hi, I wonder if you could paste the code you're using. I'm pretty noob at this so I never got his code working :eek:
     
  9. Offline

    JasonLasse

    .. Apparently not :(
     
Thread Status:
Not open for further replies.

Share This Page