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

    lokpique

    Isn't there a setting in the server.properties file to enable / disable a response to this kind of query?
     
  2. Offline

    Adriani6

    enable-query=false

    I believe it allows you to fetch some information from your server such as; player list, amount of players online, amount of slots, motd and so on.
     
  3. Offline

    lokpique

    That's what I thought.

    Kazzababe check that you don't have this feature disabled in your server.properties.
     
  4. Offline

    Jacek

    The code I posted is not using the query server, it uses the server list ping.

    Nope, its on all the time.
     
  5. Offline

    Kazzababe

    I have query enabled but it still doesn't work.
     
  6. Offline

    Adriani6

    Make sure your server provider allows external connections. I had the same problem.
     
  7. Offline

    Jacek

    You are getting this wrong. My script does not use the query server, it uses the server list ping (the same thing the game uses to show the list of servers). There is no way to disable it on the server as that would prevent clients from connecting.
     
  8. Offline

    Adriani6

    Oops. Didn't see your code in there. I assume you're Polish, by your name so, siema, co tam? :)
     
  9. Offline

    Jacek

    Nope :p My granddad was from the Ukraine but I was born in the UK.
     
  10. Offline

    Adriani6

    Ah, I see haha, well, pretty much same here, my granddad was from Ukraine, I was born in Poland and moved to UK when I was little :p haha
     
  11. Offline

    minepress


    So, I went into the code and removed 'motd' => $data[0] and 'motd' => $data[1]
    and it's printed out the array which is GREAT

    Code:
    Array ( [version] => 1.4.5 [players] => 45 [max_players] => 150 ) 
    This is the result. I love it. :)

    (For those who are wondering an array is the output and this is showing parts of the result, these Array and [] tags can be removed :) )
     
  12. Offline

    Texton

    I use PHP-Minecraft-Query code.

    Using the code supplied I was able to pull out the current players online from $aryPlayers with the following code:

    PHP:
    <?php
      $intPlayerCount 
    count($aryPlayers);
      if (!(empty(
    $aryPlayers))) {
        echo 
    "<h2 class=\"online\">Who's Online:</h2><br />";
        for (
    $i=0$i $intPlayerCount$i++) {
          echo 
    "<img src=\"images/avatar_" strtolower($aryPlayers[$i]) . ".png\" width=\"16\" height=\"16\" /> " $aryPlayers[$i] . "<br />";
        }               
      }
    ?>
     
  13. Offline

    Kazzababe

    Apparantly all of these should work. Is there something wrong with the host TreeWired? It appears these php scripts work for everyone but me, and I'd love to know why that is :(
     
  14. Offline

    Adriani6

    Would you mind sharing the whole code.
     
  15. Offline

    Texton


    Sorry, yes I could have provided a little more information. I used the 'Example' code on the link I gave as a starting point. From there I expanded it a little to get what I wanted.

    PHP:
    print_r$Query->GetInfo( ) );
    print_r$Query->GetPlayers( ) );
    $aryInfo = ($Query->GetInfo());
    $aryPlayers = ($Query->GetPlayers());
    $intPlayerCount count($aryPlayers);
    Then you need to use some HTML to format it nicely.
     
  16. Offline

    mmorton89

    I am trying to use this PHP-Minecraft-Query code and was wondering how to get rid of the Array output.

    Code:
    Array ( [Version] => 1.4.4 [Players] => 0 [MaxPlayers] => 60 )
    Also how can I make it echo if the server is actually online or not.

    I just want it to simply output,

    Status - Online
    Players - 0/60
    Version - 1.4.4

    Thank you.
     
  17. Offline

    Adriani6

    I'm working on it lol. So far, I managed to do this;
    http://adrianiwaszkiewicz.com/Development/List/php/mytest1.php
    This fetched info from my current server. I could host it for you if you want.
     
  18. Offline

    Texton

    I created a script to update the user avatar based on the user's current skin.

    I have my 'players.txt' file populated with my white-list players, but case-sensitive as it won't work with the actual white-list because all usernames are in lower-case. There might be a better way to do this.

    In my example, my website resides in a folder '/domains/minecraft.domain.name' and the URL is minecraft.domain.name, so update this to suit your setup. The OS is CentOS, and you will need the ImageMagick package installed.

    Firstly I download all the skins:
    Code:
    #!/bin/bash
    #refresh all avatars regardless of modify date
    cd /domains/minecraft.domain.name/data
    for i in `cat /domains/minecraft.domain.name/data/players.txt`; do
      wget -4 -m -nd http://minecraft.net/skin/$i.png
      convert $i.png -crop 8x8+8+8 +repage -scale 200% /domains/minecraft.domain.name/images/avatar_${i,,}.png
      chown apache:apache /domains/minecraft.domain.name/images/avatar_${i,,}.png
    done
    Then I check once a day, and only download if the skin has changed:
    Code:
    #!/bin/bash
    #check for new avatars
    cd /domains/minecraft.domain.name/data
    for i in `cat /domains/minecraft.domain.name/data/players.txt`; do
      wget -4 -m -nd http://minecraft.net/skin/$i.png
      if [ ! $(find /domains/minecraft.domain.name/data/$i.png -mtime -1 | wc -l) -eq 0 ]; then
        convert $i.png -crop 8x8+8+8 +repage -scale 200% /domains/minecraft.domain.name/images/avatar_${i,,}.png
        chown apache:apache /domains/minecraft.domain.name/images/avatar_${i,,}.png
      fi
    done
     
  19. Offline

    FunnyItsElmo

    Hey!
    I write a little php code which checks the server status, the count of the online players and the Slots.
    Here is the link: https://github.com/FunnyItsElmo/PHP-Minecraft-Server-Status-Query
    In the README.md is a tutorial how to use it.
    I hope I could help you
     
  20. Offline

    pmal10

    omg Hi Adrian XD
     
    MinopolisMc likes this.
  21. Offline

    Pathurs

    Sushi
    PHP is a server side language, mainly website, but it is still a server side language
     
  22. Offline

    Sushi

    Um what lol
     
  23. Offline

    mongy910

    Nothing is working for me either :(
    I keep getting a connection refused error
     
  24. Offline

    victornpb

    I dont see any authentication through mojang servers. Thats probably the issue
     
  25. Offline

    ohtwo

    How would I get the results to be on an image?
     
  26. Offline

    velocius

    Heres the script i use for my website. Works fine for me.


    PHP:
    class MCServerStatus {
     
     
        public 
    $server;
        public 
    $online$motd$online_players$max_players;
        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.";
            }
     
        }
     
     
     
    }
    Usage would be like this.

    PHP:
    include "MCServerStatus.php";
    $server = new MCServerStatus("Server IP Here"25565); //The second argument is optional in this case[/COLOR]
     
    $var $server->online//$server->online returns true if the server is online, and false otherwise
    echo $server->motd//Outputs the Message of the Day
    echo $server->online_players//Outputs the number of players online
    echo $server->max_players//Outputs the maximum number of players the server allows
    print_r($server); //Shows an overview of the object and its contents. (For debugging.)
     
  27. Offline

    Lancerb1

    The reason why you aren't getting an error is because the error is being suppressed in Jacek's code. You need to remove the @ symbol in front of fsockopen() to show the error that fsockopen() is throwing. Alternatively, you can leave the @ symbol, but echo $errno and $errstr to show the error:

    Code:
    $socket = @fsockopen( $this->address, $this->port, $errno, $errstr, 10 );
     
    if ( $socket === false ){
        printf( "Socket Error #%d: %s<br />", $errno, $errstr );
    }
    
     
  28. Offline

    Super User

    People who are using the avatar thing, use minotar. I've provided a sample script below.

    <?php
    function preventSQLinject() {
    //Insert escape function here if you have a sql server
    }

    $user = $_GET[username];

    print '<img src="minotar.net/helm/' . $user . '/100"';

    ?>

    Also you want to add the escape keys at print.
     
  29. Offline

    NGCraft

    Hey, I'm very new to html and php and all that.I really have no idea had to implement this into my website, no idea, cant find anything online on this. If anyone knows how, that would be great. Thanks
     
  30. Offline

    Adriani6

Thread Status:
Not open for further replies.

Share This Page