mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 02:05:41 +00:00
Improved mojang service checker, now using xpaw.ru, migrated to /minecraft
This commit is contained in:
parent
4f6a0ca5d3
commit
fab341608b
@ -1,5 +1,5 @@
|
|||||||
#Sun, 23 Jun 2013 15:16:34 +0200
|
#Mon, 01 Jul 2013 10:02:39 +0200
|
||||||
|
|
||||||
program.VERSION=2.19
|
program.VERSION=2.19
|
||||||
program.BUILDNUM=221
|
program.BUILDNUM=236
|
||||||
program.BUILDDATE=06/23/2013 03\:16 PM
|
program.BUILDDATE=07/01/2013 10\:02 AM
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
#Build Number for ANT. Do not edit!
|
#Build Number for ANT. Do not edit!
|
||||||
#Sun Jun 23 15:16:34 CEST 2013
|
#Mon Jul 01 10:02:39 CEST 2013
|
||||||
build.number=222
|
build.number=237
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_ServiceChecker;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
||||||
|
@CommandParameters(description = "Shows the uptime of all minecraft services.", usage = "/<command>")
|
||||||
|
public class Command_minecraft extends TFM_Command {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
|
{
|
||||||
|
playerMsg("Status of Mojang services:", ChatColor.BLUE);
|
||||||
|
for (String service : TFM_ServiceChecker.getAllStatuses())
|
||||||
|
{
|
||||||
|
playerMsg(service);
|
||||||
|
}
|
||||||
|
playerMsg("Version " + TFM_ServiceChecker.version + ", Last Checked: " + TFM_ServiceChecker.last_updated, ChatColor.BLUE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,41 +1,16 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
|
||||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.JSONValue;
|
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
||||||
@CommandParameters(description = "Show misc. server info.", usage = "/<command>")
|
@CommandParameters(description = "Show misc. server info.", usage = "/<command>")
|
||||||
public class Command_status extends TFM_Command
|
public class Command_status extends TFM_Command
|
||||||
{
|
{
|
||||||
public static final Map<String, String> SERVICE_MAP = new HashMap<String, String>();
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
SERVICE_MAP.put("minecraft.net", "Minecraft.net");
|
|
||||||
SERVICE_MAP.put("login.minecraft.net", "Minecraft Logins");
|
|
||||||
SERVICE_MAP.put("session.minecraft.net", "Minecraft Multiplayer Sessions");
|
|
||||||
SERVICE_MAP.put("account.mojang.com", "Mojang Accounts Website");
|
|
||||||
SERVICE_MAP.put("auth.mojang.com", "Mojang Accounts Login");
|
|
||||||
SERVICE_MAP.put("skins.minecraft.net", "Minecraft Skins");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
@ -52,59 +27,6 @@ public class Command_status extends TFM_Command
|
|||||||
playerMsg(String.format("World %d: %s - %d players.", i++, world.getName(), world.getPlayers().size()), ChatColor.BLUE);
|
playerMsg(String.format("World %d: %s - %d players.", i++, world.getName(), world.getPlayers().size()), ChatColor.BLUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
server.getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
|
||||||
{
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
URL mojang_status = new URL("http://status.mojang.com/check");
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(mojang_status.openStream()));
|
|
||||||
JSONArray status_json = (JSONArray) JSONValue.parse(in.readLine());
|
|
||||||
in.close();
|
|
||||||
|
|
||||||
Map<String, Boolean> service_status = new HashMap<String, Boolean>();
|
|
||||||
|
|
||||||
Iterator status_it = status_json.iterator();
|
|
||||||
while (status_it.hasNext())
|
|
||||||
{
|
|
||||||
JSONObject service = (JSONObject) status_it.next();
|
|
||||||
Iterator service_it = service.entrySet().iterator();
|
|
||||||
while (service_it.hasNext())
|
|
||||||
{
|
|
||||||
Entry<String, String> pair = (Entry<String, String>) service_it.next();
|
|
||||||
service_status.put(pair.getKey(), (pair.getValue().equals("green") ? Boolean.TRUE : Boolean.FALSE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> status_output = new ArrayList<String>();
|
|
||||||
|
|
||||||
Iterator<Entry<String, Boolean>> output_it = service_status.entrySet().iterator();
|
|
||||||
while (output_it.hasNext())
|
|
||||||
{
|
|
||||||
Entry<String, Boolean> pair = output_it.next();
|
|
||||||
String service_name = pair.getKey();
|
|
||||||
boolean service_online = pair.getValue().booleanValue();
|
|
||||||
|
|
||||||
if (SERVICE_MAP.containsKey(service_name))
|
|
||||||
{
|
|
||||||
service_name = SERVICE_MAP.get(service_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
status_output.add(String.format("%s is %s", service_name, (service_online ? ChatColor.GREEN + "ONLINE" + ChatColor.GRAY : ChatColor.RED + "OFFLINE" + ChatColor.GRAY)));
|
|
||||||
}
|
|
||||||
|
|
||||||
playerMsg(String.format("Mojang Service Status: %s.", StringUtils.join(status_output, ", ")), ChatColor.GRAY);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
TFM_Log.severe(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
189
src/me/StevenLawson/TotalFreedomMod/TFM_ServiceChecker.java
Normal file
189
src/me/StevenLawson/TotalFreedomMod/TFM_ServiceChecker.java
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.apache.commons.lang.WordUtils;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.JSONValue;
|
||||||
|
|
||||||
|
|
||||||
|
public class TFM_ServiceChecker {
|
||||||
|
private static final Map<String, String[]> SERVICE_MAP = new HashMap<String, String[]>();
|
||||||
|
public static String check_url = "http://xpaw.ru/mcstatus/status.json";
|
||||||
|
public static String version = "1.0";
|
||||||
|
public static String last_updated = ""; // On xpaw.ru
|
||||||
|
static
|
||||||
|
{
|
||||||
|
// <"up", "down", "problem">, <"Online", "Quite Slow", "Error 505", etc>, <String (Uptime percentage)>
|
||||||
|
SERVICE_MAP.put("website", new String[]{"up", "Online", "100.00"});
|
||||||
|
SERVICE_MAP.put("session", new String[]{"up", "Online", "100.00"});
|
||||||
|
SERVICE_MAP.put("login", new String[]{"up", "Online", "100.00"});
|
||||||
|
SERVICE_MAP.put("account", new String[]{"up", "Online", "100.00"});
|
||||||
|
SERVICE_MAP.put("skins", new String[]{"up", "Online", "100.00"});
|
||||||
|
SERVICE_MAP.put("realms", new String[]{"up", "Online", "100.00"});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Runnable checker = new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
runCheck();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void runCheck()
|
||||||
|
{
|
||||||
|
TotalFreedomMod.server.getScheduler().runTaskAsynchronously(TotalFreedomMod.plugin, new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
/* // Nubcakes be 403'ing us >;o
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(new URL(check_url).openStream()));
|
||||||
|
JSONObject service_json = (JSONObject) JSONValue.parse(in.readLine());
|
||||||
|
in.close();
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Well, lets bypass that! >:D
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) new URL(check_url).openConnection();
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||||
|
connection.setRequestProperty("Host", "xpaw.ru");
|
||||||
|
connection.setRequestProperty("Accept", "*/*");
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setDoOutput(false);
|
||||||
|
InputStream is = connection.getInputStream();
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(is));
|
||||||
|
JSONObject service_json = (JSONObject) JSONValue.parse(in.readLine());
|
||||||
|
in.close();
|
||||||
|
connection.disconnect();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
version = String.valueOf(service_json.get("v"));
|
||||||
|
last_updated = (String) service_json.get("last_updated");
|
||||||
|
|
||||||
|
JSONObject services = (JSONObject) service_json.get("report");
|
||||||
|
for (String service: SERVICE_MAP.keySet())
|
||||||
|
{
|
||||||
|
JSONObject service_info = (JSONObject) services.get(service);
|
||||||
|
SERVICE_MAP.put(service, new String[]{
|
||||||
|
(String) service_info.get("status"),
|
||||||
|
(String) service_info.get("title"),
|
||||||
|
(String) service_info.get("uptime")});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFormattedStatus(String service_name)
|
||||||
|
{
|
||||||
|
String[] service = SERVICE_MAP.get(service_name);
|
||||||
|
String status = ("up".equals(service[0]) ? ChatColor.GREEN :
|
||||||
|
("down".equals(service[0]) ? ChatColor.RED : ChatColor.GOLD)).toString();
|
||||||
|
|
||||||
|
status += service[1] + ChatColor.GRAY + " (";
|
||||||
|
|
||||||
|
status += (Float.parseFloat(service[2]) >= 96.0 ? ChatColor.GREEN :
|
||||||
|
(Float.parseFloat(service[2]) > 90.0 ? ChatColor.GOLD : ChatColor.RED));
|
||||||
|
|
||||||
|
status += service[2] + "%" + ChatColor.GRAY + ")";
|
||||||
|
|
||||||
|
return ChatColor.GRAY + WordUtils.capitalize(service_name) + ChatColor.WHITE + ": " + status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getAllStatuses()
|
||||||
|
{
|
||||||
|
List<String> statuses = new ArrayList<String>();
|
||||||
|
for (String status : SERVICE_MAP.keySet())
|
||||||
|
{
|
||||||
|
statuses.add(getFormattedStatus(status));
|
||||||
|
}
|
||||||
|
return statuses;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* // Mojang status
|
||||||
|
public static final Map<String, String> SERVICE_MAP = new HashMap<String, String>();
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
SERVICE_MAP.put("minecraft.net", "Minecraft.net");
|
||||||
|
SERVICE_MAP.put("login.minecraft.net", "Minecraft Logins");
|
||||||
|
SERVICE_MAP.put("session.minecraft.net", "Minecraft Multiplayer Sessions");
|
||||||
|
SERVICE_MAP.put("account.mojang.com", "Mojang Accounts Website");
|
||||||
|
SERVICE_MAP.put("auth.mojang.com", "Mojang Accounts Login");
|
||||||
|
SERVICE_MAP.put("skins.minecraft.net", "Minecraft Skins");
|
||||||
|
}
|
||||||
|
server.getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
||||||
|
{
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
URL mojang_status = new URL("http://status.mojang.com/check");
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(mojang_status.openStream()));
|
||||||
|
JSONArray status_json = (JSONArray) JSONValue.parse(in.readLine());
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
Map<String, Boolean> service_status = new HashMap<String, Boolean>();
|
||||||
|
|
||||||
|
Iterator status_it = status_json.iterator();
|
||||||
|
while (status_it.hasNext())
|
||||||
|
{
|
||||||
|
JSONObject service = (JSONObject) status_it.next();
|
||||||
|
Iterator service_it = service.entrySet().iterator();
|
||||||
|
while (service_it.hasNext())
|
||||||
|
{
|
||||||
|
Entry<String, String> pair = (Entry<String, String>) service_it.next();
|
||||||
|
service_status.put(pair.getKey(), (pair.getValue().equals("green") ? Boolean.TRUE : Boolean.FALSE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> status_output = new ArrayList<String>();
|
||||||
|
|
||||||
|
Iterator<Entry<String, Boolean>> output_it = service_status.entrySet().iterator();
|
||||||
|
while (output_it.hasNext())
|
||||||
|
{
|
||||||
|
Entry<String, Boolean> pair = output_it.next();
|
||||||
|
String service_name = pair.getKey();
|
||||||
|
boolean service_online = pair.getValue().booleanValue();
|
||||||
|
|
||||||
|
if (SERVICE_MAP.containsKey(service_name))
|
||||||
|
{
|
||||||
|
service_name = SERVICE_MAP.get(service_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
status_output.add(String.format("%s is %s", service_name, (service_online ? ChatColor.GREEN + "ONLINE" + ChatColor.GRAY : ChatColor.RED + "OFFLINE" + ChatColor.GRAY)));
|
||||||
|
}
|
||||||
|
|
||||||
|
playerMsg(String.format("Mojang Service Status: %s.", StringUtils.join(status_output, ", ")), ChatColor.GRAY);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TFM_Log.severe(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
@ -30,6 +30,7 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
public static final Server server = Bukkit.getServer();
|
public static final Server server = Bukkit.getServer();
|
||||||
|
|
||||||
public static final long HEARTBEAT_RATE = 5L; //Seconds
|
public static final long HEARTBEAT_RATE = 5L; //Seconds
|
||||||
|
public static final long SERVICE_CHECKER_RATE = 30L;
|
||||||
|
|
||||||
public static final String CONFIG_FILE = "config.yml";
|
public static final String CONFIG_FILE = "config.yml";
|
||||||
public static final String SUPERADMIN_FILE = "superadmin.yml";
|
public static final String SUPERADMIN_FILE = "superadmin.yml";
|
||||||
@ -102,10 +103,16 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
|
|
||||||
TFM_Util.deleteFolder(new File("./_deleteme"));
|
TFM_Util.deleteFolder(new File("./_deleteme"));
|
||||||
|
|
||||||
|
// Heartbeat
|
||||||
server.getScheduler().scheduleSyncRepeatingTask(this, new TFM_Heartbeat(this), HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
|
server.getScheduler().scheduleSyncRepeatingTask(this, new TFM_Heartbeat(this), HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
|
||||||
|
|
||||||
|
// Service uptime checker
|
||||||
|
server.getScheduler().scheduleSyncRepeatingTask(this, TFM_ServiceChecker.checker, SERVICE_CHECKER_RATE * 20L, 5 * 20L);
|
||||||
|
|
||||||
TFM_CommandLoader.getInstance().scan();
|
TFM_CommandLoader.getInstance().scan();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// metrics @ http://mcstats.org/plugin/TotalFreedomMod
|
// metrics @ http://mcstats.org/plugin/TotalFreedomMod
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user