Jump to content

Minecraft-status with JavaScript?


optimisten

Recommended Posts

HI!I've just installed ubuntu server 10.10 on my old PC and I'm running a minecraft-server + hosting a webpage on it. I'm pretty newbie to both linux and javascript, but my question is: Is it possible to add a script on my webpage telling the visitor if the minecraft-server is running or not, and if it is running, tell the visitor who's online??I'm thinking of something like:

<html><body><script type="text/javascript">var checkserver = serverstatus();var players = list-playersif (checkserver == running)   {  document.write("The server is on and + "players" + is/are online!");  }else (checkserver == not running){document.wite("The server is off.")}</script></body></html>

I've just "written something" in the code above, so if anyone has got an idea, please help me to fix the code!THANX!! :)

Link to comment
Share on other sites

How do you check if the Minecraft server is running? Do you need to ping an IP or something? Actually connect to it over some arbitrary protocol?Either way, you'll probably need to do this on the server side (with something like PHP for example). JavaScript can't do anything with other domains.

Link to comment
Share on other sites

Correct me if I'm wrong, but Minecraft doesn't run on HTTP, right?If that's the case, you'd still probably have to use a server side scripting language like PHP, because the only kind of requests JavaScript can do are HTTP requests.If it does run HTTP and is on the same server, I think you can probably just point your XMLHttpRequest to "http://yourDomain.com:8080" replacing "8080" with whatever port Minecraft is running on. Haven't really tested out that though, so it might not work.

Link to comment
Share on other sites

If you know how the Minecraft server operates, yes.By your lack of response to my questions, I'm guessing you don't know though, so it probably won't be that obvious.

Link to comment
Share on other sites

The important bit is how it communicates with Minecraft clients. Over what protocol? Does it have any sort of APIs for you to extract information from it, or at least a documentation of the protocol, so that you may create such an API yourself?

Link to comment
Share on other sites

Ok, thanx for helping! I'll check it up after I've got known with PHP :)
the point being made is that if there's no easy/meaningful way to communicate with it, then you may not be able get much further than just learning PHP. For example, facebook and youtube have API's that make requesting and retrieving user information in a standardized way, after authenticating, to use in a persons application. This is what beon is trying to get you to look up first before you learn something that my be needed. It would be better to know how, and if, you can interact with Minecraft, and then figure out what you need to learn to accomplish the task.
Link to comment
Share on other sites

Well... PHP can estabilish socket connections, so in theory, no matter how complicated the communication is, if it's over TCP/IP (as I'm most certain it is), it can be done, so PHP knowledge wouldn't be a bad idea.How it's going to be done is a whole other story... it's possible that it's really hard to do even simple stuff like finding out who's online, making the "Minecraft PHP API" a whole exciting challenge on it's own... just like the MySQLi extension is to a MySQL server (the only difference being the MySQL protocol is better documented, making creation of such APIs easier).

Link to comment
Share on other sites

Ok, thanx a lot for helping!Now I've installed a plugin in minecraft that shows a mapof the world and where the connected players are located. To open the map I have to type in "ip:8123" in my browser.Can I add something in the script that searches for webpage xx.xxx.xxx.xxx:8123? Like:"if ==answer echo The server is running.elseecho The server is not running."Here's a picture of the map I installed: http://bildr.no/view/823479 In the upper-right corner, theres a list with connected players, but I've hidden it for security reasons :)

Link to comment
Share on other sites

Read the AJAX tutorial, and try it. Like I said earlier, I think you should be able to do that, as long as the HTML page (the one containing your AJAX) is on the same IP. I'm not sure though.If you can't do it with JavaScript (and the XMLHttpRequest object, a.k.a. AJAX, in particular), you can surely do it with PHP, and in a relatively easy fashion too.

Link to comment
Share on other sites

If the Minecraft server is running on a different host to the web server, then you can't use AJAX (not sure what happens if just the port is different though).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...