Help? Working minecraft server status script for php?

Discussion in 'Bukkit Help' started by Kazzababe, Nov 18, 2012.

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

    Kazzababe

    I've seen a few php scripts for checking the status of a minecraft server, but they dont seem to work. I was wondering if anyone had one that works as of now and would be willing to share with me?
    Please and thank you!
     
  2. Offline

    Adriani6

    Only the status, "Online" "Offline" ?
     
  3. Offline

    Kazzababe

    I'd take that over nothing.
     
  4. Offline

    Adriani6

    It was a question, not a statement.
    Let me ask again, do you want it to show if the server is online/offline only?
     
  5. Offline

    lokpique

    He answered your question by expressing interest.
     
    Kazzababe likes this.
  6. Offline

    Adriani6

    No. I asked if he want only the script to show Online/Offline status or something else or/and more.
    Showing interest in what ? He didn't answer my question.
     
  7. Offline

    Kazzababe

    I'd like to get the MOTD, current players, max players, etc.
     
  8. Offline

    Adriani6

    I'll try coding something for you. Please hold on, as I have few projects currently on, this wont take long though.
     
  9. Offline

    minepress

    Kazza, I have a free Minecraft Website Server Software which offers this :)
     
  10. Offline

    lokpique

    Sounds like he's interested to me... unless "I'd take that" means something different in your language.
     
  11. Offline

    Adriani6

    You're a really hard and weird person.

    "I'd take that over nothing."

    Clearly means he/she is expecting something more WHICH he/she didn't write. Therefore stop being so smart and get on with your own things.
     
  12. Offline

    lokpique

    You definition of 'clearly' makes me giggle about your questioning of my own "smartness". Enjoy the ego, sir.

    Common sense... it's the other white meat... just sayin'...
     
  13. Offline

    Kazzababe

    I'd be very interested in getting that if you dont mind sharing.

    Much appreciated, thank you.
     
  14. Offline

    minepress

    Kazza do you have a Webhost already etc :)

    if you want RAW PHP

    PHP:
    <?php
     
    $ip 
    127.0.0.1;
    $port 25565;
     
    $online = @fsockopen$ip$port$errno$errstr200);
    if(
    $online >= 1) {
    echo 
    '<a href="#" class="MPServer_Online">Online</a>';
    }
    else {
    echo 
    '<a href="#" class="MPServer_Offline">Offline</a>';
    }
    ?>
    <p>
    <?php
    Print "Our IP is: ";
    Print 
    $ip;
    ?>
     
  15. Offline

    Jacek

    Here is something I wrote a few days ago

    Code:
    class minecraft_server {
     
        private $address;
        private $port;
     
        public function __construct($address, $port = 25565){
            $this->address = $address;
            $this->port = $port;
        }
     
        public function get_ping_info(&$info){
            $socket = @fsockopen($this->address, $this->port, $errno, $errstr, 1.0);
         
            if ($socket === false){
                return false;
            }
         
            fwrite($socket, "\xfe\x01");
         
            $data = fread($socket, 256);
         
            if (substr($data, 0, 1) != "\xff"){
                return false;
            }
         
            if (substr($data, 3, 5) == "\x00\xa7\x00\x31\x00"){
                $data = explode("\x00", mb_convert_encoding(substr($data, 15), 'UTF-8', 'UCS-2'));
            }else{
                $data = explode('§', mb_convert_encoding(substr($data, 3), 'UTF-8', 'UCS-2'));
            }
         
            if (count($data) == 3){
                $info = array(
                    'version'        => '1.3.2',
                    'motd'            => $data[0],
                    'players'        => intval($data[1]),
                    'max_players'    => intval($data[2]),
                );
            }else{
                $info = array(
                    'version'        => $data[0],
                    'motd'            => $data[1],
                    'players'        => intval($data[2]),
                    'max_players'    => intval($data[3]),
                );
            }
         
            return true;
        }
     
    }
    and a usage example

    Code:
    $server = new minecraft_server('192.168.1.20', 25565);
     
    if (!$server->get_ping_info($info)){
        // oh no server is dead
    }else{
        // yay server is alive and you can use $info
        print_r($info);
    }
     
  16. Offline

    Kazzababe

    Considering you made that a few days ago, I'm assuming it was working for you. It doesnt work for me though. Could this have something to do with the host I'm using seeing as none of the many other php scripts I have tried work.
     
  17. Offline

    Jacek

    If it's a free host they may not allow the fsockopen function.
     
  18. Offline

    Kazzababe

    Im using wiredtree which is paid hosting.
     
  19. Offline

    Sushi

    What type of error are you getting?
     
  20. Offline

    Kazzababe

    From jaceks code, $socket returns false.
    I know the servers online, I can see it, but it always returns false. No actual error.
    Could it be my server settings?
     
  21. Offline

    Jacek

    Unlikely, this uses the same method as the serverlist in game so i you can see that it should work. Try adding

    Code:
    ini_set('display_error', 'On');
    error_reporting(E_ALL);
    at the top of the page, that might show an error that is being hidden. You could also try removing the @ from before the fsockopen line since that hides all error from that function.
     
  22. Offline

    Sushi

    Or you could not use PHP.
     
  23. Offline

    Kazzababe

    How else am I supposed to do it?
     
  24. Offline

    Sushi

    A server side language?
     
  25. Offline

    Kazzababe

    If not php, what "server-side" language would I use?
     
  26. Offline

    Sushi

    asp, asp.net, java, coldfusion, node.js, perl, python, scala, groovy, c#, vb.net, or ruby?

    Basically any server side language?
     
    Super User likes this.
  27. Offline

    Kazzababe

    Which one would you suggest seeing as none of the PHP ones seem to work.
     
  28. Offline

    Sushi

    Whatever your host supports
     
  29. Offline

    md_5

    I have no idea what you plan to do with this script, but if you have a bit of technical know how and can use git, http://www.heroku.com/ is quite possible the worlds best place to host web applications, for free!
     
  30. Offline

    Sushi

    Yeah, heroku is great. You get a free dyno, and you can host PHP, JVM, node.js, Ruby or Python.
     
Thread Status:
Not open for further replies.

Share This Page