Add debug logging + more cleanup

Dieser Commit ist enthalten in:
md_5 2013-02-09 20:27:25 +11:00
Ursprung f4572d5786
Commit 41579ff315

Datei anzeigen

@ -1,4 +1,4 @@
From fd95cfd6ba9e74b9c1d8a62f2c53e321bf142681 Mon Sep 17 00:00:00 2001 From 9e2329b60e63dbab24af3aa6cc7bbeac3bdb25fc Mon Sep 17 00:00:00 2001
From: md_5 <md_5@live.com.au> From: md_5 <md_5@live.com.au>
Date: Sun, 3 Feb 2013 10:24:33 +1100 Date: Sun, 3 Feb 2013 10:24:33 +1100
Subject: [PATCH] Netty Subject: [PATCH] Netty
@ -16,13 +16,13 @@ This commit is licensed under the Creative Commons Attribution-ShareAlike 3.0 Un
.../java/net/minecraft/server/DedicatedServer.java | 2 +- .../java/net/minecraft/server/DedicatedServer.java | 2 +-
.../net/minecraft/server/PendingConnection.java | 11 +- .../net/minecraft/server/PendingConnection.java | 11 +-
src/main/java/org/spigotmc/netty/CipherCodec.java | 65 ++++++ src/main/java/org/spigotmc/netty/CipherCodec.java | 65 ++++++
.../org/spigotmc/netty/NettyNetworkManager.java | 178 +++++++++++++++ .../org/spigotmc/netty/NettyNetworkManager.java | 192 ++++++++++++++++
.../org/spigotmc/netty/NettyServerConnection.java | 99 ++++++++ .../org/spigotmc/netty/NettyServerConnection.java | 99 ++++++++
.../org/spigotmc/netty/NettySocketAdaptor.java | 248 +++++++++++++++++++++ .../org/spigotmc/netty/NettySocketAdaptor.java | 248 +++++++++++++++++++++
.../java/org/spigotmc/netty/PacketDecoder.java | 52 +++++ .../java/org/spigotmc/netty/PacketDecoder.java | 52 +++++
.../java/org/spigotmc/netty/PacketEncoder.java | 43 ++++ .../java/org/spigotmc/netty/PacketEncoder.java | 43 ++++
.../java/org/spigotmc/netty/PacketListener.java | 100 +++++++++ .../java/org/spigotmc/netty/PacketListener.java | 100 +++++++++
10 files changed, 804 insertions(+), 4 deletions(-) 10 files changed, 818 insertions(+), 4 deletions(-)
create mode 100644 src/main/java/org/spigotmc/netty/CipherCodec.java create mode 100644 src/main/java/org/spigotmc/netty/CipherCodec.java
create mode 100644 src/main/java/org/spigotmc/netty/NettyNetworkManager.java create mode 100644 src/main/java/org/spigotmc/netty/NettyNetworkManager.java
create mode 100644 src/main/java/org/spigotmc/netty/NettyServerConnection.java create mode 100644 src/main/java/org/spigotmc/netty/NettyServerConnection.java
@ -176,10 +176,10 @@ index 0000000..cfc0535
+} +}
diff --git a/src/main/java/org/spigotmc/netty/NettyNetworkManager.java b/src/main/java/org/spigotmc/netty/NettyNetworkManager.java diff --git a/src/main/java/org/spigotmc/netty/NettyNetworkManager.java b/src/main/java/org/spigotmc/netty/NettyNetworkManager.java
new file mode 100644 new file mode 100644
index 0000000..2da2422 index 0000000..c10d391
--- /dev/null --- /dev/null
+++ b/src/main/java/org/spigotmc/netty/NettyNetworkManager.java +++ b/src/main/java/org/spigotmc/netty/NettyNetworkManager.java
@@ -0,0 +1,178 @@ @@ -0,0 +1,192 @@
+package org.spigotmc.netty; +package org.spigotmc.netty;
+ +
+import io.netty.channel.Channel; +import io.netty.channel.Channel;
@ -192,6 +192,7 @@ index 0000000..2da2422
+import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ExecutorService; +import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors; +import java.util.concurrent.Executors;
+import java.util.logging.Level;
+import javax.crypto.SecretKey; +import javax.crypto.SecretKey;
+import net.minecraft.server.Connection; +import net.minecraft.server.Connection;
+import net.minecraft.server.INetworkManager; +import net.minecraft.server.INetworkManager;
@ -200,6 +201,7 @@ index 0000000..2da2422
+import net.minecraft.server.Packet252KeyResponse; +import net.minecraft.server.Packet252KeyResponse;
+import net.minecraft.server.PendingConnection; +import net.minecraft.server.PendingConnection;
+import org.bouncycastle.crypto.BufferedBlockCipher; +import org.bouncycastle.crypto.BufferedBlockCipher;
+import org.bukkit.Bukkit;
+ +
+/** +/**
+ * This class forms the basis of the Netty integration. It implements + * This class forms the basis of the Netty integration. It implements
@ -209,6 +211,9 @@ index 0000000..2da2422
+public class NettyNetworkManager extends ChannelInboundMessageHandlerAdapter<Packet> implements INetworkManager { +public class NettyNetworkManager extends ChannelInboundMessageHandlerAdapter<Packet> implements INetworkManager {
+ +
+ private static final ExecutorService threadPool = Executors.newCachedThreadPool(); + private static final ExecutorService threadPool = Executors.newCachedThreadPool();
+ private static final MinecraftServer server = MinecraftServer.getServer();
+ private static final NettyServerConnection serverConnection = (NettyServerConnection) server.ae();
+ /*========================================================================*/
+ private Queue<Packet> syncPackets = new ConcurrentLinkedQueue<Packet>(); + private Queue<Packet> syncPackets = new ConcurrentLinkedQueue<Packet>();
+ private Channel channel; + private Channel channel;
+ private SocketAddress address; + private SocketAddress address;
@ -220,27 +225,36 @@ index 0000000..2da2422
+ +
+ @Override + @Override
+ public void channelActive(ChannelHandlerContext ctx) throws Exception { + public void channelActive(ChannelHandlerContext ctx) throws Exception {
+ // Channel and address groundwork first
+ channel = ctx.channel(); + channel = ctx.channel();
+ address = channel.remoteAddress(); + address = channel.remoteAddress();
+ // Then the socket adaptor
+ socketAdaptor = NettySocketAdaptor.adapt((SocketChannel) channel); + socketAdaptor = NettySocketAdaptor.adapt((SocketChannel) channel);
+ handler = new PendingConnection(MinecraftServer.getServer(), this); + // Followed by their first handler
+ ((NettyServerConnection) MinecraftServer.getServer().ae()).pendingConnections.add((PendingConnection) handler); + handler = new PendingConnection(server, this);
+ // Finally register the connection
+ serverConnection.pendingConnections.add((PendingConnection) handler);
+ } + }
+ +
+ @Override + @Override
+ public void channelInactive(ChannelHandlerContext ctx) throws Exception { + public void channelInactive(ChannelHandlerContext ctx) throws Exception {
+ // Disconnect via the handler - this performs all plugin related cleanup + logging
+ if (dcReason != null || dcArgs != null) { + if (dcReason != null || dcArgs != null) {
+ handler.a(dcReason, dcArgs); + handler.a(dcReason, dcArgs);
+ } + }
+ // Remove channel reference to indicate we are done
+ channel = null; + channel = null;
+ syncPackets.clear();
+ } + }
+ +
+ @Override + @Override
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+ if (channel != null) { + // TODO: Remove this once we are more stable
+ a("disconnect.genericReason", new Object[]{"Internal exception: " + cause}); + Bukkit.getServer().getLogger().severe("======================= Start Netty Debug Log =======================");
+ } + Bukkit.getServer().getLogger().log(Level.SEVERE, "Error caught whilst handling " + channel, cause);
+ Bukkit.getServer().getLogger().severe("======================= End Netty Debug Log =======================");
+
+ // Disconnect with generic reason + exception
+ a("disconnect.genericReason", new Object[]{"Internal exception: " + cause});
+ } + }
+ +
+ @Override + @Override