Add debug logging + more cleanup
This commit is contained in:
parent
f4572d5786
commit
41579ff315
@ -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>
|
||||
Date: Sun, 3 Feb 2013 10:24:33 +1100
|
||||
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 +-
|
||||
.../net/minecraft/server/PendingConnection.java | 11 +-
|
||||
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/NettySocketAdaptor.java | 248 +++++++++++++++++++++
|
||||
.../java/org/spigotmc/netty/PacketDecoder.java | 52 +++++
|
||||
.../java/org/spigotmc/netty/PacketEncoder.java | 43 ++++
|
||||
.../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/NettyNetworkManager.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
|
||||
new file mode 100644
|
||||
index 0000000..2da2422
|
||||
index 0000000..c10d391
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/spigotmc/netty/NettyNetworkManager.java
|
||||
@@ -0,0 +1,178 @@
|
||||
@@ -0,0 +1,192 @@
|
||||
+package org.spigotmc.netty;
|
||||
+
|
||||
+import io.netty.channel.Channel;
|
||||
@ -192,6 +192,7 @@ index 0000000..2da2422
|
||||
+import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
+import java.util.concurrent.ExecutorService;
|
||||
+import java.util.concurrent.Executors;
|
||||
+import java.util.logging.Level;
|
||||
+import javax.crypto.SecretKey;
|
||||
+import net.minecraft.server.Connection;
|
||||
+import net.minecraft.server.INetworkManager;
|
||||
@ -200,6 +201,7 @@ index 0000000..2da2422
|
||||
+import net.minecraft.server.Packet252KeyResponse;
|
||||
+import net.minecraft.server.PendingConnection;
|
||||
+import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||
+import org.bukkit.Bukkit;
|
||||
+
|
||||
+/**
|
||||
+ * 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 {
|
||||
+
|
||||
+ 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 Channel channel;
|
||||
+ private SocketAddress address;
|
||||
@ -220,27 +225,36 @@ index 0000000..2da2422
|
||||
+
|
||||
+ @Override
|
||||
+ public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
+ // Channel and address groundwork first
|
||||
+ channel = ctx.channel();
|
||||
+ address = channel.remoteAddress();
|
||||
+ // Then the socket adaptor
|
||||
+ socketAdaptor = NettySocketAdaptor.adapt((SocketChannel) channel);
|
||||
+ handler = new PendingConnection(MinecraftServer.getServer(), this);
|
||||
+ ((NettyServerConnection) MinecraftServer.getServer().ae()).pendingConnections.add((PendingConnection) handler);
|
||||
+ // Followed by their first handler
|
||||
+ handler = new PendingConnection(server, this);
|
||||
+ // Finally register the connection
|
||||
+ serverConnection.pendingConnections.add((PendingConnection) handler);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
+ // Disconnect via the handler - this performs all plugin related cleanup + logging
|
||||
+ if (dcReason != null || dcArgs != null) {
|
||||
+ handler.a(dcReason, dcArgs);
|
||||
+ }
|
||||
+ // Remove channel reference to indicate we are done
|
||||
+ channel = null;
|
||||
+ syncPackets.clear();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
+ if (channel != null) {
|
||||
+ a("disconnect.genericReason", new Object[]{"Internal exception: " + cause});
|
||||
+ }
|
||||
+ // TODO: Remove this once we are more stable
|
||||
+ 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
|
||||
|
Loading…
Reference in New Issue
Block a user