downgrade netty to old version to fix annoying network bugs WHYYYYYYYYYYYYYYYYYYYYY?!?!?!?!
This commit is contained in:
parent
10fdaf0b1a
commit
77b5a34a33
15 changed files with 51 additions and 220 deletions
|
@ -14,8 +14,6 @@ import java.util.Locale;
|
|||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import common.log.NettyLogger;
|
||||
|
||||
public abstract class Registry {
|
||||
private static boolean crashed;
|
||||
|
||||
|
@ -116,7 +114,6 @@ public abstract class Registry {
|
|||
timer.setDaemon(true);
|
||||
timer.start();
|
||||
System.setProperty("java.net.preferIPv4Stack", "true");
|
||||
NettyLogger.init();
|
||||
register();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
package common.log;
|
||||
|
||||
public class Message {
|
||||
public final String message;
|
||||
public final long time;
|
||||
|
||||
public Message(String message, long time) {
|
||||
this.message = message;
|
||||
this.time = time;
|
||||
}
|
||||
}
|
|
@ -1,170 +0,0 @@
|
|||
package common.log;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import io.netty.util.internal.logging.AbstractInternalLogger;
|
||||
import io.netty.util.internal.logging.FormattingTuple;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
import io.netty.util.internal.logging.MessageFormatter;
|
||||
|
||||
public class NettyLogger extends AbstractInternalLogger {
|
||||
public static void init() {
|
||||
InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {
|
||||
protected InternalLogger newInstance(String name) {
|
||||
return new NettyLogger(name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private NettyLogger(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public boolean isTraceEnabled() {
|
||||
return Log.getLevel().ordinal() >= LogLevel.TRACE.ordinal();
|
||||
}
|
||||
|
||||
public void trace(String msg) {
|
||||
this.log(LogLevel.TRACE, msg, null);
|
||||
}
|
||||
|
||||
public void trace(String format, Object arg) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg);
|
||||
this.log(LogLevel.TRACE, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void trace(String format, Object argA, Object argB) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, argA, argB);
|
||||
this.log(LogLevel.TRACE, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void trace(String format, Object... argArray) {
|
||||
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
|
||||
this.log(LogLevel.TRACE, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void trace(String msg, Throwable t) {
|
||||
this.log(LogLevel.TRACE, msg, t);
|
||||
}
|
||||
|
||||
public boolean isDebugEnabled() {
|
||||
return Log.getLevel().ordinal() >= LogLevel.DEBUG.ordinal();
|
||||
}
|
||||
|
||||
public void debug(String msg) {
|
||||
this.log(LogLevel.DEBUG, msg, null);
|
||||
}
|
||||
|
||||
public void debug(String format, Object arg) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg);
|
||||
this.log(LogLevel.DEBUG, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void debug(String format, Object argA, Object argB) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, argA, argB);
|
||||
this.log(LogLevel.DEBUG, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void debug(String format, Object... argArray) {
|
||||
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
|
||||
this.log(LogLevel.DEBUG, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void debug(String msg, Throwable t) {
|
||||
this.log(LogLevel.DEBUG, msg, t);
|
||||
}
|
||||
|
||||
public boolean isInfoEnabled() {
|
||||
return Log.getLevel().ordinal() >= LogLevel.INFO.ordinal();
|
||||
}
|
||||
|
||||
public void info(String msg) {
|
||||
this.log(LogLevel.INFO, msg, null);
|
||||
}
|
||||
|
||||
public void info(String format, Object arg) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg);
|
||||
this.log(LogLevel.INFO, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void info(String format, Object argA, Object argB) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, argA, argB);
|
||||
this.log(LogLevel.INFO, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void info(String format, Object... argArray) {
|
||||
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
|
||||
this.log(LogLevel.INFO, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void info(String msg, Throwable t) {
|
||||
this.log(LogLevel.INFO, msg, t);
|
||||
}
|
||||
|
||||
public boolean isWarnEnabled() {
|
||||
return Log.getLevel().ordinal() >= LogLevel.WARN.ordinal();
|
||||
}
|
||||
|
||||
public void warn(String msg) {
|
||||
this.log(LogLevel.WARN, msg, null);
|
||||
}
|
||||
|
||||
public void warn(String format, Object arg) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg);
|
||||
this.log(LogLevel.WARN, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void warn(String format, Object argA, Object argB) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, argA, argB);
|
||||
this.log(LogLevel.WARN, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void warn(String format, Object... argArray) {
|
||||
FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
|
||||
this.log(LogLevel.WARN, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void warn(String msg, Throwable t) {
|
||||
this.log(LogLevel.WARN, msg, t);
|
||||
}
|
||||
|
||||
public boolean isErrorEnabled() {
|
||||
return Log.getLevel().ordinal() >= LogLevel.ERROR.ordinal();
|
||||
}
|
||||
|
||||
public void error(String msg) {
|
||||
this.log(LogLevel.ERROR, msg, null);
|
||||
}
|
||||
|
||||
public void error(String format, Object arg) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, arg);
|
||||
this.log(LogLevel.ERROR, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void error(String format, Object argA, Object argB) {
|
||||
FormattingTuple ft = MessageFormatter.format(format, argA, argB);
|
||||
this.log(LogLevel.ERROR, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void error(String format, Object... arguments) {
|
||||
FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
|
||||
this.log(LogLevel.ERROR, ft.getMessage(), ft.getThrowable());
|
||||
}
|
||||
|
||||
public void error(String msg, Throwable t) {
|
||||
this.log(LogLevel.ERROR, msg, t);
|
||||
}
|
||||
|
||||
private void log(LogLevel level, String msg, Throwable t) {
|
||||
Log.NETTY.log(level, msg);
|
||||
if(t != null) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter st = new PrintWriter(sw);
|
||||
t.printStackTrace(st);
|
||||
sw.flush();
|
||||
Log.NETTY.log(level, sw.toString().trim().replace('\t', ' '));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,9 @@
|
|||
package common.network;
|
||||
|
||||
import common.packet.LPacketLogin;
|
||||
import common.packet.LPacketPasswordResponse;
|
||||
import common.packet.LPacketStartEncrypt;
|
||||
|
||||
public interface ILoginHandler {
|
||||
void processPasswordResponse(LPacketPasswordResponse packet);
|
||||
void processEncryption(LPacketStartEncrypt packet);
|
||||
void processLogin(LPacketLogin packet);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import io.netty.util.concurrent.Future;
|
|||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
|
||||
public class NetConnection extends SimpleChannelInboundHandler<Packet> {
|
||||
private static final boolean DEBUG = System.getProperty("network.debug") != null;
|
||||
private static final Pattern IP_REPLACER = Pattern.compile("([0-9]*)\\.([0-9]*)\\.[0-9]*\\.[0-9]*");
|
||||
public static final AttributeKey<PacketRegistry> ATTR_STATE = AttributeKey.<PacketRegistry>valueOf("protocol");
|
||||
|
||||
|
@ -52,7 +53,8 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet> {
|
|||
public void setConnectionState(PacketRegistry newState) {
|
||||
this.channel.attr(ATTR_STATE).set(newState);
|
||||
this.channel.config().setAutoRead(true);
|
||||
// Log.debug("Automatisches Lesen eingeschaltet");
|
||||
if(DEBUG)
|
||||
Log.SYSTEM.info("Automatisches Lesen eingeschaltet");
|
||||
}
|
||||
|
||||
public void channelInactive(ChannelHandlerContext context) throws Exception {
|
||||
|
@ -75,6 +77,8 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet> {
|
|||
}
|
||||
|
||||
protected void channelRead0(ChannelHandlerContext context, Packet packet) throws Exception {
|
||||
if(DEBUG)
|
||||
Log.SYSTEM.info("EIN: [" + context.channel().attr(NetConnection.ATTR_STATE).get() + "] " + packet.getClass().getName());
|
||||
if(this.channel.isOpen()) {
|
||||
try {
|
||||
packet.processPacket(this.handler);
|
||||
|
@ -132,7 +136,8 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet> {
|
|||
final PacketRegistry current = this.channel.attr(ATTR_STATE).get();
|
||||
|
||||
if(current != state) {
|
||||
// Log.debug("Automatisches Lesen ausgeschaltet");
|
||||
if(DEBUG)
|
||||
Log.SYSTEM.info("Automatisches Lesen ausgeschaltet");
|
||||
this.channel.config().setAutoRead(false);
|
||||
}
|
||||
|
||||
|
@ -141,6 +146,8 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet> {
|
|||
this.setConnectionState(state);
|
||||
}
|
||||
|
||||
if(DEBUG)
|
||||
Log.SYSTEM.info("AUS: [" + this.channel.attr(NetConnection.ATTR_STATE).get() + "] " + packet.getClass().getName());
|
||||
ChannelFuture future = this.channel.writeAndFlush(packet);
|
||||
|
||||
if(listeners != null) {
|
||||
|
@ -156,6 +163,8 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet> {
|
|||
NetConnection.this.setConnectionState(state);
|
||||
}
|
||||
|
||||
if(DEBUG)
|
||||
Log.SYSTEM.info("AUS: [" + NetConnection.this.channel.attr(NetConnection.ATTR_STATE).get() + "] " + packet.getClass().getName());
|
||||
ChannelFuture future = NetConnection.this.channel.writeAndFlush(packet);
|
||||
|
||||
if(listeners != null) {
|
||||
|
@ -190,6 +199,8 @@ public class NetConnection extends SimpleChannelInboundHandler<Packet> {
|
|||
this.handler.update();
|
||||
if(this.channel != null)
|
||||
this.channel.flush();
|
||||
if(DEBUG)
|
||||
Log.SYSTEM.info("Pakete synchronisiert");
|
||||
}
|
||||
|
||||
public String getCutAddress() {
|
||||
|
|
|
@ -27,6 +27,5 @@ public class PacketDecoder extends ByteToMessageDecoder {
|
|||
throw new IOException("Paket " + ((PacketRegistry)context.channel().attr(NetConnection.ATTR_STATE).get()).ordinal() + "/" + id + " ("
|
||||
+ packet.getClass() + ") war größer als erwartet, " + pbuf.readableBytes() + " weitere Bytes wurden beim Lesen von Paket " + id + " gefunden");
|
||||
output.add(packet);
|
||||
// common.log.Log.SYSTEM.info("EIN: [" + context.channel().attr(NetConnection.ATTR_STATE).get() + ":" + id + "] " + packet.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ public class PacketEncoder extends MessageToByteEncoder<Packet> {
|
|||
Integer id = context.channel().attr(NetConnection.ATTR_STATE).get().getId(this.client, packet);
|
||||
if(id == null)
|
||||
throw new IOException("Kann nicht registriertes Paket nicht serialisieren");
|
||||
// common.log.Log.SYSTEM.debug("AUS: [" + context.channel().attr(NetConnection.ATTR_STATE).get() + ":" + id + "] " + packet.getClass().getName());
|
||||
PacketBuffer pbuf = new PacketBuffer(output);
|
||||
pbuf.writeVarInt(id);
|
||||
try {
|
||||
|
|
|
@ -22,7 +22,6 @@ import common.packet.CPacketPlayer;
|
|||
import common.packet.CPacketSign;
|
||||
import common.packet.CPacketSkin;
|
||||
import common.packet.HPacketHandshake;
|
||||
import common.packet.LPacketLogin;
|
||||
import common.packet.LPacketPasswordResponse;
|
||||
import common.packet.LPacketStartEncrypt;
|
||||
import common.packet.RPacketDisconnect;
|
||||
|
@ -105,7 +104,6 @@ public enum PacketRegistry {
|
|||
this.server(RPacketLoginSuccess.class);
|
||||
this.server(RPacketEnableCompression.class);
|
||||
|
||||
this.client(LPacketLogin.class);
|
||||
this.client(LPacketStartEncrypt.class);
|
||||
this.client(LPacketPasswordResponse.class);
|
||||
}},
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package common.packet;
|
||||
|
||||
import java.io.IOException;
|
||||
import common.network.ILoginHandler;
|
||||
import common.network.Packet;
|
||||
import common.network.PacketBuffer;
|
||||
|
||||
public class LPacketLogin implements Packet<ILoginHandler> {
|
||||
public LPacketLogin() {
|
||||
}
|
||||
|
||||
public void readPacketData(PacketBuffer buf) throws IOException {
|
||||
buf.readString(16);
|
||||
}
|
||||
|
||||
public void writePacketData(PacketBuffer buf) throws IOException {
|
||||
buf.writeString("TESTtestPlceHldr");
|
||||
}
|
||||
|
||||
public void processPacket(ILoginHandler handler) {
|
||||
handler.processLogin(this);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue