I made an applet for my server's website and decided it was time to post the code here!
It does exactly what you think: pings the server, returns a JSON of the info retrieved, and then sorts it and posts spans of text describing the following: The server's Minecraft version, Server MOTD, wether or not the server is online, and who is online. It updates about once a minute and uses syfaro's server status api and jquery but no downloads are needed, just copy and paste this code where you want it in your website.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Server Status</title>
<script src="" rel="noopener nofollow" target="_blank">http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body>
//Server Applet by BtheDestroyer
<p id="lastUpdate"></p>
<p id="version">Loading Minecraft Version...</p>
<p id="serverVersion">Loading Server Version...</p>
<h1 id="online">Loading Server...</h1>
<h2>List of online players:</h2><p id="playerListHTML">Loading players...</p>
<script>$.getJSON('https://api.syfaro.net/minecraft/1.2/server/info?ip=[b][u]INSERT SERVER IP HERE[/u][/b]&port=25565', function(data) {
document.getElementById('lastUpdate').textContent="Last Update: "+data.last_update+"(GMT-6)";
document.getElementById('version').textContent="Minecraft Version: MC Release V. "+data.version;
document.getElementById('serverVersion').textContent="Server MOTD: "+data.motd;
if(data.status=="success"){
document.getElementById('online').textContent = "Server is online!";
if(data.players === 0){
document.getElementById('playerListHTML').textContent = "No players are currently online.";
}else{
document.getElementById('playerListHTML').textContent = data.playerList;
}
}else{
document.getElementById('online').textContent = "Server is not online... try again later.";
document.getElementById('playersListHTML').textContent = "Server is not online... try again later.";
}
});</script>
//Server Applet by BtheDestroyer
</body>
</html>
Just copy-paste this code into your website and replace INSERT SERVER IP HERE with the server's IP.
I hope this helps everyone who wants to make a website for their minecraft servers!
~BtheDestroyer
I made an applet for my server's website and decided it was time to post the code here!
It does exactly what you think: pings the server, returns a JSON of the info retrieved, and then sorts it and posts spans of text describing the following: The server's Minecraft version, Server MOTD, wether or not the server is online, and who is online. It updates about once a minute and uses syfaro's server status api and jquery but no downloads are needed, just copy and paste this code where you want it in your website.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Server Status</title>
<script src="" rel="noopener nofollow" target="_blank">http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body>
<p id="lastUpdate"></p>
<p id="version">Loading Minecraft Version...</p>
<p id="serverVersion">Loading Server Version...</p>
<h1 id="online">Loading Server...</h1>
<h2>List of online players:</h2><p id="playerListHTML">Loading players...</p>
<script>$.getJSON('https://api.syfaro.net/minecraft/1.2/server/info?ip=76.171.110.176&amp;port=25565', function(data) {
document.getElementById('lastUpdate').textContent="Last Update: "+data.last_update+"(GMT-6)";
document.getElementById('version').textContent="Minecraft Version: MC Release V. "+data.version;
document.getElementById('serverVersion').textContent="Server MOTD: "+data.motd;
if(data.status=="success"){
document.getElementById('online').textContent = "Server is online!";
if(data.players === 0){
document.getElementById('playerListHTML').textContent = "No players are currently online.";
}else{
document.getElementById('playerListHTML').textContent = data.playerList;
}
}else{
document.getElementById('online').textContent = "Server is not online... try again later.";
document.getElementById('playersListHTML').textContent = "Server is not online... try again later.";
}
});</script>
</body>
</html>
I hope this helps everyone who wants to make a website for their minecraft servers!
~BtheDestroyer
You really don't need jQuery for this! (it's a huge library for just one function)
If the server doesn't have query enabled (or you don't know if it does or not), you should use /status instead
Here's the script that I'd use instead (with the same HTML, except you don't need to load jQuery):
(function(f,g){var h="//api.syfaro.net/minecraft/1.2/server/"+(g?"info":"status")+"?",k=Object.keys(f).map(function(B){return encodeURIComponent(B)+"="+encodeURIComponent(f[b])}).join("&"),e=new XMLHttpRequest;e.open("GET",h+k,!0);e.onload=function(B){if(200!==this.status)return console.error("Error loading server status");var a=JSON.parse(this.response);document.getElementById("lastUpdate").textContent="Last update: "+a.last_update+" (GMT-6)";var c,d;g&&"success"==a.status?(b=a.version,c=a.motd,
d="Server is online!",a=a.playerList.join(", ")):a.online?(b=a.version,c=a.motd,d=!0===a.online?"Online":"Offline",a="Unknown"):(c=b="Offline",d="Server is not online! Please try again later",a="Offline");document.getElementById("version").textContent="Minecraft Version: "+b;document.getElementById("serverVersion").textContent="Server MoTD: "+c;document.getElementById("online").textContent=d;document.getElementById("playerListHTML").textContent=a};e.send()})(
{
ip: '76.171.110.176', // change to server IP
port: '25565' // change to server port
}, true // change to false if the server doesn't have query enabled
);
You really don't need jQuery for this! (it's a huge library for just one function)
If the server doesn't have query enabled (or you don't know if it does or not), you should use /status instead
Here's the script that I'd use instead (with the same HTML, except you don't need to load jQuery):
(function(f,g){var h="//api.syfaro.net/minecraft/1.2/server/"+(g?"info":"status")+"?",k=Object.keys(f).map(function(B){return encodeURIComponent(B)+"="+encodeURIComponent(f[b])}).join("&"),e=new XMLHttpRequest;e.open("GET",h+k,!0);e.onload=function(B){if(200!==this.status)return console.error("Error loading server status");var a=JSON.parse(this.response);document.getElementById("lastUpdate").textContent="Last update: "+a.last_update+" (GMT-6)";var c,d;g&&"success"==a.status?(b=a.version,c=a.motd,
d="Server is online!",a=a.playerList.join(", ")):a.online?(b=a.version,c=a.motd,d=!0===a.online?"Online":"Offline",a="Unknown"):(c=b="Offline",d="Server is not online! Please try again later",a="Offline");document.getElementById("version").textContent="Minecraft Version: "+b;document.getElementById("serverVersion").textContent="Server MoTD: "+c;document.getElementById("online").textContent=d;document.getElementById("playerListHTML").textContent=a};e.send()})(
{
ip: '76.171.110.176', // change to server IP
port: '25565' // change to server port
}, true // change to false if the server doesn't have query enabled
);
Thanks for this Syfaro. I couldn't figure out a better way to do it but I will definitely use this and it should quicken the load time.
Thanks again,
~BtheDestroyer
So I've tried and tried to get this to work. Nothing I've tried works. Do I need to use the port the server is listening on or the specified Query Port? I've tried both and neither work so its really moot. Does this suport 1.7?
Thanks.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Server Status</title>
<script src="" rel="noopener nofollow" target="_blank">http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body>
//Server Applet by BtheDestroyer
<p id="lastUpdate"></p>
<p id="version">Loading Minecraft Version...</p>
<p id="serverVersion">Loading Server Version...</p>
<h1 id="online">Loading Server...</h1>
<h2>List of online players:</h2><p id="playerListHTML">Loading players...</p>
<script>$.getJSON('https://api.syfaro.net/minecraft/1.2/server/info?ip=23.226.68.247&port=25565', function(data) {
document.getElementById('lastUpdate').textContent="Last Update: "+data.last_update+"(GMT-6)";
document.getElementById('version').textContent="Minecraft Version: MC Release V. "+data.version;
document.getElementById('serverVersion').textContent="Server MOTD: "+data.motd;
if(data.status=="success"){
document.getElementById('online').textContent = "Server is online!";
if(data.players === 0){
document.getElementById('playerListHTML').textContent = "No players are currently online.";
}else{
document.getElementById('playerListHTML').textContent = data.playerList;
}
}else{
document.getElementById('online').textContent = "Server is not online... try again later.";
document.getElementById('playersListHTML').textContent = "Server is not online... try again later.";
}
});</script>
//Server Applet by BtheDestroyer
</body>
</html>
I made an applet for my server's website and decided it was time to post the code here!
It does exactly what you think: pings the server, returns a JSON of the info retrieved, and then sorts it and posts spans of text describing the following: The server's Minecraft version, Server MOTD, wether or not the server is online, and who is online. It updates about once a minute and uses syfaro's server status api and jquery but no downloads are needed, just copy and paste this code where you want it in your website.
Just copy-paste this code into your website and replace INSERT SERVER IP HERE with the server's IP.
I hope this helps everyone who wants to make a website for their minecraft servers!
~BtheDestroyer
I love you. So much.
subdavis.com - my little home.
If you call gold "Budder" you're not my friend anymore.
Just a few things
Thanks for this Syfaro. I couldn't figure out a better way to do it but I will definitely use this and it should quicken the load time.
Thanks again,
~BtheDestroyer
Thanks.
subdavis.com - my little home.
It shouldn't, no. (at least with using /server/status instead of /server/info)