forked from ChomeNS/chomens-bot-java
add packet sniffer for some reason
This commit is contained in:
parent
61930c8c37
commit
85c779062a
2 changed files with 42 additions and 0 deletions
|
@ -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<Bot> 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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue