Introduced new "pluginreport" permission node and command that will allow for basic information about the server on which the plugin is being used to be easily transmitted to us.

This commit is contained in:
David Berdik 2016-02-14 14:18:44 -05:00
parent d54f9f0e2b
commit 335d078b3f
3 changed files with 185 additions and 4 deletions

View File

@ -0,0 +1,130 @@
package net.theprogrammersworld.herobrine.AI;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStreamWriter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import net.theprogrammersworld.herobrine.ConfigDB;
public class BugReport {
public static String sendBugReport(Player player, String[] messageWords) {
// Collect the necessary information and POST it to the server where bug reports will be
// collected. Based on the result of the submission, return a string.
// (0 = report failed, 1 = unofficial version, 2 = unsupported version, Report ID => success)
String report;
String checksum;
// Collect basic information including the UUID of the player who made the submission, the
// IP address of the server, the port on which the server is running, and the plugin version.
String playerUUID;
try {
playerUUID = player.getUniqueId().toString();
} catch (Exception e) {
playerUUID = "CONSOLE";
}
report = "Submission UUID: " + playerUUID + "\r\n" +
"Server IP Address: " + getServerIP() + "\r\n" +
"Server Port: " + Bukkit.getServer().getPort() + "\r\n" +
"Version: " + ConfigDB.pluginVersionNumber + "\r\n\r\n";
// Assemble the array of words in to a single message.
for(int x = 1; x < messageWords.length; x++) {
report += messageWords[x] + " ";
}
// Determine the MD5 hash of the plugin.
checksum = computeMD5();
// After all of the necessary information has been acquired, submit the report.
try {
String postData = URLEncoder.encode("report", "UTF-8") + "=" + URLEncoder.encode(report, "UTF-8") +
"&" + URLEncoder.encode("checksum", "UTF-8") + "=" + URLEncoder.encode(checksum, "UTF-8");
URL submitURL = new URL("https://theprogrammersworld.net/Herobrine/pluginBugReporter.php");
URLConnection urlConn = submitURL.openConnection();
urlConn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(urlConn.getOutputStream());
wr.write(postData);
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String serverResponse;
while((serverResponse = rd.readLine()) != null) {
if(serverResponse.equals("1")) {
// Report Failed - Unofficial Version
rd.close();
wr.close();
return "1";
}
else if(serverResponse.equals("2")) {
// Report Failed - Unsupported Version
rd.close();
wr.close();
return "2";
}
else if(serverResponse.equals("3")) {
// Report Successful - Get the Report ID
String reportID = rd.readLine();
rd.close();
wr.close();
return reportID;
}
}
} catch (Exception e){}
// The report failed because for some reason, the server could not be reached.
return "0";
}
private static String getServerIP() {
// Get the IP address of the server by calling a page on the website that will return the IP.
URL ipFetchURL;
try {
ipFetchURL = new URL("https://theprogrammersworld.net/Herobrine/pluginIPFetcher.php");
InputStreamReader ipFetchISR = new InputStreamReader(ipFetchURL.openStream());
BufferedReader ipFetchBR = new BufferedReader(ipFetchISR);
String ipAddress = ipFetchBR.readLine();
ipFetchBR.close();
ipFetchISR.close();
return ipAddress;
} catch (Exception e) {
return "";
}
}
private static String computeMD5() {
// Determine the MD5 hash of the plugin.
File pluginFile = new File(BugReport.class.getProtectionDomain().getCodeSource().getLocation().getPath());
String filepath = pluginFile.getAbsolutePath();
StringBuilder hash = new StringBuilder();
try
{
MessageDigest md = MessageDigest.getInstance("MD5");
FileInputStream fis = new FileInputStream(filepath);
byte[] dataBytes = new byte[1024];
int nread = 0;
while((nread = fis.read(dataBytes)) != -1)
md.update(dataBytes, 0, nread);
byte[] mdbytes = md.digest();
for(int i=0; i<mdbytes.length; i++)
hash.append(Integer.toString((mdbytes[i] & 0xff) + 0x100 , 16).substring(1));
fis.close();
return hash.toString();
}
catch(Exception e)
{
return "";
}
}
}

View File

