Saturday, April 19, 2014

Introducing MineStat - A Minecraft Server Status Checker

My daughter and I have been playing Minecraft for the past year or so. After configuring a server of our own, I wanted a way to check its status. I initially wrote a Ruby class thinking our website would be a Rails application. I decided to port the code to Java and use JSP instead since I already had a Tomcat server running. I cleaned up the code this evening and figured I would release the source in case it could be of use to anyone else.

The project can be found on GitHub at https://github.com/ldilley/minestat. You can use the software to whip up a monitoring script that periodically polls multiple Minecraft servers or allow visitors of your website to see the status of your Minecraft server. Examples for C#, Java, PHP, and Ruby are below for demonstration purposes.

C# Example:


using System;

class Example
{
  public static void Main()
  {
    MineStat ms = new MineStat("cubekingdom.net", 25565);
    Console.WriteLine("Minecraft server status of {0} on port {1}:", ms.GetAddress(), ms.GetPort());
    if(ms.IsServerUp())
    {
      Console.WriteLine("Server is online running version {0} with {1} out of {2} players.", ms.GetVersion(), ms.GetCurrentPlayers(), ms.GetMaximumPlayers());
      Console.WriteLine("Message of the day: {0}", ms.GetMotd());
    }
    else
      Console.WriteLine("Server is offline!");
  }
}  


Java Example:


import org.devux.MineStat;  
   
class Example  
{  
  public static void main(String[] args)  
  {  
    MineStat ms = new MineStat("cubekingdom.net", 25565);    
    System.out.println("Minecraft server status of " + ms.getAddress() + " on port " + ms.getPort() + ":");  
    if(ms.isServerUp())  
    {  
      System.out.println("Server is online running version " + ms.getVersion() + " with " + ms.getCurrentPlayers() + " out of " + ms.getMaximumPlayers() + " players.");  
      System.out.println("Message of the day: " + ms.getMotd());  
    }  
    else  
      System.out.println("Server is offline!");  
  }  
}  


PHP Example:


<?php
require_once('minestat.php');

$ms = new MineStat("cubekingdom.net", 25565);
printf("Minecraft server status of %s on port %s:<br>", $ms->get_address(), $ms->get_port());
if($ms->is_online())
{
  printf("Server is online running version %s with %s out of %s players.<br>", $ms->get_version(), $ms->get_current_players(), $ms->get_max_players());
  printf("Message of the day: %s<br>", $ms->get_motd());
}
else
{
  printf("Server is offline!<br>");
}
?>


Ruby Example:


require_relative 'minestat'

ms = MineStat.new("cubekingdom.net", 25565)  
puts "Minecraft server status of #{ms.address} on port #{ms.port}:"
if ms.online
  puts "Server is online running version #{ms.version} with #{ms.current_players} out of #{ms.max_players} players."
  puts "Message of the day: #{ms.motd}"
else
  puts "Server is offline!"
end

Enjoy!

11 comments:

  1. Thanks for your review about minecraft server, get a cheap minecraft hosting in your budget with Cloudfrost Hosting.

    ReplyDelete
  2. I don't know that, It is new for my knowledge and It is good to know about the programming to check the status of minecraft. You can also take the high performance Minecraft Server Hosting services at best price.

    ReplyDelete
  3. You have shared such a nice experience about the status checking of Minecraft game and I always play this video game with my friends. I use Minecraft Hosting server for connecting with my friends and enjoyed a lot, you can try it if you want to play this game with your friends.

    ReplyDelete
  4. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head.
    I am highly impressed with your blog. It is very nicely explained.
    Your article adds best knowledge to our Java Online Training from India. or learn thru Java Online Training from India Students.

    ReplyDelete
  5. Lets play in minecraft with our cool skins, here you can find characters from games, books, anime etc. skins4minecraft.com

    ReplyDelete
  6. An advantage which people can really appreciate when playing them is simply getting the chance to relax following a monotonous days work. Games ought to be a simple and frequently mysterious experience that we as gamers can get a ton of prizes from.top minecraft servers

    ReplyDelete
  7. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place.. g2a cashback code July 2018

    ReplyDelete
  8. Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject. fnaf world update 3

    ReplyDelete
  9. gambling club games like roulette and opening machines, military war games, PC games, different sorts of play among youngsters, and the rundown goes on.Unblocked Games Club

    ReplyDelete
  10. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. minecraft like games

    ReplyDelete