From ce6767c717842014da6c1a25aa8ff0945f1d5c58 Mon Sep 17 00:00:00 2001 From: SuPaH sPii Date: Wed, 2 Jan 2013 14:09:08 -0600 Subject: [PATCH] Add new feature to Pastebin reports! Test permission of other players! ./anticheat debug --- .../net/h31ix/anticheat/CommandHandler.java | 12 +++ .../h31ix/anticheat/util/Configuration.java | 4 + .../h31ix/anticheat/util/PastebinReport.java | 100 +++++++++++++++++- 3 files changed, 115 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/h31ix/anticheat/CommandHandler.java b/src/main/java/net/h31ix/anticheat/CommandHandler.java index 04a1028..985a659 100644 --- a/src/main/java/net/h31ix/anticheat/CommandHandler.java +++ b/src/main/java/net/h31ix/anticheat/CommandHandler.java @@ -87,6 +87,16 @@ public class CommandHandler implements CommandExecutor { } } + public void handleDebug(CommandSender cs, Player tp) { + if (Permission.SYSTEM_REPORT.get(cs)) { + PastebinReport report = new PastebinReport(cs, tp); + cs.sendMessage(GREEN + "Debug information posted to: " + WHITE + report.getURL()); + cs.sendMessage(GREEN + "Please include this link when making bug reports."); + } else { + cs.sendMessage(PERMISSIONS_ERROR); + } + } + public void handleXRay(CommandSender cs, String[] args) { if (Permission.SYSTEM_XRAY.get(cs)) { if (CONFIG.logXRay()) { @@ -411,6 +421,8 @@ public class CommandHandler implements CommandExecutor { handleLog(cs, args); } else if (args[0].equalsIgnoreCase("xray")) { handleXRay(cs, args); + } else if (args[0].equalsIgnoreCase("debug")) { + handleDebug(cs, Bukkit.getPlayer(args[1])); } else if (args[0].equalsIgnoreCase("reset")) { handleReset(cs, args); } else if (args[0].equalsIgnoreCase("spy")) { diff --git a/src/main/java/net/h31ix/anticheat/util/Configuration.java b/src/main/java/net/h31ix/anticheat/util/Configuration.java index 45b5789..7f09c18 100644 --- a/src/main/java/net/h31ix/anticheat/util/Configuration.java +++ b/src/main/java/net/h31ix/anticheat/util/Configuration.java @@ -305,4 +305,8 @@ public class Configuration { Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex); } } + + public String getMainConfigurationDump() { + return config.saveToString(); + } } diff --git a/src/main/java/net/h31ix/anticheat/util/PastebinReport.java b/src/main/java/net/h31ix/anticheat/util/PastebinReport.java index 02d0da1..52a5154 100644 --- a/src/main/java/net/h31ix/anticheat/util/PastebinReport.java +++ b/src/main/java/net/h31ix/anticheat/util/PastebinReport.java @@ -51,6 +51,21 @@ public class PastebinReport { postReport(); } + public PastebinReport(CommandSender cs, Player tp) { + Player player = null; + if (tp == null) { + cs.sendMessage(ChatColor.RED + "We were unable to detect the target player when making this report. Skipping permstester"); + } else { + player = tp; + } + + createReport(player); + try { + writeReport(); + } catch (IOException e) {} + postReport(); + } + public String getURL() { return url; } @@ -62,8 +77,14 @@ public class PastebinReport { for (Permission node : Permission.values()) { report.append(player.getName() + ": " + node.toString() + " " + node.get(player) + '\n'); } - } + /* Not working at the moment. + private void dumpConfiguration() { + report.append("------------Main Configuration (differences only)-----------" + '\n'); + report.append(writeDifferencesByLine(Anticheat.getManager().getConfiguration().getMainConfigurationDump(), getDataFromURL("https://raw.github.com/h31ix/AntiCheat/master/src/main/resources/config.yml"))); + report.append("------------Magic Configuration (differences only)-----------" + '\n'); + report.append(writeDifferencesByLine(Anticheat.getManager().getConfiguration().getMagic().saveToString(), getDataFromURL("https://raw.github.com/h31ix/AntiCheat/master/src/main/resources/magic.yml"))); + } */ private void createReport(Player player) { report.append("------------ AntiCheat Report - " + format.format(date) + " ------------" + '\n'); @@ -77,6 +98,7 @@ public class PastebinReport { } report.append("------------Permission Tester------------" + '\n'); appendPermissionsTester(player); + //dumpConfiguration(); report.append("------------Event Chains------------" + '\n'); eventHandlersDump(); report.append("-----------End Of Report------------"); @@ -148,4 +170,80 @@ public class PastebinReport { } } + private static String getDataFromURL(String url) { + try { + URL urls = new URL(url); + HttpURLConnection conn = (HttpURLConnection) urls.openConnection(); + conn.setConnectTimeout(5000); + conn.setReadTimeout(5000); + conn.setRequestMethod("GET"); + conn.setInstanceFollowRedirects(false); + conn.setDoOutput(true); + OutputStream out = conn.getOutputStream(); + + out.flush(); + out.close(); + + if (conn.getResponseCode() == 200) { + InputStream receive = conn.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(receive)); + String line; + StringBuffer response = new StringBuffer(); + while ((line = reader.readLine()) != null) { + response.append(line); + response.append("\n"); + } + reader.close(); + + String result = response.toString().trim(); + System.out.println(result); + url = result; + } else { + url = "Failed to get"; + } + } catch (Exception e) { + e.printStackTrace(); + url = "Failed to get"; + } + + return url; + } + + private static String writeDifferencesByLine(String one, String two) { + String diff = ""; + String[] diff1 = one.split("\n"); + String[] diff2 = two.split("\n"); + int i = 0; + while (true) { + if (i >= diff1.length) { + for(int g = i; g < diff2.length; g++) { + diff += diff2[g] + " (End of File)" + '\n'; + } + break; + } else if (i >= diff2.length) { + for(int g = i; g < diff1.length; g++) { + diff += diff1[g] + " (End of File)" + '\n'; + } + break; + } + + String d1 = diff1[i]; + String d2 = diff2[i]; + + if (d1.startsWith("#") || d2.startsWith("#")) + { + i++; + continue; + } + + if(!d1.equalsIgnoreCase(d2)) { + diff += d1 + " (" + d2 + ")" + '\n'; + } + + i++; + } + + return two; + } + }