@ -89,10 +89,10 @@ public class ConfigDB
public boolean UseSound = true;
public boolean ShowInTabList = false;
public boolean CheckForUpdates = true;
public static String pluginVersionNumber = Bukkit.getServer().getPluginManager().getPlugin("Herobrine").
getDescription().getVersion();
private boolean isStartupDone = false;
private String pluginVersionNumber = Bukkit.getServer().getPluginManager().getPlugin("Herobrine").
getDescription().getVersion();
public ConfigDB(Logger l)
{

View File

@ -4,6 +4,7 @@ import java.util.logging.Logger;
import net.theprogrammersworld.herobrine.Herobrine;
import net.theprogrammersworld.herobrine.AI.AICore;
import net.theprogrammersworld.herobrine.AI.BugReport;
import net.theprogrammersworld.herobrine.AI.Core;
import net.theprogrammersworld.herobrine.AI.Message;
import net.theprogrammersworld.herobrine.AI.Help;
@ -530,6 +531,35 @@ public class CmdExecutor implements CommandExecutor {
+ ChatColor.GREEN
+ "/herobrine speak <message>");
}
} else if (args[0].equalsIgnoreCase("pluginreport")) {
if (args.length > 1) {
if(player.hasPermission("herobrine.pluginreport")) {
String reportResponse = BugReport.sendBugReport(null, args);
if(reportResponse.equals("0"))
player.sendMessage(ChatColor.RED + "Your report was not was submitted because the report server could not " +
"be reached. Please try again later.");
else if(reportResponse.equals("1"))
player.sendMessage(ChatColor.RED + "Your report was not submitted because this version of Herobrine does not " +
"appear to be an official release. Please download an official version of the " +
"plugin at: https://www.theprogrammersworld.net/Herobrine/download.php");
else if(reportResponse.equals("2"))
player.sendMessage(ChatColor.RED + "Your report was not submitted because this version of Herobrine is no " +
"longer supported. Please download a newer version of the plugin at: " +
"https://www.theprogrammersworld.net/Herobrine/download.php");
else
player.sendMessage(ChatColor.GREEN + "Your report was successfully submitted. For further assistance, please " +
"post on our forum at https://www.theprogrammersworld.net/forum/ and " +
"reference this report in your post with the following ID: " +
reportResponse);
} else {
player.sendMessage(ChatColor.RED
+ "You do not have the necessary permissions to submit Herobrine bug reports.");
}
} else {
player.sendMessage(ChatColor.RED + "Usage: "
+ ChatColor.GREEN
+ "/herobrine pluginreport <message>");
}
} else if (args[0].equalsIgnoreCase("cancel")) {
if (player.hasPermission("herobrine.cancel")) {
P_Core.getAICore().cancelTarget(Core.CoreType.ANY);
@ -894,6 +924,28 @@ public class CmdExecutor implements CommandExecutor {
} else {
log.info("Usage: /herobrine speak <message>");
}
} else if (args[0].equalsIgnoreCase("pluginreport")) {
if (args.length > 1) {
String reportResponse = BugReport.sendBugReport(null, args);
if(reportResponse.equals("0"))
log.info("Your report was not was submitted because the report server could not " +
"be reached. Please try again later.");
else if(reportResponse.equals("1"))
log.info("Your report was not submitted because this version of Herobrine does not " +
"appear to be an official release. Please download an official version of the " +
"plugin at: https://www.theprogrammersworld.net/Herobrine/download.php");
else if(reportResponse.equals("2"))
log.info("Your report was not submitted because this version of Herobrine is no " +
"longer supported. Please download a newer version of the plugin at: " +
"https://www.theprogrammersworld.net/Herobrine/download.php");
else
log.info("Your report was successfully submitted. For further assistance, please " +
"post on our forum at https://www.theprogrammersworld.net/forum/ and " +
"reference this report in your post with the following ID: " +
reportResponse);
} else {
log.info("Usage: /herobrine pluginreport <message>");
}
} else if (args[0].equalsIgnoreCase("cancel")) {
P_Core.getAICore().cancelTarget(Core.CoreType.ANY);
log.info(ChatColor.RED
@ -928,8 +980,7 @@ public class CmdExecutor implements CommandExecutor {
log.info("/herobrine speakrandom <player> - Sends a random Herobrine message to the player");
log.info("/herobrine speak <message> - Sends a chat message on Herobrine's behalf");
log.info("/herobrine allworlds - Grants Herobrine access to all worlds");
}
if (args[0].equalsIgnoreCase("allworlds")) {
} else if (args[0].equalsIgnoreCase("allworlds")) {
Herobrine.getPluginCore().getConfigDB().addAllWorlds();
log.info("[Herobrine] All worlds have been added to the configuration file. Herobrine can now access all of the server's worlds.");
log.info("[Herobrine] WARNING! - One or more worlds was determined to have a space in its name. Please be aware that worlds with spaces in their name may cause problems.");