Finished TFM_ServiceChecker, added /services

This commit is contained in:
JeromSar 2013-08-09 17:08:16 +02:00
parent 5b34facdd3
commit 03553b6254
6 changed files with 51 additions and 20 deletions

View File

@ -1,6 +1,6 @@
#Mon, 29 Jul 2013 20:32:38 -0400
#Fri, 09 Aug 2013 17:04:56 +0200
program.VERSION=2.21
program.BUILDNUM=370
program.BUILDDATE=07/29/2013 08\:32 PM
program.BUILDNUM=384
program.BUILDDATE=08/09/2013 05\:04 PM

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Mon Jul 29 20:32:38 EDT 2013
build.number=371
#Fri Aug 09 17:04:56 CEST 2013
build.number=385

View File

@ -138,4 +138,3 @@ logs_register_url:
# Mojang service checker
service_checker_url: http://status.mojang.com/check
service_checker_timeout: 200

View File

@ -0,0 +1,28 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ServiceChecker;
import me.StevenLawson.TotalFreedomMod.TFM_ServiceChecker.TFM_ServiceChecker_ServiceStatus;
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 status of all Mojang services", usage = "/<command>")
public class Command_services extends TFM_Command {
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
playerMsg("Mojang Services" + ChatColor.WHITE + ":", ChatColor.BLUE);
for (TFM_ServiceChecker_ServiceStatus service : TFM_ServiceChecker.getInstance().getAllStatuses())
{
playerMsg(service.getFormattedStatus());
}
playerMsg("Version" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getInstance().version, ChatColor.DARK_PURPLE);
playerMsg("Last Check" + ChatColor.WHITE + ": " + TFM_ServiceChecker.getInstance().lastCheck, ChatColor.DARK_PURPLE);
return true;
}
}

View File

@ -2,7 +2,6 @@ package me.StevenLawson.TotalFreedomMod;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
@ -19,23 +18,24 @@ import org.json.simple.JSONValue;
public class TFM_ServiceChecker
{
public final Map<String, TFM_ServiceChecker_ServiceStatus> services = new HashMap<String, TFM_ServiceChecker_ServiceStatus>();
public String lastCheck = "never";
public String lastCheck = "Unknown";
public String version = "1.0-Mojang";
public TFM_ServiceChecker()
{
services.put("minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft.net"));
services.put("login.minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft Logins"));
services.put("session.minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft Multiplayer Sessions"));
services.put("account.mojang.com", new TFM_ServiceChecker_ServiceStatus("Mojang Accounts Website"));
services.put("auth.mojang.com", new TFM_ServiceChecker_ServiceStatus("Mojang Accounts Login"));
services.put("account.mojang.com", new TFM_ServiceChecker_ServiceStatus("Mojang Account Website"));
services.put("authserver.mojang.com", new TFM_ServiceChecker_ServiceStatus("Mojang Authentication"));
services.put("skins.minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft Skins"));
services.put("auth.mojang.com", new TFM_ServiceChecker_ServiceStatus("Mojang Authentiation (Legacy)"));
services.put("login.minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft Logins (Legacy)"));
services.put("session.minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft Sessions (Legacy)"));
}
public void update()
public BukkitRunnable getUpdateRunnable()
{
new BukkitRunnable()
return new BukkitRunnable()
{
@Override
@ -58,6 +58,7 @@ public class TFM_ServiceChecker
while (service_it.hasNext())
{
Entry<String, String> pair = (Entry<String, String>) service_it.next();
if ("lastcheck".equals(pair.getKey()))
{
serviceChecker.lastCheck = pair.getValue();
@ -82,19 +83,19 @@ public class TFM_ServiceChecker
{
TFM_ServiceChecker_ServiceStatus status = serviceChecker.services.get(pair.getKey());
status.setColor(pair.getValue());
status.setMessage(("red".equals(pair.getValue()) ? "Offline" : ("yellow".equals(pair.getValue()) ? "Problem" : "Offline")));
status.setMessage(("red".equals(pair.getValue()) ? "Offline" : ("yellow".equals(pair.getValue()) ? "Problem" : "Online")));
}
}
}
TFM_Log.info("Mojang Service pull completed.");
}
catch (Exception ex)
{
TFM_Log.severe("Error updating mojang services from " + TotalFreedomMod.serviceCheckerURL);
TFM_Log.severe(ex);
}
}
}.runTaskAsynchronously(TotalFreedomMod.plugin);
};
}
public List<TFM_ServiceChecker_ServiceStatus> getAllStatuses()
@ -121,7 +122,7 @@ public class TFM_ServiceChecker
{
private String name;
private String uptime = "100.0"; // skins.minecraft.net, minecraft.net, etc..
private ChatColor color = ChatColor.GREEN;
private ChatColor color = ChatColor.DARK_GREEN;
private String message = "Online"; // Online, Offline, Quite Slow, 404 Error, 500 Error, etc..
public TFM_ServiceChecker_ServiceStatus(String name)
@ -161,7 +162,7 @@ public class TFM_ServiceChecker
public String getFormattedStatus()
{
String status = ChatColor.BLUE + "- " + name + ChatColor.WHITE + ": " + color + message + ChatColor.WHITE;
String status = ChatColor.BLUE + "- " + ChatColor.GRAY + name + ChatColor.WHITE + ": " + color + message + ChatColor.WHITE;
if (!TFM_ServiceChecker.getInstance().version.contains("Mojang"))
{

View File

@ -29,7 +29,7 @@ public class TotalFreedomMod extends JavaPlugin
public static final Server server = Bukkit.getServer();
//
public static final long HEARTBEAT_RATE = 5L; //Seconds
public static final long SERVICE_CHECKER_RATE = 30L;
public static final long SERVICE_CHECKER_RATE = 120L;
//
public static final String CONFIG_FILE = "config.yml";
public static final String SUPERADMIN_FILE = "superadmin.yml";
@ -143,6 +143,8 @@ public class TotalFreedomMod extends JavaPlugin
TFM_Log.info("Plugin Enabled - Version: " + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber + " by Madgeek1450 and DarthSalamon");
TFM_ServiceChecker.getInstance().getUpdateRunnable().runTaskTimerAsynchronously(plugin, 40L, SERVICE_CHECKER_RATE * 20L);
new BukkitRunnable()
{
@Override
@ -152,6 +154,7 @@ public class TotalFreedomMod extends JavaPlugin
TFM_CommandBlockerNew.getInstance().parseBlockingRules();
}
}.runTaskLater(this, 20L);
}
@Override