Skip to content

Commit

Permalink
Add debug recording + submission
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 20, 2013
1 parent eb3efac commit 522efd8
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
52 changes: 50 additions & 2 deletions src/main/java/net/aufdemrand/denizen/CommandHandler.java
@@ -1,6 +1,12 @@
package net.aufdemrand.denizen;


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.*;

import net.aufdemrand.denizen.listeners.AbstractListener;
Expand Down Expand Up @@ -697,13 +703,52 @@ public void chatbot(CommandContext args, CommandSender sender, NPC npc) throws C
}


/*
* DENIZEN SUBMIT
*/
@Command(
aliases = { "denizen" }, usage = "submit",
desc = "Submits recorded logs triggered by /denizen debug -r", modifiers = { "submit" },
min = 1, max = 3, permission = "denizen.submit")
public void submit(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (!dB.record) {
Messaging.send(sender, ChatColor.RED + "Use /denizen debug -r to record debug information to be submitted");
return;
}
dB.record = false;
try {

This comment has been minimized.

Copy link
@fullwall

fullwall Oct 20, 2013

Contributor

URL requests should be in a separate thread.

This comment has been minimized.

Copy link
@mcmonkey4eva

mcmonkey4eva Oct 20, 2013

Author Member

D: fiiiine I'll do it properly.

(I was so busy arguing with Java's poor attempts to use HTTP properly that I forgot to split it out when I finished. Thanks, fully!)

URL url = new URL("http://mcmonkey4eva.dyndns.org/paste");
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
uc.setDoInput(true);
uc.setDoOutput(true);
uc.setConnectTimeout(10000); // Max 10 seconds - don't crash a server if the pastebin is down!
uc.connect();
uc.getOutputStream().write(
("postid=pastetext&pastetype=log"
+ "&response=micro&pastetitle=Denizen+Debug+Logs+From+" + URLEncoder.encode(Bukkit.getServer().getMotd().replace(ChatColor.COLOR_CHAR, (char)0x01))
+ "&pastecontents=" + dB.Recording)
.getBytes("UTF-8"));
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
Messaging.send(sender, ChatColor.GREEN + "Successfully submitted to http://mcmonkey4eva.dyndns.org" + in.readLine());
in.close();
dB.Recording = "";
}
catch (Exception e) {
if (dB.showStackTraces) {
e.printStackTrace();
}
dB.Recording = "";
Messaging.send(sender, ChatColor.RED + "Error while submitting.");
}
}

/*
* DENIZEN DEBUG
*/
@Command(
aliases = { "denizen" }, usage = "debug",
desc = "Toggles debug mode for Denizen.", modifiers = { "debug", "de", "db" },
min = 1, max = 3, permission = "denizen.debug", flags = "sceb")
min = 1, max = 3, permission = "denizen.debug", flags = "scebr")
public void debug(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (args.hasFlag('s')) {
if (!dB.debugMode) dB.toggle();
Expand All @@ -717,10 +762,13 @@ public void debug(CommandContext args, CommandSender sender, NPC npc) throws Com
} else if (args.hasFlag('b')) {
if (!dB.debugMode) dB.toggle();
dB.showScriptBuilder = !dB.showScriptBuilder;
} else if (args.hasFlag('r')) {
dB.record = !dB.record;
dB.Recording = "";
} else dB.toggle();

Messaging.send(sender, ChatColor.YELLOW + "Denizen debugger is " + (dB.debugMode ?
((dB.showStackTraces) ? "enabled and showing stack-traces." : "enabled.") : "disabled."));
((dB.showStackTraces) ? "enabled and showing stack-traces." : "enabled.") : "disabled.") + (dB.record ? " (Recording Active)": ""));
}

/*
Expand Down
Expand Up @@ -1048,7 +1048,7 @@ public void run() {
// <0-23>:00 in <world>
// time <0-23> in <world>
//
// @Triggers when a block is set on fire.
// @Triggers when the current time changes in a world (once per mine-hour).
// @Context
// <context.time> returns the current time.
// <context.world> returns the world.
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/aufdemrand/denizen/tags/core/TextTags.java
Expand Up @@ -81,6 +81,8 @@ else if (event.getName().equals("&Uuml"))
final String[] code = {"0","1","2","3","4","5","6","7","8","9"
,"a","b","c","d","e","f","k","l","m","n","o","r"};

// TODO: Meta for all of these! All of them!

@EventHandler
public void colorTags(ReplaceableTagEvent event) {
Attribute attribute =
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/net/aufdemrand/denizen/tags/core/UtilTags.java
Expand Up @@ -285,7 +285,6 @@ public void serverTags(ReplaceableTagEvent event) {
// @description
// Returns a list of all offline ops.
// -->
// server.list_offline_ops
if (attribute.startsWith("list_offline_ops")) {
ArrayList<dPlayer> players = new ArrayList<dPlayer>();
for (OfflinePlayer player : Bukkit.getOfflinePlayers())
Expand All @@ -294,6 +293,18 @@ public void serverTags(ReplaceableTagEvent event) {
return;
}

// <--[tag]
// @attribute <server.motd>
// @returns Element
// @description
// Returns the server's current MOTD
// -->
if (attribute.startsWith("list_offline_ops")) {
event.setReplaced(new Element(Bukkit.getServer().getMotd()).getAttribute(attribute.fulfill(1)));
return;
}
// TODO: Add everything else from Bukkit.getServer().*

}

@EventHandler
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/net/aufdemrand/denizen/utilities/debugging/dB.java
Expand Up @@ -6,6 +6,8 @@
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.net.URLEncoder;
import java.util.Calendar;

/**
* Preferred method of outputting debugger information with Denizen and
Expand Down Expand Up @@ -59,6 +61,8 @@ public class dB {
public static boolean showScriptBuilder = false;
public static boolean showColor = true;
public static boolean showEventsFiring = false;
public static boolean record = false;
public static String Recording = "";

/**
* Can be used with echoDebug(...) to output a header, footer,
Expand Down Expand Up @@ -132,9 +136,26 @@ public static void sendMessage(String string) {
} // 16:05:06 [INFO]
}
// Send buffer to the player
dB.Recording += URLEncoder.encode(getDate() + " [INFO] " + buffer.replace(ChatColor.COLOR_CHAR, (char)0x01) + "\n");

This comment has been minimized.

Copy link
@aufdemrand

aufdemrand Oct 21, 2013

Contributor

I think this is causing issue #482

This comment has been minimized.

Copy link
@mcmonkey4eva

mcmonkey4eva Oct 21, 2013

Author Member

Ooops! I forgot to check if recording was active. Eck!

if (showColor)
commandSender.sendMessage(buffer);
else commandSender.sendMessage(ChatColor.stripColor(buffer));


}

static String getDate() {
Calendar calendar = Calendar.getInstance();

This comment has been minimized.

Copy link
@fullwall

fullwall Oct 21, 2013

Contributor

Really slow to call this every debug call. Just send the System.currentTimeMillis() and decode it on the server.

int h = calendar.get(Calendar.HOUR_OF_DAY);
int m = calendar.get(Calendar.MINUTE);
int s = calendar.get(Calendar.SECOND);
String toret = "";
if (h < 10) toret += "0" + h; else toret += h;
toret += ":";
if (m < 10) toret += "0" + m; else toret += m;
toret += ":";
if (s < 10) toret += "0" + s; else toret += s;
return toret;
}
}

Expand Down

0 comments on commit 522efd8

Please sign in to comment.