From 85c779062a421b1f5c625f32a5b52c06f22fd9f0 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 11 Jun 2023 16:39:30 +0700 Subject: [PATCH] add packet sniffer for some reason --- .../chipmunk/chayapak/chomens_bot/Bot.java | 2 + .../plugins/PacketSnifferPlugin.java | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PacketSnifferPlugin.java diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java index 4010e2f..1f9164f 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java @@ -71,6 +71,7 @@ public class Bot { @Getter private FilterPlugin filter; @Getter private CommandSuggestionPlugin commandSuggestion; @Getter private MailPlugin mail; + @Getter private PacketSnifferPlugin packetSniffer; public Bot (Configuration.BotOption botOption, List bots, Configuration config) { this.host = botOption.host; @@ -115,6 +116,7 @@ public class Bot { this.filter = new FilterPlugin(this); this.commandSuggestion = new CommandSuggestionPlugin(this); this.mail = new MailPlugin(this); + this.packetSniffer = new PacketSnifferPlugin(this); for (Listener listener : listeners) listener.loadedPlugins(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PacketSnifferPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PacketSnifferPlugin.java new file mode 100644 index 0000000..945bf07 --- /dev/null +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PacketSnifferPlugin.java @@ -0,0 +1,40 @@ +package land.chipmunk.chayapak.chomens_bot.plugins; + +import com.github.steveice10.packetlib.Session; +import com.github.steveice10.packetlib.packet.Packet; +import land.chipmunk.chayapak.chomens_bot.Bot; +import lombok.Getter; +import lombok.Setter; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; + +public class PacketSnifferPlugin extends Bot.Listener { + @Getter @Setter private boolean enabled = false; + + private OutputStreamWriter writer; + + public PacketSnifferPlugin (Bot bot) { + if (!enabled) return; + + try { + writer = new OutputStreamWriter(new FileOutputStream("packets.log"), StandardCharsets.UTF_8); + } catch (IOException e) { + e.printStackTrace(); + } + + bot.addListener(this); + } + + @Override + public void packetReceived(Session session, Packet packet) { + try { + writer.write(packet.toString() + "\n"); + writer.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } +}